NES Hello World code

Includes iNES and UNIF linkage.
This commit is contained in:
Michael Martin 2012-06-03 15:09:18 -07:00
parent a9f406489d
commit 809bf51239
4 changed files with 211 additions and 0 deletions

View File

@ -0,0 +1,20 @@
;; NES "Hello World" character tables
;; We spell out "Hello World" and we make sure that the colors are
;; different so our palette shift works.
.text
.org $0000
.byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.byte $c6,$c6,$c6,$fe,$c6,$c6,$c6,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; H (color 1) #1
.byte $00,$00,$00,$00,$00,$00,$00,$00,$fe,$c0,$c0,$fc,$c0,$c0,$fe,$00 ; E (color 2) #2
.byte $60,$60,$60,$60,$60,$60,$7e,$00,$60,$60,$60,$60,$60,$60,$7e,$00 ; L (color 3) #3
.byte $60,$60,$60,$60,$60,$60,$7e,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; L (color 1) #4
.byte $00,$00,$00,$00,$00,$00,$00,$00,$7c,$c6,$c6,$c6,$c6,$c6,$7c,$00 ; O (color 2) #5
.byte $c6,$c6,$d6,$fe,$fe,$ee,$c6,$00,$c6,$c6,$d6,$fe,$fe,$ee,$c6,$00 ; W (color 3) #6
.byte $7c,$c6,$c6,$c6,$c6,$c6,$7c,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; O (color 1) #7
.byte $00,$00,$00,$00,$00,$00,$00,$00,$fc,$c6,$c6,$fc,$d8,$cc,$c6,$00 ; R (color 2) #8
; L (color 3) #3
.byte $f8,$cc,$c6,$c6,$c6,$cc,$f8,$00,$00,$00,$00,$00,$00,$00,$00,$00 ; D (color 1) #9
.advance $2000 ; Fill in the rest of the CHR-ROM chip.

View File

@ -0,0 +1,5 @@
; iNES header
.byte $4e,$45,$53,$1a,$01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
.include "hello_prg.oph"
.include "hello_chr.oph"

View File

@ -0,0 +1,162 @@
;; PRG-ROM for our NES demo program.
.alias sprites $200 ; Keep our OAM DMA here.
.data
.org $0000
.space count 1
.space palette 32
.text
.org $C000
reset: sei
cld
; Wait two VBLANKs.
* lda $2002
bpl -
* lda $2002
bpl -
; Disable all graphics.
lda #$00
sta $2000
sta $2001
; Mask out sound IRQs.
lda #$40
sta $4017
; Clear out RAM.
lda #$00
ldx #$00
* sta $000,x
sta $100,x
sta $200,x
sta $300,x
sta $400,x
sta $500,x
sta $600,x
sta $700,x
inx
bne -
; Reset the stack pointer.
ldx #$FF
txs
; Clear the name tables.
lda #$24
sta $2006
ldy #$00
sty $2006
ldx #$08
lda #0
ldy #0
* sta $2007
iny
bne -
dex
bne -
; Load the palette from later on in the ROM.
lda #$3F
ldx #$00
sta $2006
stx $2006
* lda palette'rom,x
sta palette,x
sta $2007
inx
cpx #$20
bne -
; Load the proper sprite data into place.
ldx #$00
* lda graphics,x
sta sprites,x
inx
bne -
lda #$1E
sta count ; Update twice a second
; Un-scroll everything, just to be safe.
lda #$00
sta $2006
sta $2006
sta $2005
sta $2005
; Re-enable the displays.
lda #$80
sta $2000
lda #$1E
sta $2001
; FINALLY. We've set up the system. From here on it's all up to
; the NMI interrupt to handle things.
cli
* jmp -
vblank: ; Refresh the SPR-RAM.
lda #$02
sta $4014
; Time to update the palette?
dec count
bne irq ; If not, done.
lda #$1E
sta count ; Update twice a second
; Update those parts of the palette that aren't transparent.
ldx #$11
* txa
and #$03
beq + ; Don't update transparents
jsr bump'palette
* inx
cpx #$20
bne --
; Now re-blast that palette to VRAM.
lda #$3F
ldx #$00
sta $2006
stx $2006
* lda palette,x
sta $2007
inx
cpx #$20
bne -
; And reset the name tables.
lda #$00
sta $2006
sta $2006
sta $2005
sta $2005
irq: rti
bump'palette:
inc palette,x
lda palette,x
and #$0F
sec
sbc #$0D
bpl bump'palette
rts
palette'rom:
.byte $0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d,$0d
.byte $0d,$01,$02,$03,$0d,$04,$05,$06,$0d,$07,$08,$09,$0d,$0a,$0b,$0c
graphics:
.byte $70,$01,$00,$6c,$70,$02,$00,$74,$70,$03,$00,$7c,$70,$04,$01,$84
.byte $70,$05,$01,$8c
.byte $78,$06,$01,$6c,$78,$07,$02,$74,$78,$08,$02,$7c,$78,$03,$02,$84
.byte $78,$09,$03,$8c
.advance $FFFA
.word vblank, reset, irq

View File

@ -0,0 +1,24 @@
.byte "UNIF"
.dword 7
.advance $20
.byte "MAPR"
.dword ++-+
*
.byte "NES-NROM-256",0
*
.byte "NAME"
.dword ++-+
*
.byte "Ophis Hello World Demo",0
*
.byte "PRG0"
.dword $4000
.include "hello_prg.oph"
.byte "MIRR"
.dword 1
.byte 0
.byte "CHR0"
.dword $2000
.include "hello_chr.oph"