diff --git a/defines.S b/defines.S new file mode 100644 index 0000000..7dc9606 --- /dev/null +++ b/defines.S @@ -0,0 +1,6 @@ +playerx=$0010 +playery=$0011 +curSpriteAttrOffset=$0012 +curSpriteTileOffset=$0013 +curSpriteXOffset=$0014 +curSpriteYOffset=$0015 diff --git a/nesgame.S b/nesgame.S index 096547a..112b1e8 100644 --- a/nesgame.S +++ b/nesgame.S @@ -8,6 +8,8 @@ .inesmap 0 ;; use mapper 0; NROM, no bank swapping .inesmir 1 ;; background mirroring (we don't care for now) + .include "defines.S" + ;; For NESASM, we need to tell it where each bank begins. .bank 0 @@ -166,38 +168,58 @@ _MAIN_LoadPaletteLoop: LDA #%00010000 ;; turn on sprites, no more background color STA $2001 ;; Write to PPU Control Register 2 LDX #$0 -_MAIN_CopyMarioToOAM: - LDA sprMario, x - STA $0200, x - INX - CPX #$20 - BNE _MAIN_CopyMarioToOAM - LDX #$0 -_MAIN_MoveMarioToPlayer_x: - LDA playerx - ADC $0203, x - STA $0203, x - INX - INX - INX - INX - CPX #$20 - BNE _MAIN_MoveMarioToPlayer_x - LDX #$0 -_MAIN_MoveMarioToPlayer_y: - LDA playery - ADC $0200, x - STA $0200, x - INX - INX - INX - INX - CPX #$20 - BNE _MAIN_MoveMarioToPlayer_y + + LDA #$80 + STA playerx + STA playery + LDA #$0 + STA curSpriteAttrOffset + STA curSpriteTileOffset + STA curSpriteXOffset + STA curSpriteYOffset _MAIN_loop: JMP _MAIN_loop ;; Loop forever NMI: + LDX #$0 +_NMI_CopyMarioToOAM: + LDA playery + LDY curSpriteYOffset + CLC + ADC sprMario_off_y, x + STA $0200, y + LDA #$4 + ADC curSpriteYOffset + STA curSpriteYOffset + + LDY curSpriteTileOffset + LDA sprMario, x + STA $0201, y + LDA #$4 + CLC + ADC curSpriteTileOffset + STA curSpriteTileOffset + + LDA #$00 + LDY curSpriteAttrOffset + STA $0202, y + LDA #$4 + CLC + ADC curSpriteAttrOffset + STA curSpriteAttrOffset + + LDA playerx + LDY curSpriteXOffset + ADC sprMario_off_x, x + STA $0203, y + LDA #$4 + CLC + ADC curSpriteXOffset + STA curSpriteXOffset + + INX + CPX #08 + BNE _MAIN_CopyMarioToOAM ;; We need to copy all our OAM data to put sprites on screen during ;; vblank. $2003 is the PPU OAM address, so we're going to tell it ;; to pull OAM from $0200, and do a DMA transfer. @@ -221,31 +243,12 @@ NMI: palette: .db $0F,$31,$32,$33,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$0F .db $0F,$1C,$15,$14,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C -playerx: - .db $08 -playery: - .db $08 -curSprIndex: - .db $00 - ;; I put the OAM copy here instead of $0200 because I want to - ;; allow me to initialize some basic sprite organizations (such as - ;; mario standing) without having to do a bunch of pokes into my - ;; OAM copy, because the only thing that ever actually changes is - ;; the X and Y position. But I couldn't get the NMI copying to work - ;; correctly when trying to set a bank to .org at $0200; I'm probably - ;; just doing it wrong, but for now this works. sprMario: - ;; each 4-byte pair goes directly into the OAM - .db $00,$00,$00 ; mario top left Y,tile,attrs -sprMario_x: - .db $00 ; mario top left X - .db $00,$01,$00,$08 ; mario top right - .db $08,$02,$00,$00 ; mario middle left - .db $08,$03,$00,$08 ; mario middle right - .db $10,$04,$00,$00 ; mario middle bottom left - .db $10,$05,$00,$08 ; mario middle bottom right - .db $18,$06,$00,$00 ; mario bottom left - .db $18,$07,$00,$08 ; mario bottom right + .db $00,$01,$02,$03,$04,$05,$06,$07 +sprMario_off_x: + .db $00,$08,$00,$08,$00,$08,$00,$08 +sprMario_off_y: + .db $00,$00,$08,$08,$10,$10,$18,$18 .bank 1 .org $FFFA