Reformat main file.
Mostly moved stuff around so that it's in a more sensible order.
This commit is contained in:
parent
1319e4f52d
commit
7b6cd3f583
191
pewpew.asm
191
pewpew.asm
@ -30,7 +30,7 @@
|
|||||||
; 0000-000F: scratch space for functions.
|
; 0000-000F: scratch space for functions.
|
||||||
; 0010-0011: controller state of joypad #1.
|
; 0010-0011: controller state of joypad #1.
|
||||||
; 0012-0013: controller state of joypad #2.
|
; 0012-0013: controller state of joypad #2.
|
||||||
; 0014-0017: 32-bit counter of vblanks.
|
; 0014-0016: 24-bit counter of vblanks.
|
||||||
; 0018-0019: 16-bit pointer to next random byte.
|
; 0018-0019: 16-bit pointer to next random byte.
|
||||||
; 0020-0021: (x, y) coordinates of player.
|
; 0020-0021: (x, y) coordinates of player.
|
||||||
; 0022-0024: RGB color values to use for background color, from [0-31].
|
; 0022-0024: RGB color values to use for background color, from [0-31].
|
||||||
@ -45,8 +45,15 @@
|
|||||||
Start:
|
Start:
|
||||||
InitializeSNES
|
InitializeSNES
|
||||||
|
|
||||||
|
; Store zeroes to the controller status registers.
|
||||||
|
; TODO(mcmillen): is this needed? I think the system will overwrite these
|
||||||
|
; automatically.
|
||||||
|
stz JOY1H
|
||||||
|
stz JOY1L
|
||||||
|
|
||||||
jsr LoadPaletteAndTileData
|
jsr LoadPaletteAndTileData
|
||||||
jsr InitializeSpriteTables
|
jsr InitializeSpriteTables
|
||||||
|
jsr InitializeWorld
|
||||||
|
|
||||||
; Set screen mode: 16x16 tiles for backgrounds, mode 1.
|
; Set screen mode: 16x16 tiles for backgrounds, mode 1.
|
||||||
lda #%11000001
|
lda #%11000001
|
||||||
@ -72,29 +79,6 @@ Start:
|
|||||||
lda #%10000001
|
lda #%10000001
|
||||||
sta NMITIMEN
|
sta NMITIMEN
|
||||||
|
|
||||||
; Store zeroes to the controller status registers.
|
|
||||||
; TODO(mcmillen): is this needed? I think the system will overwrite these
|
|
||||||
; automatically.
|
|
||||||
stz JOY1H
|
|
||||||
stz JOY1L
|
|
||||||
|
|
||||||
; Start the background color as a dark blue.
|
|
||||||
lda #4
|
|
||||||
sta $24
|
|
||||||
|
|
||||||
; Player's initial starting location.
|
|
||||||
lda #(256 / 4)
|
|
||||||
sta $20
|
|
||||||
lda #((224 - 32) / 2)
|
|
||||||
sta $21
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MainLoop:
|
|
||||||
wai ; Wait for interrupt.
|
|
||||||
jsr JoypadHandler
|
|
||||||
jsr SetBackgroundColor
|
|
||||||
jsr UpdateGraphics
|
|
||||||
jmp MainLoop
|
jmp MainLoop
|
||||||
|
|
||||||
|
|
||||||
@ -277,35 +261,45 @@ InitializeSpriteTables:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
VBlankHandler:
|
InitializeWorld:
|
||||||
jsr VBlankCounter
|
; Start the background color as a dark blue.
|
||||||
jsr DMASpriteTables
|
lda #4
|
||||||
rti
|
sta $24
|
||||||
|
|
||||||
|
; Player's initial starting location.
|
||||||
|
lda #(256 / 4)
|
||||||
|
sta $20
|
||||||
|
lda #((224 - 32) / 2)
|
||||||
|
sta $21
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
VBlankCounter:
|
MainLoop:
|
||||||
; Increment a counter of how many VBlanks we've done.
|
wai ; Wait for interrupt.
|
||||||
inc $14
|
jsr JoypadDebug
|
||||||
lda $14
|
jsr JoypadHandler
|
||||||
cmp #$00
|
jsr UpdateWorld
|
||||||
bne VBlankCounterDone
|
jsr SetBackgroundColor
|
||||||
inc $15
|
jmp MainLoop
|
||||||
lda $15
|
|
||||||
cmp #$00
|
|
||||||
bne VBlankCounterDone
|
|
||||||
inc $16
|
JoypadDebug:
|
||||||
lda $16
|
; Load joypad registers into RAM for easier inspection.
|
||||||
cmp #$00
|
lda JOY1L
|
||||||
bne VBlankCounterDone
|
sta $10
|
||||||
inc $17
|
lda JOY1H
|
||||||
VBlankCounterDone:
|
sta $11
|
||||||
|
lda JOY2L
|
||||||
|
sta $12
|
||||||
|
lda JOY2H
|
||||||
|
sta $13
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JoypadHandler:
|
JoypadHandler:
|
||||||
jsr JoypadDebug ; DEBUG
|
|
||||||
|
|
||||||
JoypadUp:
|
JoypadUp:
|
||||||
lda JOY1H
|
lda JOY1H
|
||||||
@ -413,7 +407,7 @@ JoypadR:
|
|||||||
|
|
||||||
JoypadB:
|
JoypadB:
|
||||||
lda JOY1H
|
lda JOY1H
|
||||||
and #$80 ; Start.
|
and #$80 ; B
|
||||||
cmp #$80
|
cmp #$80
|
||||||
bne JoypadDone
|
bne JoypadDone
|
||||||
jsr MaybeShoot
|
jsr MaybeShoot
|
||||||
@ -423,20 +417,6 @@ JoypadDone:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
JoypadDebug:
|
|
||||||
; Load joypad registers into RAM for easier inspection.
|
|
||||||
lda JOY1L
|
|
||||||
sta $10
|
|
||||||
lda JOY1H
|
|
||||||
sta $11
|
|
||||||
lda JOY2L
|
|
||||||
sta $12
|
|
||||||
lda JOY2H
|
|
||||||
sta $13
|
|
||||||
rts
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MaybeShoot:
|
MaybeShoot:
|
||||||
; If the cooldown timer is non-zero, don't shoot.
|
; If the cooldown timer is non-zero, don't shoot.
|
||||||
lda $25
|
lda $25
|
||||||
@ -457,39 +437,7 @@ MaybeShoot:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
SetBackgroundColor:
|
UpdateWorld:
|
||||||
; $22 $23 $24 are (R, G, B), each ranging from [0-31].
|
|
||||||
; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr]
|
|
||||||
|
|
||||||
; Set the background color.
|
|
||||||
; Entry 0 corresponds to the SNES background color.
|
|
||||||
stz CGADDR
|
|
||||||
|
|
||||||
; Compute and the low-order byte and store it in CGDATA.
|
|
||||||
lda $23 ; Green.
|
|
||||||
.rept 5
|
|
||||||
asl
|
|
||||||
.endr
|
|
||||||
ora $22 ; Red.
|
|
||||||
sta CGDATA
|
|
||||||
|
|
||||||
; Compute the high-order byte and store it in CGDATA.
|
|
||||||
lda $24 ; Blue.
|
|
||||||
.rept 2
|
|
||||||
asl
|
|
||||||
.endr
|
|
||||||
sta $00
|
|
||||||
lda $23 ; Green.
|
|
||||||
.rept 3
|
|
||||||
lsr
|
|
||||||
.endr
|
|
||||||
ora $00
|
|
||||||
sta CGDATA
|
|
||||||
rts
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
UpdateGraphics:
|
|
||||||
; Update shot cooldown.
|
; Update shot cooldown.
|
||||||
lda $0025
|
lda $0025
|
||||||
cmp #0
|
cmp #0
|
||||||
@ -576,6 +524,63 @@ ShotDone:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SetBackgroundColor:
|
||||||
|
; $22 $23 $24 are (R, G, B), each ranging from [0-31].
|
||||||
|
; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr]
|
||||||
|
|
||||||
|
; Set the background color.
|
||||||
|
; Entry 0 corresponds to the SNES background color.
|
||||||
|
stz CGADDR
|
||||||
|
|
||||||
|
; Compute and the low-order byte and store it in CGDATA.
|
||||||
|
lda $23 ; Green.
|
||||||
|
.rept 5
|
||||||
|
asl
|
||||||
|
.endr
|
||||||
|
ora $22 ; Red.
|
||||||
|
sta CGDATA
|
||||||
|
|
||||||
|
; Compute the high-order byte and store it in CGDATA.
|
||||||
|
lda $24 ; Blue.
|
||||||
|
.rept 2
|
||||||
|
asl
|
||||||
|
.endr
|
||||||
|
sta $00
|
||||||
|
lda $23 ; Green.
|
||||||
|
.rept 3
|
||||||
|
lsr
|
||||||
|
.endr
|
||||||
|
ora $00
|
||||||
|
sta CGDATA
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
VBlankHandler:
|
||||||
|
jsr VBlankCounter
|
||||||
|
jsr DMASpriteTables
|
||||||
|
rti
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
VBlankCounter:
|
||||||
|
; Increment a counter of how many VBlanks we've done.
|
||||||
|
; This is a 24-bit counter. At 60 vblanks/second, this will take over
|
||||||
|
; 77 hours to wrap around; that's good enough for me :)
|
||||||
|
inc $14
|
||||||
|
lda $14
|
||||||
|
cmp #$00
|
||||||
|
bne VBlankCounterDone
|
||||||
|
inc $15
|
||||||
|
lda $15
|
||||||
|
cmp #$00
|
||||||
|
bne VBlankCounterDone
|
||||||
|
inc $16
|
||||||
|
VBlankCounterDone:
|
||||||
|
rts
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DMASpriteTables:
|
DMASpriteTables:
|
||||||
rep #%00010000 ; 16-bit X/Y.
|
rep #%00010000 ; 16-bit X/Y.
|
||||||
sep #%00100000 ; 8-bit A.
|
sep #%00100000 ; 8-bit A.
|
||||||
|
Loading…
Reference in New Issue
Block a user