@lidnariq:
Oh, that's right.
Let me reiterate:
Pointer + 0 is always 0, so that one doesn't matter since Y is the actual low byte value.
The value in Pointer + 1 will go from $00 to $07 during the algorithm.
But since the pointer is in zeropage, its own location in memory will always be guaranteed to be $00xx.
And this means Pointer + 1 is only overwritten with 0 when when Pointer + 1 has the value 0 anyway.
Or to say it like this:
The loop cannot suddenly jump from $1234 to $0034 due to Pointer + 1 being overwritten with a 0 because the pointer will never be in a memory location $12xx, only $00xx.
Is that correct?
mikejmoffitt wrote:
Why such a complicated RAM-clearing routine?
Two reasons:
1. I find a loop more elegant than manually writing 0, 100, 300, 400, 500, 600, 700.
2. There's an additional piece of code in my initialization routine that doesn't have anything to do with my original question, so I left it out, but it's required if you want to keep, for example, the highscore when pressing reset:
Code:
; There is a certain RAM area that
; shall not be initialized with zeroes
; because this area shall be persistent
; when the Reset button is pressed.
; We check if we reached that RAM area.
; The high byte of the address is checked.
LDA Pointer + 1
CMP #>__NO_RESET_LOAD__
BNE @noNoResetSkip
; The low byte is checked.
CPY #<__NO_RESET_LOAD__
BNE @noNoResetSkip
; If we reached the
; reset-persistent area,
; we change the address to
; the first value after the area.
; This way, the reset-persistent
; area doesn't get changed.
LDY #<(__NO_RESET_LOAD__ + __NO_RESET_SIZE__)
LDA #>(__NO_RESET_LOAD__ + __NO_RESET_SIZE__)
STA Pointer + 1
@noNoResetSkip:
; Set the value of 0
; to the current address.
LDA #0
STA (Pointer), Y