I initialise the first sprite in OAM to an x_pos of 8. In main, I just check to see if right is pressed, and if so, increase x_pos by 4.
Why is it (visually, and in memory viewer) that the sprite can take seemingly any position, regardless of whether it is a multiple of 4? If the x_pos starts at 8, and I'm only ever increasing it in increments of 4 per frame, how is it possible that the sprite can move this way? FCEUX's hex editor shows $0203 as holding 0x52, 0x9D, and so on....
I've removed everything I thought could possibly affect it, like NMI flags and whatnot, encase it was due to some kind of misunderstanding regarding something else. Here's the code:
After clearing memory, and waiting twice for vblank to let PPU warm up:
Code: Select all
setup_first_screen:
init_sprite_0:
LDA #$08
STA $0200
STA $0203
LDA #$00
STA $0201
STA $0202
JSR fill_palettes
init_rendering:
LDA #%00010000 ; enable sprites
STA PPUMASK
LDA #%10000000 ; enable NMIs
STA PPUCTRL
main:
JSR wait_nmi
JSR read_joy
@if_right:
LDA buttons
AND #%00000001
BEQ +
LDA $0203
ADC #$04
STA $0203
+ JMP main
NMI:
pushregs
INC nmi_flag
dma_transfer:
LDA #$00
STA OAMADDR
LDA #$02
STA OAMDMA
pullregs
RTI
Code: Select all
wait_nmi:
LDA nmi_flag
- CMP nmi_flag
BEQ -
RTS
