It got me thinking - what else can we do faster utilising the stack pointer?
I discovered a "clear memory" routine in my code which I figured could go faster:
Code: Select all
; clear 256 byte heap
LD HL, heap_addr ; divisible by $100 [10]
XOR A ; [4]
REPT 256
LD (HL), A ; [7] x256
INC L ; [4] x256
ENDM
Using SP:
Code: Select all
; clear 256 byte heap
LD (sp_store), SP ; [20]
LD SP, heap_addr + $100 ; [10]
LD HL, 0 ; [10]
REPT 128
PUSH HL ; [11] x128
ENDM
LD SP, (sp_store) ; [20]
I've also manipulated SP in a look-up table when drawing sprites; after each row, I simply POP the screen address at which the next pixel row starts, and then just add the sprite's x position... much quicker than the arithmetic & logic required to determine and adjust for the cell / block boundaries (at least within my implementation!) but also much simpler-looking code, cleaner and easier to understand without all those extra logical caveats.
I'm sure none of this is anything new, so my question is: which other cool SP-based tricks can you think of?