Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Speed measuring of a Z80 CPU into a ZX Spectrum
- ;The core of the routine is a tight loop in which HL is incremented and an
- ;unconditional relative jump is made to the INC instruction again and
- ;again. This continues until an interrupt is triggered, which modifies the
- ;target address of the relative jump so the loop actually finishes.
- ;Label RealStart begins ressetting the counter (HL). Then waits for an INT
- ;and resets the target address for the relative jump. The count begins...
- ;... until a new interrupt is triggered. The task of the interrupt routine
- ;is just to change the target of the jump instruction so it does not jump
- ;to the INC HL instruction anymore. The current value of HL is transfered
- ;to BC and interrupts are restored to IM 1. From BASIC, it is possible to
- ;read the value of the counter (now in BC) and using it to derive the actual
- ;number of T-states consumed during an interrupt interval (which in a stock
- ;48K Spectrum is 69688 T-states, divided into 312 scans of 224T each. 224T
- ;equals to 64 microseconds)
- TRGJUMP equ 253
- org 65000
- InstallINT di
- ld a,253
- ld i,a
- im 2
- jp RealStart ;install IM2 handler and go to start
- org 65023
- dw NewINT
- NewINT xor a ; 4T
- ld (JumpOpc+1),a ;13T
- ei ; 4T
- ret ;10T
- ;---- = 31T + 24T(ack when interrupted within the loop) = 55T
- RealStart ld hl,0 ;reset counter
- ei
- halt
- ld a,TRGJUMP ; 7T (the interrupt has ended, time starts here! )
- ld (JumpOpc+1),a ; 13T
- ;---- Counting code ------------ ;----- = 20T (time pre-loop)
- KeepInc inc hl ; 6T
- JumpOpc jr KeepInc ; 12T
- ;----- End of counting --------- ;------ = 18T
- di ; (the interrupt has ended -again-, time stops here! )
- ld b,h
- ld c,l
- im 1
- ei
- ret
- end InstallINT
- ;SPEED (MHz) = (7+13+18*BC+55)/(312*64) = (75+BC*18)/(312*64)
Add Comment
Please, Sign In to add comment