2019-02-09 18:42:35 +00:00
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
include "nesdefs.asm"
|
|
|
|
|
|
|
|
;;;;; VARIABLES
|
|
|
|
|
|
|
|
seg.u RAM
|
2018-07-27 17:39:09 +00:00
|
|
|
org $0
|
|
|
|
|
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-13 22:17:36 +00:00
|
|
|
|
|
|
|
;;;;; START OF CODE
|
|
|
|
|
|
|
|
Start:
|
2019-03-02 23:15:03 +00:00
|
|
|
; wait for PPU warmup; clear CPU RAM
|
2018-08-13 22:17:36 +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
|
2019-03-02 23:15:03 +00:00
|
|
|
jsr HelloVRAM ; print message in name table
|
|
|
|
; reset PPU address and scroll registers
|
2018-07-27 17:39:09 +00:00
|
|
|
lda #0
|
|
|
|
sta PPU_ADDR
|
2018-08-13 22:17:36 +00:00
|
|
|
sta PPU_ADDR ; PPU addr = $0000
|
2018-07-27 17:39:09 +00:00
|
|
|
sta PPU_SCROLL
|
2019-03-02 23:15:03 +00:00
|
|
|
sta PPU_SCROLL ; PPU scroll = $0000
|
|
|
|
; activate PPU graphics
|
2018-11-19 14:10:13 +00:00
|
|
|
lda #CTRL_NMI
|
2018-08-13 22:17:36 +00:00
|
|
|
sta PPU_CTRL ; enable NMI
|
2019-02-09 18:42:35 +00:00
|
|
|
lda #MASK_BG
|
2018-08-13 22:17:36 +00:00
|
|
|
sta PPU_MASK ; enable rendering
|
2018-07-27 17:39:09 +00:00
|
|
|
.endless
|
2018-08-13 22:17:36 +00:00
|
|
|
jmp .endless ; endless loop
|
2018-07-27 17:39:09 +00:00
|
|
|
|
2019-02-09 18:42:35 +00:00
|
|
|
; fill video RAM with "Hello World" msg
|
|
|
|
HelloVRAM: subroutine
|
2019-02-28 21:08:41 +00:00
|
|
|
; set PPU address to name table A (row 1, col 1)
|
2019-03-04 14:35:33 +00:00
|
|
|
PPU_SETADDR $2021
|
2019-02-28 21:08:41 +00:00
|
|
|
ldy #0 ; set Y counter to 0
|
2018-07-27 17:39:09 +00:00
|
|
|
.loop:
|
2019-02-09 18:42:35 +00:00
|
|
|
lda HelloMsg,y ; get next character
|
|
|
|
beq .end ; is 0? exit loop
|
|
|
|
sta PPU_DATA ; store+advance PPU
|
|
|
|
iny ; next character
|
|
|
|
bne .loop ; loop
|
|
|
|
.end
|
|
|
|
rts ; return to caller
|
2019-02-28 21:08:41 +00:00
|
|
|
|
2019-02-09 18:42:35 +00:00
|
|
|
; ASCII message to display on screen
|
|
|
|
HelloMsg:
|
|
|
|
.byte "Hello, World!"
|
|
|
|
.byte 0 ; zero terminator
|
2018-07-27 17:39:09 +00:00
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
; set palette colors
|
|
|
|
SetPalette: subroutine
|
2019-02-28 21:08:41 +00:00
|
|
|
; set PPU address to palette start
|
2019-03-04 14:35:33 +00:00
|
|
|
PPU_SETADDR $3f00
|
|
|
|
ldy #0
|
2018-08-13 22:17:36 +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-07-27 17:39:09 +00:00
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
;;;;; COMMON SUBROUTINES
|
|
|
|
|
|
|
|
include "nesppu.asm"
|
|
|
|
|
2018-07-27 17:39:09 +00:00
|
|
|
;;;;; INTERRUPT HANDLERS
|
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
NMIHandler:
|
2019-02-28 21:08:41 +00:00
|
|
|
rti ; return from interrupt
|
2018-07-27 17:39:09 +00:00
|
|
|
|
|
|
|
;;;;; 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-07-27 17:39:09 +00:00
|
|
|
|
|
|
|
;;;;; CPU VECTORS
|
|
|
|
|
2018-08-13 22:17:36 +00:00
|
|
|
NES_VECTORS
|
2018-07-27 17:39:09 +00:00
|
|
|
|
|
|
|
;;;;; TILE SETS
|
|
|
|
|
|
|
|
org $10000
|
2019-02-09 18:42:35 +00:00
|
|
|
incbin "jroatch.chr"
|