UrForth: some fixes ;-)
[urasm.git] / samples / timetest / timetest.txt
blobdac3f845b23da77ff60c033bc8bba6f396033355
1 33339 ei
2 33340 halt (interrupt jumps to 32512)
3 32512 ld (33154),hl (redirects interrupt to jump to 33348)
4 32515 ei
5 32516 inc bc
6 32517 jr 32516 (this is exited by interrupt)
7 33348 .....
9 (I=128, points to 33153, all in uncontended memory)
10 (SP=33280, in uncontended memory)
12 This is the code used in Overscan Demo, it is entered with bc=0 and the
13 interrupt routine just a jp 32512, ld (33154),hl sets the
14 jp to 33348 which is the comparing routine.
16 Consider that 33345 and 33346 take up 18 t-states, and that there are 70908
17 t-states in the 128Ks interrupt cycle.  70908/18=3939 so that bc should
18 equal approximately 3939.
20 x128 has bc=3937,
21 A real Spectrum 128 has the value bc=3185 !!!
22 Z80 V3.02 gives the value bc=2803 (I have no idea where it gets this from).
23 Z80 V3.03 has the value bc=3212 which is a bit unlucky because it just
24 falls outside the timing required:
26 This is the timing desired by the comparing routine:
28 3115-3131 Spectrum 48K
29 3177-3193 Spectrum 128K/+2
30 3608-3624 Spectrum +2A/+3
32 Note that Z80 V3.03 in 48K mode produces bc=3155, which is unlucky again!
34 The reason for this is the slowdown caused by the code executing below
35 32768 (contended memory), as a result - the loop is executed less times
36 than usual before the interrupt occurs.
38 When you think about it, if you want to get the emulator to return 3185
39 as the value then:
41 (19 = IM 2 setup time, 16 = ld(NN),hl, 4 = ei)
43 70908 - 19 - 16 - 4 = 70869 (slowdown ignored in this case)
45 70869/3185 = 22.251 t-states
47 If you want to assume full slowdown then,
49 (19 = IM 2 setup time, 28 = ld(NN),hl, 8 = ei)
51 70908 - 19 - 28 - 8 = 70853 (assume 4 extra t states per mem read)
53 70853/3185 = 22.245 t-states
55 In other words, 'inc bc' and 'jr -3' must be set up to take about 22.25
56 t-states for the Overscan Demo to detect properly.
58 But, 22 or 23 is not good enough,
60 (first 70869 t's then 70853 t's)
62 22.0 would give bc=3221 or bc=3220 (illegal)
63 23.0 would give bc=3081 or bc=3080 (illegal)
64 22.1 would give bc=3206 or bc=3206 (illegal)
65 22.2 would give bc=3192 or bc=3191 (legal)
66 22.3 would give bc=3177 or bc=3177 (on the limit, probably outside)