-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.z80
115 lines (108 loc) · 2.97 KB
/
score.z80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
; score is up to 9999990 (according to Puzznic arcade game)
; represent as bcd, with one trailing 0 digits
score_bcd_1: defb 0
score_bcd_2: defb 0
score_bcd_3: defb 0
init_score:
; start of game but not between levels!
xor a
ld (score_bcd_1), a
ld (score_bcd_2), a
ld (score_bcd_3), a
ld (score_changed), a ; poke a nop - score has changed so re-render on next opportunity
ret
add_score:
xor a ; poke a nop - score has changed so re-render on next opportunity
ld (score_changed), a
; add a bcd amount in bc to the score
ld a, (score_bcd_3)
add a, c
daa
ld (score_bcd_3), a
ld a, (score_bcd_2)
adc b
daa
ld (score_bcd_2), a
ret nc
ld a, (score_bcd_1)
adc 0
daa
ld (score_bcd_1), a
ret
render_score:
score_changed: equ $ ; poke NOP or RET here
nop
ld a, 201 ; next time round this will be a RET!
ld (score_changed), a
; skip leading zeros until we find a non-zero
; and then don't skip anything
ld c, 0x11 ; WHITE
ld de, SCORE_Y_OFFSET*128+SCORE_X_OFFSET/2
ld a, (score_bcd_1)
and a
jr z, @+skip_bcd1
and 240
jr z, @+skip_bcd1_hi
rrca
rrca
rrca
rrca
call digit_a_xy_de
@skip_bcd1_hi:
ld de, SCORE_Y_OFFSET*128+SCORE_X_OFFSET/2 + 4
ld a, (score_bcd_1)
and 15
call digit_a_xy_de
@skip_bcd1_do_bcd2:
ld de, SCORE_Y_OFFSET*128+SCORE_X_OFFSET/2 + 8
ld a, (score_bcd_2)
and 240
rrca
rrca
rrca
rrca
call digit_a_xy_de
@skip_bcd2_hi:
ld de, SCORE_Y_OFFSET*128+SCORE_X_OFFSET/2 + 12
ld a, (score_bcd_2)
and 15
call digit_a_xy_de
@skip_bcd2_do_bcd3:
ld de, SCORE_Y_OFFSET*128+SCORE_X_OFFSET/2 + 16
ld a, (score_bcd_3)
and 240
rrca
rrca
rrca
rrca
call digit_a_xy_de
@skip_bcd3_hi:
ld de, SCORE_Y_OFFSET*128+SCORE_X_OFFSET/2 + 20
ld a, (score_bcd_3)
and 15
call digit_a_xy_de
@final_zero:
; always render a final '0' character
; TODO, this never changes, so maybe only render
; it when first drawing the screen
ld de, SCORE_Y_OFFSET*128+SCORE_X_OFFSET/2 + 24
ld a, 0
;call digit_a_xy_de ; optimize, JP instead of call+ret?
;ret
jp digit_a_xy_de
@skip_bcd1:
; we skipped two leading zeros, we might need to skip more.
ld a, (score_bcd_2)
and a
jr z, @+skip_bcd2
and 240
jr z, @-skip_bcd2_hi
jp @-skip_bcd1_do_bcd2
@skip_bcd2:
; we skipped four leading zeros, we might need to skip more.
ld a, (score_bcd_3)
and a
jr z, @-final_zero
and 240
jr z, @-skip_bcd3_hi
jp @-skip_bcd2_do_bcd3