peasant: centralize score code

This commit is contained in:
Vince Weaver 2021-08-28 23:05:36 -04:00
parent 4da5609d60
commit 90a49ff439
7 changed files with 102 additions and 53 deletions

View File

@ -96,7 +96,7 @@ peasant1.o: peasant1.s zp.inc \
hgr_7x28_sprite_mask.s hgr_1x5_sprite.s hgr_save_restore.s \
wait_a_bit.s draw_peasant.s hgr_text_box.s \
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
peasant_move.s score.s
ca65 -o peasant1.o peasant1.s -l peasant1.lst
###
@ -111,7 +111,7 @@ peasant2.o: peasant2.s zp.inc \
hgr_7x28_sprite_mask.s hgr_1x5_sprite.s hgr_save_restore.s \
wait_a_bit.s draw_peasant.s hgr_text_box.s \
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
peasant_move.s score.s
ca65 -o peasant2.o peasant2.s -l peasant2.lst
@ -127,7 +127,7 @@ peasant3.o: peasant3.s zp.inc \
hgr_7x28_sprite_mask.s hgr_1x5_sprite.s hgr_save_restore.s \
wait_a_bit.s draw_peasant.s hgr_text_box.s \
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
peasant_move.s score.s
ca65 -o peasant3.o peasant3.s -l peasant3.lst
###
@ -142,13 +142,9 @@ peasant4.o: peasant4.s zp.inc \
hgr_7x28_sprite_mask.s hgr_1x5_sprite.s hgr_save_restore.s \
wait_a_bit.s draw_peasant.s hgr_text_box.s \
keyboard.s parse_input.s new_map_location.s \
peasant_move.s
peasant_move.s score.s
ca65 -o peasant4.o peasant4.s -l peasant4.lst
###
COPY_CHECK: copy_check.o

View File

@ -120,6 +120,10 @@ escape_handler:
sta PEASANT_XADD
sta PEASANT_YADD
sta SCORE_HUNDREDS
sta SCORE_TENS
sta SCORE_ONES
lda #4
sta MAP_X
lda #1

View File

@ -25,9 +25,6 @@ peasant_quest:
; Y=0, A=0 after this called
lda #0
sta FRAME
@ -35,6 +32,9 @@ peasant_quest:
jsr update_map_location
; update score
jsr update_score
;=============================
;=============================
@ -94,12 +94,7 @@ new_location:
; put score
lda #<score_text
sta OUTL
lda #>score_text
sta OUTH
jsr hgr_put_string
jsr print_score
;====================
; save background
@ -152,12 +147,6 @@ game_over:
peasant_text:
.byte 25,2,"Peasant's Quest",0
score_text:
.byte 0,2,"Score: 0 of 150",0
.include "decompress_fast_v2.s"
.include "wait_keypress.s"
@ -184,6 +173,8 @@ score_text:
.include "parse_input.s"
.include "score.s"
.include "keyboard.s"
.include "wait_a_bit.s"

View File

@ -34,6 +34,9 @@ peasant_quest:
jsr update_map_location
; update score
jsr update_score
;=============================
;=============================
@ -94,12 +97,7 @@ new_location:
; put score
lda #<score_text
sta OUTL
lda #>score_text
sta OUTH
jsr hgr_put_string
jsr print_score
;====================
; save background
@ -152,10 +150,6 @@ game_over:
peasant_text:
.byte 25,2,"Peasant's Quest",0
score_text:
.byte 0,2,"Score: 0 of 150",0
@ -181,6 +175,8 @@ score_text:
.include "new_map_location.s"
.include "peasant_move.s"
.include "score.s"
.include "parse_input.s"
.include "keyboard.s"

View File

@ -34,6 +34,10 @@ peasant_quest:
jsr update_map_location
; update score
jsr update_score
;=============================
;=============================
@ -93,12 +97,7 @@ new_location:
; put score
lda #<score_text
sta OUTL
lda #>score_text
sta OUTH
jsr hgr_put_string
jsr print_score
;====================
; save background
@ -150,11 +149,6 @@ game_over:
peasant_text:
.byte 25,2,"Peasant's Quest",0
score_text:
.byte 0,2,"Score: 0 of 150",0
.include "decompress_fast_v2.s"
@ -179,6 +173,8 @@ score_text:
.include "new_map_location.s"
.include "peasant_move.s"
.include "score.s"
.include "parse_input.s"
.include "keyboard.s"

View File

@ -34,6 +34,9 @@ peasant_quest:
jsr update_map_location
; update score
jsr update_score
;=============================
;=============================
@ -93,12 +96,7 @@ new_location:
; put score
lda #<score_text
sta OUTL
lda #>score_text
sta OUTH
jsr hgr_put_string
jsr print_score
;====================
; save background
@ -151,9 +149,6 @@ game_over:
peasant_text:
.byte 25,2,"Peasant's Quest",0
score_text:
.byte 0,2,"Score: 0 of 150",0
@ -179,6 +174,8 @@ score_text:
.include "peasant_move.s"
.include "score.s"
.include "new_map_location.s"
.include "parse_input.s"

69
games/peasant/score.s Normal file
View File

@ -0,0 +1,69 @@
;========================
; print score
;========================
print_score:
lda #<score_text
sta OUTL
lda #>score_text
sta OUTH
jmp hgr_put_string
; tail call does rts for us
;==========================
; update score
;==========================
; we have to handle 1, 2 or 3 digits
update_score:
ldx #9 ; offset of first digit in string
sed ; set decimal mode
update_hundreds:
lda SCORE_HUNDREDS
beq update_tens
clc
adc #'0'
sta score_text,X
inx
update_tens:
lda SCORE_TENS
beq update_ones
clc
adc #'0'
sta score_text,X
inx
update_ones:
lda SCORE_ONES
clc
adc #'0'
sta score_text,X
inx
ldy #0
copy_tail_loop:
lda score_tail,Y
sta score_text,X
beq done_copy_tail_loop
inx
iny
jmp copy_tail_loop
done_copy_tail_loop:
cld ; clear decimal mode
rts
score_text:
.byte 0,2,"Score: 0 of 150",0,0,0
score_tail:
.byte " of 150",0