So I am trying to make a Pong (because I don't know anything easier) and I am still wrapping my head around over the verbosity of the assembler.
From one side, I want to save RAM, from other side iterating through OAM with limitations of 6502 is quite painful and verbose.
My question is should it be? What is the common sense approach? Should I treat OAM as player/mob/item source and hardcode them or should I store x,y,type and oam index separately and assign the OAM sprite(s) "dynamically"? Obviously it does not matter for my Pong, but it does for almost any other dynamic game.
From one side, I want to save RAM, from other side iterating through OAM with limitations of 6502 is quite painful and verbose.
My question is should it be? What is the common sense approach? Should I treat OAM as player/mob/item source and hardcode them or should I store x,y,type and oam index separately and assign the OAM sprite(s) "dynamically"? Obviously it does not matter for my Pong, but it does for almost any other dynamic game.
Code:
; Init above ^
; I put some comments for the post to explain what I am trying to achieve
@forever:
lda ppu_nmi_done ; Execute main loop once per frame
; Flag is set in the end of NMI
beq @forever
lda #0
sta ppu_nmi_done ; And reset by the main loop
; The only thing NMI does is runs DMA on $200 ram address
; So here I check the pads and set the direction
lda #0
sta tmp1 ; reset the variable with direction verctor
lda #PAD_DOWN
bit controls_buttons
beq :+
lda #$01
sta tmp1
:
lda #PAD_UP
bit controls_buttons
beq :+
lda #$FF ; -1
sta tmp1
:
lda tmp1 ; because we don't know if it was set above
beq @endPlayerMove ; if vector is 0 loop around
; Collision check
; The following code is where I move player around and it
; is my main question
lda OamData
; OamData is just label to $2000
; So I "reserved" spries 1 to 4 for my "paddle"
; Just checking Y from OAM ram of first sprite against the boundaries
ldx tmp1 ; move direction
cmp #0 ; up boundary
bne :+
cpx #$FF ; up
beq @endPlayerMove ; boundary hit
:
cmp #208 ; down boundary
bne :+
cpx #$01 ; down
beq @endPlayerMove
:
; And now I just change the coordinates directly
ldx #0
:
lda OamData, x
clc
; Adding my vector here; 5 + 1 = 6 but 5 + $FF = 4
adc tmp1
sta OamData, x
inx
inx
inx
inx
cpx #20 ; 4 * sizeof(OamSprite) I have 4 sprites for the paddle
bne :-
@endPlayerMove:
jmp @forever
; I put some comments for the post to explain what I am trying to achieve
@forever:
lda ppu_nmi_done ; Execute main loop once per frame
; Flag is set in the end of NMI
beq @forever
lda #0
sta ppu_nmi_done ; And reset by the main loop
; The only thing NMI does is runs DMA on $200 ram address
; So here I check the pads and set the direction
lda #0
sta tmp1 ; reset the variable with direction verctor
lda #PAD_DOWN
bit controls_buttons
beq :+
lda #$01
sta tmp1
:
lda #PAD_UP
bit controls_buttons
beq :+
lda #$FF ; -1
sta tmp1
:
lda tmp1 ; because we don't know if it was set above
beq @endPlayerMove ; if vector is 0 loop around
; Collision check
; The following code is where I move player around and it
; is my main question
lda OamData
; OamData is just label to $2000
; So I "reserved" spries 1 to 4 for my "paddle"
; Just checking Y from OAM ram of first sprite against the boundaries
ldx tmp1 ; move direction
cmp #0 ; up boundary
bne :+
cpx #$FF ; up
beq @endPlayerMove ; boundary hit
:
cmp #208 ; down boundary
bne :+
cpx #$01 ; down
beq @endPlayerMove
:
; And now I just change the coordinates directly
ldx #0
:
lda OamData, x
clc
; Adding my vector here; 5 + 1 = 6 but 5 + $FF = 4
adc tmp1
sta OamData, x
inx
inx
inx
inx
cpx #20 ; 4 * sizeof(OamSprite) I have 4 sprites for the paddle
bne :-
@endPlayerMove:
jmp @forever