2019-02-21 00:38:30 +00:00
|
|
|
|
2019-05-11 01:25:21 +00:00
|
|
|
include "nesdefs.dasm"
|
2018-08-17 02:45:59 +00:00
|
|
|
|
2018-08-17 19:13:58 +00:00
|
|
|
;;;;; ZERO-PAGE VARIABLES
|
2018-08-17 02:45:59 +00:00
|
|
|
|
|
|
|
seg.u ZEROPAGE
|
|
|
|
org $0
|
2019-04-26 19:38:34 +00:00
|
|
|
|
2018-08-17 19:13:58 +00:00
|
|
|
;;;;; OTHER VARIABLES
|
2018-08-17 02:45:59 +00:00
|
|
|
|
|
|
|
seg.u RAM
|
2019-04-07 01:47:42 +00:00
|
|
|
; page-align to prevent messing up the timing
|
2018-08-17 02:45:59 +00:00
|
|
|
org $300
|
|
|
|
LineXLo ds 224
|
2019-04-07 01:47:42 +00:00
|
|
|
align $100
|
2018-08-17 02:45:59 +00:00
|
|
|
LineXHi ds 224
|
|
|
|
|
|
|
|
;;;;; NES CARTRIDGE HEADER
|
|
|
|
|
|
|
|
NES_HEADER 0,2,1,0 ; mapper 0, 2 PRGs, 1 CHR, horiz. mirror
|
|
|
|
|
|
|
|
;;;;; START OF CODE
|
|
|
|
|
|
|
|
Start:
|
|
|
|
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
|
|
|
|
lda #0
|
|
|
|
sta PPU_ADDR
|
|
|
|
sta PPU_ADDR ; PPU addr = $0000
|
|
|
|
sta PPU_SCROLL
|
|
|
|
sta PPU_SCROLL ; scroll = $0000
|
2018-08-17 19:13:58 +00:00
|
|
|
lda #MASK_BG|MASK_SPR
|
2018-08-17 02:45:59 +00:00
|
|
|
sta PPU_MASK ; enable rendering
|
2019-04-26 19:38:34 +00:00
|
|
|
lda #CTRL_NMI
|
|
|
|
sta PPU_CTRL ; enable NMI
|
2018-08-17 02:45:59 +00:00
|
|
|
.endless
|
|
|
|
jmp .endless ; endless loop
|
|
|
|
|
|
|
|
; fill video RAM
|
|
|
|
FillVRAM: subroutine
|
2019-04-18 18:52:59 +00:00
|
|
|
PPU_SETADDR $2000
|
2018-08-17 02:45:59 +00:00
|
|
|
ldy #$10
|
|
|
|
.loop:
|
|
|
|
sta PPU_DATA
|
|
|
|
adc #7
|
|
|
|
inx
|
|
|
|
bne .loop
|
|
|
|
dey
|
|
|
|
bne .loop
|
|
|
|
rts
|
|
|
|
|
|
|
|
; set palette colors
|
|
|
|
SetPalette: subroutine
|
2019-04-18 18:52:59 +00:00
|
|
|
PPU_SETADDR $3f00
|
2018-08-17 02:45:59 +00:00
|
|
|
ldx #32
|
|
|
|
.loop:
|
|
|
|
lda Palette,y
|
|
|
|
sta PPU_DATA
|
|
|
|
iny
|
|
|
|
dex
|
|
|
|
bne .loop
|
|
|
|
rts
|
|
|
|
|
2018-08-17 19:13:58 +00:00
|
|
|
; set sprite 0
|
|
|
|
SetSprite0: subroutine
|
|
|
|
sta $200 ;y
|
2019-04-26 19:38:34 +00:00
|
|
|
lda #$a0 ;code
|
2018-08-17 19:13:58 +00:00
|
|
|
sta $201
|
2019-04-07 01:47:42 +00:00
|
|
|
lda #$20 ;flags
|
2018-08-17 19:13:58 +00:00
|
|
|
sta $202
|
2019-04-07 01:47:42 +00:00
|
|
|
lda #$fe ;xpos
|
2018-08-17 19:13:58 +00:00
|
|
|
sta $203
|
|
|
|
rts
|
2018-08-17 02:45:59 +00:00
|
|
|
|
|
|
|
;;;;; COMMON SUBROUTINES
|
|
|
|
|
2019-05-11 01:25:21 +00:00
|
|
|
include "nesppu.dasm"
|
2018-08-17 02:45:59 +00:00
|
|
|
|
|
|
|
;;;;; INTERRUPT HANDLERS
|
|
|
|
|
|
|
|
NMIHandler: subroutine
|
|
|
|
SAVE_REGS
|
2019-04-07 01:47:42 +00:00
|
|
|
lda #0
|
|
|
|
sta PPU_SCROLL
|
|
|
|
sta PPU_SCROLL
|
|
|
|
lda #111
|
2018-08-17 19:13:58 +00:00
|
|
|
jsr SetSprite0
|
|
|
|
; load sprites
|
|
|
|
lda #$02
|
|
|
|
sta PPU_OAM_DMA
|
|
|
|
; wait for sprite 0
|
|
|
|
.wait0 bit PPU_STATUS
|
2019-05-13 22:36:25 +00:00
|
|
|
bvs .wait0 ; until bit 6 set
|
2018-08-17 19:13:58 +00:00
|
|
|
.wait1 bit PPU_STATUS
|
2019-05-13 22:36:25 +00:00
|
|
|
bvc .wait1 ; until bit 6 clear
|
|
|
|
SLEEP 14
|
2018-08-17 02:45:59 +00:00
|
|
|
ldy #0
|
|
|
|
.loop
|
2019-05-13 22:36:25 +00:00
|
|
|
; add two cycles every 6th line
|
|
|
|
lda Div3Table,y ; is non-zero?
|
|
|
|
bne .skipcyc ; branch adds +1 cycle
|
2019-04-26 19:38:34 +00:00
|
|
|
.skipcyc
|
|
|
|
; pad out rest of scanline
|
2019-05-13 22:36:25 +00:00
|
|
|
SLEEP 66
|
2019-02-21 00:38:30 +00:00
|
|
|
; alter horiz. scroll position for each scanline
|
2018-08-17 02:45:59 +00:00
|
|
|
tya
|
2019-05-13 22:36:25 +00:00
|
|
|
clc
|
2018-08-17 02:45:59 +00:00
|
|
|
adc LineXLo,y
|
|
|
|
sta LineXLo,y
|
|
|
|
lda LineXHi,y
|
|
|
|
adc #0
|
|
|
|
sta LineXHi,y
|
|
|
|
sta PPU_SCROLL ; horiz byte
|
|
|
|
lda #0
|
|
|
|
sta PPU_SCROLL ; vert byte
|
2019-04-26 19:38:34 +00:00
|
|
|
; next iteration of loop
|
2018-08-17 02:45:59 +00:00
|
|
|
iny
|
2019-05-13 22:36:25 +00:00
|
|
|
cpy #112 ; out of lines?
|
|
|
|
bne .loop ; no, repeat
|
2018-08-17 02:45:59 +00:00
|
|
|
RESTORE_REGS
|
|
|
|
rti
|
|
|
|
|
|
|
|
;;;;; CONSTANT DATA
|
|
|
|
|
2019-05-13 22:36:25 +00:00
|
|
|
align $100 ; align to page boundary
|
|
|
|
Div3Table:
|
|
|
|
REPEAT 38 ; repeat 3*38 times
|
|
|
|
.byte 0,1,1 ; repeating 0-1-1 bytes
|
|
|
|
REPEND ; end of repeat block
|
|
|
|
|
2018-08-17 02:45:59 +00:00
|
|
|
Palette:
|
|
|
|
hex 1f ;background
|
|
|
|
hex 09092c00 ;bg0
|
|
|
|
hex 09091900 ;bg1
|
|
|
|
hex 09091500 ;bg2
|
|
|
|
hex 09092500 ;bg3
|
|
|
|
|
|
|
|
;;;;; CPU VECTORS
|
|
|
|
|
|
|
|
NES_VECTORS
|
|
|
|
|
|
|
|
;;;;; TILE SETS
|
|
|
|
|
|
|
|
org $10000
|
2019-02-10 16:04:31 +00:00
|
|
|
incbin "jroatch.chr"
|