I have a snippet that clears memory before initializing a game in NES 6502 assembly. When I leave the code inside the reset proc like so, it works:
.proc reset
SEI
CLD
LDX #0
ClearRAM:
STA $000,x
STA $100,x
STA $200,x
STA $300,x
STA $400,x
STA $500,x
STA $600,x
STA $700,x
INX
BNE ClearRAM
.endproc
However, if I try to move this ClearRAM snippet inside a scoped proc:
.scope Memory
.proc clear
LDX #0
ClearRAM:
STA $000,x
STA $100,x
STA $200,x
STA $300,x
STA $400,x
STA $500,x
STA $600,x
STA $700,x
INX
BNE ClearRAM
RTS
.endproc
.endscope
And then load it like so:
.proc reset
SEI
CLD
JSR Memory::clear
.endproc
It stops working. It's like it loops forever in the ClearRAM loop.
Any idea what I am doing wrong?
Thank you!