1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-27 01:51:35 +00:00
8bitworkshop/presets/nes/ex1.dasm

101 lines
2.2 KiB
Plaintext
Raw Normal View History

include "nesdefs.dasm"
;;;;; VARIABLES
2019-08-03 21:23:38 +00:00
seg.u ZEROPAGE
2018-07-27 17:39:09 +00:00
org $0
;;;;; NES CARTRIDGE HEADER
NES_HEADER 0,2,1,0 ; mapper 0, 2 PRGs, 1 CHR, horiz. mirror
;;;;; START OF CODE
Start:
; wait for PPU warmup; clear CPU RAM
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)
; set palette and nametable VRAM
jsr SetPalette ; set palette colors
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
sta PPU_ADDR ; PPU addr = $0000
2018-07-27 17:39:09 +00:00
sta PPU_SCROLL
sta PPU_SCROLL ; PPU scroll = $0000
; activate PPU graphics
lda #MASK_BG
sta PPU_MASK ; enable rendering
lda #CTRL_NMI
sta PPU_CTRL ; enable NMI
2018-07-27 17:39:09 +00:00
.endless
jmp .endless ; endless loop
2018-07-27 17:39:09 +00:00
2019-07-22 02:55:50 +00:00
; set palette colors
SetPalette: subroutine
; set PPU address to palette start
PPU_SETADDR $3f00
ldy #0
.loop:
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
; 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)
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:
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
; ASCII message to display on screen
HelloMsg:
.byte "Hello, World!"
.byte 0 ; zero terminator
2018-07-27 17:39:09 +00:00
;;;;; COMMON SUBROUTINES
include "nesppu.dasm"
2018-07-27 17:39:09 +00:00
;;;;; INTERRUPT HANDLERS
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
2019-04-09 14:24:23 +00:00
hex 01112100 ;background 0
hex 02122200 ;background 1
hex 02112100 ;background 2
hex 01122200 ;background 3
2019-07-23 02:29:05 +00:00
hex 19293900 ;sprite 0
hex 1a2a3a00 ;sprite 1
hex 1b2b3b00 ;sprite 2
hex 1c2c3c ;sprite 3
2018-07-27 17:39:09 +00:00
;;;;; CPU VECTORS
NES_VECTORS
2018-07-27 17:39:09 +00:00
;;;;; TILE SETS
org $10000
incbin "jroatch.chr"
2019-08-03 21:23:38 +00:00
incbin "jroatch.chr"