From b2d38dd0de9b0f4b52d6f83b973e1b7878cea7df Mon Sep 17 00:00:00 2001 From: david Date: Fri, 13 Feb 2009 18:53:49 +0100 Subject: [PATCH] o add snes test sample --- snes/simpletest/LoadGraphics.asm | 143 +++++++++++++++++ snes/simpletest/Makefile | 30 ++++ snes/simpletest/biker.clr | Bin 0 -> 32 bytes snes/simpletest/biker.pcx | Bin 0 -> 1444 bytes snes/simpletest/biker.pic | Bin 0 -> 2048 bytes snes/simpletest/header.inc | 61 +++++++ snes/simpletest/init.inc | 262 +++++++++++++++++++++++++++++++ snes/simpletest/sprite.asm | 209 ++++++++++++++++++++++++ 8 files changed, 705 insertions(+) create mode 100644 snes/simpletest/LoadGraphics.asm create mode 100644 snes/simpletest/Makefile create mode 100644 snes/simpletest/biker.clr create mode 100644 snes/simpletest/biker.pcx create mode 100644 snes/simpletest/biker.pic create mode 100644 snes/simpletest/header.inc create mode 100644 snes/simpletest/init.inc create mode 100644 snes/simpletest/sprite.asm diff --git a/snes/simpletest/LoadGraphics.asm b/snes/simpletest/LoadGraphics.asm new file mode 100644 index 0000000..3c0908a --- /dev/null +++ b/snes/simpletest/LoadGraphics.asm @@ -0,0 +1,143 @@ +;============================================================================ +; Macros +;============================================================================ + +;============================================================================ +;LoadPalette - Macro that loads palette information into CGRAM +;---------------------------------------------------------------------------- +; In: SRC_ADDR -- 24 bit address of source data, +; START -- Color # to start on, +; SIZE -- # of COLORS to copy +;---------------------------------------------------------------------------- +; Out: None +;---------------------------------------------------------------------------- +; Modifies: A,X +; Requires: mem/A = 8 bit, X/Y = 16 bit +;---------------------------------------------------------------------------- +.MACRO LoadPalette + lda #\2 + sta $2121 ; Start at START color + lda #:\1 ; Using : before the parameter gets its bank. + ldx #\1 ; Not using : gets the offset address. + ldy #(\3 * 2) ; 2 bytes for every color + jsr DMAPalette +.ENDM + +;============================================================================ +; LoadBlockToVRAM -- Macro that simplifies calling LoadVRAM to copy data to VRAM +;---------------------------------------------------------------------------- +; In: SRC_ADDR -- 24 bit address of source data +; DEST -- VRAM address to write to (WORD address!!) +; SIZE -- number of BYTEs to copy +;---------------------------------------------------------------------------- +; Out: None +;---------------------------------------------------------------------------- +; Modifies: A, X, Y +;---------------------------------------------------------------------------- + +;LoadBlockToVRAM SRC_ADDRESS, DEST, SIZE +; requires: mem/A = 8 bit, X/Y = 16 bit +.MACRO LoadBlockToVRAM + lda #$80 + sta $2115 + ldx #\2 ; DEST + stx $2116 ; $2116: Word address for accessing VRAM. + lda #:\1 ; SRCBANK + ldx #\1 ; SRCOFFSET + ldy #\3 ; SIZE + jsr LoadVRAM +.ENDM + + + + +;============================================================================ +; Routines +;============================================================================ + +.BANK 0 +.ORG 0 +.SECTION "LoadVRAMCode" SEMIFREE + +;============================================================================ +; LoadVRAM -- Load data into VRAM +;---------------------------------------------------------------------------- +; In: A:X -- points to the data +; Y -- Number of bytes to copy (0 to 65535) (assumes 16-bit index) +;---------------------------------------------------------------------------- +; Out: None +;---------------------------------------------------------------------------- +; Modifies: none +;---------------------------------------------------------------------------- +; Notes: Assumes VRAM address has been previously set!! +;---------------------------------------------------------------------------- +LoadVRAM: + pha + phx + phy + phb + php ; Preserve Registers + + sep #$20 + + stx $4302 ; Store Data offset into DMA source offset + sta $4304 ; Store data Bank into DMA source bank + sty $4305 ; Store size of data block + + lda #$01 + sta $4300 ; Set DMA mode (word, normal increment) + lda #$18 ; Set the destination register (VRAM write register) + sta $4301 + lda #$01 ; Initiate DMA transfer (channel 1) + sta $420B + + plp ; restore registers + plb + ply + plx + pla + rts ; return +;============================================================================ + +.ENDS + +.BANK 0 +.ORG 0 +.SECTION "DMAPaletteCode" SEMIFREE + +;============================================================================ +; DMAPalette -- Load entire palette using DMA +;---------------------------------------------------------------------------- +; In: A:X -- points to the data +; Y -- Size of data +;---------------------------------------------------------------------------- +; Out: None +;---------------------------------------------------------------------------- +; Modifies: none +;---------------------------------------------------------------------------- +DMAPalette: + pha + phx + phb + php ; Preserve Registers + + sep #$20 + + stx $4302 ; Store data offset into DMA source offset + sta $4304 ; Store data bank into DMA source bank + sty $4305 ; Store size of data block + + stz $4300 ; Set DMA Mode (byte, normal increment) + lda #$22 ; Set destination register ($2122 - CGRAM Write) + sta $4301 + lda #$01 ; Initiate DMA transfer + sta $420B + + plp ; Restore registers + plb + plx + pla + rts ; return from subroutine +;============================================================================ + +.ENDS \ No newline at end of file diff --git a/snes/simpletest/Makefile b/snes/simpletest/Makefile new file mode 100644 index 0000000..96ec431 --- /dev/null +++ b/snes/simpletest/Makefile @@ -0,0 +1,30 @@ +#wla-65816 -o %1.asm %1.obj +#wlalink -vr temp.prj %1.smc + + +AS=wla-65816 +LD=wlalink + +OBJS=sprite.o +APP=sprite.smc +GFX=biker.pic +EMU=/Applications/ZSNES.app/Contents/MacOS/ZSNES + +all: clean $(APP) + +run: + $(EMU) $(APP) + + +linkfile: + echo "[objects]" > linkerfile.prj + +%.o: %.asm + echo "$@" >> linkerfile.prj + $(AS) -o $? $@ + +$(APP): linkfile $(GFX) $(OBJS) $(GFX) + $(LD) -vr linkerfile.prj $@ + +clean: + rm -vf $(APP) *.prj *.o diff --git a/snes/simpletest/biker.clr b/snes/simpletest/biker.clr new file mode 100644 index 0000000000000000000000000000000000000000..39735003ac9427476eb614b82f2c95ba1a3df313 GIT binary patch literal 32 ocmb0y*l+!VcfOiD!$gkzmJ&S61pe3mNXph#cFZjN&!kWb0LZ)yN&o-= literal 0 HcmV?d00001 diff --git a/snes/simpletest/biker.pcx b/snes/simpletest/biker.pcx new file mode 100644 index 0000000000000000000000000000000000000000..d56fe686ee4a663cf0586b079b789b876eb2295a GIT binary patch literal 1444 zcmeHFJ967F5M7c0@c>a|N_CD)m$`hAkCHYssd5bDEj1}z zT2%@G!{P43e%^kPuOK{Eyq|fC{4Rg?mx7prq zcfZOgLX+yFR2JaOb0-si$|Uf?1&<$cSj5&P$|`EOwk~G8iXeL`$~PDALPHI%&F0rS z(}Pmelln?EyByRzk0Wh!pm&QJlVm(Fn4jPy>I@aQ))7+FjeSI$s#Z9!W~rz=ts1Sh zslo95gxTPx_Na(?r9gPb-NL!4bMp;-Mka5jV?uMyNO6T;k+e@ymltTKU|^&i=@JQ& zj&>|f5mqT8B2Dql3rkeDO84l~$$aP#4r~eko^C1kOLPVrl#q2q*F!gvk1iCUL$L)M^2}YlxLrE%KX%|R!rrx6 literal 0 HcmV?d00001 diff --git a/snes/simpletest/biker.pic b/snes/simpletest/biker.pic new file mode 100644 index 0000000000000000000000000000000000000000..84a474e3fced76389be5b5124e0d30bb33e3d9da GIT binary patch literal 2048 zcmeHHu}Z^G6g_F$CTcJ-v>36H2QBE2f=(m(M(cAjjzR_yI>J|4?NzvXSkPhcn?sOY|6-Z>iN#zMZFGHO>4SY@p(XF z04%X_UWw&)B;P;3POd palette starting color > 24 (00011100), make 0 + sta PalNum + + jmp Infinity ; bwa hahahahaha + +;============================================================================ +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 + + + + stz $2121 + lda PalNum + sta $2122 + sta $2122 + + + lda $4210 ; Clear NMI flag + rep #$30 ; A/Mem=16 bits, X/Y=16 bits + + PLD + PLY + PLX + PLA + PLB + + sep #$20 + RTI + +;============================================================================ +.ENDS + +;============================================================================ +; Character Data +;============================================================================ +.BANK 1 SLOT 0 +.ORG 0 +.SECTION "CharacterData" +Sprite: + .INCBIN "biker.pic" + +SprPal: + .INCBIN "biker.clr" + +.ENDS