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
|
|
|
|
|
2019-02-28 21:08:41 +00:00
|
|
|
ScrollPos word ; used during NMI
|
2018-08-03 18:06:08 +00:00
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
;;;;; NES CARTRIDGE HEADER
|
|
|
|
|
2019-03-04 14:35:33 +00:00
|
|
|
NES_HEADER 0,2,1,1 ; mapper 0, 2 PRGs, 1 CHR, vert. 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-03-02 23:15:03 +00:00
|
|
|
; wait for PPU warmup; clear CPU RAM
|
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)
|
2019-03-02 23:15:03 +00:00
|
|
|
; set palette and nametable VRAM
|
2019-02-09 18:42:35 +00:00
|
|
|
jsr SetPalette ; set palette colors
|
|
|
|
jsr FillVRAM ; set PPU video RAM
|
2019-03-02 23:15:03 +00:00
|
|
|
; reset PPU address and scroll registers
|
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
|
2019-03-02 23:15:03 +00:00
|
|
|
; activate PPU graphics
|
2019-02-09 18:42:35 +00:00
|
|
|
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
|
2019-02-28 21:08:41 +00:00
|
|
|
PPU_SETADDR $2000
|
2019-02-26 15:56:51 +00:00
|
|
|
ldy #$10 ; set $10 pages ($1000 bytes)
|
2018-08-05 14:00:53 +00:00
|
|
|
.loop:
|
2019-02-28 21:08:41 +00:00
|
|
|
tya ; Y -> A
|
|
|
|
ora #$40 ; A = A OR $40
|
2019-03-02 23:15:03 +00:00
|
|
|
sta PPU_DATA ; A -> PPU data port
|
2019-02-26 15:56:51 +00:00
|
|
|
inx ; X = X + 1
|
|
|
|
bne .loop ; repeat until 256 bytes
|
|
|
|
dey ; Y = Y - 1
|
|
|
|
bne .loop ; repeat until Y is 0
|
|
|
|
rts ; return to caller
|
2018-08-05 14:00:53 +00:00
|
|
|
|
2018-08-03 18:06:08 +00:00
|
|
|
; set palette colors
|
|
|
|
SetPalette: subroutine
|
2019-02-28 21:08:41 +00:00
|
|
|
PPU_SETADDR $3f00
|
2019-03-04 14:35:33 +00:00
|
|
|
ldy #0
|
2018-08-03 18:06:08 +00:00
|
|
|
.loop:
|
2019-02-26 15:56:51 +00:00
|
|
|
lda Palette,y ; lookup byte in ROM
|
|
|
|
sta PPU_DATA ; store byte to PPU data
|
|
|
|
iny ; Y = Y + 1
|
|
|
|
cpy #32 ; is Y equal to 32?
|
|
|
|
bne .loop ; not yet, loop
|
|
|
|
rts ; return to caller
|
2018-08-03 18:06:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;;;; COMMON SUBROUTINES
|
|
|
|
|
|
|
|
include "nesppu.asm"
|
|
|
|
|
|
|
|
;;;;; INTERRUPT HANDLERS
|
|
|
|
|
|
|
|
NMIHandler:
|
|
|
|
; save registers
|
2019-02-28 21:08:41 +00:00
|
|
|
SAVE_REGS
|
2018-08-03 18:06:08 +00:00
|
|
|
; update scroll position (must be done after VRAM updates)
|
2019-02-28 21:08:41 +00:00
|
|
|
inc ScrollPos ; increment low byte
|
|
|
|
bne .noinc ; Z flag set if wrapped to 0
|
|
|
|
inc ScrollPos+1 ; increment high byte
|
|
|
|
.noinc
|
|
|
|
; store X and Y scroll position
|
|
|
|
lda ScrollPos ; A -> low byte
|
|
|
|
sta PPU_SCROLL ; set horiz scroll
|
|
|
|
lda #0 ; A -> zero
|
|
|
|
sta PPU_SCROLL ; set vert scroll
|
|
|
|
; store 8th bit into name table selector
|
|
|
|
; name table A or B ($2000 or $2400)
|
|
|
|
lda ScrollPos+1 ; load high byte
|
|
|
|
and #1 ; select its low bit
|
|
|
|
ora #CTRL_NMI ; set rest of bits
|
|
|
|
sta PPU_CTRL
|
|
|
|
; restore registers, return from interrupt
|
|
|
|
RESTORE_REGS
|
2018-08-03 18:06:08 +00:00
|
|
|
rti
|
|
|
|
|
|
|
|
;;;;; CONSTANT DATA
|
|
|
|
|
|
|
|
Palette:
|
2019-02-28 21:08:41 +00:00
|
|
|
hex 1f ;screen color
|
|
|
|
hex 09092c00 ;background 0
|
|
|
|
hex 09091900 ;background 1
|
|
|
|
hex 09091500 ;background 2
|
|
|
|
hex 09092500 ;background 3
|
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"
|
|
|
|
|