-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asm
327 lines (250 loc) · 5.81 KB
/
main.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
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
TITLE MASM Template (main.asm)
; Description:
;
; Revision date:
INCLUDE Irvine32.inc
;==========================================================
;MACRO definitions
;==========================================================
;----------------------------------------------------------
DrawOptionsMenu MACRO
;----------------------------------------------------------
LOCAL MENUEnterName
.data
MENUEnterName BYTE "Enter your name --> ",0dh,0ah,0
.code
MOV EDX,OFFSET MENUEnterName
CALL WriteString
ENDM
;----------------------------------------------------------
DrawEnterNameMenu MACRO
;----------------------------------------------------------
LOCAL MENUEnterName
.data
MENUEnterName BYTE "Enter your name --> ",0dh,0ah,0
.code
MOV EDX,OFFSET MENUEnterName
CALL WriteString
ENDM
;----------------------------------------------------------
DrawHelpMenu MACRO
;----------------------------------------------------------
LOCAL MENUHelpTitle
LOCAL MENUHelpLineA
LOCAL MENUHelpLineB
LOCAL MENUHelpLineC
LOCAL MENUHelpLineD
LOCAL MENUHelpLineE
.data
MENUHelpTitle BYTE 0dh,0ah,0"Help",0dh,0ah,0
MENUHelpLineA BYTE "Try to get through the maze with the best score possible.",0dh,0ah,0
MENUHelpLineB BYTE "Red tiles are worth 10 points, blue tiles are worth 20 points.",0dh,0ah,0
MENUHelpLineC BYTE "Lose 1 point every 5 seconds until reaching the end.",0dh,0ah,0
MENUHelpLineD BYTE "Use WASD keys to navigate the maze.",0dh,0ah,0
MENUHelpLineE BYTE "Press any key to continue...",0dh,0ah,0
.code
MOV EDX,OFFSET MENUHelpTitle
CALL WriteString
MOV EDX,OFFSET MENUHelpLineA
CALL WriteString
MOV EDX,OFFSET MENUHelpLineB
CALL WriteString
MOV EDX,OFFSET MENUHelpLineC
CALL WriteString
MOV EDX,OFFSET MENUHelpLineD
CALL WriteString
MOV EDX,OFFSET MENUHelpLineE
CALL WriteString
CALL ReadChar
ENDM
;----------------------------------------------------------
DrawMainMenu MACRO
;----------------------------------------------------------
LOCAL MENUBreakLine
LOCAL MENUMenuHeader
LOCAL MENUInputName
LOCAL MENUOptions
LOCAL MENUHelp
LOCAL MENUPlay
LOCAL MENUExit
.data
MENUBreakLine BYTE "*****************************************************************",0dh,0ah,0
MENUMenuHeader BYTE "* Super Happy Fun Time Maze Game *",0dh,0ah,0
MENUInputName BYTE "1> Input your name",0dh,0ah,0
MENUOptions BYTE "2> Options",0dh,0ah,0
MENUHelp BYTE "3> Help",0dh,0ah,0
MENUPlay BYTE "4> Play",0dh,0ah,0
MENUExit BYTE "5> Exit",0dh,0ah,0
.code
CALL Clrscr
MOV EDX,OFFSET MENUBreakLine
CALL WriteString
MOV EDX,OFFSET MENUMenuHeader
CALL WriteString
MOV EDX,OFFSET MENUBreakLine
CALL WriteString
MOV EDX,OFFSET MENUInputName
CALL WriteString
MOV EDX,OFFSET MENUOptions
CALL WriteString
MOV EDX,OFFSET MENUHelp
CALL WriteString
MOV EDX,OFFSET MENUPlay
CALL WriteString
MOV EDX,OFFSET MENUExit
CALL WriteString
ENDM
;----------------------------------------------------------
DrawMaze MACRO mzdata:REQ
;----------------------------------------------------------
LOCAL xrep
LOCAL yrep
.data
xrep BYTE 20
yrep BYTE 20
.code
MOV ESI,OFFSET mzdata
MOV xrep,1
MOV yrep,1
CALL Clrscr
.REPEAT
MOV xrep,1
.REPEAT
MOV DH,yrep
MOV DL,xrep
CALL Gotoxy
MOV AL,[ESI]
.IF AL == '0'
MOV EAX,white + (lightBlue * 16)
CALL SetTextColor
MOV AL,' '
.ENDIF
.IF AL == '1'
MOV EAX,white + (black * 16)
CALL SetTextColor
MOV AL,' '
.ENDIF
.IF AL == '2'
MOV EAX,white + (blue * 16)
CALL SetTextColor
MOV AL,' '
.ENDIF
.IF AL == '3'
MOV EAX,white + (red * 16)
CALL SetTextColor
MOV AL,' '
.ENDIF
.IF AL == '4'
MOV EAX,white + (green * 16)
CALL SetTextColor
MOV AL,' '
.ENDIF
.IF AL == '5'
MOV EAX,white + (black * 16)
CALL SetTextColor
MOV AL,' '
.ENDIF
.IF AL == '6'
MOV EAX,white + (black * 16)
CALL SetTextColor
MOV AL,' '
.ENDIF
CALL WriteChar
INC ESI
INC xrep
.UNTIL xrep == 21
INC yrep
.UNTIL yrep==21
MOV EAX,white + (black * 16)
CALL SetTextColor
ENDM
DrawPlayer MACRO x:REQ, y:REQ
.code
MOV DH,y
MOV DL,x
CALL Gotoxy
MOV AL,'*'
CALL WriteChar
ENDM
.data
selection BYTE ?
playerName BYTE "New Player",0
mazeData BYTE 400 DUP(?)
selectionPrompt BYTE "Selection, ",0
enterNamePrompt BYTE 0dh,0ah,"Enter your name --> ",0
filename BYTE "mazedata.txt",0
filehandle DWORD ?
playerX BYTE 1
playerY BYTE 20
playerB WORD 381
testTile WORD ?
.code
main PROC
call Clrscr
DisplayMainMenu:
DrawMainMenu
MOV EDX,OFFSET selectionPrompt
CALL WriteString
MOV EDX,OFFSET playerName
CALL WriteString
CALL ReadChar
MOV selection,AL
CMP selection,"1"
JE DisplayEnterName
CMP selection,"3"
JE DisplayHelpMenu
CMP selection,"4"
JE StartGame
CMP selection,"5"
JE ExitGame
JMP DisplayMainMenu ;Invalid selection, go back to menu display
DisplayEnterName:
MOV EDX,OFFSET enterNamePrompt
CALL WriteString
MOV EDX,OFFSET playerName
MOV ECX,SIZEOF playerName
CALL ReadString
JMP DisplayMainMenu
DisplayHelpMenu:
DrawOptionsMenu
JMP DisplayMainMenu
StartGame:
;start the main game loop
;Load the mazedata - should only need to do this once
MOV EDX,OFFSET filename
CALL OpenInputFile
MOV EDX,OFFSET mazeData
MOV ECX,SIZEOF mazeData
CALL ReadFromFile
GameLoop:
DrawMaze mazeData
DrawPlayer playerX, playerY
CALL ReadChar
MOV selection,AL
.IF selection == 'q'
JMP ExitGame
.ENDIF
.IF selection == 'd'
;ADD playerX,1
;ADD PlayerB,1
;MOV testTile,playerB
;ADD testTile,1
MOV AX,playerB
ADD AX,1
MOV testTile,AX
MOV ESI,OFFSET mazeData
;MOV AX,[ESI + testTile]
;MOV ESI,382
;MOV AX,mazeData[ESI*2]
ADD ESI,762
MOV AX,[ESI]
.IF AX == '1'
ADD playerX,1
ADD playerB,1
.ENDIF
.ENDIF
JMP GameLoop
ExitGame:
exit
main ENDP
END main