-
Notifications
You must be signed in to change notification settings - Fork 0
/
ghosts.asm
138 lines (130 loc) · 3.35 KB
/
ghosts.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
ghostDis .EQU 8113H ;ghost move distance from pacman
caughtJaleTime .EQU 20H
ghostNextMove:
CALL rGhostNextMove
CALL oGhostNextMove
CALL pGhostNextMove
CALL tGhostNextMove
RET
clearGhost:
CALL rGhostClear
CALL oGhostClear
CALL pGhostClear
CALL tGhostClear
RET
printGhost:
CALL rGhostPrint
CALL oGhostPrint
CALL pGhostPrint
CALL tGhostPrint
RET
colideGhost:
CALL rGhostColide
CALL oGhostColide
CALL pGhostColide
CALL tGhostColide
RET
initGhost:
CALL rGhostInit
CALL oGhostInit
CALL pGhostInit
CALL tGhostInit
RET
moveGhost:
CALL rGhostMove
CALL oGhostMove
CALL pGhostMove
CALL tGhostMove
RET
printSGhost:
BIT 0,A
JP Z,sGhost1Print
LD HL, sGhost0
CALL print
RET
sGhost1Print:
LD HL, sGhost1
CALL print
RET
ghostMove:
CP 'W'
JR Z,ghostMoveU
CP 'A'
JR Z,ghostMoveL
CP 'S'
JR Z,ghostMoveD
JR ghostMoveR
ghostMoveU:
LD A, (DE)
LD L,A ;ld x
LD A, (BC)
DEC A
AND 00011111B
LD H,A ;ld y
CALL ghostCheckStack
LD (BC),A
RET
ghostMoveD:
LD A, (DE)
LD L,A ;ld x
LD A, (BC)
INC A
AND 00011111B
LD H,A ;ld y
CALL ghostCheckStack
LD (BC),A
RET
ghostMoveL:
LD A, (BC)
LD H,A ;ld y
LD A, (DE)
DEC A
AND 00011111B
LD L,A ;ld x
CALL ghostCheckStack
LD (DE),A
RET
ghostMoveR:
LD A, (BC)
LD H,A ;ld y
LD A, (DE)
INC A
AND 00011111B
LD L,A ;ld x
CALL ghostCheckStack
LD (DE),A
RET
ghostCheckStack:
PUSH AF
PUSH BC
PUSH DE
CALL rGhostStack
JP Z,ghostDoStack
CALL oGhostStack
JP Z,ghostDoStack
CALL pGhostStack
JP Z,ghostDoStack
CALL tGhostStack
JP Z,ghostDoStack
POP DE
POP BC
POP AF
RET
ghostDoStack:
POP DE
POP BC
POP AF
POP AF
RET
eatGhost:
LD HL,(score)
LD BC,10
ADD HL,BC
LD (score),HL
RET
include ghosts/red.asm
include ghosts/orange.asm
include ghosts/pink.asm
include ghosts/teal.asm
sGhost0: .BYTE 1BH,"[34mM",1BH,"[0m",0
sGhost1: .BYTE 1BH,"[97mM",1BH,"[0m",0