2018-08-03 18:06:08 +00:00
|
|
|
|
|
|
|
include "nesdefs.asm"
|
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
;;;;; VARIABLES
|
2018-08-03 18:06:08 +00:00
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
seg.u RAM
|
2018-08-03 18:06:08 +00:00
|
|
|
org $0
|
|
|
|
|
|
|
|
ScrollPos byte ; used during NMI
|
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
;;;;; NES CARTRIDGE HEADER
|
|
|
|
|
2019-02-09 18:42:35 +00:00
|
|
|
NES_HEADER 0,2,1,0 ; mapper 0, 2 PRGs, 1 CHR, horiz. mirror
|
2018-08-03 18:06:08 +00:00
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
;;;;; START OF CODE
|
|
|
|
|
2018-08-03 18:06:08 +00:00
|
|
|
Start:
|
2019-02-09 18:42:35 +00:00
|
|
|
NES_INIT ; set up stack pointer, turn off PPU
|
|
|
|
jsr WaitSync ; wait for VSYNC
|
|
|
|
jsr ClearRAM ; clear RAM
|
|
|
|
jsr WaitSync ; wait for VSYNC (and PPU warmup)
|
|
|
|
|
|
|
|
jsr SetPalette ; set palette colors
|
|
|
|
jsr FillVRAM ; set PPU video RAM
|
2018-08-03 18:06:08 +00:00
|
|
|
lda #0
|
|
|
|
sta PPU_ADDR
|
2019-02-09 18:42:35 +00:00
|
|
|
sta PPU_ADDR ; PPU addr = $0000
|
2018-08-03 18:06:08 +00:00
|
|
|
sta PPU_SCROLL
|
2019-02-09 18:42:35 +00:00
|
|
|
sta PPU_SCROLL ; scroll = $0000
|
|
|
|
lda #CTRL_NMI
|
|
|
|
sta PPU_CTRL ; enable NMI
|
|
|
|
lda #MASK_BG
|
|
|
|
sta PPU_MASK ; enable rendering
|
2018-08-03 18:06:08 +00:00
|
|
|
.endless
|
2019-02-09 18:42:35 +00:00
|
|
|
jmp .endless ; endless loop
|
2018-08-03 18:06:08 +00:00
|
|
|
|
2018-08-05 14:00:53 +00:00
|
|
|
; fill video RAM
|
|
|
|
FillVRAM: subroutine
|
|
|
|
txa
|
|
|
|
ldy #$20
|
|
|
|
sty PPU_ADDR
|
|
|
|
sta PPU_ADDR
|
|
|
|
ldy #$10
|
|
|
|
.loop:
|
2019-02-09 18:42:35 +00:00
|
|
|
stx PPU_DATA
|
2018-08-05 14:00:53 +00:00
|
|
|
inx
|
|
|
|
bne .loop
|
|
|
|
dey
|
|
|
|
bne .loop
|
|
|
|
rts
|
|
|
|
|
2018-08-03 18:06:08 +00:00
|
|
|
; set palette colors
|
|
|
|
SetPalette: subroutine
|
|
|
|
ldy #$00
|
|
|
|
lda #$3f
|
|
|
|
sta PPU_ADDR
|
|
|
|
sty PPU_ADDR
|
|
|
|
ldx #32
|
|
|
|
.loop:
|
|
|
|
lda Palette,y
|
|
|
|
sta PPU_DATA
|
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne .loop
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
;;;;; COMMON SUBROUTINES
|
|
|
|
|
|
|
|
include "nesppu.asm"
|
|
|
|
|
|
|
|
;;;;; INTERRUPT HANDLERS
|
|
|
|
|
|
|
|
NMIHandler:
|
|
|
|
; save registers
|
|
|
|
pha ; save A
|
|
|
|
; update scroll position (must be done after VRAM updates)
|
|
|
|
inc ScrollPos
|
|
|
|
lda ScrollPos
|
2019-02-09 18:42:35 +00:00
|
|
|
sta PPU_SCROLL ; horiz byte
|
2018-08-03 18:06:08 +00:00
|
|
|
lda #0
|
2019-02-09 18:42:35 +00:00
|
|
|
sta PPU_SCROLL ; vert byte
|
2018-08-03 18:06:08 +00:00
|
|
|
; reload registers
|
|
|
|
pla ; reload A
|
|
|
|
rti
|
|
|
|
|
|
|
|
;;;;; CONSTANT DATA
|
|
|
|
|
|
|
|
align $100
|
|
|
|
Palette:
|
|
|
|
hex 1f ;background
|
2019-02-09 18:42:35 +00:00
|
|
|
hex 09092c00 ;bg0
|
2018-08-03 18:06:08 +00:00
|
|
|
hex 09091900 ;bg1
|
2019-02-09 18:42:35 +00:00
|
|
|
hex 09091500 ;bg2
|
|
|
|
hex 09092500 ;bg3
|
2018-08-03 18:06:08 +00:00
|
|
|
|
|
|
|
;;;;; CPU VECTORS
|
|
|
|
|
|
|
|
NES_VECTORS
|
|
|
|
|
|
|
|
;;;;; TILE SETS
|
|
|
|
|
|
|
|
org $10000
|
2019-02-09 18:42:35 +00:00
|
|
|
incbin "jroatch.chr"
|
|
|
|
|