fish: hook up score code

was more of a pain than you'd think.  have to be careful reusing
sprite code
This commit is contained in:
Vince Weaver 2024-06-11 16:21:49 -04:00
parent cc0a348394
commit 524717f987
6 changed files with 301 additions and 26 deletions

View File

@ -19,6 +19,8 @@ fish.o: fish.s zx02_optim.s \
graphics/fish_sprites.inc \
sounds/fish.btc.zx02 \
sounds/get_in_boat.btc.zx02 \
hgr_sprite.s \
hgr_sprite_mask.s \
hgr_sprite_big.s \
audio.s play_sounds.s \
zp.inc hardware.inc

View File

@ -216,6 +216,12 @@ load_background:
sta HGR_PAGE
jsr hgr_make_tables
; testing
lda #$12
sta SCORE_L
lda #$78
sta SCORE_H
; start at least 8k in?
@ -229,24 +235,16 @@ main_loop:
jsr flip_page
.if 0
;========================
; copy over background
;========================
reset_loop:
; draw the scene
;========================
;========================
lda FRAME
and #$2
beq odd_bg
even_bg:
lda #$A0
bne do_bg
odd_bg:
lda #$80
do_bg:
jsr hgr_copy
.endif
;==================================
; copy over (erase) old background
lda #<bg_data
sta ZX0_src
@ -262,8 +260,7 @@ do_bg:
inc FRAME
;==========================
; copy over proper boat
;==========================
; draw boat
lda FRAME
; lsr
@ -286,8 +283,10 @@ do_bg:
jsr hgr_draw_sprite_big
;===========================
; draw strong bad
; draw ripples
;===========================
; draw strong bad
draw_strong_bad:
@ -352,14 +351,19 @@ draw_common_animation:
jsr hgr_draw_sprite_big
;==========================
; update score?
;===========================
;============================
; draw fish
;============================
; draw reed (over fish)
;==========================
; draw score
jsr draw_score
;============================
; play sound
@ -403,6 +407,9 @@ do_jig:
lda #10
sta ANIMATION_COUNT
ldx #0
jsr update_score
jmp main_loop
do_lure:
@ -454,6 +461,83 @@ done_flip:
rts
;===================================
; draw score
;===================================
; score is at 6,7,8,9,10. 10 is always 0
draw_score:
lda SCORE_L
and #$f
tax
lda #9
jsr actual_draw_score
lda SCORE_L
lsr
lsr
lsr
lsr
tax
lda #8
jsr actual_draw_score
lda SCORE_H
and #$f
tax
lda #7
jsr actual_draw_score
lda SCORE_H
lsr
lsr
lsr
lsr
tax
lda #6
; jsr actual_draw_score
; rts
actual_draw_score:
sta SPRITE_X
lda numbers_l,X
sta INL
lda numbers_h,X
sta INH
lda #177
sta SPRITE_Y
jmp hgr_draw_sprite
; rts
;====================================
; update score
;====================================
; offset of update value in X
; score is BCD and in SCORE_H,SCORE_L
update_score:
sed
lda score_values,X
clc
adc SCORE_L
sta SCORE_L
lda #0
adc SCORE_H
sta SCORE_H
cld
rts
score_values:
; 50 100 400 500
.byte $05, $10, $40, $50
boat_sprites_l:
.byte <boat2_sprite,<boat1_sprite,<boat3_sprite,<boat1_sprite
@ -500,6 +584,18 @@ lure_sprites_h:
.byte >sb_sprite,>sb_fish1_sprite
.byte >sb_sprite
numbers_h:
.byte >zero_sprite,>one_sprite,>two_sprite
.byte >three_sprite,>four_sprite,>five_sprite
.byte >six_sprite,>seven_sprite,>eight_sprite
.byte >nine_sprite
numbers_l:
.byte <zero_sprite,<one_sprite,<two_sprite
.byte <three_sprite,<four_sprite,<five_sprite
.byte <six_sprite,<seven_sprite,<eight_sprite
.byte <nine_sprite
bg_data:
.incbin "graphics/fish_bg.hgr.zx02"
@ -510,6 +606,10 @@ bg_data:
.include "hgr_tables.s"
.include "hgr_sprite_big.s"
.include "hgr_sprite_mask.s"
.include "hgr_sprite.s"
; .include "hgr_copy_fast.s"
.include "audio.s"
.include "play_sounds.s"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -0,0 +1,79 @@
;================================================
; hgr draw sprite (only at 7-bit boundaries)
;================================================
; just plain draw the sprite
; no masking or transparency
; draws to page DRAWPAGE
; SPRITE in INL/INH
; Location at SPRITE_X SPRITE_Y
; xsize, ysize in first two bytes
hgr_draw_sprite:
ldy #0
lda (INL),Y ; load xsize
clc
adc SPRITE_X
sta hds_sprite_width_end_smc+1 ; self modify for end of line
iny ; load ysize
lda (INL),Y
sta hds_sprite_ysize_smc+1 ; self modify
; point smc to sprite
lda INL ; 16-bit add
sta hds_sprite_smc1+1
lda INH
sta hds_sprite_smc1+2
ldx #0 ; X is pointer offset
stx CURRENT_ROW ; actual row
ldx #2
hgr_ds_yloop:
lda CURRENT_ROW ; row
clc
adc SPRITE_Y ; add in cursor_y
; calc GBASL/GBASH
tay ; get output ROW into GBASL/H
lda hposn_low,Y
sta GBASL
lda hposn_high,Y
clc
adc DRAW_PAGE
sta GBASH
ldy SPRITE_X
hgr_ds_inner_loop:
hds_sprite_smc1:
lda $f000,X ; load sprite data
sta (GBASL),Y ; store to screen
inx ; increment sprite offset
iny ; increment output position
hds_sprite_width_end_smc:
cpy #6 ; see if reached end of row
bne hgr_ds_inner_loop ; if not, loop
inc CURRENT_ROW ; row
lda CURRENT_ROW ; row
hds_sprite_ysize_smc:
cmp #31 ; see if at end
bne hgr_ds_yloop ; if not, loop
rts

View File

@ -0,0 +1,92 @@
;================================================
; hgr draw sprite mask (only at 7-bit boundaries)
;================================================
; SPRITE in INL/INH
; MASK in MASKL/MASKH
; Location at SPRITE_X SPRITE_Y
; xsize, ysize in first two bytes
; sprite AT INL/INH
hgr_draw_sprite_mask:
ldy #0
lda (INL),Y ; load xsize
clc
adc SPRITE_X
sta hsm_sprite_width_end_smc+1 ; self modify for end of line
iny ; load ysize
lda (INL),Y
sta hsm_sprite_ysize_smc+1 ; self modify
; point smc to sprite
lda INL ; 16-bit add
sta hsm_sprite_smc1+1
lda INH
sta hsm_sprite_smc1+2
lda MASKL
sta hsm_mask_smc1+1
lda MASKH
sta hsm_mask_smc1+2
ldx #0 ; X is pointer offset
stx CURRENT_ROW ; actual row
ldx #2
hgr_sm_sprite_yloop:
lda CURRENT_ROW ; row
clc
adc SPRITE_Y ; add in cursor_y
; calc GBASL/GBASH
tay ; get output ROW into GBASL/H
lda hposn_low,Y
sta GBASL
lda hposn_high,Y
clc
adc DRAW_PAGE
sta GBASH
ldy SPRITE_X
hgr_sm_sprite_inner_loop:
lda (GBASL),Y ; load bg
hsm_sprite_smc1:
eor $f000,X ; load sprite data
hsm_mask_smc1:
and $f000,X
eor (GBASL),Y
sta (GBASL),Y ; store to screen
inx ; increment sprite offset
iny ; increment output position
hsm_sprite_width_end_smc:
cpy #6 ; see if reached end of row
bne hgr_sm_sprite_inner_loop ; if not, loop
inc CURRENT_ROW ; row
lda CURRENT_ROW ; row
hsm_sprite_ysize_smc:
cmp #31 ; see if at end
bne hgr_sm_sprite_yloop ; if not, loop
rts

View File

@ -137,11 +137,13 @@ CURRENT_DISK = $DC
; More zero-page addresses
; we try not to conflict with anything DOS, MONITOR or BASIC related
SCORE_L = $E0
SCORE_H = $E1
D1_SCORE = $E0
D1_SCORE_H = $E1
D2_SCORE = $E2
D2_SCORE_H = $E3
;D1_SCORE = $E0
;D1_SCORE_H = $E1
;D2_SCORE = $E2
;D2_SCORE_H = $E3
D1_STATE = $E4
DUCK_MISSING = $00