-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimon.asm
More file actions
389 lines (311 loc) ยท 9.42 KB
/
Copy pathsimon.asm
File metadata and controls
389 lines (311 loc) ยท 9.42 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
.model small
.stack 100h
.data
titleMsg db "SIMON - A MEMORY GAME$", 0Dh, 0Ah, "$"
intructMsg db "Press The Keys According To The Display Sequence$", 0Dh, 0Ah, "$"
keysMsg db "Keys:", 0Dh, 0Ah, "$"
greenMsg db "q = Green", 0Dh, 0Ah, "$"
RedMsg db "w = Red", 0Dh, 0Ah, "$"
blueMsg db "a = Blue", 0Dh, 0Ah, "$"
yellowMsg db "s = Yellow", 0Dh, 0Ah, "$"
endMsg db "ESC = End game", 0Dh, 0Ah, "$"
startMsg db "Press ENTER To Start", 0Dh, 0Ah, "$"
lostMsg db "DEFEAT - You LOST", 0Dh, 0Ah, "$"
WinMsg db "Victory - You WON", 0Dh, 0Ah, "$"
ExitMsg db "Press ENTER To Exit", 0Dh, 0Ah, "$"
keysToMove db 'w', 'a', 'q', 's'
temp dw 3
.code
main proc ; main procedure to clear the screen and display Messages of first screen
mov ax, @data
mov ds, ax
; Display start screen and instructions
call clearScreen
mov dh, 3
mov dl, 28
call positioningTheCursor
mov bh, 0
mov dx, offset titleMsg
call printString
mov dh, 5
mov dl, 16
call positioningTheCursor
mov dx, offset intructMsg
call printString
mov dh, 7
mov dl, 19
call positioningTheCursor
mov dx, offset keysMsg
call printString
mov dh, 8
mov dl, 25
call positioningTheCursor
mov dx, offset greenMsg
call printString
mov dh, 9
mov dl, 25
call positioningTheCursor
mov dx, offset RedMsg
call printString
mov dh, 10 ; y axis (upside down)
mov dl, 25 ; x axis
call positioningTheCursor
mov dx, offset blueMsg
call printString
mov dh, 11 ; y axis (upside down)
mov dl, 25 ; x axis
call positioningTheCursor
mov dx, offset yellowMsg
call printString
mov dh, 15 ; y axis
mov dl, 25 ; x axis
call positioningTheCursor
mov dx, offset startMsg
call printString
;------------------drawing first screen finished----------------------
waitForEnter: ; Level to wait for user to press Enter
mov ah, 00h
int 16h
cmp al, 0dh
jne waitForEnter
;------------------Start the game----------------------
call clearScreenWithoutBlink ;to prevent mouse flashing
call cursorHider
call drawSquares
loopTheGame: ; Loop the Game
inc temp
mov si, offset keysToMove
mov cx, 0 ;check how many times we looped already
displayInSeq: ; Display the sequence and Play the Notes
mov al, [si]
call PlayAndDraw
inc si
inc cx
cmp cx, temp
jb displayInSeq
mov si, offset keysToMove
mov cx, 0
userInputSeq: ; Get user Input of Sequence
push cx
mov ah, 07h ;checks input from keyboard
int 21h
call PlayAndDraw ;after user input, play his choice on the screen
cmp al, 1bh ;al stores the key pressed
jne notCancel
jmp exit
notCancel: ; Compare the inputs with actual sequence
cmp al, [si]
jne wrongInput ;lost the game
inc si
pop cx
inc cx ;how many times we looped
cmp cx, temp
jb userInputSeq
mov dl, [si]
mov dh, [si + 1]
je lvlEnd ;won the game
jmp loopTheGame ;we never reach this code, because we already exited, I tried to make the game loop forever but had bugs.
wrongInput: ; If the User's Input sequence is not Correct
mov dh, 3
mov dl, 36
call positioningTheCursor
mov dx, offset lostMsg
call printString
jmp exit
lvlEnd: ; If the User's Input sequence is Correct, Display Victory Message
mov dh, 3
mov dl, 36
call positioningTheCursor
mov dx, offset WinMsg
call printString
exit: ; If the User's Input sequence is not Correct, Exit the Game
call positioningTheCursor
mov dh, 18
mov dl, 23
mov dx, offset ExitMsg
call printString
waitForExit: ; Wait for user to Press Enter before Exit the Game
mov ah, 00h
int 16h
cmp al, 0dh ;compare with enter
jne waitForExit
mov ax, 0003h ;exit program
int 10h
mov ax, 4c00h
int 21h
main endp
clearScreen proc ; Procedure to Clear the screen
mov ah, 06h
mov al, 00h ; Clear the screen
mov bh, 07h ; Attribute (white on black for text mode)
mov cx, 0000h ; Upper left corner of the window (row 0, column 0)
mov dx, 184fh ; Lower right corner of the window (row 24, column 79)
int 10h ; BIOS interrupt to execute the function
ret ; Returns from the procedure
clearScreen endp
clearScreenWithoutBlink proc ; Procedure to CLear the Screen without blink to increase the Useability
mov ax, 1003h ; Set cursor mode (disable blinking)
mov bx, 0
int 10h
call clearScreen
ret
clearScreenWithoutBlink endp
cursorHider proc ; Procedure to hide the cursor during the Game
mov ch, 32
mov ah, 01h
int 10h
ret
cursorHider endp
positioningTheCursor proc ; Setting the cursor position to Display at specific (x,y)
mov ah, 02h
mov dh, dh ;y axis
mov dl, dl ;x axis
mov bh, 00h
int 10h
ret
positioningTheCursor endp
printString proc ; Procedure to print the strings (Mainly used to Message Printing)
mov ah, 09h ;prints the string in dx register at the position of the cursor
int 21h
ret
printString endp
PlayAndDraw proc ; Procedure to Play and draw the Squares by comparing with Input
push ax
cmp al, 'q'
jne ifNotGreen
call newGreen
mov bx, 5709 ;sound code
call playMusic
call newGreen2
jmp incomplete ;incomplete for finish
ifNotGreen:
cmp al, 'w'
jne ifNotRed
call newred
mov bx, 4870
call playMusic
call newred2
jmp incomplete
ifNotRed:
cmp al, 'a'
jne ifNotBlue
call NewBlue2
mov bx, 2875
call playMusic
call NewBlue
jmp incomplete
ifNotBlue:
cmp al, 's'
jne ifNotyellow
call white
mov bx, 3837
call playMusic
call yellow
jmp incomplete
ifNotyellow: ;skipped everything
incomplete:
pop ax
ret
PlayAndDraw endp
playMusic proc ; Procedure to play the music on each Square
push cx ;plays the sound according to the value in bx register
mov al, 10110110B
out 43H, al
mov ax, bx
out 42H, al
mov al, ah
out 42H, al
in al, 61H
or al, 00000011B
out 61H, al
mov ah, 86h
mov cx, 7
mov dx, 0a120h
int 15h
in al, 61H
and al, 11111100B
out 61H, al
pop cx
ret
playMusic endp
drawSquares proc ; Procedure to draw the squares
call newGreen2
call newred2
call NewBlue
call yellow
ret
drawSquares endp
;___________________________________________________________ Procedures to print different shades of colors when the note is played
newGreen proc ;light green
mov bl, 0aah ;color
mov dl, 29 ;y axis
mov dh, 5 ;x axis
call drawLines ;draw
ret
newGreen endp
newGreen2 proc ;dark green
mov bl, 022h
mov dl, 29
mov dh, 5
call drawLines
ret
newGreen2 endp
newred proc ;light
mov bl, 0CCh
mov dl, 41
mov dh, 5
call drawLines
ret
newred endp
newred2 proc ;dark
mov bl, 044h
mov dl, 41
mov dh, 5
call drawLines
ret
newred2 endp
NewBlue2 proc ;light
mov bl, 099h
mov dl, 29
mov dh, 11
call drawLines
ret
NewBlue2 endp
NewBlue proc ;dark
mov bl, 011h
mov dl, 29
mov dh, 11
call drawLines
ret
NewBlue endp
yellow proc
mov bl, 0EEh ;color
mov dl, 41
mov dh, 11
call drawLines
ret
yellow endp
white proc
mov bl, 0ffh
mov dl, 41
mov dh, 11
call drawLines
ret
white endp
drawLines proc ; Procedure to draw lines
push cx ;very old cx value
mov cx, 5 ;5 rows
mov bh, 0 ;for the correct color
mov al, 0 ;so draw will work well - default character to draw
drawSquaresLevel: ;10 columns
push cx ;save the value of cx (was 5) for rows
mov cx, 10 ;draw 10 columns
mov ah, 13h ;draw to screen
int 10h
inc dh ;move to the next row y axis increases
pop cx ;return previous cx value (was 5)
loop drawSquaresLevel
pop cx ;push the value in the stack (ืืืกื ืืช) to cx
ret
drawLines endp
end main