-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmapLibs.asm
More file actions
332 lines (310 loc) · 7.12 KB
/
Copy pathmapLibs.asm
File metadata and controls
332 lines (310 loc) · 7.12 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
pathFindDepth .EQU 30H
fruitTicks .EQU 0B0H
fruitTimer .EQU 8106H ;Fruit Timer Location
fruitX .EQU 15
fruitY .EQU 14
;-------- Map -------;
;InitiMap
initMap:
LD A,fruitTicks
LD (fruitTimer),A
LD BC,400H
LD HL,map
LD DE,liveMap
LDIR
RET
;------- Get Map Data ----;
; C - X
; B - Y
getMapAddress:
push bc
rlc b ;Shift b left 5
rlc b ;Shift b left 5
rlc b ;Shift b left 5
rlc b ;Shift b left 5
rlc b ;Shift b left 5
ld a,b
and 11100000b ;Mask lower adress
or c ;Combine with C
ld l,a ;A is now low byte of adress
ld a,b
and 00000011b ;Mask upper adress
or 0E0H ;Start of map
ld h,a
pop bc
ret
checkFruit:
LD A,(fruitTimer)
OR A
RET Z
DEC A
LD (fruitTimer), A
OR A
RET NZ
LD C,fruitX
LD B,fruitY
CALL getMapAddress
SET sfBit,(HL)
CALL printMapAt
RET
;--------Check map for pellets ------;
checkNextLevel:
CALL checkMap
LD A,E
OR A
RET NZ
LD A,D
OR A
RET NZ
LD HL,(level)
INC HL
LD (level),HL
CALL countdown
CALL initMap
CALL initGhost
CALL resetPacman
LD HL, home ;Go home
CALL print
CALL printMap
ret
checkMap:
ld a,32
ld b,a ; 32 chars per line
ld c,a ; 32 lines per map
ld hl,liveMap
ld de,0
checkMapLoop: ld a,(hl) ; get char
call checkMapChar; check the char
inc hl ; next char
djnz checkMapLoop; if were not at the end of a line, print next char
ld b,c ;are we at the end of a block
djnz checkMapNextLine
ret
checkMapNextLine:
ld c,b ;copy decremented b back to c
ld a,32 ;refill b withj 32
ld b,a
jr checkMapLoop;draw next char
checkMapChar:
bit pelletBit,a
CALL NZ,incrementDE
bit powerpBit,a
CALL NZ,incrementDE
RET
incrementDE:
INC DE
RET
;------- Get Path Find Map Address----;
; C - X
; B - Y
getAddressPF:
push bc
rlc b ;Shift b left 5
rlc b ;Shift b left 5
rlc b ;Shift b left 5
rlc b ;Shift b left 5
rlc b ;Shift b left 5
ld a,b
and 11100000b ;Mask lower adress
or c ;Combine with C
ld l,a ;A is now low byte of adress
ld a,b
and 00000011b ;Mask upper adress
or 0D0H ;Start of map
ld h,a
pop bc
ret
;--------- Map print -------- ;
; C - X
; B - Y
printMapAt:
PUSH BC
INC C
INC B
CALL moveCursor
POP BC
CALL getMapAddress
LD A,(HL)
CALL pmChar
RET
printMap:
ld a,32
ld b,a ; 32 chars per line
ld c,a ; 32 lines per map
ld hl,liveMap
pmLoop: ld a,(hl) ; get char
call pmChar ; decode what to print
inc hl ; next char
djnz pmLoop ; if were not at the end of a line, print next char
call newline ; if we are, print a new line
ld b,c ;are we at the end of a block
djnz pmNextLine
ret
pmNextLine:
ld c,b ;copy decremented b back to c
ld a,32 ;refill b withj 32
ld b,a
jr pmLoop ;draw next char
pmChar: ;-- Print map char a
push hl
bit powerpBit,a
jr nz,printPP
bit pelletBit,a
jr nz,printP
bit wallBit,a
jr nz,printWall
bit sfBit,a
jr nz,printSF
jr printVoid
printPP:
ld hl,powerPellet
call print
jr pmCharRet
printP:
ld hl,pellet
call print
jr pmCharRet
printWall:
ld hl,wall
call print
jr pmCharRet
printSF:
ld hl,superFruit
call print
jr pmCharRet
printVoid:
ld hl,void
call print
jr pmCharRet
pmCharRet:
pop hl
ret
;-------- Path Find Map -------;
;Initi Path Find Map
initPathFind:
ld a,32
ld b,a ; 32 chars per line
ld c,a ; 32 lines per map
ld hl,pathFindMap
initpPFLoop: ld D,0FFH ; set char
LD (HL),D
inc hl ; next char
djnz initpPFLoop ; if were not at the end of a line, print next char
ld b,c ;are we at the end of a block
djnz pfNextRow
ret
pfNextRow:
ld c,b ;copy decremented b back to c
ld a,32 ;refill b withj 32
ld b,a
jp initpPFLoop ;draw next char
;Calculate Map
calculatePathMap:
ld BC,0FFFFH ;Push Stack terminator
PUSH BC
LD A, (pacx) ;Push X to stack
LD C,A
LD A, (pacy) ;Push Y to stack
LD B,A
CALL getAddressPF
LD (HL),00H
PUSH BC
calculatePathMapLoop:
POP BC ;Get node to visit
LD A,B ;Check Its not FFFF
OR A
CP 0FFH
RET Z ;We only have to check half the byte as its imposable to have a cord more than 20h
LD (originalBC),BC
CALL getAddressPF
LD A,(HL)
INC A
CP pathFindDepth
JP Z,calculatePathMapLoop ;Skip if wer getting too long
LD E,A ;Keep the distance were working with safe
CALL getMapAddress
LD D,(HL)
LD A, 'W' ;check up
CALL isMoveValid
CALL NZ,calculateMapU
LD A, 'S' ;down
CALL isMoveValid
CALL NZ,calculateMapD
LD A, 'A' ;left
CALL isMoveValid
CALL NZ,calculateMapL
LD A, 'D' ;right
CALL isMoveValid
CALL NZ,calculateMapR
JP calculatePathMapLoop
calculateMapU:
LD BC,(originalBC) ;We want to preserve the OG BC Through this process so it can be used again in sub directions
LD A, B ;Make modifications to corod
DEC A
AND 00011111B ;Mask for looping
LD B,A
JP calculateMapCell
calculateMapD:
LD BC,(originalBC)
LD A, B
INC A
AND 00011111B
LD B,A
JP calculateMapCell
calculateMapL:
LD BC,(originalBC)
LD A, C
DEC A
AND 00011111B
LD C,A
JP calculateMapCell
calculateMapR:
LD BC,(originalBC)
LD A, C
INC A
AND 00011111B
LD C,A
JP calculateMapCell
calculateMapCell:
CALL getAddressPF
LD A,(HL)
CP E ;Compare current data (A) with E (the path were looking at)
RET C ;If carry is set (A < E)(whats there already < our path) then this route is a dud
RET Z ;If its equal we dont want to continue as we alreay have an equally fast route
LD (HL),E
POP HL ;We need the return adress on the top of the stack
PUSH BC ;Push Cell so it can be visited
PUSH HL
RET
printPFMap:
LD C, $01
LD B, $1A
CALL moveCursor
ld a,32
ld b,a ; 32 chars per line
ld a,$1A
ld c,a ; 32 lines per map
ld hl,pathFindMap
pmPFLoop: ld a,(hl) ; get char
cp 0FFH
JP Z,pmPFSkip
call NumToHex ; decode what to print
pmPFAfterSkip: ld a,' '
rst 08H
inc hl ; next char
djnz pmPFLoop ; if were not at the end of a line, print next char
call newline ; if we are, print a new line
ld b,c ;are we at the end of a block
djnz pmPFNextLine
ret
pmPFNextLine:
ld c,b ;copy decremented b back to c
ld a,32 ;refill b withj 32
ld b,a
jr pmPFLoop ;draw next char
pmPFSkip:
ld a,' '
rst 08H
ld a,' '
rst 08H
JP pmPFAfterSkip