https://wiki.superfamicom.org/snes-sprites
So I was successful in getting it to load my own sprite. I was even able to change the code from doing the flashing background thing to just a black background, because I wanted my first program to be plain and simple.
And my there was my first successful SNES program! And I was very happy.
So since then I had goals to add a little more to it.
First I wanted to add some text to it.
And, I wanted to be able to do a palette swap.
I was attempted to figure out the palette swap on my own with what I knew.
My idea was to have a number, called choice,
and the user would press left or right to increase or decrease the number,
and each of those numbers would load a certain palette.
So, so far I my attempts haven't been quite successful.
So in this project I was just using the included includes, with it's own header, initializer, and LoadGraphics,
when I was just trying to load my sprite.
But since I've been trying to do the other things, I added includes from Neviksti's SNES_Starter kit, like Strings.asm and 2input.asm.
At first I was just trying to load text to it, I copied the loading text line and the text from walker.asm (Just to get sample words to work first)
After attempting this a couple times, my program work the same and displayed my sprite, but my text did not show up.
I decided to worry about later and attempt to do my palette swapping idea.
So far I only have 2 palettes.
So I did what what I did, trying to do it with branches and stuff.
After a couple a couple attempts at this, and when I tested it after each, the program displays again but flickers over and over.
Code: Select all
.INCLUDE "header.inc"
.INCLUDE "init.inc"
.INCLUDE "LoadGraphics.asm"
.INCLUDE "Strings.asm"
.INCLUDE "2input.asm"
;Definition
.DEFINE choice $01
.BANK 0 SLOT 0
.ORG 0
.SECTION "main"
main:
InitSNES
rep #$10 ; X Y 16-bit
sep #$20 ; A 8-bit
lda #%00001001
sta $2105 ; Mode 1
stz $2121
stz $2122
stz $2122
;choice
lda choice
cmp #$01
beq loadpalette1
cmp #$02
beq loadpalette2
;Pallete lables
loadpalette1:
LoadPalette emitpal0, 128, 16
jmp rest
loadpalette2:
LoadPalette emitpal1, 128, 16
jmp rest
rest:
LoadBlockToVRAM emit, $0000, $0800
LoadBlockToVRAM text, $5000, $0800
jsr SpriteInit
;Emit's location
lda #(256/2 - 16)
sta $0000
lda #(224/2 - 16)
sta $0001
stz $0002
lda #%00110000 ; no flips, set priority
sta $0003
;lda #%11000000
;sta $0100
lda #%01010100
sta $0200
; ---12345678901234567890123456789012---
PrintString " 'Look Ma, I can Walk!' \n"
PrintString " Tile pics: from Darrok \n"
PrintString " Walker pics: from a Demo ROM\n"
PrintString " - coded by: Neviksti - "
jsr SetupVideo
;lda #$80
;sta $4200
continue:
JSR JoyInit ;setup joypads and enable NMI
sep #$30 ; X Y 16-bit
lda choice
tax
WAI
_up:
lda Joy1+1
and #$08
beq _down
bra _done
_down:
lda Joy1+1
and #$04
beq _left
bra _done
; left decreses
_left:
lda Joy1+1
and #$02
beq _right
dex
bra _done
;right increases
_right:
lda Joy1+1
and #$01
beq _done
inx
bra _done
_done:
txa
cmp #$00
beq if0
cmp #$03
beq if3
jmp reallydone
if0:
lda #$02
jmp reallydone
if3:
lda #$01
jmp reallydone
reallydone:
sta choice
jmp main
;============================================================================
SpriteInit:
php
rep #$30 ;16bit mem/A, 16 bit X/Y
ldx #$0000
lda #$0001
_setoffscr:
sta $0000,X
inx
inx
inx
inx
cpx #$0200
bne _setoffscr
;==================
ldx #$0000
lda #$5555
_clr:
sta $0200, X ;initialize all sprites to be off the screen
inx
inx
cpx #$0020
bne _clr
;==================
plp
rts
;============================================================================
;============================================================================
; SetupVideo -- Sets up the video mode and tile-related registers
;----------------------------------------------------------------------------
; In: None
;----------------------------------------------------------------------------
; Out: None
;----------------------------------------------------------------------------
SetupVideo:
php
rep #$10
sep #$20
stz $2102
stz $2103
;*********transfer sprite data
stz $2102 ; set OAM address to 0
stz $2103
LDY #$0400
STY $4300 ; CPU -> PPU, auto increment, write 1 reg, $2104 (OAM Write)
stz $4302
stz $4303 ; source offset
LDY #$0220
STY $4305 ; number of bytes to transfer
LDA #$7E
STA $4304 ; bank address = $7E (work RAM)
LDA #$01
STA $420B ;start DMA transfer
lda #%10100000
sta $2101
lda #%00010000 ; Enable BG1
sta $212C
lda #$0F
sta $2100 ; Turn on screen, full Brightness
plp
rts
;============================================================================
VBlank:
rep #$30 ; A/mem=16 bits, X/Y=16 bits (to push all 16 bits)
phb
pha
phx
phy
phd
sep #$20 ; A/mem=8 bit
lda $4210 ; Clear NMI flag
rep #$30 ; A/Mem=16 bits, X/Y=16 bits
PLD
PLY
PLX
PLA
PLB
sep #$20
RTI
;============================================================================
.ends
;-----Graphics data------
.BANK 1 SLOT 0
.ORG 0
.SECTION "graphics"
emit:
.INCBIN "emit.pic"
emitpal0:
.INCBIN "emit.clr"
emitpal1:
.INCBIN "emitred.clr"
text:
.INCBIN "ascii.pic"
.ENDS
I was wondering if it was because Nev's Strings.asm conflicts with this other programmer's coding of his source code and included sources, like his own LoadGraphics.
When I did the loadgraphics text line, I just copy and pasted from Walker.asm so maybe it just has to do with how it's loaded at those addresses here?
Otherwise, maybe how I written things interferes with Vblank and stuff, which I'm still learning about.
For the input, again I copied and pasted from walker, but I got rid of the frame loading stuff.
And I'm wondering the way I tried to write to accomplish this paletteswap idea is functional at all.
I'm still learning about vblank and all that, but I just wondered about what things I'm doing wrong, so I can understand more about how all these things work.
Am I just loading and setting things in the wrong order? Am I messing up on loading the graphics?
Like at
Code: Select all
jsr SetupVideo
;lda #$80
;sta $4200
continue:
JSR JoyInit ;setup joypads and enable NMI
That brings up the point, at what points should I have enabled NMI?
Again, a lot of this because I still don't understand everything and am still learning how all this Vblank and stuff works, so I'm just looking for a little guidance on working with this.
Thank you for your time!