So I got myseld the SNES Programming Manual that is floating around the web and wrote a simple initialisation routine and basic code, that will display a green screen(most SNES tutorials seem to start with this).
Alas, my code won't work. After one hour of checking and re-checking my init routine, I turn to you in hope of finding someone who will find my error.
I work with the ca65 assembler, since I used that for my NES programming and I'm most comfortable with it.
so, here goes my code.
My "main" file:
Code: Select all
; my first SNES ROM
.p816 ; 65816 processor
.i16 ; X/Y are 16 bits
;.a8 ; A is 8 bits
.segment "ROMREG"
.include "RomRegisterData.inc"
.segment "VECTORS"
.word 0, 0, 0, 0, 0, 0, 0, 0
.word 0, 0, 0, 0, 0, NMI, reset, 0
.segment "CODE"
.include "SNESInit.asm"
.include "tiles.inc"
reset:
jsr InitSNES
; set background to green
lda #$1f
sta $2122
lda #$00
sta $2122
; Max screen brightness
lda #$0f
sta $2100
forever:
jmp forever
NMI:
rti
Code: Select all
; init SNES according to SNES Programming Manual chapter 23
.include "SNESRegisters.inc"
;----------------------------------------------------------
InitSNES:
; basic pre-init setup
sei ; disable interrupts
clc ; switch to...
xce ; ...native mode
rep #$38 ; X,Y and A are 16 bits, decimal mode off
ldx #$1fff ; set up stack
txs
lda #$0000 ; set Data Register to zero
tcd
; turn on forced blanking / turn of screen
sep #$20 ; A is 8 bits
lda #$8F
sta INIDISP
;rep #$20 ; A is 16 bits
; clear Registers
phk ; Data Bank = Program Bank
plb
ldx #$2101
loop00: ; Regs $2101 - $210c
stz $00,x
inx
cpx #$210d
bne loop00
loop01: ; Regs $201d - $2114
stz $00,x
stz $00,x
inx
cpx #$2115
bne loop01
lda #$80 ; set VRAM mode
sta $2115
stz $2116
stz $2117
; $2118 and $2119 need no initialisation
stz $211a
ldx #$211b
loop03: ; Regs $211b - $2120
stz $00,x
stz $00,x
inx
cpx #$2121
bne loop03
stz $2121
; $2122 need no initialisation
ldx #$2123
loop04: ; Regs $2123 - $2133
stz $00,x
inx
cpx #$2134
bne loop04
ldx #$4200
loop05: ; Regs $4200 - $420d
stz $00,x
inx
cpx #$420e
bne loop05
lda #$30 ; turn on fixed color addition
sta $2130
lda #$e0 ; turn on RGB
sta $2132
lda #$ff ; turn on I/O port
sta $4201
; set Main Registers
;lda #$1f ; turn on all BGs and OBJ
;sta $212c
; set BG1 - 4 and OBJ
; OAM, CG Data setting with DMA
jsr InitOAMandCG
; VRAM Data setting with DMA
jsr InitVRAM
; release forced blanking
lda #$0F
sta INIDISP
; enable NMI and standard controller
lda #$81
sta $4200
cli
rts
;----------------------------------------------------------
; init OAM and CG RAM
InitOAMandCG:
rts
;----------------------------------------------------------
; init VRAM
InitVRAM:
rts
SNESRegisters.inc (I plan to expand this...)
Code: Select all
; register aliases
INIDISP = $2100
Code: Select all
; ROM Registration Data as specified in SNES Manual 1-2-25
.word $ffff ; maker code
.byte $47, $52, $45, $4e ; game code
.byte $00, $00, $00, $00, $00, $00, $00
.byte $00 ; no expansion RAM
.byte $00 ; no special version
.byte $00 ; no special/sub cartridge
.byte "MY FIRST TILES" ; game title
.byte $20, $20, $20, $20 ; game title fill
.byte $30 ; high speed, Mode 20
.byte $00 ; ROM only cartridge
.byte $07 ; 1Mb/128kB, NOT DOCUMENTED
.byte $00 ; 0B, no RAM
.byte $00 ; Japan
.byte $33 ; fixed value
.byte $00 ; revision number
.word $aaaa ; checksum
.word $5555 ; complement checksum
Any help is greatly welcomed.