2015-05-22 18:08:57 +00:00
|
|
|
.INCLUDE "header.asm"
|
2015-05-23 19:42:47 +00:00
|
|
|
.INCLUDE "init.asm"
|
2015-05-22 23:39:43 +00:00
|
|
|
.INCLUDE "registers.asm"
|
2015-05-22 17:34:37 +00:00
|
|
|
|
2015-05-23 18:00:43 +00:00
|
|
|
|
|
|
|
|
2015-05-25 12:04:15 +00:00
|
|
|
; Assumes 16-bit X & 8-bit A.
|
|
|
|
; Stores result to A.
|
|
|
|
; Modifies X.
|
|
|
|
; Updates $0018-$0019 to point at the next available random byte.
|
|
|
|
.MACRO GetRandomByte
|
|
|
|
ldx $18
|
|
|
|
lda $028000, X ; $028000: beginning of ROM bank 2.
|
|
|
|
inx
|
|
|
|
cpx #$8000 ; This is the size of the entire ROM bank.
|
|
|
|
bne +
|
|
|
|
ldx #0
|
|
|
|
+
|
|
|
|
stx $18
|
|
|
|
.ENDM
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-22 17:34:37 +00:00
|
|
|
.BANK 0 SLOT 0
|
|
|
|
.ORG 0
|
|
|
|
.SECTION "MainCode"
|
|
|
|
|
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
; Memory layout:
|
2015-05-24 14:43:25 +00:00
|
|
|
; 0000-000F: scratch space for functions.
|
|
|
|
; 0010-0011: controller state of joypad #1.
|
|
|
|
; 0012-0013: controller state of joypad #2.
|
|
|
|
; 0014-0017: 32-bit counter of vblanks.
|
2015-05-25 12:04:15 +00:00
|
|
|
; 0018-0019: 16-bit pointer to next random byte.
|
2015-05-24 14:43:25 +00:00
|
|
|
; 0020-0021: (x, y) coordinates of player.
|
|
|
|
; 0022-0024: RGB color values to use for background color, from [0-31].
|
|
|
|
;
|
|
|
|
; Sprite table buffers -- copied each frame to OAM during VBlank, using DMA.
|
|
|
|
; 0100-02FF: table 1 (4 bytes each: x/y coord, tile #, flip/priority/palette)
|
|
|
|
; 0300-031F: table 2 (2 bits each: high x-coord bit, size)
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
Start:
|
2015-05-23 18:00:43 +00:00
|
|
|
InitializeSNES
|
|
|
|
|
|
|
|
jsr LoadPaletteAndTileData
|
2015-05-24 14:43:25 +00:00
|
|
|
jsr InitializeSpriteTables
|
|
|
|
|
2015-05-24 23:50:10 +00:00
|
|
|
; Set screen mode: 16x16 tiles for backgrounds, mode 1.
|
|
|
|
lda #%11000001
|
2015-05-24 18:44:26 +00:00
|
|
|
sta SCREENMODE
|
2015-05-24 17:22:42 +00:00
|
|
|
|
2015-05-24 14:43:25 +00:00
|
|
|
; Set sprite size to 16x16 (small) and 32x32 (large).
|
|
|
|
lda #%01100000
|
|
|
|
sta OAMSIZE
|
|
|
|
|
2015-05-24 23:50:10 +00:00
|
|
|
; Main screen: enable sprites & BG3.
|
|
|
|
lda #%00010100
|
2015-05-24 14:43:25 +00:00
|
|
|
sta MSENABLE
|
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
; Turn on the screen.
|
|
|
|
; Format: x000bbbb
|
|
|
|
; x: 0 = screen on, 1 = screen off, bbbb: Brightness ($0-$F)
|
|
|
|
lda #%00001111
|
2015-05-22 23:39:43 +00:00
|
|
|
sta INIDISP
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
; Enable NMI interrupt & joypad.
|
|
|
|
; n-vh---j n: NMI interrupt enable v: vertical counter enable
|
|
|
|
; h: horizontal counter enable j: joypad enable
|
2015-05-23 18:00:43 +00:00
|
|
|
lda #%10000001
|
2015-05-22 23:39:43 +00:00
|
|
|
sta NMITIMEN
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
; Store zeroes to the controller status registers.
|
2015-05-22 23:39:43 +00:00
|
|
|
; TODO(mcmillen): is this needed? I think the system will overwrite these
|
|
|
|
; automatically.
|
|
|
|
stz JOY1H
|
|
|
|
stz JOY1L
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
; Write something recognizable into our scratch space.
|
|
|
|
jsr FillScratch
|
|
|
|
|
2015-05-24 18:44:26 +00:00
|
|
|
; Start the background color as a dark blue.
|
2015-05-25 00:32:41 +00:00
|
|
|
lda #4
|
2015-05-23 18:00:43 +00:00
|
|
|
sta $24
|
|
|
|
|
2015-05-23 22:00:49 +00:00
|
|
|
; Player's initial starting location.
|
|
|
|
lda #(256 / 4)
|
|
|
|
sta $20
|
2015-05-25 13:42:54 +00:00
|
|
|
lda #((224 - 16) / 2)
|
2015-05-23 22:00:49 +00:00
|
|
|
sta $21
|
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
|
2015-05-22 17:34:37 +00:00
|
|
|
|
|
|
|
MainLoop:
|
|
|
|
wai ; Wait for interrupt.
|
|
|
|
jmp MainLoop
|
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
|
2015-05-23 18:00:43 +00:00
|
|
|
LoadPaletteAndTileData:
|
2015-05-23 19:38:27 +00:00
|
|
|
; For more details on DMA, see:
|
|
|
|
; http://wiki.superfamicom.org/snes/show/Grog%27s+Guide+to+DMA+and+HDMA+on+the+SNES
|
|
|
|
; http://wiki.superfamicom.org/snes/show/Making+a+Small+Game+-+Tic-Tac-Toe
|
|
|
|
;
|
|
|
|
; A lot of the graphics-related registers are explained in Qwertie's doc:
|
|
|
|
; http://emu-docs.org/Super%20NES/General/snesdoc.html
|
|
|
|
; ... but be careful, because there are some errors in this doc.
|
|
|
|
;
|
|
|
|
; bazz's tutorial (available from http://wiki.superfamicom.org/snes/) is
|
|
|
|
; quite helpful with palette / sprites / DMA, especially starting at
|
|
|
|
; http://wiki.superfamicom.org/snes/show/Working+with+VRAM+-+Loading+the+Palette
|
|
|
|
|
2015-05-23 18:00:43 +00:00
|
|
|
; 16-bit X/Y registers. Used for DMA source address & transfer size, both of
|
|
|
|
; which want 16-bit values.
|
2015-05-24 14:43:25 +00:00
|
|
|
rep #%00010000
|
2015-05-23 18:00:43 +00:00
|
|
|
; 8-bit A/B registers. Used for DMA source bank & destination address.
|
|
|
|
sep #%00100000
|
|
|
|
|
2015-05-23 21:17:39 +00:00
|
|
|
; Initialize the palette memory in a loop.
|
2015-05-23 18:00:43 +00:00
|
|
|
; We could also do this with a DMA transfer (like we do with the tile data
|
2015-05-23 21:17:39 +00:00
|
|
|
; below), but it seems overkill for just a few bytes. :)
|
2015-05-24 17:22:42 +00:00
|
|
|
; TODO(mcmillen): do it with a DMA transfer.
|
|
|
|
|
|
|
|
; First, sprite palette data:
|
2015-05-23 21:17:39 +00:00
|
|
|
ldx #0
|
2015-05-24 14:43:25 +00:00
|
|
|
lda #128 ; Palette entries for sprites start at 128.
|
2015-05-23 18:00:43 +00:00
|
|
|
sta CGADDR
|
2015-05-23 21:17:39 +00:00
|
|
|
-
|
2015-05-24 14:43:25 +00:00
|
|
|
lda.l SpritePalette, X
|
2015-05-23 18:00:43 +00:00
|
|
|
sta CGDATA
|
2015-05-23 21:17:39 +00:00
|
|
|
inx
|
2015-05-24 14:43:25 +00:00
|
|
|
cpx #32 ; 32 bytes of palette data.
|
2015-05-23 21:17:39 +00:00
|
|
|
bne -
|
2015-05-23 18:00:43 +00:00
|
|
|
|
2015-05-24 23:50:10 +00:00
|
|
|
; Now, BG3 palette data.
|
|
|
|
; Palette entries for BG3 start at 0.
|
|
|
|
; TODO(mcmillen): BG2 started at 32, but maybe that's only in mode 0?
|
2015-05-24 17:22:42 +00:00
|
|
|
ldx #0
|
2015-05-24 23:50:10 +00:00
|
|
|
lda #0
|
2015-05-24 17:22:42 +00:00
|
|
|
sta CGADDR
|
|
|
|
-
|
|
|
|
lda.l TilePalette, X
|
|
|
|
sta CGDATA
|
|
|
|
inx
|
|
|
|
cpx #8 ; 8 bytes of palette data.
|
|
|
|
bne -
|
|
|
|
|
|
|
|
; TODO(mcmillen): make the "DMA stuff into VRAM" a macro or function.
|
|
|
|
; Set VMADDR to where we want the DMA to start. We'll store sprite data
|
|
|
|
; at the beginning of VRAM.
|
|
|
|
ldx #$0000
|
|
|
|
stx VMADDR
|
2015-05-23 18:00:43 +00:00
|
|
|
; DMA 0 source address & bank.
|
2015-05-24 14:43:25 +00:00
|
|
|
ldx #SpriteData
|
2015-05-23 18:00:43 +00:00
|
|
|
stx DMA0SRC
|
2015-05-24 14:43:25 +00:00
|
|
|
lda #:SpriteData
|
2015-05-23 18:00:43 +00:00
|
|
|
sta DMA0SRCBANK
|
2015-05-25 13:42:54 +00:00
|
|
|
; DMA 0 transfer size. Equal to the size of sprites32.pic.
|
|
|
|
ldx #2048
|
2015-05-24 14:43:25 +00:00
|
|
|
stx DMA0SIZE
|
2015-05-23 18:00:43 +00:00
|
|
|
; DMA 0 control register.
|
|
|
|
; Transfer type 001 = 2 addresses, LH.
|
|
|
|
lda #%00000001
|
|
|
|
sta DMA0CTRL
|
|
|
|
; DMA 0 destination.
|
2015-05-24 17:22:42 +00:00
|
|
|
lda #$18 ; The upper byte is assumed to be $21, so this is $2118 & $2119.
|
2015-05-23 18:00:43 +00:00
|
|
|
sta DMA0DST
|
2015-05-24 17:22:42 +00:00
|
|
|
; Enable DMA channel 0.
|
|
|
|
lda #%00000001
|
|
|
|
sta DMAENABLE
|
|
|
|
|
|
|
|
; Store background tile data at byte $2000 of VRAM.
|
|
|
|
; (VMADDR is a word address, so multiply by 2 to get the byte address.)
|
|
|
|
ldx #$1000
|
2015-05-24 14:43:25 +00:00
|
|
|
stx VMADDR
|
2015-05-24 17:22:42 +00:00
|
|
|
; DMA 0 source address & bank.
|
|
|
|
ldx #TileData
|
|
|
|
stx DMA0SRC
|
|
|
|
lda #:TileData
|
|
|
|
sta DMA0SRCBANK
|
2015-05-25 13:42:54 +00:00
|
|
|
; DMA 0 transfer size. Equal to the size of tiles.pic.
|
|
|
|
ldx #512
|
2015-05-24 17:22:42 +00:00
|
|
|
stx DMA0SIZE
|
|
|
|
; DMA 0 control register.
|
|
|
|
; Transfer type 001 = 2 addresses, LH.
|
|
|
|
lda #%00000001
|
|
|
|
sta DMA0CTRL
|
|
|
|
; DMA 0 destination.
|
|
|
|
lda #$18 ; The upper byte is assumed to be $21, so this is $2118 & $2119.
|
|
|
|
sta DMA0DST
|
2015-05-23 18:00:43 +00:00
|
|
|
; Enable DMA channel 0.
|
|
|
|
lda #%00000001
|
|
|
|
sta DMAENABLE
|
|
|
|
|
2015-05-24 23:50:10 +00:00
|
|
|
; Tell the system that the BG3 tilemap starts at $4000.
|
2015-05-24 18:44:26 +00:00
|
|
|
lda #%00100000
|
2015-05-24 23:50:10 +00:00
|
|
|
sta BG3TILEMAP
|
|
|
|
; ... and that the background tile data for BG3 starts at $2000.
|
|
|
|
lda #%00000001
|
|
|
|
sta BG34NBA
|
2015-05-24 18:44:26 +00:00
|
|
|
|
2015-05-24 23:50:10 +00:00
|
|
|
; Set up the BG3 tilemap.
|
2015-05-24 17:22:42 +00:00
|
|
|
; VRAM write mode: increments the address every time we write a word.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda #%10000000
|
|
|
|
sta VMAIN
|
2015-05-24 17:22:42 +00:00
|
|
|
; Set word address for accessing VRAM.
|
2015-05-24 23:50:10 +00:00
|
|
|
ldx #$2000 ; BG 3 tilemap starts here. (Byte address $4000.)
|
2015-05-23 18:00:43 +00:00
|
|
|
stx VMADDR
|
2015-05-24 17:22:42 +00:00
|
|
|
; Now write entries into the tile map.
|
|
|
|
ldy #0
|
|
|
|
-
|
2015-05-25 12:04:15 +00:00
|
|
|
GetRandomByte
|
|
|
|
sta $00
|
|
|
|
ldx #$0000 ; This is a blank tile.
|
|
|
|
; 1 in 8 chance that we choose a non-blank tile.
|
|
|
|
and #%00000111
|
|
|
|
cmp #%00000111
|
|
|
|
bne +
|
2015-05-24 23:50:10 +00:00
|
|
|
ldx #$0002
|
2015-05-25 12:04:15 +00:00
|
|
|
lda $00
|
|
|
|
and #%10000000
|
|
|
|
cmp #%10000000
|
|
|
|
bne +
|
|
|
|
ldx #$8002 ; Flip vertically.
|
|
|
|
+
|
2015-05-24 18:44:26 +00:00
|
|
|
stx VMDATA
|
|
|
|
iny
|
|
|
|
; The tile map is 32x32 (1024 entries).
|
2015-05-25 12:04:15 +00:00
|
|
|
cpy #1024
|
2015-05-24 17:22:42 +00:00
|
|
|
bne -
|
2015-05-23 18:00:43 +00:00
|
|
|
|
2015-05-24 14:43:25 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InitializeSpriteTables:
|
|
|
|
; This page is a good reference on SNES sprite formats:
|
|
|
|
; http://wiki.superfamicom.org/snes/show/SNES+Sprites
|
|
|
|
; It uses the same approach we're using, in which we keep a buffer of the
|
|
|
|
; sprite tables in RAM, and DMA the sprite tables to the system's OAM
|
|
|
|
; during VBlank.
|
|
|
|
rep #%00110000 ; 16-bit A/X/Y.
|
|
|
|
|
|
|
|
ldx #$0000
|
|
|
|
; Fill sprite table 1. 4 bytes per sprite, laid out as follows:
|
|
|
|
; Byte 1: xxxxxxxx x: X coordinate
|
|
|
|
; Byte 2: yyyyyyyy y: Y coordinate
|
|
|
|
; Byte 3: cccccccc c: Starting tile #
|
|
|
|
; Byte 4: vhoopppc v: vertical flip h: horizontal flip o: priority bits
|
|
|
|
; p: palette #
|
|
|
|
lda #$01
|
|
|
|
-
|
|
|
|
sta $0100, X ; We keep our sprite table at $0100 and DMA it to OAM later.
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
cpx #$0200
|
|
|
|
bne -
|
|
|
|
|
|
|
|
; Fill sprite table 2. 2 bits per sprite, like so:
|
2015-05-24 17:22:42 +00:00
|
|
|
; bits 0,2,4,6 - High bit of the sprite's x-coordinate.
|
2015-05-24 14:43:25 +00:00
|
|
|
; bits 1,3,5,7 - Toggle Sprite size: 0 - small size 1 - large size
|
2015-05-24 17:22:42 +00:00
|
|
|
; Setting all the high bits keeps the sprites offscreen.
|
2015-05-24 14:43:25 +00:00
|
|
|
lda #%0101010101010101
|
|
|
|
-
|
|
|
|
sta $0100, X
|
|
|
|
inx
|
|
|
|
inx
|
|
|
|
cpx #$0220
|
|
|
|
bne -
|
2015-05-23 18:00:43 +00:00
|
|
|
|
2015-05-24 14:43:25 +00:00
|
|
|
sep #%00100000 ; 8-bit A.
|
2015-05-23 18:00:43 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
VBlankHandler:
|
|
|
|
jsr VBlankCounter ; DEBUG
|
|
|
|
jsr JoypadHandler
|
|
|
|
jsr SetBackgroundColor
|
2015-05-24 17:22:42 +00:00
|
|
|
jsr UpdateGraphics
|
2015-05-24 14:43:25 +00:00
|
|
|
jsr DMASpriteTables
|
2015-05-22 16:49:40 +00:00
|
|
|
rti
|
|
|
|
|
|
|
|
|
2015-05-22 17:34:37 +00:00
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
VBlankCounter:
|
2015-05-22 17:34:37 +00:00
|
|
|
; Increment a counter of how many VBlanks we've done.
|
2015-05-22 16:49:40 +00:00
|
|
|
inc $14
|
|
|
|
lda $14
|
|
|
|
cmp #$00
|
|
|
|
bne VBlankCounterDone
|
|
|
|
inc $15
|
|
|
|
lda $15
|
|
|
|
cmp #$00
|
|
|
|
bne VBlankCounterDone
|
|
|
|
inc $16
|
|
|
|
lda $16
|
|
|
|
cmp #$00
|
|
|
|
bne VBlankCounterDone
|
|
|
|
inc $17
|
|
|
|
VBlankCounterDone:
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
2015-05-22 17:34:37 +00:00
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
JoypadHandler:
|
|
|
|
jsr JoypadDebug ; DEBUG
|
|
|
|
|
|
|
|
JoypadUp:
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1H
|
2015-05-22 16:49:40 +00:00
|
|
|
and #$08 ; Up
|
|
|
|
cmp #$08
|
|
|
|
bne JoypadDown ; Button not pressed.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $21
|
|
|
|
cmp #0
|
2015-05-22 16:49:40 +00:00
|
|
|
beq JoypadDown ; Value saturated.
|
2015-05-23 18:00:43 +00:00
|
|
|
dec $21
|
|
|
|
dec $21
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
JoypadDown:
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1H
|
|
|
|
and #$04
|
2015-05-22 16:49:40 +00:00
|
|
|
cmp #$04
|
|
|
|
bne JoypadLeft ; Button not pressed.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $21
|
2015-05-25 13:42:54 +00:00
|
|
|
cmp #(224 - 32)
|
2015-05-22 16:49:40 +00:00
|
|
|
beq JoypadLeft ; Value saturated.
|
2015-05-23 18:00:43 +00:00
|
|
|
inc $21
|
|
|
|
inc $21
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
JoypadLeft:
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1H
|
2015-05-22 16:49:40 +00:00
|
|
|
and #$02 ; Left
|
|
|
|
cmp #$02
|
|
|
|
bne JoypadRight ; Button not pressed.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $20
|
2015-05-22 16:49:40 +00:00
|
|
|
cmp #0
|
|
|
|
beq JoypadRight ; Value saturated.
|
2015-05-23 18:00:43 +00:00
|
|
|
dec $20
|
|
|
|
dec $20
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
JoypadRight:
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1H
|
2015-05-22 16:49:40 +00:00
|
|
|
and #$01
|
|
|
|
cmp #$01 ; Right
|
|
|
|
bne JoypadB ; Button not pressed.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $20
|
2015-05-25 13:42:54 +00:00
|
|
|
cmp #(256 - 32)
|
2015-05-22 16:49:40 +00:00
|
|
|
beq JoypadB ; Value saturated.
|
2015-05-23 18:00:43 +00:00
|
|
|
inc $20
|
|
|
|
inc $20
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
JoypadB:
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1H
|
2015-05-22 16:49:40 +00:00
|
|
|
and #$80 ; B
|
|
|
|
cmp #$80
|
2015-05-23 18:00:43 +00:00
|
|
|
bne JoypadA ; Button not pressed.
|
|
|
|
lda $22
|
|
|
|
cmp #0
|
|
|
|
beq JoypadA ; Value saturated.
|
|
|
|
dec $22
|
|
|
|
|
|
|
|
JoypadA:
|
|
|
|
lda JOY1L
|
|
|
|
and #$80 ; A
|
|
|
|
cmp #$80
|
2015-05-22 16:49:40 +00:00
|
|
|
bne JoypadY ; Button not pressed.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $22
|
2015-05-22 16:49:40 +00:00
|
|
|
cmp #31
|
|
|
|
beq JoypadY ; Value saturated.
|
2015-05-23 18:00:43 +00:00
|
|
|
inc $22
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
JoypadY:
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1H
|
2015-05-22 16:49:40 +00:00
|
|
|
and #$40 ; Y
|
|
|
|
cmp #$40
|
2015-05-23 18:00:43 +00:00
|
|
|
bne JoypadX ; Button not pressed.
|
|
|
|
lda $23
|
|
|
|
cmp #0
|
|
|
|
beq JoypadX ; Value saturated.
|
|
|
|
dec $23
|
|
|
|
|
|
|
|
JoypadX:
|
|
|
|
lda JOY1L
|
|
|
|
and #$40 ; X
|
|
|
|
cmp #$40
|
|
|
|
bne JoypadL ; Button not pressed.
|
|
|
|
lda $23
|
|
|
|
cmp #31
|
|
|
|
beq JoypadL ; Value saturated.
|
|
|
|
inc $23
|
|
|
|
|
|
|
|
JoypadL:
|
|
|
|
lda JOY1L
|
|
|
|
and #$20 ; L
|
|
|
|
cmp #$20
|
|
|
|
bne JoypadR ; Button not pressed.
|
|
|
|
lda $24
|
2015-05-22 16:49:40 +00:00
|
|
|
cmp #0
|
2015-05-23 18:00:43 +00:00
|
|
|
beq JoypadR ; Value saturated.
|
|
|
|
dec $24
|
|
|
|
|
|
|
|
JoypadR:
|
|
|
|
lda JOY1L
|
|
|
|
and #$10 ; R
|
|
|
|
cmp #$10
|
|
|
|
bne JoypadDone ; Button not pressed.
|
|
|
|
lda $24
|
|
|
|
cmp #31
|
2015-05-22 19:09:14 +00:00
|
|
|
beq JoypadDone ; Value saturated.
|
2015-05-23 18:00:43 +00:00
|
|
|
inc $24
|
|
|
|
|
|
|
|
; TODO(mcmillen): have Start and Select do something too.
|
2015-05-22 16:49:40 +00:00
|
|
|
|
|
|
|
JoypadDone:
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
2015-05-22 17:34:37 +00:00
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
JoypadDebug:
|
|
|
|
; Load joypad registers into RAM for easier inspection.
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1L
|
2015-05-22 16:49:40 +00:00
|
|
|
sta $10
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY1H
|
2015-05-22 16:49:40 +00:00
|
|
|
sta $11
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY2L
|
2015-05-22 16:49:40 +00:00
|
|
|
sta $12
|
2015-05-22 23:39:43 +00:00
|
|
|
lda JOY2H
|
2015-05-22 16:49:40 +00:00
|
|
|
sta $13
|
|
|
|
rts
|
|
|
|
|
|
|
|
|
2015-05-22 17:34:37 +00:00
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
SetBackgroundColor:
|
2015-05-23 18:00:43 +00:00
|
|
|
; $22 $23 $24 are (R, G, B), each ranging from [0-31].
|
2015-05-22 17:34:37 +00:00
|
|
|
; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr]
|
|
|
|
|
2015-05-23 18:00:43 +00:00
|
|
|
; Set the background color.
|
|
|
|
; Entry 0 corresponds to the SNES background color.
|
|
|
|
stz CGADDR
|
|
|
|
|
2015-05-22 19:09:14 +00:00
|
|
|
; Compute and the low-order byte and store it in CGDATA.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $23 ; Green.
|
2015-05-22 17:34:37 +00:00
|
|
|
.rept 5
|
|
|
|
asl
|
|
|
|
.endr
|
2015-05-23 18:00:43 +00:00
|
|
|
ora $22 ; Red.
|
2015-05-22 23:39:43 +00:00
|
|
|
sta CGDATA
|
2015-05-22 17:34:37 +00:00
|
|
|
|
2015-05-22 19:09:14 +00:00
|
|
|
; Compute the high-order byte and store it in CGDATA.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $24 ; Blue.
|
2015-05-22 17:34:37 +00:00
|
|
|
.rept 2
|
|
|
|
asl
|
|
|
|
.endr
|
2015-05-22 16:49:40 +00:00
|
|
|
sta $00
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $23 ; Green.
|
2015-05-22 17:34:37 +00:00
|
|
|
.rept 3
|
|
|
|
lsr
|
|
|
|
.endr
|
2015-05-22 16:49:40 +00:00
|
|
|
ora $00
|
2015-05-22 23:39:43 +00:00
|
|
|
sta CGDATA
|
2015-05-23 18:00:43 +00:00
|
|
|
rts
|
2015-05-22 19:09:14 +00:00
|
|
|
|
2015-05-23 18:00:43 +00:00
|
|
|
|
|
|
|
|
2015-05-24 17:22:42 +00:00
|
|
|
UpdateGraphics:
|
2015-05-24 14:43:25 +00:00
|
|
|
; Copy player coords into sprite table.
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $0020
|
2015-05-24 14:43:25 +00:00
|
|
|
sta $0100
|
2015-05-23 18:00:43 +00:00
|
|
|
lda $0021
|
2015-05-24 14:43:25 +00:00
|
|
|
sta $0101
|
2015-05-24 23:50:10 +00:00
|
|
|
; Choose which sprite based on frame count.
|
2015-05-24 17:22:42 +00:00
|
|
|
; Set priority bits so that the sprite is drawn in front.
|
|
|
|
lda #%00110000
|
|
|
|
sta $0103
|
2015-05-24 14:43:25 +00:00
|
|
|
; Clear x-MSB so that the sprite is displayed.
|
|
|
|
lda $0300
|
|
|
|
and #%11111110
|
2015-05-25 13:42:54 +00:00
|
|
|
ora #%00000010 ; ... and make it the large size. (32x32)
|
2015-05-24 14:43:25 +00:00
|
|
|
sta $0300
|
2015-05-24 17:22:42 +00:00
|
|
|
|
2015-05-24 18:44:26 +00:00
|
|
|
; Make the background scroll. Horizontal over time; vertical depending on
|
|
|
|
; player's y-coordinate.
|
2015-05-24 17:22:42 +00:00
|
|
|
lda $14
|
2015-05-24 23:50:10 +00:00
|
|
|
sta BG3HOFS
|
2015-05-24 17:22:42 +00:00
|
|
|
lda $15
|
2015-05-24 23:50:10 +00:00
|
|
|
sta BG3HOFS
|
2015-05-24 18:44:26 +00:00
|
|
|
lda $21
|
|
|
|
.rept 3
|
|
|
|
lsr
|
|
|
|
.endr
|
2015-05-24 23:50:10 +00:00
|
|
|
sta BG3VOFS
|
|
|
|
stz BG3VOFS
|
2015-05-24 17:22:42 +00:00
|
|
|
|
2015-05-24 14:43:25 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DMASpriteTables:
|
|
|
|
rep #%00010000 ; 16-bit X/Y.
|
|
|
|
sep #%00100000 ; 8-bit A.
|
|
|
|
; Store at the base OAM address.
|
|
|
|
ldx #$0000
|
|
|
|
stx OAMADDR
|
|
|
|
; Default DMA control; destination $2104 (OAM data register).
|
|
|
|
stz DMA0CTRL
|
|
|
|
lda #$04
|
|
|
|
sta DMA0DST
|
|
|
|
; Our sprites start at $0100 in bank 0 and are #$220 bytes long.
|
|
|
|
ldx #$0100
|
|
|
|
stx DMA0SRC
|
|
|
|
stz DMA0SRCBANK
|
|
|
|
ldx #$0220
|
|
|
|
stx DMA0SIZE
|
|
|
|
; Kick off the DMA transfer.
|
|
|
|
lda #%00000001
|
|
|
|
sta DMAENABLE
|
2015-05-22 16:49:40 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
2015-05-22 17:34:37 +00:00
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
FillScratch:
|
2015-05-24 14:43:25 +00:00
|
|
|
lda #$42 ; ASCII "B"
|
2015-05-22 16:49:40 +00:00
|
|
|
ldx #0
|
2015-05-24 14:43:25 +00:00
|
|
|
-
|
|
|
|
sta $00, X
|
2015-05-22 16:49:40 +00:00
|
|
|
inx
|
|
|
|
cpx #$10
|
2015-05-24 14:43:25 +00:00
|
|
|
bne -
|
2015-05-22 16:49:40 +00:00
|
|
|
rts
|
|
|
|
|
2015-05-24 14:43:25 +00:00
|
|
|
|
2015-05-22 16:49:40 +00:00
|
|
|
.ENDS
|
2015-05-23 18:00:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-25 12:04:15 +00:00
|
|
|
; Bank 1 is used for our graphics assets.
|
2015-05-23 18:00:43 +00:00
|
|
|
.BANK 1 SLOT 0
|
|
|
|
.ORG 0
|
2015-05-25 12:04:15 +00:00
|
|
|
.SECTION "GraphicsData"
|
2015-05-25 13:42:54 +00:00
|
|
|
|
|
|
|
SpriteData:
|
|
|
|
.INCBIN "sprites32.pic"
|
|
|
|
SpritePalette:
|
|
|
|
.INCBIN "sprites32.clr"
|
|
|
|
|
|
|
|
TileData:
|
|
|
|
.INCBIN "tiles.pic"
|
|
|
|
TilePalette:
|
|
|
|
.INCBIN "tiles.clr"
|
|
|
|
|
2015-05-23 19:38:27 +00:00
|
|
|
.ENDS
|
2015-05-24 17:22:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-25 12:04:15 +00:00
|
|
|
; Fill an entire bank with random numbers.
|
|
|
|
.SEED 1
|
2015-05-24 17:22:42 +00:00
|
|
|
.BANK 2 SLOT 0
|
|
|
|
.ORG 0
|
2015-05-25 12:04:15 +00:00
|
|
|
.SECTION "RandomBytes"
|
|
|
|
.DBRND 32 * 1024, 0, 255
|
|
|
|
.ENDS
|