@@ 1,13 1,16 @@
;; header
- .db "NES", $1a ; identification of the iNES header
- .db 1 ; number of 16KB PRG-ROM pages
- .db $01 ; number of 8KB CHR-ROM pages
- .db $00 ; NROM
- .dsb $09,$00 ; clear the remaining bytes
- .fillvalue $FF ; Sets all unused space in rom to value $FF
- .org $C000
+ .db "NES",$1A
+ .db $02 ;Size of PRG ROM in 16 KB units
+ .db $00 ;Size of CHR ROM in 8 KB units (Value 0 means the board uses CHR RAM)
+ .db $20 ;Flags 6 (BNROM)
+ .db $20 ;Flags 7 (BNROM)
+ .db $00 ;Size of PRG RAM in 8 KB units (Value 0 infers 8 KB for compatibility)
+ .db $00 ;Flags 9
+ .db $00 ;Flags 10 (unofficial)
+ .db 0,0,0,0,0
+ .org $8000
;; constants
@@ 60,6 63,7 @@
rate .dsb 1
timer .dsb 1
seed .dsb 1
+ ptr_src .dsb 1
.ende
;; reset
@@ 100,6 104,14 @@ Vblankwait2: ; Second wait for vblank
;; setup phase
+ JSR ClearVram
+ ;load sprite base
+ LDA #$00
+ STA PPUADDR
+ LDA #$00
+ STA PPUADDR
+ JSR LoadSprites
+
SetupPalettes:
LDA PPUSTATUS
LDA #$3F
@@ 550,9 562,52 @@ Cleanup:
STA PPUSCROLL
RTI ; return from interrupt
-;; tables
+ClearVram:
+ LDA #$00
+ STA PPUADDR
+ STA PPUADDR
+ TAY
+ LDX #6
+
+ClearVramLoop:
+ STA PPUDATA
+ STA PPUDATA
+ STA PPUDATA
+ STA PPUDATA
+ STA PPUDATA
+ STA PPUDATA
+ STA PPUDATA
+ STA PPUDATA
+ DEY
+ BNE ClearVramLoop
+ DEX
+ BNE ClearVramLoop
+ RTS
- .org $E000
+;; Move sprites
+
+LoadSprites:
+ LDA #Sprites&255
+ STA ptr_src
+ LDA #Sprites/256
+ STA ptr_src+1
+ LDY #0 ; starting index into the first page
+ STY PPUMASK ; turn off rendering just in case
+ STY PPUADDR ; load the destination address into the PPU
+ STY PPUADDR
+ LDX #32 ; number of 256-byte pages to copy
+
+Loop:
+ LDA (ptr_src),y ; copy one byte
+ STA PPUDATA
+ INY
+ BNE Loop ; repeat until we finish the page
+ INC ptr_src+1 ; go to the next page
+ DEX
+ BNE Loop ; repeat until we've copied enough pages
+ RTS
+
+;; tables
Palettes: ;
.db $0F,$3B,$16,$30, $3B,$3B,$0F,$0F, $0F,$3B,$0F,$0F, $0F,$3B,$0F,$0F
@@ 580,15 635,11 @@ NotesLo:
.db $7e,$77,$70,$6a,$64,$5e,$59,$54,$4f,$4b,$46,$42
.db $3f,$3b,$38,$34,$31,$2f,$2c,$29,$27,$25,$23,$21
-;; Vectors
-
- .pad $FFFA
- .dw NMI
- .dw RESET
- .dw 0
+;; sprites
-;; Sprites
+ .org $D000
+Sprites:
.db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.db $fe,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.db $00,$00,$00,$00,$00,$00,$00,$00,$fe,$00,$00,$00,$00,$00,$00,$00
@@ 649,4 700,10 @@ NotesLo:
.db $7c,$82,$82,$fe,$82,$82,$82,$00,$7c,$82,$82,$fe,$82,$82,$82,$00
.db $74,$8a,$84,$fa,$82,$82,$82,$00,$74,$8a,$84,$fa,$82,$82,$82,$00
.db $fc,$82,$82,$fc,$82,$82,$fc,$00,$fc,$82,$82,$fc,$82,$82,$fc,$00
- .dsw 3624,$0000
+
+;; Vectors
+
+ .pad $FFFA
+ .dw NMI
+ .dw RESET
+ .dw 0