-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtetris.asm
1818 lines (1529 loc) · 42.1 KB
/
tetris.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
.Model large
.Stack 100h
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Data
.Data
score db 0
previous_time db ?
shape_kind db 0; ;0 = horizontal ;1 = square ;2 = L_Shape ;3 = T_Shape ;4 = S_Shape
next_shape_kind db 0; ;0 = horizontal ;1 = square ;2 = L_Shape ;3 = T_Shape ;4 = S_Shape
next_next_shape_kind db 0; ;0 = horizontal ;1 = square ;2 = L_Shape ;3 = T_Shape ;4 = S_Shape
rows dw ?
cols dw ?
left_move_validation dw 1
right_move_validation dw 1
down_move_validation dw 1
rotation_validation dw 1
shape_color db ?
next_shape_color db ?
next_next_shape_color db ?
f_is_pressed db 0
first_element_of_filled_row dw 0
rotation_state db 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Cordinates
left_border dw 90
right_border dw 230
down_border dw 190
top_border dw 20
blocks_in_row db 14
blocks_in_col db 17
blocks_in_screen dw 238
block_up_side db 0
block_down_side db 0
block_left_side db 0
block_right_side db 0
block_up_side_word dw 0
block_down_side_word dw 0
block_left_side_word dw 0
block_right_side_word dw 0
row_index db 0
col_index db 0
block_size db 10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Strings
game_over_string db "GAME IS OVER!$"
msg_next db "Next$"
msg_next_next db "Next-Next$"
msg_score db "Score:$"
msg_down db "DOWN:$"
msg_left db "LEFT:$"
msg_right db "RIGHT:$"
value1 db "0000$"
value2 db "0000$"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Shapes(patterns)
;top down left right
horizontal dw 20,30,160,170
dw 20,30,170,180
dw 20,30,180,190
dw 20,30,190,200
dw 20,30,160,200
dw 1
horizontal_90 dw 20,30,160,170
dw 30,40,160,170
dw 40,50,160,170
dw 50,60,160,170
dw 20,60,160,170
dw 1
horizontal_180 dw 20,30,160,170
dw 20,30,170,180
dw 20,30,180,190
dw 20,30,190,200
dw 20,30,160,200
dw 1
horizontal_270 dw 20,30,160,170
dw 30,40,160,170
dw 40,50,160,170
dw 50,60,160,170
dw 20,60,160,170
dw 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
square dw 20,30,160,170
dw 20,30,170,180
dw 30,40,160,170
dw 30,40,170,180
dw 20,40,160,180
dw 3
square_90 dw 20,30,160,170
dw 20,30,170,180
dw 30,40,160,170
dw 30,40,170,180
dw 20,40,160,180
dw 3
square_180 dw 20,30,160,170
dw 20,30,170,180
dw 30,40,160,170
dw 30,40,170,180
dw 20,40,160,180
dw 3
square_270 dw 20,30,160,170
dw 20,30,170,180
dw 30,40,160,170
dw 30,40,170,180
dw 20,40,160,180
dw 3
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
L_Shape dw 20,30,160,170
dw 30,40,160,170
dw 40,50,160,170
dw 40,50,170,180
dw 20,50,160,180
dw 4
L_Shape_90 dw 30,40,160,170
dw 30,40,170,180
dw 30,40,180,190
dw 40,50,160,170
dw 30,50,160,190
dw 4
L_Shape_180 dw 20,30,160,170
dw 20,30,170,180
dw 30,40,170,180
dw 40,50,170,180
dw 20,50,160,180
dw 4
L_Shape_270 dw 30,40,150,160
dw 30,40,160,170
dw 30,40,170,180
dw 20,30,170,180
dw 20,40,150,180
dw 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
T_Shape dw 20,30,160,170
dw 20,30,170,180
dw 20,30,180,190
dw 30,40,170,180
dw 20,40,160,190
dw 5
T_Shape_90 dw 30,40,160,170
dw 20,30,170,180
dw 30,40,170,180
dw 40,50,170,180
dw 20,50,160,180
dw 5
T_Shape_180 dw 20,30,170,180
dw 30,40,160,170
dw 30,40,170,180
dw 30,40,180,190
dw 20,40,160,190
dw 5
T_Shape_270 dw 20,30,170,180
dw 30,40,170,180
dw 40,50,170,180
dw 30,40,180,190
dw 20,50,170,190
dw 5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
S_Shape dw 20,30,160,170
dw 30,40,160,170
dw 30,40,170,180
dw 40,50,170,180
dw 20,50,160,180
dw 6
S_Shape_90 dw 40,50,150,160
dw 40,50,160,170
dw 30,40,160,170
dw 30,40,170,180
dw 30,50,150,180
dw 6
S_Shape_180 dw 20,30,160,170
dw 30,40,160,170
dw 30,40,170,180
dw 40,50,170,180
dw 20,50,160,180
dw 6
S_Shape_270 dw 40,50,150,160
dw 40,50,160,170
dw 30,40,160,170
dw 30,40,170,180
dw 30,50,150,180
dw 6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
current_shape dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw ?
current_shape_0 dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw ?
current_shape_90 dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw ?
current_shape_180 dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw ?
current_shape_270 dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw ?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
next_shape dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw ?
next_next_shape dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw 0,0,0,0
dw ?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Array db 0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;14 * 17
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
ArrayUpperPart db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0,0,0,0,0,0,0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Macros
show_number Macro msg,number,row,col
Local L
push ax
push bx
push cx
push dx
mov cx,10d
xor bx,bx
mov bx,3
mov ah,0
mov al,number
L:
xor dx,dx
div cx
or dl,30h
mov msg[bx],dl
dec bx
or ax,ax
jne L
display_string msg,row,col,4,8
pop dx
pop cx
pop bx
pop ax
endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
draw_row Macro row,begin_col,end_col,color
Local L
push ax
push bx
push cx
push dx
mov ah, 0ch
mov al, color
mov cx, begin_col
mov dx, row
L:
int 10h
inc cx
cmp cx, end_col
jl L
pop dx
pop cx
pop bx
pop ax
EndM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
draw_column Macro col,begin_row,end_row,color
Local L
push ax
push bx
push cx
push dx
mov ah, 0ch
mov al, color
mov cx, col
mov dx, begin_row
L:
int 10h
inc dx
cmp dx, end_row
jl L
pop dx
pop cx
pop bx
pop ax
EndM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
copy Macro pattern_from,pattern_to
local L
push ax
push bx
xor bx,bx
L:
mov ax,pattern_from[bx]
mov pattern_to[bx],ax
add bx,2
cmp bx,40
jle L
pop bx
pop ax
endm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
display_string Macro msg,row,column,length,color
push ax
push bx
push cx
push dx
mov ax, @data
mov es, ax
mov ah, 13h ; string writing
mov al, 00h ; move cursor
xor bh, bh ; page 0
mov bl, color ; set string color
mov bp, offset msg ; BP points to string to be printed
mov cx, length ; string length
mov dh, row ; row location
mov dl, column ; col location
int 10h ; draw the string
pop dx
pop cx
pop bx
pop ax
EndM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
draw_block Macro start_row, end_row, start_column, end_column, color_block
Local L
push ax
push bx
push cx
push dx
mov dx, start_row
L:
draw_row dx, start_column, end_column,color_block
inc dx
cmp dx, end_row
jle L
pop dx
pop cx
pop bx
pop ax
EndM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
draw_shape Macro pattern
Local L
push ax
push bx
push cx
push dx
mov bx,0
L:
draw_block [pattern+bx],[pattern+bx+2],[pattern+bx+4],[pattern+bx+6],shape_color
add bx,8
cmp bx,24
jle L
pop dx
pop cx
pop bx
pop ax
EndM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
draw_black_shape Macro pattern
Local L
push ax
push bx
push cx
push dx
mov bx,0
L:
draw_block [pattern+BX],[pattern+BX+2],[pattern+BX+4],[pattern+BX+6],0
add bx,8
cmp bx,24
jle L
pop dx
pop cx
pop bx
pop ax
EndM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MAIN
.CODE
MAIN PROC
;set data segment
mov ax,@data
mov ds,ax
call set_graphical_mode
call draw_screen
call set_first_shape_horizontal
WHILE_TRUE:
show_number value1,score,11,6
call delay
draw_black_shape current_shape
call move_shape_down
call check_keyboard
call set_current_shape_color
draw_shape current_shape
call check_game_over
jmp WHILE_TRUE
MAIN ENDP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Procedures
set_first_shape_horizontal proc near
push ax
copy horizontal,current_shape
copy horizontal,current_shape_0
copy horizontal_90,current_shape_90
copy horizontal_180,current_shape_180
copy horizontal_270,current_shape_270
mov ax,current_shape[40] ;Set color of shape
mov ah,0
mov shape_color,al
draw_shape current_shape
pop ax
ret
set_first_shape_horizontal endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
set_graphical_mode proc near
;set screen 320x200
mov AH,0
MOV AL,13h
int 10h
;set background color
mov ah,0bh
mov bh,0
mov bl,15
int 10h
ret
set_graphical_mode endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
delay proc near
WAIST_TIME:
mov ah, 2ch
int 21h
cmp dl, previous_time
je WAIST_TIME
mov previous_time, dl
WAIST_TIME2:
mov ah, 2ch
int 21h
cmp dl, previous_time
je WAIST_TIME2
mov previous_time, dl
WAIST_TIME3:
mov ah, 2ch
int 21h
cmp dl, previous_time
je WAIST_TIME3
mov previous_time, dl
ret
delay endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
big_delay proc near
WAIST_TIME4:
mov ah, 2ch
int 21h
cmp dh, previous_time
je WAIST_TIME4
mov previous_time, dh
WAIST_TIME5:
mov ah, 2ch
int 21h
cmp dh, previous_time
je WAIST_TIME5
mov previous_time, dh
WAIST_TIME6:
mov ah, 2ch
int 21h
cmp dh, previous_time
je WAIST_TIME6
mov previous_time, dh
ret
big_delay endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
draw_screen proc near
;draw_screen_play_area
draw_row 19,89,230,3
draw_column 89,19,191,3
draw_column 230,19,191,3
draw_row 191,89,230,3
;draw_screen_next_shape
draw_row 10,20,80,2
draw_column 20,10,60,2
draw_column 80,10,60,2
draw_row 60,20,80,2
;draw_screen_next_next_shape
draw_row 10,240,300,2
draw_column 240,10,60,2
draw_column 300,10,60,2
draw_row 60,240,300,2
;draw_screen_strings
display_string msg_next,8,4,4,2
display_string msg_next_next,8,30,9,2
display_string msg_score,11,0,6,5
ret
draw_screen endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move_left proc near
push ax
push bx
mov ax,[si+36] ;left border of pattern
sub ax,10
cmp ax,left_border
jl exit1
mov [si+36],ax
mov ax,[si+38]
sub ax,10
mov [si+38],ax
mov bx,4 ;go to start-col of block
L1:
mov ax,[si+bx]
sub ax,10
mov [si+bx],ax
add bx,2 ;go to end-col of block
mov ax,[si+bx]
sub ax,10
mov [si+bx],ax
add bx,6 ;go to next block
cmp bx,28
jle L1
exit1:
pop bx
pop ax
ret
move_left endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move_right proc near
push ax
push bx
mov ax,[si+38] ;right border of pattern
add ax,10
cmp ax,right_border
jg exit2
mov [si+38],ax
mov ax,[si+36]
add ax,10
mov [si+36],ax
mov bx,4 ;go to start-col of block
L2:
mov ax,[si+bx]
add ax,10
mov [si+bx],ax
add bx,2 ;go to end-col of block
mov ax,[si+bx]
add ax,10
mov [si+bx],ax
add bx,6 ;go to next block
cmp bx,28
jle L2
exit2:
pop bx
pop ax
ret
move_right endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move_down proc near
push ax
push bx
mov ax,[si+34] ;down border of pattern
add ax,10
cmp ax,down_border
jg exit3
mov [si+34],ax
mov ax,[si+32]
add ax,10
mov [si+32],ax
mov bx,0
L3:
mov ax,[si+bx]
add ax,10
mov [si+bx],ax
add bx,2 ;go to down-edge of block
mov ax,[si+bx]
add ax,10
mov [si+bx],ax
add bx,6 ;go to next block of pattern
cmp bx,24
jle L3
exit3:
pop bx
pop ax
ret
endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
is_down_move_valid proc near
push ax
push bx
push cx
push dx
mov si,offset current_shape
mov ax,[si+34] ;down border of pattern
add ax,10
cmp ax,down_border
jg EXIT_AND_STOP_SHAPE
mov cx,2 ;go to down side of first block
CHECK_FOR_ALL_BLOCKS_OF_THIS_SHAPE:
mov bx,cx
mov dx,[si+bx] ;down side of block
mov ax,190
sub ax,dx
xor bh,bh
mov bl,10
div bl
mov dx,ax
dec dx
mov rows,dx
;now dx has the distance of this block from down (in blocks)
add cx,4 ;go to right side of block
mov bx,cx
mov dx,[si+bx]
mov ax,230
sub ax,dx
xor bh,bh
mov bl,10
div bl
mov dx,ax
mov cols,dx
;now dx has the distance of this block from right (in blocks)
mov ax,14 ;block count in a row
mov bx,rows
mul bx
add ax,cols
;now ax has index of down block of the block that we entered in CHECK_FOR_ALL_BLOCKS_OF_THIS_SHAPE with
mov bx,ax
mov ah,Array[bx]
cmp ah,0
jne EXIT_AND_STOP_SHAPE
add cx,4 ;go to down side of next block
cmp cx,30
jl CHECK_FOR_ALL_BLOCKS_OF_THIS_SHAPE
mov down_move_validation,1
jmp exit4
EXIT_AND_STOP_SHAPE:
mov down_move_validation,0
jmp exit4
exit4:
pop dx
pop cx
pop bx
pop ax
ret
is_down_move_valid endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
is_left_move_valid proc near
push ax
push bx
push cx
push dx
mov si,offset current_shape
mov ax,[si+36] ;left border of pattern
sub ax,10
cmp ax,left_border
jl SET_LEFT_MOVE_VALIDATION_0
mov cx,2 ;go to down side of first block
LOOP_FOR_ALL_BLOCKS_OF_THIS_SHAPE:
mov bx,cx
mov dx,[si+bx] ;down side of block
mov ax,190
sub ax,dx
xor bl,bl
mov bl,10
div bl
mov dx,ax
mov rows,dx
;now dx has the distance of this block from down (in blocks)
add cx,4 ;go to right side of block
mov bx,cx
mov dx,[si+bx]
mov ax,230
sub ax,dx
xor bh,bh
mov bl,10
div bl
mov dx,ax
mov cols,dx
;now cx has the distance of this block from right (in blocks)
mov ax,14 ;block count in a row
mov bx,rows
mul bx
add ax,cols
inc ax ;left neighbor block in Array
;now ax has index of down block of the block that we entered in CHECK_FOR_ALL_BLOCKS_OF_THIS_SHAPE with
mov bx,ax
cmp Array[bx],0
jne SET_LEFT_MOVE_VALIDATION_0
add cx,4 ;go to down side of next block
cmp cx,30
jl LOOP_FOR_ALL_BLOCKS_OF_THIS_SHAPE
mov left_move_validation,1
jmp exit8
SET_LEFT_MOVE_VALIDATION_0:
mov left_move_validation,0
exit8:
pop dx
pop cx
pop bx
pop ax
ret
is_left_move_valid endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
is_right_move_valid proc near
push ax
push bx
push cx
push dx
mov si,offset current_shape
mov ax,[si+38] ;right border of pattern
add ax,10
cmp ax,right_border
jg SET_RIGHT_MOVE_VALIDATION_0
mov cx,2 ;go to down side of first block
LOOP_FOR_ALL_BLOCKS_OF_THIS_SHAPE2:
mov bx,cx
mov dx,[si+bx] ;down side of block
mov ax,190
sub ax,dx
xor bl,bl
mov bl,10
div bl
mov dx,ax
mov rows,dx
;now dx has the distance of this block from down (in blocks)
add cx,4 ;go to right side of block
mov bx,cx
mov dx,[si+bx]
mov ax,230
sub ax,dx
xor bh,bh
mov bl,10
div bl
mov dx,ax
mov cols,dx
;now cx has the distance of this block from right (in blocks)
mov ax,14 ;block count in a row
mov bx,rows
mul bx
add ax,cols
dec ax ;right neighbor block in Array
;now ax has index of down block of the block that we entered in CHECK_FOR_ALL_BLOCKS_OF_THIS_SHAPE with
mov bx,ax
cmp Array[bx],0
jne SET_RIGHT_MOVE_VALIDATION_0
add cx,4 ;go to down side of next block
cmp cx,30
jl LOOP_FOR_ALL_BLOCKS_OF_THIS_SHAPE2
mov right_move_validation,1
jmp exit9
SET_RIGHT_MOVE_VALIDATION_0:
mov right_move_validation,0
exit9:
pop dx
pop cx
pop bx
pop ax
ret
is_right_move_valid endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
move_shape_down proc near
mov si,offset current_shape
mov ax,[si+34] ;down border of pattern
add ax,10
cmp ax,down_border
jg STOP_SHAPE2
call is_down_move_valid
cmp down_move_validation,1
je CALL_MOVE_DOWN2
STOP_SHAPE2:
call stop_current_shape
call initial_new_shape
call initial_new_next_shape
call initial_new_next_next_shape
jmp exit13
CALL_MOVE_DOWN2:
call move_all_rotated_patterns_down
mov si,offset current_shape
call move_down
exit13:
ret
move_shape_down endp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
check_keyboard proc near
;check if any key pressed
mov ah,01h
int 16h
jz exit5_HELPER
;check which key is pressed
mov ah,00h
int 16h
cmp al,61h ;if 'a' is pressed
je MOVE_LEFT_LABEL
cmp al,64h ;if 'd' is pressed
je MOVE_RIGHT_LABEL
cmp al,66h ;if 'f' is pressed
je SET_F_IS_PRESSED_1
cmp al,73h ;if 's' is pressed
je MOVE_DOWN_LABEL
cmp al,77h ;if 'w' is pressed
je ROTATE_LABEL
jmp exit5 ;press a not valid key
ROTATE_LABEL:
call rotate
jmp exit5
SET_F_IS_PRESSED_1:
mov f_is_pressed,1
jmp MOVE_DOWN_LABEL
MOVE_LEFT_LABEL:
call is_left_move_valid
cmp left_move_validation,0
je exit5
mov si,offset current_shape
call move_left
call move_all_rotated_patterns_left
jmp exit5