An update on my side: together with obschan I am looking into the math delays.

The first step is to find out how long a delay actually takes:

From the Epyx documentation "

*Divides take 176 + 14*N ticks where N is the number of most significant zeros in the divisor.*"

I have written a little program based on code from obschan that will do a math divide with different divisors.

POKEW(MATHNP, div);
POKEW(MATHGH, b2);
POKEW(MATHEF, b1);
WAITSUZY;

The heart of the program is a piece of assembly that will loop until the math is done.

;
; WAITSUZY;
;
lda #$0
notready:
inc a
bit $fc92
bmi notready
sta $77

Inside the loop it will wait for the 7th bit (MATHINPROGRESS) of FC92 to become zero again, increasing A on every iteration. Once the math is done, it will store the number of iterations in $77 (randomly picked as a zeropage address to store A).

The rest of the code will read the contents of $77.

The results are as follows

Significant zeros Ticks Iterations 0 176 4 1 190 5 2 204 5 3 218 5 4 232 6 5 246 6 6 260 6 7 274 7 9 302 7 10 316 8 12 344 8 14 372 9 15 386 9

The columns show the number of significant zeros, the calculated number of ticks according to the formula and the number of iterations that occurred.

Now, I was amazed that the low number of iterations through the loop. I was expecting something higher, because a single loop takes about 9 cycles. Even for 0 significant zeros a division would take 176 ticks, but the iterations are just 4. So, what gives: either a mistake on my part or ticks and cycles are not the same. I have also looked up the timings of memory access:

"Cycle Min Max

---------------------------------------------------

Page Mode RAM(read) 4 4

Normal RAM(r/w) 5 5

Page Mode ROM 4 4

Normal ROM 5 5

Available Hardware(r/w) 5 5

Mikey audio DPRAM(r/w) 5 20

Mikey color palette DPRAM(r/w) 5 5

Suzy Hardware(write) 5 5

Suzy Hardware(read) 9 15"

With these values I decomposed the various cycles and looked at the type of access that it would take and the number of ticks required. That came to about 40-45 ticks for this loop. If you do the calculations on this, then for 4 iterations it comes to 4*40 or 4*45 = 160-180 ticks (176 if you use 44). For 15 significant zeros it is 176 + 14*15 = 386 where 9 iterations times 44 means 396. All pretty close if you ask me.

Instruction

Cycles

Ticks per cycle

LDA #$00

2

5 Fetch opcode

5 Fetch value

notready:

INC A

2

5 Fetch opcode

1? Write to A

BIT $FC92

4

5 Fetch opcode

5 Fetch low order effective address byte

5 Fetch low order effective address byte

9-15 Fetch Data (Suzy hardware)

BMI notready

3

5 Fetch opcode

5 Fetch branch offset

1? Offset added to PC

Questions for all:

- Does anyone know the exact difference between a tick and a cycle?
- Any comments on this math of mine?
- Source code anyone to further analyse?

Thanks in advance