I've recently started looking into programming for the NES. So far I've been playing around with sprites and nametables, just trying to get a feel for how it all works.
In one such experiment, I have the following two subroutines:
Code: Select all
create_mario:
ldx #$00
@loop:
lda spriteData, x
sta $0200, x
inx
cpx #$10
bne @loop
rts
;;;;;;;;;;;;;;;;;;;;;;
create_luigi:
ldx #$00
@loop:
lda spriteData+16, x
sta $0200+16, x
inx
cpx #$10
bne @loop
rts
;;;;;;;;;;;;;;;;;;;;;;
spriteData:
.byte $80, $32, $00, $80 ; mario sprite 0
.byte $80, $33, $00, $88 ; mario sprite 1
.byte $88, $34, $00, $80 ; mario sprite 2
.byte $88, $35, $00, $88 ; mario sprite 3
.byte $90, $32, $01, $80 ; luigi sprite 0
.byte $90, $33, $01, $88 ; luigi sprite 1
.byte $98, $34, $01, $80 ; luigi sprite 2
.byte $98, $35, $01, $88 ; luigi sprite 3
My question is, how possible would it be to combine the create_mario and create_luigi subroutines into a single subroutine, using two variables (stored possibly in the stack/zero page/registers - wherever is best?) to define the sprite data and sprite RAM offsets?
Like in the following pseudocode:
Code: Select all
create_sprite:
ldx #$00
@loop:
lda spriteData+[SPRITE_DATA_OFFSET], x
sta $0200+[SPRITE_RAM_OFFSET], x
inx
cpx #$10
bne @loop
rts
(I'm using ca65, if this affects the answer)