Alright, so I had a little gremlin...it bugged me enough to just play around in a dummy file. For the life of me, I can't figure out what is going on here.
Here's the simple program:
Calculation:
LDA gamepad
AND #PAD_R
BEQ notPressingRight
LDA number
CLC
ADC #$01
STA number
CMP #$80
BMI keepGoing
JMP RESET
keepGoing:
RTS
This is as simple as simple can get, as far as I can tell. There's nothing about this I don't understand. In this dummy program, I hold down the right button for a few seconds and it resets. No problem.
But if I change the number #$80 to any higher number (even just to #$81), this resets immediately. Always alright, any number up to #$80...I don't understand why.
Pulled it into the debugger - wrote the value of *number* to an arbitrary RAM address, and breaking when that address is written to. The first run always returns #$FE upon pressing the right arrow key. I can even literally code in:
LDA #$00
STA ;whatever ram address
And that first read still comes up as #$FE. There is nothing else writing to that address. So I suppose this is a two fold head scratcher for me. Why would the math up top be funky when i use a compare against numbers higher than #$80? And also, any words of wisdom as to why FCEUX's debugger would return #$FE on its first pull no matter what? Is that just a thing? If anything, I would think this would be zero...
Thanks!
Here's the simple program:
Code:
Calculation:
LDA gamepad
AND #PAD_R
BEQ notPressingRight
LDA number
CLC
ADC #$01
STA number
CMP #$80
BMI keepGoing
JMP RESET
keepGoing:
RTS
This is as simple as simple can get, as far as I can tell. There's nothing about this I don't understand. In this dummy program, I hold down the right button for a few seconds and it resets. No problem.
But if I change the number #$80 to any higher number (even just to #$81), this resets immediately. Always alright, any number up to #$80...I don't understand why.
Pulled it into the debugger - wrote the value of *number* to an arbitrary RAM address, and breaking when that address is written to. The first run always returns #$FE upon pressing the right arrow key. I can even literally code in:
Code:
LDA #$00
STA ;whatever ram address
And that first read still comes up as #$FE. There is nothing else writing to that address. So I suppose this is a two fold head scratcher for me. Why would the math up top be funky when i use a compare against numbers higher than #$80? And also, any words of wisdom as to why FCEUX's debugger would return #$FE on its first pull no matter what? Is that just a thing? If anything, I would think this would be zero...
Thanks!