This program is untested, and it is incomplete because it needs a linker script to tell ld65 where in memory to put each segment, but it should give you an idea of what needs to be done to set up the NES hardware:
Code:
PPUCTRL = $2000
PPUMASK = $2001
PPUSTATUS = $2002
PPUADDR = $2006
PPUDATA = $2007
.segment "CODE"
nmi:
irq:
rti
reset:
sei ; turn off most interrupts
ldx #0
stx PPUCTRL ; turn off PPU interrupts
stx PPUMASK ; turn off PPU rendering
cld ; turn off 6502 decimal mode
; the NES doesn't have it but some famiclones and debuggers do
dex ; set up the stack pointer
txs
; before writing anything to PPU registers $2003 through $2007
; we must wait for PPUSTATUS bit 7 (the "sign bit") to be set twice
:
lda PPUSTATUS
bpl :-
; usually there will be about 30,000 CPU cycles between the first two
; times it is set, so use that time to clear out the RAM or something
; (omitted here)
:
lda PPUSTATUS
bpl :-
; set the VRAM write cursor to $3F00 (start of palette area)
lda #$3F
sta PPUADDR
lda #$00
sta PPUADDR
; write a green value to color 0, which is ordinarily displayed
; on the whole screen when rendering is turned off
lda #$1A
sta PPUDATA
; set the VRAM write cursor to $0000, which is outside the palette area
; otherwise, garbage will appear on the screen
lda #$00
sta PPUADDR
sta PPUADDR
; freeze the CPU so that you can see the green screen
:
jmp :-
.segment "VECTORS"
.addr nmi, reset, irq