Okay, after cleaning up the code and running into some more issues, here's where I'm at now:
ROM:
http://tomato.fobby.net/junk/sprites/2/sprites.nesSource:
http://tomato.fobby.net/junk/sprites/2/sprites.asmHere's the main loop now:
Forever:
controller_check:
LDA #$01 ; get ready to read controllers
STA $4016
LDA #$00
STA $4016
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
check_up:
LDA $4016 ; read Up button on controller 1
AND #1
BEQ check_down ; if not pressed, move on
LDA $00 ; if y >= 7 y--
CMP #08
BCC check_down
SBC #1
STA $00
check_down:
LDA $4016 ; read Down button on controller 1
check_left:
LDA $4016 ; read Left button on controller 1
AND #1
BEQ check_right ; if not pressed, move on
LDA $01 ; if x >= 8 x--
CMP #09
BCC check_right
SBC #1
STA $01
check_right:
LDA $4016 ; read Right button on controller 1
check_end:
LDA $00
STA $0200 ; set sprite 0's x coordinate
LDA $01
STA $0203 ; set sprite 0's y coordinate
JMP Forever ; jump back to Forever, infinite loopI 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.nesWhat'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!