This is a great improvement. If you compare the two methods, you're basically using half the amount of T-states (13 for djnz) for most iterations instead of 26 for every iteration. Do a bit of loop unrolling on top of that and you'll really cut down on time. Thanks for sharing.Einar Saukas wrote: ↑Sun Oct 04, 2020 11:05 pmOps! My math was wrong, it should be B=n%256 and C=(n+255)/256Einar Saukas wrote: ↑Sat Oct 03, 2020 11:05 pm DJNZ ...
DEC C
JR NZ, ...
Same size but much faster. However you need to initialize BC differently: B=n%256 and C=1+(n/256)
Traditional method:
DEC BC 6
LD A,B 4
OR C 4
JR NZ, ... 12
total 26 t-states
Faster method:
DJNZ ... 13
DEC C 4
JR NZ, ... 12
total 29 t-states, but only 13 on most iterations