/
score.asm
145 lines (135 loc) · 2.98 KB
/
score.asm
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
PUSHS
SECTION "Scores WRAM",WRAM0
score: DS 3
POPS
; a -> X position
initScore:
ld b, a
ld hl, score
ld a, 0
ld [hl+], a
ld [hl+], a
ld [hl], a
ld hl, shadowOAM + 34 * 4
ld d, 6
ld a, b
.loop
ld [hl], 20 ; y-coordinate
inc hl
ld [hl+], a ; x-coordinate
ld [hl], $44 ; tile-index
inc hl
inc hl ; skip over attributes
add a, 7
dec d
jp nz, .loop
ret
increaseScore:
; If we're in the death chunk, don't increase the score. (Otherwise the cutscene)
; that plays gives us free points
ld a, [SpriteList + SPRITE_CHUNK]
ld b, a
ld a, [deathChunk];
cp b
jp nz, .proceed
ret
.proceed
ld hl, score + 2
ld a, [hl]
add a, 1
daa
ld [hl-], a
jp c, .hundreds
ret
.hundreds
ld a, [hl]
add a, 1
daa
ld [hl-], a
jp c, .tenThousands
ret
.tenThousands
ld a, [hl]
add a, 1
daa
ld [hl], a
ret
displayScore:
ld hl, shadowOAM + 34 * 4 + 2
ld a, [score]
call displayScoreByte
ld a, [score + 1]
call displayScoreByte
ld a, [score + 2]
call displayScoreByte
ret
; hl - address of first digit's tile attribute
; a - BCD value to display
; -> hl - address of third digit's tile attribute
; -> a, b, c - trashed
displayScoreByte:
; save left digit in a, right digit in b
ld c, a
and a, %00001111
ld b, a
ld a, c
swap a
and a, %00001111
; calculate and write tile
sla a
add a, $44
ld [hl], a
; advance to next digit tile attribute
inc hl
inc hl
inc hl
inc hl
ld a, b
; calculate and write tile
sla a
add a, $44
ld [hl], a
; advance to next digit tile attribute
inc hl
inc hl
inc hl
inc hl
ret
updateHighScore:
; ld a, [highScore + 0]
; ld b, a
; ld a, [score + 0]
; sub a, b
; jp nc, .setHighScore
; ld a, [highScore + 1]
; ld b, a
; ld a, [score + 1]
; sub a, b
; jp c, .setHighScore
; ld a, [highScore + 2]
; ld b, a
; ld a, [score + 2]
; sub a, b
; jp nc, .setHighScore
ld a, [highScore + 2]
ld b, a
ld a, [score + 2]
sub a, b
ld a, [highScore + 1]
ld b, a
ld a, [score + 1]
sbc a, b
ld a, [highScore + 0]
ld b, a
ld a, [score + 0]
sbc a, b
jp nc, .setHighScore
ret
.setHighScore
ld a, [score + 0]
ld [highScore + 0], a
ld a, [score + 1]
ld [highScore + 1], a
ld a, [score + 2]
ld [highScore + 2], a
ret