Hey! I'm curious about different techniques to tackle instanced entities on the 6502.
Using asm6 where there are no structs, I've come up with my own solution where I define constants for the index of the properties of my data types:
I then have a constant defining what page my projectiles will be on and use that to loop through all of them.
this approach works for me but when I want to deal with data types that don't have a whole page reserved to them and also might cross pages, I end up writing a lot of code indexing with indirect addresses.
Depending on how complex logic I need to do, I can end up adding and subtracting from those curr_pointer values a lot and I can't help but wonder if I'm doing it right. This approach must be quite performance expensive?
So another approach I've tried is to have variables dedicated to be parameters or temp values:
This approach works but I end up basically having to reserve RAM for three players when there are actually only two playable ones in the game. One tradeoff though, is that I can reuse my "curr_player_" variables for other datatypes before or after I update my players.
My approaches to this works but having no previous experience in assembly and also failing to find anything covering this subject on google, I'm really curious about how other people here on the forum tackle this on the 6502.
Cheers!
Using asm6 where there are no structs, I've come up with my own solution where I define constants for the index of the properties of my data types:
Code:
PROJECTILE_STATE = 0
PROJECTILE_POS_X_LO = 1
PROJECTILE_POS_X_HI = 2
PROJECTILE_POS_Y_LO = 3
PROJECTILE_POS_Y_HI = 4
PROJECTILE_...
PROJECTILE_POS_X_LO = 1
PROJECTILE_POS_X_HI = 2
PROJECTILE_POS_Y_LO = 3
PROJECTILE_POS_Y_HI = 4
PROJECTILE_...
I then have a constant defining what page my projectiles will be on and use that to loop through all of them.
Code:
lda #PROJECTILES_RAM+#PROJECTILE_STATE, x
; do some game logic
lda #PROJECTILES_RAM+#PROJECTILE_POS_X_LO, x
; do some other game logic
; do some game logic
lda #PROJECTILES_RAM+#PROJECTILE_POS_X_LO, x
; do some other game logic
this approach works for me but when I want to deal with data types that don't have a whole page reserved to them and also might cross pages, I end up writing a lot of code indexing with indirect addresses.
Code:
lda #<(player1)
ldx #>(player1)
jsr CheckSomeCollision
...
CheckSomeCollision:
sta curr_pointer_lo
stx curr_pointer_hi
ldy #0
...
lda curr_pointer_lo
clc
adc #PLAYER_POS_X_LO
sta curr_pointer_lo
lda curr_pointer_hi
adc #0
sta curr_pointer_hi
lda (curr_pointer), y
; do some stuff
...
rts
ldx #>(player1)
jsr CheckSomeCollision
...
CheckSomeCollision:
sta curr_pointer_lo
stx curr_pointer_hi
ldy #0
...
lda curr_pointer_lo
clc
adc #PLAYER_POS_X_LO
sta curr_pointer_lo
lda curr_pointer_hi
adc #0
sta curr_pointer_hi
lda (curr_pointer), y
; do some stuff
...
rts
Depending on how complex logic I need to do, I can end up adding and subtracting from those curr_pointer values a lot and I can't help but wonder if I'm doing it right. This approach must be quite performance expensive?
So another approach I've tried is to have variables dedicated to be parameters or temp values:
Code:
lda player1_state
sta curr_player_state
lda player1_posx_lo
sta curr_player_posx_lo
lda player1_posx_hi
sta curr_player_posx_hi
; I have quite a few variables to do this with
jsr UpdatePlayer
; Now I have to pass the values back to the correct player variables
lda curr_player_state
sta player1_state
lda curr_player_posx_lo
sta player1_posx_lo
lda curr_player_posx_hi
sta player1_posx_hi
; and so on...
sta curr_player_state
lda player1_posx_lo
sta curr_player_posx_lo
lda player1_posx_hi
sta curr_player_posx_hi
; I have quite a few variables to do this with
jsr UpdatePlayer
; Now I have to pass the values back to the correct player variables
lda curr_player_state
sta player1_state
lda curr_player_posx_lo
sta player1_posx_lo
lda curr_player_posx_hi
sta player1_posx_hi
; and so on...
This approach works but I end up basically having to reserve RAM for three players when there are actually only two playable ones in the game. One tradeoff though, is that I can reuse my "curr_player_" variables for other datatypes before or after I update my players.
My approaches to this works but having no previous experience in assembly and also failing to find anything covering this subject on google, I'm really curious about how other people here on the forum tackle this on the 6502.
Cheers!