Add the ability to shoot with the B button.

Forgot to update the main file.
This commit is contained in:
Colin McMillen 2015-05-25 12:07:08 -04:00
parent 782db84d48
commit 1319e4f52d

View File

@ -34,6 +34,8 @@
; 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].
; 0025: shot cooldown timer.
; 0030-0032: enable / x / y of shot.
; ;
; Sprite table buffers -- copied each frame to OAM during VBlank, using DMA. ; 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) ; 0100-02FF: table 1 (4 bytes each: x/y coord, tile #, flip/priority/palette)
@ -76,9 +78,6 @@ Start:
stz JOY1H stz JOY1H
stz JOY1L stz JOY1L
; Write something recognizable into our scratch space.
jsr FillScratch
; Start the background color as a dark blue. ; Start the background color as a dark blue.
lda #4 lda #4
sta $24 sta $24
@ -86,13 +85,16 @@ Start:
; Player's initial starting location. ; Player's initial starting location.
lda #(256 / 4) lda #(256 / 4)
sta $20 sta $20
lda #((224 - 16) / 2) lda #((224 - 32) / 2)
sta $21 sta $21
MainLoop: MainLoop:
wai ; Wait for interrupt. wai ; Wait for interrupt.
jsr JoypadHandler
jsr SetBackgroundColor
jsr UpdateGraphics
jmp MainLoop jmp MainLoop
@ -276,10 +278,7 @@ InitializeSpriteTables:
VBlankHandler: VBlankHandler:
jsr VBlankCounter ; DEBUG jsr VBlankCounter
jsr JoypadHandler
jsr SetBackgroundColor
jsr UpdateGraphics
jsr DMASpriteTables jsr DMASpriteTables
rti rti
@ -345,27 +344,27 @@ JoypadRight:
lda JOY1H lda JOY1H
and #$01 and #$01
cmp #$01 ; Right cmp #$01 ; Right
bne JoypadB ; Button not pressed. bne JoypadStart ; Button not pressed.
lda $20 lda $20
cmp #(256 - 32) cmp #(256 - 32)
beq JoypadB ; Value saturated. beq JoypadStart ; Value saturated.
inc $20 inc $20
inc $20 inc $20
JoypadB: JoypadStart:
lda JOY1H lda JOY1H
and #$80 ; B and #$10 ; Start
cmp #$80 cmp #$10
bne JoypadA ; Button not pressed. bne JoypadSelect ; Button not pressed.
lda $22 lda $22
cmp #0 cmp #0
beq JoypadA ; Value saturated. beq JoypadSelect ; Value saturated.
dec $22 dec $22
JoypadA: JoypadSelect:
lda JOY1L lda JOY1H
and #$80 ; A and #$20 ; Select
cmp #$80 cmp #$20
bne JoypadY ; Button not pressed. bne JoypadY ; Button not pressed.
lda $22 lda $22
cmp #31 cmp #31
@ -406,13 +405,18 @@ JoypadR:
lda JOY1L lda JOY1L
and #$10 ; R and #$10 ; R
cmp #$10 cmp #$10
bne JoypadDone ; Button not pressed. bne JoypadB ; Button not pressed.
lda $24 lda $24
cmp #31 cmp #31
beq JoypadDone ; Value saturated. beq JoypadB ; Value saturated.
inc $24 inc $24
; TODO(mcmillen): have Start and Select do something too. JoypadB:
lda JOY1H
and #$80 ; Start.
cmp #$80
bne JoypadDone
jsr MaybeShoot
JoypadDone: JoypadDone:
rts rts
@ -433,6 +437,26 @@ JoypadDebug:
MaybeShoot:
; If the cooldown timer is non-zero, don't shoot.
lda $25
cmp #0
bne +
; Enable shot; set its position to player position.
lda #1
sta $30
lda $20
sta $31
lda $21
sta $32
; Set cooldown timer.
lda #16
sta $25
+
rts
SetBackgroundColor: SetBackgroundColor:
; $22 $23 $24 are (R, G, B), each ranging from [0-31]. ; $22 $23 $24 are (R, G, B), each ranging from [0-31].
; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr] ; The palette color format is 15-bit: [0bbbbbgg][gggrrrrr]
@ -466,12 +490,22 @@ SetBackgroundColor:
UpdateGraphics: UpdateGraphics:
; Update shot cooldown.
lda $0025
cmp #0
beq +
dea
sta $0025
+
; Copy player coords into sprite table. ; Copy player coords into sprite table.
lda $0020 lda $0020
sta $0100 sta $0100
lda $0021 lda $0021
sta $0101 sta $0101
; Choose which sprite based on frame count. ; Set the sprite.
lda #0
sta $0102
; Set priority bits so that the sprite is drawn in front. ; Set priority bits so that the sprite is drawn in front.
lda #%00110000 lda #%00110000
sta $0103 sta $0103
@ -481,6 +515,50 @@ UpdateGraphics:
ora #%00000010 ; ... and make it the large size. (32x32) ora #%00000010 ; ... and make it the large size. (32x32)
sta $0300 sta $0300
; Move shot coords.
ldx $0
lda $30
cmp #1
bne DisableShot
lda $31
; TODO(mcmillen): do this with an add, then check the carry bit?
.rept 6
ina
cmp #$00 ; If it wraps around, disable it.
bne +
stz $30
+
.endr
sta $0031 ; Store new x-coord.
; See if sprite is still enabled after move.
lda $0030
cmp #1
bne DisableShot
; Set up shot sprite.
lda $0031 ; x
sta $0104
lda $0032 ; y
sta $0105
lda #8 ; which sprite
sta $0106
lda $0300
and #%11111011 ; Display it.
ora #%00001000 ; and set it to large size.
sta $0300
jmp ShotDone
DisableShot:
; Disable it by setting x-position to zero and setting the high x-bit.
stz $104
lda $0300
ora #%00000100
sta $0300
ShotDone:
; Make the background scroll. Horizontal over time; vertical depending on ; Make the background scroll. Horizontal over time; vertical depending on
; player's y-coordinate. ; player's y-coordinate.
lda $14 lda $14
@ -521,17 +599,6 @@ DMASpriteTables:
FillScratch:
lda #$42 ; ASCII "B"
ldx #0
-
sta $00, X
inx
cpx #$10
bne -
rts
.ENDS .ENDS