Milestone 3 - the _MAIN_*Mario* code works better than it did now, but it still freaks out and cascades the tiles across the screen if I put it into the main loop.
This commit is contained in:
51
nesgame.S
51
nesgame.S
@@ -30,6 +30,7 @@ START:
|
|||||||
TXS ;; Move the contents of X to the stack pointer
|
TXS ;; Move the contents of X to the stack pointer
|
||||||
INX ;; increment X by 1, which causes overflow, so
|
INX ;; increment X by 1, which causes overflow, so
|
||||||
;; now X is 0
|
;; now X is 0
|
||||||
|
|
||||||
STX $2000 ;; set PPU flag to disable NMI (0x2000 = 0)
|
STX $2000 ;; set PPU flag to disable NMI (0x2000 = 0)
|
||||||
STX $2001 ;; set PPU flag to disable rendering (0x2001 = 0)
|
STX $2001 ;; set PPU flag to disable rendering (0x2001 = 0)
|
||||||
STX $4010 ;; disable APU IRQs, no audio
|
STX $4010 ;; disable APU IRQs, no audio
|
||||||
@@ -61,7 +62,7 @@ _START_clearmem:
|
|||||||
;; (0200-07FF)
|
;; (0200-07FF)
|
||||||
|
|
||||||
LDA #$FE ;; These two are clearing all of the sprite
|
LDA #$FE ;; These two are clearing all of the sprite
|
||||||
STA sprStartClearing, x ;; OAM; previous tutorial had this at 0300,
|
STA $0200, x ;; OAM; previous tutorial had this at 0300,
|
||||||
;; which may have been wrong. We don't HAVE
|
;; which may have been wrong. We don't HAVE
|
||||||
;; to reserve this range for OAM; we could
|
;; to reserve this range for OAM; we could
|
||||||
;; just manually poke bits into the PPU, but
|
;; just manually poke bits into the PPU, but
|
||||||
@@ -164,12 +165,18 @@ _MAIN_LoadPaletteLoop:
|
|||||||
|
|
||||||
LDA #%00010000 ;; turn on sprites, no more background color
|
LDA #%00010000 ;; turn on sprites, no more background color
|
||||||
STA $2001 ;; Write to PPU Control Register 2
|
STA $2001 ;; Write to PPU Control Register 2
|
||||||
_MAIN_loop:
|
LDX #$0
|
||||||
|
_MAIN_CopyMarioToOAM:
|
||||||
|
LDA sprMario, x
|
||||||
|
STA $0200, x
|
||||||
|
INX
|
||||||
|
CPX #$20
|
||||||
|
BNE _MAIN_CopyMarioToOAM
|
||||||
LDX #$0
|
LDX #$0
|
||||||
_MAIN_MoveMarioToPlayer_x:
|
_MAIN_MoveMarioToPlayer_x:
|
||||||
LDA playerx
|
LDA playerx
|
||||||
ADC sprMario_x, x
|
ADC $0203, x
|
||||||
STA sprMario_x, x
|
STA $0203, x
|
||||||
INX
|
INX
|
||||||
INX
|
INX
|
||||||
INX
|
INX
|
||||||
@@ -179,14 +186,15 @@ _MAIN_MoveMarioToPlayer_x:
|
|||||||
LDX #$0
|
LDX #$0
|
||||||
_MAIN_MoveMarioToPlayer_y:
|
_MAIN_MoveMarioToPlayer_y:
|
||||||
LDA playery
|
LDA playery
|
||||||
ADC sprMario, x
|
ADC $0200, x
|
||||||
STA sprMario, x
|
STA $0200, x
|
||||||
INX
|
INX
|
||||||
INX
|
INX
|
||||||
INX
|
INX
|
||||||
INX
|
INX
|
||||||
CPX #$20
|
CPX #$20
|
||||||
BNE _MAIN_MoveMarioToPlayer_y
|
BNE _MAIN_MoveMarioToPlayer_y
|
||||||
|
_MAIN_loop:
|
||||||
JMP _MAIN_loop ;; Loop forever
|
JMP _MAIN_loop ;; Loop forever
|
||||||
|
|
||||||
NMI:
|
NMI:
|
||||||
@@ -195,7 +203,7 @@ NMI:
|
|||||||
;; to pull OAM from $0200, and do a DMA transfer.
|
;; to pull OAM from $0200, and do a DMA transfer.
|
||||||
LDA #$00
|
LDA #$00
|
||||||
STA $2003
|
STA $2003
|
||||||
LDA #$FF
|
LDA #$02
|
||||||
STA $4014 ; 4014 is the OAM_DMA operation, which will
|
STA $4014 ; 4014 is the OAM_DMA operation, which will
|
||||||
; do a DMA from the (LDA|$2003) address,
|
; do a DMA from the (LDA|$2003) address,
|
||||||
; for FF bytes (in our case $0200-$02FF),
|
; for FF bytes (in our case $0200-$02FF),
|
||||||
@@ -210,17 +218,15 @@ NMI:
|
|||||||
;; between them.
|
;; between them.
|
||||||
;; .. How to know when we have written enough
|
;; .. How to know when we have written enough
|
||||||
;; code? ..
|
;; code? ..
|
||||||
|
|
||||||
palette:
|
palette:
|
||||||
.db $0F,$31,$32,$33,$0F,$35,$36,$37,$0F,$39,$3A,$3B,$0F,$3D,$3E,$0F
|
.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
|
.db $0F,$1C,$15,$14,$0F,$02,$38,$3C,$0F,$1C,$15,$14,$0F,$02,$38,$3C
|
||||||
playerx:
|
playerx:
|
||||||
.db $01
|
.db $08
|
||||||
playery:
|
playery:
|
||||||
.db $01
|
.db $08
|
||||||
playerSprIndex:
|
curSprIndex:
|
||||||
.db $00
|
.db $00
|
||||||
|
|
||||||
;; I put the OAM copy here instead of $0200 because I want to
|
;; I put the OAM copy here instead of $0200 because I want to
|
||||||
;; allow me to initialize some basic sprite organizations (such as
|
;; allow me to initialize some basic sprite organizations (such as
|
||||||
;; mario standing) without having to do a bunch of pokes into my
|
;; mario standing) without having to do a bunch of pokes into my
|
||||||
@@ -228,21 +234,18 @@ playerSprIndex:
|
|||||||
;; the X and Y position. But I couldn't get the NMI copying to work
|
;; 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
|
;; correctly when trying to set a bank to .org at $0200; I'm probably
|
||||||
;; just doing it wrong, but for now this works.
|
;; just doing it wrong, but for now this works.
|
||||||
.org $FF00
|
|
||||||
sprMario:
|
sprMario:
|
||||||
;; each 4-byte pair goes directly into the OAM
|
;; each 4-byte pair goes directly into the OAM
|
||||||
.db $10,$00,$00 ; mario top left Y,tile,attrs
|
.db $00,$00,$00 ; mario top left Y,tile,attrs
|
||||||
sprMario_x:
|
sprMario_x:
|
||||||
.db $10 ; mario top left X
|
.db $00 ; mario top left X
|
||||||
.db $10,$01,$00,$18 ; mario top right
|
.db $00,$01,$00,$08 ; mario top right
|
||||||
.db $18,$02,$00,$10 ; mario middle left
|
.db $08,$02,$00,$00 ; mario middle left
|
||||||
.db $18,$03,$00,$18 ; mario middle right
|
.db $08,$03,$00,$08 ; mario middle right
|
||||||
.db $20,$04,$00,$10 ; mario middle bottom left
|
.db $10,$04,$00,$00 ; mario middle bottom left
|
||||||
.db $20,$05,$00,$18 ; mario middle bottom right
|
.db $10,$05,$00,$08 ; mario middle bottom right
|
||||||
.db $28,$06,$00,$10 ; mario bottom left
|
.db $18,$06,$00,$00 ; mario bottom left
|
||||||
.db $28,$07,$00,$18 ; mario bottom right
|
.db $18,$07,$00,$08 ; mario bottom right
|
||||||
sprStartClearing:
|
|
||||||
.db $00
|
|
||||||
|
|
||||||
.bank 1
|
.bank 1
|
||||||
.org $FFFA
|
.org $FFFA
|
||||||
|
|||||||
Reference in New Issue
Block a user