Okay, after cleaning up the code and running into some more issues, here's where I'm at now:
Here's the main loop now:
LDA #$01 ; get ready to read controllers
LDA $4016 ; read A button on controller 1
LDA $4016 ; read B button on controller 1
LDA $4016 ; read Select button on controller 1
LDA $4016 ; read Start button on controller 1
LDA $4016 ; read Up button on controller 1
BEQ check_down ; if not pressed, move on
LDA $00 ; if y >= 7 y--
LDA $4016 ; read Down button on controller 1
LDA $4016 ; read Left button on controller 1
BEQ check_right ; if not pressed, move on
LDA $01 ; if x >= 8 x--
LDA $4016 ; read Right button on controller 1
STA $0200 ; set sprite 0's x coordinate
STA $0203 ; set sprite 0's y coordinate
JMP Forever ; jump back to Forever, infinite loop
I took out the code for the right button and the down button right now because (for whatever reason) they were the only ones that acted as expected.
So what happens right now is that as soon as the ROM loads, the tomato slowly moves up and left on its own. I spent a lot of time trying to figure out why - and clearing/setting various stuff (like CLC, SEC) - but all I've figured out is that somehow, every once in a while it breaks through the checks for the button presses.
Stranger still is that Nestopia and FCEUX exhibit this behavior, while Mednafen acts exactly as I would've hoped. It makes me wonder how it works on the real deal, but I get the feeling Nestopia and FCEUX are showing the correct behavior.
I can't work on this any more tonight, but do you guys have any more insight? It most likely IS just me screwing up some carry bit stuff or decimal mode/binary mode stuff, so I'll study that more too when I can.
March 26, 2012, 11:11:29 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
After some quick fiddling around I figured out that if I take the big loop out of the "Forever" loop and stick it in the NMI section (which I'm not really sure what it is) that it all works super nicely, exactly as planned
If anyone's interested in controlling a little tomato, here you go. It's the greatest game ever, we can end the industry now.http://tomato.fobby.net/junk/sprites/3/sprites.nes
What's most interesting though is how different emulators handled my weird program differently. I wonder which way is the correct way, and if it somehow produced some bizarre test case never seen in professional releases. Oh well, on to more learning!