Okay, here's some code I threw together with help of Bazz's tutorial (available here). In bsnes it works fine, so I thought it should work on the SNES PowerPak after a quick ucon64 -padn=524288. It doesn't.
The point is showing a Mario sprite in the middle of the screen and doing nothing until Right on the D-pad is pressed. That's when the Mario sprite should do... Guess what!
So far I've had no trouble with padding something small/homebrew for the PowerPak and getting it to run (for example, when I had no joypad code and only wanted to put Mario on screen).
This time Mario either pops up on screen, does nothing when I press anything and after a while dissapears off screen. Huh?! Sometimes when I reset or recopy the code from CF, he doesn't appear on screen at all. I'm very puzzled by all this.
Anyway, here's the code. Also, any good programming tips I might be able to use are highly appreciated. Sorry for the code being messy as all hell.
The point is showing a Mario sprite in the middle of the screen and doing nothing until Right on the D-pad is pressed. That's when the Mario sprite should do... Guess what!
So far I've had no trouble with padding something small/homebrew for the PowerPak and getting it to run (for example, when I had no joypad code and only wanted to put Mario on screen).
This time Mario either pops up on screen, does nothing when I press anything and after a while dissapears off screen. Huh?! Sometimes when I reset or recopy the code from CF, he doesn't appear on screen at all. I'm very puzzled by all this.
Anyway, here's the code. Also, any good programming tips I might be able to use are highly appreciated. Sorry for the code being messy as all hell.
Code:
.INCLUDE "header.inc"
.INCLUDE "initsnes.asm"
.MACRO LoadPalette ;DMA transfers a palette to CGRAM (A:8b,XY:16b)
lda #\2 ;args: 24b source, 8b dest, 8b number of colors
sta $2121
lda #:\1
ldx #\1
ldy #(\3*2)
jsr DMAPalette
.ENDM
.MACRO LoadBlockToVRAM ;DMA transfers a block to VRAM (A:8b,XY:16b)
ldx #\2 ;args: 24b source, 16b dest, 8b size in bytes
stx $2116
lda #:\1
ldx #\1
ldy #\3
jsr LoadVRAM
.ENDM
.BANK 0 SLOT 0
.ORG 0
.ENUM $0002
Joy1Raw DW ; Holder of RAW joypad data from register (from last frame)
Joy2Raw DW
Joy1Press DW ; Contains only pressed buttons (not held down)
Joy2Press DW
Joy1Held DW ; Contains only buttons that are Held
Joy2Held DW
.ENDE
.SECTION "Main"
Start:
InitSNES
lda #$80
sta $4200
lda #$80 ;don't increment VRAM address until written to $2119
sta $2115 ;(as opposed to $2118)
LoadPalette SprPal, 128, 16 ;sprite palettes start at 128
LoadBlockToVRAM Sprite, $0000, $0800
jsr SpriteInit
lda #(256/2-16)
sta $0000
lda #(224/2-16)
sta $0001
lda #%01010100
sta $0200
jsr SetupVideo
loop:
wai
lda Joy1Press+1
and #$01
beq loop
inc $0000
inc $0000
jmp loop
SetupVideo:
php
rep #$10
sep #$20
stz $2102
stz $2103
ldy #$0400
sty $4300
stz $4302
stz $4303
lda #$7E
sta $4304
ldy #$0220
sty $4305
lda #$01
sta $420B
lda #%10100000
sta $2101
lda #%00010000
sta $212C
lda #$0F
sta $2100
plp
rts
LoadVRAM: ;initiates DMA transfer to VRAM
php
stx $4302
sta $4304
sty $4305
lda #$01
sta $4300 ;first write to $2118, then $2119, then $2118...
lda #$18
sta $4301
lda #$01
sta $420B
plp
rts
DMAPalette: ;initiates DMA transfer to CGRAM
php
stx $4302
sta $4304
sty $4305
stz $4300 ;only write to $2122
lda #$22
sta $4301
lda #$01
sta $420B
plp
rts
SpriteInit: ;move all sprites off screen
php
rep #$30
ldx #$0000
lda #$01
_offscreen:
sta $0000,x
inx
inx
inx
inx
cpx #$0200
bne _offscreen
lda #$5555
ldx #$0000
_xsmb:
sta $0200,x
inx
inx
cpx #$0020
bne _xsmb
plp
rts
VBlank:
php
jsr Joypad
stz $2102
stz $2103
sep #$20
lda $0000
sta $2104
lda $0001
sta $2104
plp
rti
Joypad:
php
rep #$30
lda $4212
and #$01
beq Joypad
lda #$81
sta $4200
ldx Joy1Raw
lda $4218
sta Joy1Raw
txa
eor Joy1Raw
and Joy1Raw
sta Joy1Press
txa
and Joy1Raw
sta Joy1Held
plp
rts
.ENDS
.BANK 1 SLOT 0
.ORG 0
.SECTION "CharacterData"
Sprite:
.INCBIN "biker.pic"
SprPal:
.INCBIN "biker.clr"
.ENDS
.INCLUDE "initsnes.asm"
.MACRO LoadPalette ;DMA transfers a palette to CGRAM (A:8b,XY:16b)
lda #\2 ;args: 24b source, 8b dest, 8b number of colors
sta $2121
lda #:\1
ldx #\1
ldy #(\3*2)
jsr DMAPalette
.ENDM
.MACRO LoadBlockToVRAM ;DMA transfers a block to VRAM (A:8b,XY:16b)
ldx #\2 ;args: 24b source, 16b dest, 8b size in bytes
stx $2116
lda #:\1
ldx #\1
ldy #\3
jsr LoadVRAM
.ENDM
.BANK 0 SLOT 0
.ORG 0
.ENUM $0002
Joy1Raw DW ; Holder of RAW joypad data from register (from last frame)
Joy2Raw DW
Joy1Press DW ; Contains only pressed buttons (not held down)
Joy2Press DW
Joy1Held DW ; Contains only buttons that are Held
Joy2Held DW
.ENDE
.SECTION "Main"
Start:
InitSNES
lda #$80
sta $4200
lda #$80 ;don't increment VRAM address until written to $2119
sta $2115 ;(as opposed to $2118)
LoadPalette SprPal, 128, 16 ;sprite palettes start at 128
LoadBlockToVRAM Sprite, $0000, $0800
jsr SpriteInit
lda #(256/2-16)
sta $0000
lda #(224/2-16)
sta $0001
lda #%01010100
sta $0200
jsr SetupVideo
loop:
wai
lda Joy1Press+1
and #$01
beq loop
inc $0000
inc $0000
jmp loop
SetupVideo:
php
rep #$10
sep #$20
stz $2102
stz $2103
ldy #$0400
sty $4300
stz $4302
stz $4303
lda #$7E
sta $4304
ldy #$0220
sty $4305
lda #$01
sta $420B
lda #%10100000
sta $2101
lda #%00010000
sta $212C
lda #$0F
sta $2100
plp
rts
LoadVRAM: ;initiates DMA transfer to VRAM
php
stx $4302
sta $4304
sty $4305
lda #$01
sta $4300 ;first write to $2118, then $2119, then $2118...
lda #$18
sta $4301
lda #$01
sta $420B
plp
rts
DMAPalette: ;initiates DMA transfer to CGRAM
php
stx $4302
sta $4304
sty $4305
stz $4300 ;only write to $2122
lda #$22
sta $4301
lda #$01
sta $420B
plp
rts
SpriteInit: ;move all sprites off screen
php
rep #$30
ldx #$0000
lda #$01
_offscreen:
sta $0000,x
inx
inx
inx
inx
cpx #$0200
bne _offscreen
lda #$5555
ldx #$0000
_xsmb:
sta $0200,x
inx
inx
cpx #$0020
bne _xsmb
plp
rts
VBlank:
php
jsr Joypad
stz $2102
stz $2103
sep #$20
lda $0000
sta $2104
lda $0001
sta $2104
plp
rti
Joypad:
php
rep #$30
lda $4212
and #$01
beq Joypad
lda #$81
sta $4200
ldx Joy1Raw
lda $4218
sta Joy1Raw
txa
eor Joy1Raw
and Joy1Raw
sta Joy1Press
txa
and Joy1Raw
sta Joy1Held
plp
rts
.ENDS
.BANK 1 SLOT 0
.ORG 0
.SECTION "CharacterData"
Sprite:
.INCBIN "biker.pic"
SprPal:
.INCBIN "biker.clr"
.ENDS