-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscape.asm
1528 lines (1467 loc) · 29.5 KB
/
Escape.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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;A huge thanks to Alon Bar-Lev and Sarit Lolav to teaching me almost everything I know about programming
ideal
p8086
model small
stack 100h
segment textseg at 0b800h
text db 80*24*2 dup(?) ;The memory of the graphic card for text mode
ends
dataseg
startdata db 1,1,2,0,0,0,0 ;Data that will be used if the player will restart the game
;
;The location of the player
;
X db 1 ;The location in the Quarter in his X axis
Y db 1 ;The location in the Quarter in his Y axis
Q db 2 ;What quarter the player is in right now
HitingWall db 0 ;Does the sound when the player is hitting a wall is on or off. 0 off, 1 on
MovingSound db 0 ;Does the sound when the player is moving is on or off. 0 off, 1 on
NumberMoves dw 0 ;The number of moves the player done
;
;Information about bits type
;
wall db 219d,039h
road db 32d,03Ah
player db 02h,03Ah
;' ',03Ah= road
;219d,039h=wall
;02h,03Ah=player
;How the first Screen is
UL db 80 dup(219d,039h) ;first line
db 219d,039h,' ',03Ah,27 dup(219d,039h),16 dup(' ',03Ah),35 dup (219d,039h); second line
db 2 dup (219d,039h,' ',03Ah,40 dup(219d,039h),' ',03Ah,37 dup (219d,039h)); third&forth line
db 219d,039h, 7 dup(' ',03Ah),10 dup(219d,039h),40 dup (' ',03Ah),10 dup(219d,039h),12 dup(' ',03Ah); fifth line
db 219d,039h, ' ',03Ah, 5 dup(219d,039h),12 dup (' ',03Ah),10 dup(219d,039h),' ',03Ah,12 dup(219d,039h),' ',03Ah,14 dup(219d,039h),12 dup (' ',03Ah),11 dup (219d,039h); sixth line
db 219d,039h, ' ',03Ah,10 dup (219d,039h),' ',03Ah,16 dup(219d,039h),10 dup (' ',03Ah),3 dup (219d,039h),' ',03Ah,25 dup(219d,039h),12 dup (' ',03Ah);seventh line
db 219d,039h, ' ',03Ah,5 dup(219d,039h),6 dup(' ',03Ah), 16 dup(219d,039h),' ',03Ah,8 dup (219d,039h),' ',03Ah,3 dup (219d,039h), 17 dup (' ',03Ah), 21 dup (219d,039h); eighth line
db 219d,039h, ' ',03Ah,5 dup(219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,16 dup (219d,039h), 2 dup (' ',03Ah),17 dup (219d,039h),' ',03Ah, 31 dup (219d,039h); ninth line
db 219d,039h, ' ',03Ah,5 dup(219d,039h),2 dup (' ',03Ah), 3 dup (219d,039h),11 dup (' ',03Ah),7 dup (219d,039h),' ',03Ah,7 dup (219d,039h),42 dup (' ',03Ah); tenth line
db 219d,039h, ' ',03Ah,6 dup(219d,039h),' ',03Ah,3 dup (219d,039h),' ',03Ah, 17 dup (219d,039h),2 dup (' ',03Ah),6 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,31 dup (219d,039h) ;eleventh line
db 219d,039h, ' ',03Ah,6 dup(219d,039h),' ',03Ah,3 dup (219d,039h),' ',03Ah, 18 dup (219d,039h),' ',03Ah,6 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,31 dup (219d,039h) ;twelfth line
db 219d,039h, ' ',03Ah,6 dup(219d,039h),' ',03Ah,3 dup (219d,039h),' ',03Ah, 18 dup (219d,039h),2 dup (' ',03Ah),5 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,4 dup (219d,039h),32 dup (' ',03Ah);thirteenth line
db 219d,039h, ' ',03Ah,6 dup(219d,039h), 2 dup (' ',03Ah),2 dup (219d,039h),' ',03Ah, 19 dup (219d,039h),' ',03Ah,5 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,9 dup (219d,039h),' ',03Ah,17 dup (219d,039h),' ',03Ah, 8 dup (219d,039h) ; fourteenth line
db 219d,039h, ' ',03Ah,7 dup(219d,039h), ' ',03Ah,2 dup (219d,039h),' ',03Ah, 19 dup (219d,039h),2 dup(' ',03Ah),4 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,9 dup (219d,039h),' ',03Ah,17 dup (219d,039h),' ',03Ah,8 dup (219d,039h) ; fifteenth line
db 219d,039h, ' ',03Ah,7 dup(219d,039h),2 dup (' ',03Ah),219d,039h, 22 dup (' ',03Ah),4 dup (219d,039h),' ',03Ah,14 dup (219d,039h),4 dup (' ',03Ah),12 dup (219d,039h),3 dup (' ',03Ah),8 dup (219d,039h); sixteenth line
db 219d,039h, ' ',03Ah,8 dup(219d,039h), ' ',03Ah, 5 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,16 dup (219d,039h),' ',03Ah,13 dup (219d,039h), 2 dup (' ',03Ah), 2 dup (219d,039h),' ',03Ah,10 dup (219d,039h), 3 dup (' ',03Ah), 219d,039h, 9 dup (' ',03Ah) ; seventeenth line
db 219d,039h, ' ',03Ah,8 dup(219d,039h), 2 dup (' ',03Ah), 4 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah,15 dup (219d,039h), 2 dup (' ',03Ah),13 dup (219d,039h), ' ',03Ah,3 dup (219d,039h),14 dup (' ',03Ah), 4 dup (219d,039h),' ',03Ah, 5 dup (219d,039h) ; eighteenth line
db 219d,039h, 9 dup (' ',03Ah),219d,039h,' ',03Ah,4 dup (219d,039h),' ',03Ah,4 dup (219d,039h), 32 dup (' ',03Ah),10 dup (219d,039h),' ',03Ah,10 dup (219d,039h),' ',03Ah,5 dup (219d,039h) ; nineteenth line
db 219d,039h, ' ',03Ah, 2 dup(219d,039h),' ',03Ah, 4 dup (219d,039h),' ',03Ah,219d,039h, ' ',03Ah, 4 dup (219d,039h),' ',03Ah,4 dup (219d,039h), ' ',03Ah, 22 dup (219d,039h),' ',03Ah,7 dup (219d,039h),2 dup (' ',03Ah,10 dup (219d,039h)),' ',03Ah, 5 dup (219d,039h) ; twenty line
db 219d,039h, ' ',03Ah, 2 dup(219d,039h),' ',03Ah, 4 dup (219d,039h),' ',03Ah,219d,039h, ' ',03Ah, 4 dup (219d,039h),' ',03Ah,4 dup (219d,039h), ' ',03Ah, 219d,039h, 22 dup (' ',03Ah),7 dup (219d,039h),' ',03Ah,10 dup (219d,039h),' ',03Ah,16 dup (219d,039h) ;twenty first century breakdown
db 219d,039h, 2 dup (' ',03Ah, 2 dup(219d,039h)), 3 dup (' ',03Ah),219d,039h,11 dup (' ',03Ah),219d,039h,' ',03Ah, 20 dup (219d,039h),' ',03Ah, 7 dup (219d,039h),' ',03Ah,10 dup (219d,039h),' ',03Ah,16 dup (219d,039h) ; twenty second line
db 219d,039h,' ',03Ah, 2 dup (2 dup(219d,039h),' ',03Ah), 2 dup (219d,039h,' ',03Ah),2 dup (4 dup (219d,039h),' ',03Ah),219d,039h,57 dup (' ',03Ah) ; twenty third line
db 2 dup (219d,039h,' ',03Ah, 2 dup (2 dup(219d,039h),' ',03Ah), 2 dup (219d,039h,' ',03Ah),2 dup (4 dup (219d,039h),' ',03Ah),219d,039h,' ',03Ah, 20 dup (219d,039h),' ',03Ah, 7 dup (219d,039h),' ',03Ah,5 dup (219d,039h),' ',03Ah,4 dup (219d,039h),' ',03Ah, 8 dup (219d,039h),' ',03Ah, 7 dup (219d,039h)) ; twenty third and the twenty forth line
UR db 'UR.txt',0 ;The name of the text document that the information of UR is in it
DLow db 'DL.txt',0 ;The name of the text document that the information of DL is in it
DR db 'DR.txt',0 ;The name of the text document that the information of DR is in it
Open db 'Open.txt',0 ;The name of the text document that the information of Open is in it
MSG db 82*25+3 dup (?) ;The size of the memory position when the information of the Screens will be saved
PressAnyKeyMSG db 'Press any Key to start'
endPress=$
Instractor db 'W/ Up Arrow to move Up '
endI=$
InstractorA db 'A/ Left Arrow to move left '
endA=$
InstractorS db 'S/Down Arrow to move down '
endIS=$
InstractorD db 'D/Right Arrow to move Right'
endD=$
StartMSG db 'Start'
endStartMSG=$
RulesMSG db 'Rules'
endRules=$
WinMSG1 db 'You Won!',0dh, 0ah, 'You moved ','$' ;The winning message part 1
WinMsg2 db ' times.', 0dh, 0ah, 'Press Esc to Exit or Enter to restart the game.','$' ;The winning message part 2
MovesHelper db ?,?,?,?,?,'$' ;The digits when we change the number of move from Hex base to Dec Base will be saved over here
;Music and sound
Wallnote dw 12580D
Movenote dw 10847D
musicplayed db 0 ;Is any music is played right now
sec db ? ;The ending second will be saved over here
mil db ? ;The ending milliseconds will be saved over here
codeseg
Initielize:
mov ax, @data
mov ds, ax
;
;Change cursor position to row 25
;
mov DH,25
mov DL,25
call cleanset
;
;make segment textseg usable
;
mov ax, textseg
mov es, ax
assume es:textseg
;
;Open the start and all its things
;
OpenScreen: ;Show us the opening screen
lea dx,[Open]
call ChangeScreen ;Will open and screen the screen in Open.txt
mov ax, textseg
mov es, ax
assume es:textseg ;Making textseg usable
;Print the word 'Rules', In (13,19)
xor ax,ax
mov al,19
push ax ;Y size
mov al,13
push ax ;X size
call calculate_Location
mov bx,ax
mov si, offset RulesMSG
mov cx, offset endRules-offset RulesMSG
call PrintToScreen
;Print the word 'Start', (63,19)
xor ax,ax
mov al,19 ;Y size
push ax
mov al,63 ;X size
push ax
call calculate_Location
mov bx,ax
mov si, offset StartMSG
mov cx, offset endStartMSG-offset StartMSG
call PrintToScreen
RulesStart:
;Print a rectangle around rules, his left upper corner is in (10, 17)
xor ax,ax
mov al,17 ;Y size
push ax
mov al,10 ;X size
push ax
call calculate_Location
push ax
call DrawRectangle
AroundLoop:
xor ah, ah ; wait for key and read
int 16h ; bios keyboard
cmp ah, 4Dh ;Right Key
JNE NotStartRight
;
; Delete the rectangle that his left upper corner is in (10, 17)
;
xor ax,ax
mov al,17
push ax
mov al,10
push ax
call calculate_Location
push ax
call DeleteRectangle
JMP AroundStart
NotStartRight:
CMP ah, 1Ch ;Enter
JE RulesScreen
JMP AroundLoop
AroundStart:
;Print a rectangle around rules
xor ax,ax
mov al,17
push ax
mov al,60
push ax
call calculate_Location
push ax
call DrawRectangle
StartLoop:
xor ah, ah ; wait for key and read
int 16h ; bios keyboard
cmp ah, 4Bh ;Left Arrow
JNE NotStartLeft
;If you press Left Arrow, you delete the the rectangle first and then move
xor ax,ax
mov al,17
push ax
mov al,60
push ax
call calculate_Location
push ax
call DeleteRectangle
JMP RulesStart
NotStartLeft:
CMP ah, 1Ch ;Enter
JE move
JMP StartLoop
RulesScreen:
mov cx,80*24
xor bx,bx
RulesLoop:
mov [text+bx],219d
mov [text+bx+1],039h
add bx,2
loop RulesLoop
;print "Rules"
xor ax,ax
mov al, 4
push ax
mov al,37
push ax
call calculate_Location
mov bx,ax
mov bx,ax
mov si, offset RulesMSG
mov cx, offset endRules-offset RulesMSG
call PrintToScreen
xor ax,ax
mov al,6
push ax
mov al,27
push ax
call calculate_Location
mov bx,ax
;Print Instractor
mov si, offset Instractor
mov cx, offset endI-offset Instractor
call PrintToScreen
add bx,160
;Print InstractorA
mov si, offset InstractorA
mov cx, offset endA-offset InstractorA
call PrintToScreen
add bx,160
;Print InstractorS
mov si, offset InstractorS
mov cx, offset endIS - offset InstractorS
call PrintToScreen
add bx,160
;Print InstractorD
mov si, offset InstractorD
mov cx, offset endD - offset InstractorD
call PrintToScreen
add bx,320
;Print PressAnyKeyMSG
mov si, offset PressAnyKeyMSG
mov cx, offset endPress - offset PressAnyKeyMSG
call PrintToScreen
xor ah, ah ; wait for key and read
int 16h ; bios keyboard
;
;move the the data from UL (the first screen we see) to textseg so we will be able to see it
;
move:
mov al,[byte UL+bx]
mov [byte ptr text+bx],al
inc bx
loop move
mov [text+162],02h
mov [text+163],03Ah
AfterIn:
;
;Check if there is a need to stop sound
;
CMP [musicplayed],1
JNE nomusic
;
;Get system time
;
mov ah,2ch
int 21h
CMP [sec],dh
JA nomusic
CMP [mil],dl
JA nomusic
; close the speaker
closespeaker:
in al, 61h
and al, 11111100b
out 61h, al
mov [musicplayed],0
mov [HitingWall],0
mov [MovingSound],0
nomusic:
mov ah, 1 ; get keystroke status
int 16h ; bios keyboard
jz AfterIn ; has key?
;
; ah - scan code
;
;
;if Up arrow is pressed
;
cmp ah, 48h
jne notUp
UpArrow:
xor ax,ax
mov al,[Y]
dec al
push ax
xor al,al
mov al,[X]
push ax
call calculate_Location
mov bx,ax
call checkmovment
cmp ax,0
jne MovUp
CMP [HitingWall], al;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE UpGoBack;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,75d ; for 50 milliseconds
xor ah,ah
push ax
mov ax,[Wallnote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [HitingWall],1;To show that the sound where you hit the wall happens
UpGoBack:
JMP GoBack
MovUp:
inc [NumberMoves]
call Up;moving the player one pixel Up and update his location info
mov al,[Y]
dec al
mov [Y],al
CMP [MovingSound], 0;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE ChangeUp;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,10d ; for 10 milliseconds
xor ah,ah
push ax
mov ax,[Movenote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [MovingSound],1
ChangeUp:
jmp Change
notUp:
;
;if W is pressed
;
cmp ah,11h
je UpArrow
;
;if Left arrow is pressed
;
cmp ah, 4Bh
jne notLeft
LeftKey:
xor ax,ax
mov al,[Y]
push ax
xor al,al
mov al,[X]
dec al
push ax
call calculate_Location
mov bx,ax
call checkmovment
cmp ax,0
jne movleft
CMP [HitingWall], al;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE LeftGoBack;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,75d ; for 50 milliseconds
xor ah,ah
push ax
mov ax,[Wallnote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [HitingWall],1;To show that the sound where you hit the wall happens
LeftGoBack:
JMP GoBack
movleft:
inc [NumberMoves]
call Left;moving the player one pixel Left and update his location info
mov al,[X]
dec al
mov [X],al
CMP [MovingSound], 0;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE ChangeLeft;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,10d ; for 10 milliseconds
xor ah,ah
push ax
mov ax,[Movenote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [MovingSound],1
ChangeLeft:
jmp Change
notLeft:
;
; if A is pressed
;
cmp ah,1Eh
je LeftKey
;
;if down arrow is pressed
;
cmp ah, 50h
jne notDown
Downarrow:
xor ax,ax
mov al,[Y]
inc al
push ax
xor al,al
mov al,[X]
push ax
call calculate_Location
mov bx,ax
call checkmovment
cmp ax,0
jne movdown
CMP [HitingWall], al;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE DownGoBack;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,75d ; for 50 milliseconds
xor ah,ah
push ax
mov ax,[Wallnote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [HitingWall],1;To show that the sound where you hit the wall happens
DownGoBack:
JMP GoBack
movdown:;moving the player one pixel down and update his location info
inc [NumberMoves]
call Down
mov al,[Y]
inc al
mov [Y],al
CMP [MovingSound], 0;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE ChangeDown;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,10d ; for 10 milliseconds
xor ah,ah
push ax
mov ax,[Movenote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [MovingSound],1
ChangeDown:
jmp Change
notDown:
;
; if S is pressed
;
cmp ah,1Fh
je Downarrow
;
;if Right arrow is pressed
;
cmp ah, 4Dh
jne notRight
RightKey:
xor ax,ax
mov al,[Y]
push ax
xor al,al
mov al,[X]
inc al
push ax
call calculate_Location
mov bx,ax
call checkmovment
cmp ax,0
jne movRight
CMP [HitingWall], al;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE RightGoBack ;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,75d; for 75 milliseconds
xor ah,ah
push ax
mov ax,[Wallnote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [HitingWall],1 ;To show that the sound where you hit the wall happens
RightGoBack:
JMP GoBack
movRight:
inc [NumberMoves]
;moving the player one pixel right and update his location info
call Right
mov al,[X]
inc al
mov [X],al
CMP [MovingSound], 0;if hittingwall equal 0, the voice when you hit the wall is not happening
JNE ChangeRight;putting the parameters of TurnOnMusic (the function where you turn any music on)
mov al,10d ; for 10 milliseconds
xor ah,ah
push ax
mov ax,[Movenote]
push ax
lea ax,[mil]
push ax
lea ax,[sec]
push ax
call TurnOnMusic
mov [MovingSound],1
ChangeRight:
jmp Change
notRight:
;
;If D is pressed
;
cmp ah,20h
je RightKey
esckey:
;
;if esc pressed, exit
;
cmp ah,01
jne Change
exit:
;
; resetting es so we can use it in the future
;
assume es:nothing
push ds
pop es
; close the speaker
in al, 61h
and al, 11111100b
out 61h, al
;
; move the cursor to the left right corenr of the screen
;
mov DH,0
mov DL,0
call cleanset
;
;get page number
;
mov ah,0fh
int 10h
;
;exit using dos
;
mov al,0
mov ah, 04ch
int 21h
;
;This case the player reach to the end of the screen and change it
;
Change:
ChangeofQ2:
CMP [Q],2
JNE ChangeofQ1
ULtoUR:
CMP [X],79d
JNE ULtoDL
lea dx,[UR]
call ChangeScreen
xor ax,ax
mov al,[Y]
push ax
mov [Q],1
sub [X],79d
xor ax,ax
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
jmp NoChagne
ULtoDL:
CMP[Y],24d
JNE ChangeofQ1
lea dx,[DLow]
call ChangeScreen
xor ax,ax
mov [Q],3
mov [Y],0
mov al,[Y]
push ax
xor ax,ax
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
jmp NoChagne
ChangeofQ1:
CMP [Q],1
JE SkipQ1
JMP ChangeofQ3
SkipQ1:
CMP [X],0d
JNE URtoDR
URtoUL:
mov [Q],2
add [X],79d
mov cx, 4000d ; the size of textseg is 4000d
mov ax, textseg
mov es, ax
assume es:textseg
xor bx,bx
;
;move the the data from UL (the first screen we see) to textseg so we will be able to see it
;
moveUL:
mov al,[byte UL+bx]
mov [byte ptr text+bx],al
inc bx
loop moveUL
xor ax,ax
mov al,[Y]
push ax
xor ax,ax
mov [X],79d
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
jmp NoChagne
URtoDR:
CMP[Y],24d
JNE ChangeofQ3
lea dx,[DR]
call ChangeScreen
xor ax,ax
mov [Q],4
mov [Y],0
mov al,[Y]
push ax
xor ax,ax
add [X],1
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
xor ax,ax
mov al,24
push ax
mov al,77d
push ax
call calculate_Location
mov bx,ax
;
;Marking the pixels around the door with red
;
mov [text+bx+1],044h
mov [text+bx+5],044h
jmp NoChagne
ChangeofQ3:
cmp [Q],3
JE Skip
JMP ChangeofQ4
Skip:
DLowtoUL:
CMP [Y],0
JNE DLtoDR
mov [Q],2
mov [Y],24d
mov cx, 4000d ; the size of textseg is 4000d
mov ax, textseg
mov es, ax
assume es:textseg
xor bx,bx
;move the the data from UL (the first screen we see) to textseg so we will be able to see it
loopDLowtoUL:
mov al,[byte UL+bx]
mov [byte ptr text+bx],al
inc bx
loop loopDLowtoUL
xor ax,ax
mov [Y],24d
mov al,[Y]
push ax
xor ax,ax
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
jmp NoChagne
DLtoDR:
CMP [X],79d
JNE ChangeofQ4
lea dx,[DR]
call ChangeScreen
xor ax,ax
mov [Q],4
mov [X],0
mov al,[Y]
push ax
xor ax,ax
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
xor ax,ax
mov al,24
push ax
mov al,77d
push ax
call calculate_Location
mov bx,ax
mov [text+bx+1],044h
mov [text+bx+5],044h
jmp NoChagne
ChangeofQ4:
CMP [Q],4
JNE NoChagne
CMP [Y],0d
JNE DRtoDL
DRtoUR:
mov [Q],1
mov [Y],24d
lea dx,[UR]
call ChangeScreen
xor ax,ax
mov al,[Y]
push ax
sub [X],1
xor ax,ax
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
jmp NoChagne
DRtoDL:
;Switch the screen from Down Right to Down left
CMP [X],0
JNE NoChagne
mov [Q],3
mov [X],79d
lea dx,[DLow]
call ChangeScreen
xor ax,ax
mov al,[Y]
push ax
xor ax,ax
mov al,[X]
push ax
call calculate_Location
mov bx,ax
mov ax, textseg
mov es, ax
assume es:textseg
mov al,02h
mov [text+bx],al
mov al,03Ah
mov [text+bx+1],al
jmp NoChagne
NoChagne:
; Check if you win
CMP [Q],4d
JE SkipNochange1
JMP GoBack
SkipNochange1:
CMP [X],78d
JE SkipNochange2
JMP GoBack
SkipNochange2:
CMP [Y],25d
JE SkipNochange3
JMP GoBack
SkipNochange3:
mov DH,0
mov DL,0
call cleanset
Lea dx, [WinMSG1]
mov ah, 9
int 21h
;
;Change the number in [NumberMoves] to Decimally
;
mov ax,[NumberMoves]
mov di,10d
lea si,[MovesHelper+5]
ChangeMoves:
dec si
xor dx,dx
div di
mov bx,dx
add bl,'0'
mov [si],bl
cmp si,offset MovesHelper
jne ChangeMoves
xor bx, bx
Remove0Loop:
CMP [MovesHelper+bx],'0'
JNE PrintMoveHelper
inc bx
JMP Remove0Loop
PrintMoveHelper:
lea dx, [MovesHelper+bx]
mov ah, 9
int 21h
Lea dx, [WinMSG2]
mov ah, 9
int 21h
; open speaker
in al, 61h
or al, 00000011b
out 61h, al
; send control word to change frequency
mov al, 0B6h
out 43h, al
; play frequency
mov ax, 2711
out 42h, al ; Sending lower byte
mov al, ah
out 42h, al ; Sending upper byte
mov ah,2ch
int 21h
mov [sec],dh
mov [mil],dl
add [mil],22
CMP [mil],100
JNA SkipMusicwin1
sub [mil],100
inc [sec]
SkipMusicwin1:
mov ah,2ch
int 21h
CMP [sec],dh
JA SkipMusicwin1
CMP [mil],dl
JA SkipMusicwin1
;
;Winning music
;A huge thanks to Yaheli Yahiri in teaching me how music work
;
; send control word to change frequency
mov al, 0B6h
out 43h, al
; play frequency
mov ax, 2560
out 42h, al ; Sending lower byte
mov al, ah
out 42h, al ; Sending upper byte
mov ah,2ch
int 21h
mov [sec],dh
mov [mil],dl
add [mil],22
CMP [mil],100
JNA SkipMusicwin2
sub [mil],100
inc [sec]
SkipMusicwin2:
mov ah,2ch
int 21h
CMP [sec],dh
JA SkipMusicwin2
CMP [mil],dl
JA SkipMusicwin2
; send control word to change frequency
mov al, 0B6h
out 43h, al
; play frequency
mov ax, 2415
out 42h, al ; Sending lower byte
mov al, ah
out 42h, al ; Sending upper byte
mov ah,2ch
int 21h
mov [sec],dh
mov [mil],dl
add [mil],22
CMP [mil],100
JNA SkipMusicwin3
sub [mil],100
inc [sec]
SkipMusicwin3:
mov ah,2ch
int 21h
CMP [sec],dh
JA SkipMusicwin3
CMP [mil],dl
JA SkipMusicwin3
; send control word to change frequency
mov al, 0B6h
out 43h, al
; play frequency
mov ax, 2281
out 42h, al ; Sending lower byte
mov al, ah
out 42h, al ; Sending upper byte
mov ah,2ch
int 21h
mov [sec],dh
mov [mil],dl
add [mil],12
add [sec],1
CMP [mil],100
JNA SkipMusicwin4
sub [mil],100
inc [sec]
SkipMusicwin4:
mov ah,2ch
int 21h
CMP [sec],dh
JA SkipMusicwin4
CMP [mil],dl
JA SkipMusicwin4
; close the speaker
in al, 61h
and al, 11111100b
out 61h, al
WinLoop:
xor ah, ah ; wait for key and read
int 16h ; bios keyboard
cmp AH,1 ;ESC
JNE SkipWinLoop
JMP Exit