-
Notifications
You must be signed in to change notification settings - Fork 1
/
Source.asm
604 lines (539 loc) · 9.32 KB
/
Source.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
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
Include Irvine32.inc
Include macros.inc
BUFFER_SIZE = 1000
.data
str1 BYTE "Enter Word:",0
input BYTE 10 DUP(?)
score BYTE 0
Lives BYTE 3
check BYTE 1
word_list BYTE "FAST","APPLE","SPOT","TOUCH","SHOUT",0
word_list1 BYTE "VALUE","EMPLOYEE","SUCCESS","LAW","VIRUS",0
word_list2 BYTE "FINANCE","MONEY","REWARD","WALLET","WARE",0
arr_L1 BYTE 5 DUP(1)
arr_L2 BYTE 5 DUP(1)
arr_L3 BYTE 5 DUP(1)
file_L1 BYTE "level1.txt",0
file_L2 BYTE "level2.txt",0
file_L3 BYTE "level3.txt",0
file_L4 BYTE "instruction.txt",0
char BYTE 4 Dup("0")
;read file
buffer BYTE BUFFER_SIZE DUP(0)
fileHandle HANDLE ?
;write high score to file
filename BYTE "high_score.txt",0
stringLength DWORD ?
.code
main proc
Again:
call clrscr
mWrite<" 1-Quick Play",0dh,0ah," 2-Instruction",0dh,0ah," 3-Setting",0dh,0ah>
mWrite<" 4-High Score",0dh,0ah, " 5-Quit",0dh,0dh,0ah,0ah>
mWrite<"Enter Choice:",0>
mov eax,0
call readdec
cmp al,1
jne next
call Quick_play
jmp quit
next:
cmp al,2
jne next1
call instruction
jmp quit
next1:
cmp al,3
jne next2
call setting
jmp quit
next2:
cmp al,4
jne next3
mWrite<"High Score:",0>
mov edx,offset filename
call read_file
call crlf
jmp quit
next3:
cmp al,5
jne next4
mov check,0
jmp Quit1
next4:
mWrite <"You Enter Invalid Number",0dh,0ah>
mov eax,500
call delay
jmp Again
quit:
call readdec
cmp check,0
jne Again
Quit1:
exit
main endp
Quick_play PROC
call clrscr
call level1
call clrscr
call level2
call clrscr
call level3
ret
Quick_play endp
setting PROC
mWrite<" 1-change Color",0dh,0ah>
Again:
mWrite<"Enter Choice:",0>
mov eax,0
call readdec
cmp al,1
jne next
call changecolor
jmp next1
next:
mWrite<"You enter Invalid number",0dh,0ah>
mov eax,500
call delay
jmp Again
next1:
ret
setting endp
changecolor PROC
call clrscr
mWrite<" 1-Blue",0dh,0ah," 2-White",0dh,0ah," 3-Green",0dh,0ah>
mWrite<" 4-Red",0dh,0ah," 5-Magenta",0dh,0ah," 6-Yellow",0dh,0ah>
mWrite<" 7-Cyan",0dh,0ah," 8-Brown",0dh,0ah>
mWrite<"Select Color:",0>
mov eax,0
call readdec
cmp al,1
jne next
mov eax,blue
call settextcolor
jmp quit
next:
cmp al,2
jne next1
mov eax,white
call settextcolor
jmp quit
next1:
cmp al,3
jne next2
mov eax,green
call settextcolor
jmp quit
next2:
cmp al,4
jne next3
mov eax,red
call settextcolor
jmp quit
next3:
cmp al,5
jne next4
mov eax,magenta
call settextcolor
jmp quit
next4:
cmp al,6
jne next5
mov eax,yellow
call settextcolor
jmp quit
next5:
cmp al,7
jne next6
mov eax,cyan
call settextcolor
jmp quit
next6:
cmp al,8
jne next7
mov eax,brown
call settextcolor
jmp quit
next7:
mWrite <"You Enter Invalid Number",0dh,0ah>
quit:
ret
changecolor endp
level1 PROC
whileloop:
cmp lives,0
je quit
mWrite<"Lives:",0>
movzx eax,lives
call writedec
mWrite<" Score:",0>
movzx eax,score
call WriteDec
call crlf
call crlf
mov edx,offset file_L1
call read_file
call crlf
mov edx,offset str1
call writestring
mov edx,OFFSET input
mov ecx,9
call ReadString
mov al,arr_L1[0]
cmp al,1
jne else1
cld
mov esi,offset input
mov edi,offset word_list[0]
mov ecx,4
repe cmpsb
jnZ else1
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L1[0],0
jmp next
else1:
mov al,arr_L1[1]
cmp al,1
jne else2
cld
mov esi,offset input
mov edi,offset word_list[4]
mov ecx,5
repe cmpsb
jnz else2
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L1[1],0
jmp next
else2:
mov al,arr_L1[2]
cmp al,1
jne else3
cld
mov esi,offset input
mov edi,offset word_list[9]
mov ecx,4
repe cmpsb
jnz else3
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L1[2],0
jmp next
else3:
mov al,arr_L1[3]
cmp al,1
jne else4
cld
mov esi,offset input
mov edi,offset word_list[13]
mov ecx,5
repe cmpsb
jnz else4
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L1[3],0
jmp next
else4:
mov al,arr_L1[4]
cmp al,1
jne else5
cld
mov esi,offset input
mov edi,offset word_list[18]
mov ecx,5
repe cmpsb
jnz else5
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L1[4],0
jmp next
else5:
mWrite<"You enter word not found!",0dh,0ah>
dec lives
next:
MOV EAX,500
CALL delay
call clrscr
MOV AL,score
cmp al,5
jl whileloop
quit:
ret
level1 endp
level2 Proc
whileloop:
cmp lives,0
je quit
mWrite<"Lives:",0>
movzx eax,lives
call writedec
mWrite<" Score:",0>
movzx eax,score
call WriteDec
call crlf
call crlf
mov edx,offset file_L2
call read_file
call crlf
mov edx,offset str1
call writestring
mov edx,OFFSET input
mov ecx,9
call ReadString
mov al,arr_L2[0]
cmp al,1
jne else1
cld
mov esi,offset input
mov edi,offset word_list1[0]
mov ecx,5
repe cmpsb
jnZ else1
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L2[0],0
;call clrscr
jmp next
else1:
mov al,arr_L2[1]
cmp al,1
jne else2
cld
mov esi,offset input
mov edi,offset word_list1[5]
mov ecx,8
repe cmpsb
jnz else2
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L2[1],0
jmp next
else2:
mov al,arr_L2[2]
cmp al,1
jne else3
cld
mov esi,offset input
mov edi,offset word_list1[13]
mov ecx,7
repe cmpsb
jnz else3
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L2[2],0
jmp next
else3:
mov al,arr_L2[3]
cmp al,1
jne else4
cld
mov esi,offset input
mov edi,offset word_list1[20]
mov ecx,3
repe cmpsb
jnz else4
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L2[3],0
jmp next
else4:
mov al,arr_L2[4]
cmp al,1
jne else5
cld
mov esi,offset input
mov edi,offset word_list1[23]
mov ecx,5
repe cmpsb
jnz else5
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L2[4],0
jmp next
else5:
mWrite<"You enter word not found!",0dh,0ah>
dec lives
next:
MOV EAX,500
CALL delay
call clrscr
MOV AL,score
cmp al,10
jl whileloop
quit:
ret
level2 endp
level3 Proc
whileloop:
cmp lives,0
je quit
mWrite<" Lives:",0>
movzx eax,lives
call writedec
mWrite<" Score:",0>
movzx eax,score
call WriteDec
call crlf
call crlf
mov edx,offset file_L3
call read_file
call crlf
mov edx,offset str1
call writestring
mov edx,OFFSET input
mov ecx,9
call ReadString
mov al,arr_L3[0]
cmp al,1
jne else1
cld
mov esi,offset input
mov edi,offset word_list2[0]
mov ecx,7
repe cmpsb
jnZ else1
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L3[0],0
;call clrscr
jmp next
else1:
mov al,arr_L3[1]
cmp al,1
jne else2
cld
mov esi,offset input
mov edi,offset word_list2[7]
mov ecx,5
repe cmpsb
jnz else2
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L3[1],0
jmp next
else2:
mov al,arr_L3[2]
cmp al,1
jne else3
cld
mov esi,offset input
mov edi,offset word_list2[12]
mov ecx,6
repe cmpsb
jnz else3
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L3[2],0
jmp next
else3:
mov al,arr_L3[3]
cmp al,1
jne else4
cld
mov esi,offset input
mov edi,offset word_list2[18]
mov ecx,6
repe cmpsb
jnz else4
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L3[3],0
jmp next
else4:
mov al,arr_L3[4]
cmp al,1
jne else5
cld
mov esi,offset input
mov edi,offset word_list2[24]
mov ecx,4
repe cmpsb
jnz else5
mWrite <"your enter word found",0dh,0ah>
inc score
mov arr_L3[4],0
jmp next
else5:
mWrite<"You enter word not found!",0dh,0ah>
dec lives
next:
MOV EAX,500
CALL delay
call clrscr
MOV AL,score
cmp al,15
jl whileloop
quit:
ret
level3 endp
read_file proc
call OpenInputFile
mov fileHandle,eax
; Check for errors.
cmp eax,INVALID_HANDLE_VALUE ; error opening file?
jne file_ok ; no: skip
mWrite <"Cannot open file",0dh,0ah>
jmp quit ; and quit
file_ok:
; Read the file into a buffer.
mov edx,OFFSET buffer
mov ecx,BUFFER_SIZE
call ReadFromFile
jnc check_buffer_size ; error reading?
mWrite "Error reading file. " ; yes: show error message
call WriteWindowsMsg
jmp close_file
check_buffer_size:
cmp eax,BUFFER_SIZE ; buffer large enough?
jb buf_size_ok ; yes
mWrite <"Error: Buffer too small for the file",0dh,0ah>
jmp quit ; and quit
buf_size_ok:
mov buffer[eax],0 ; insert null terminator
;mWrite "File size: "
;call WriteDec ; display file size
;call Crlf
; Display the buffer.
;mWrite <"Buffer:",0dh,0ah,0dh,0ah>
mov edx,OFFSET buffer ; display the buffer
call WriteString
call Crlf
close_file:
mov eax,fileHandle
call CloseFile
quit:
ret
read_file endp
instruction PROC
mov edx,offset file_L4
call read_file
call crlf
ret
instruction endp
write_file PROC
; Create a new text file.
mov edx,OFFSET filename
call CreateOutputFile
mov fileHandle,eax
; Check for errors.
cmp eax, INVALID_HANDLE_VALUE ; error found?
jne file_ok ; no: skip
mWrite<"Cannot create file",0dh,0ah,0> ; display error
jmp quit
file_ok:
mov eax,0
cld
mov al,score
mov edi,offset char
stosd
; Write the buffer to the output file.
mov eax,fileHandle
mov edx,offset char
mov ecx,4
call WriteToFile
call CloseFile
quit:
ret
write_file endp
end main