-
Notifications
You must be signed in to change notification settings - Fork 2
/
Logic.asm
3969 lines (3416 loc) · 78.2 KB
/
Logic.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
EXTRN InitBoard:FAR
EXTRN DrawSquare:FAR
EXTRN DrawPiece:FAR
EXTRN DrawPieces:FAR
EXTRN DrawBoard:FAR
EXTRN RedrawBoardSq:FAR
EXTRN RedrawPiece:FAR
EXTRN DrawPossibleMoves:FAR
EXTRN DrawPossibleAttacks:FAR
EXTRN DrawDeadP:FAR
EXTRN DrawCooldown:FAR
EXTRN DrawRightPiece:FAR
EXTRN name1:byte
EXTRN name2:byte
EXTRN CursorColor:byte
EXTRN MovesColor:byte
EXTRN AttackColor:byte
EXTRN Ana_El_Tl3t:Byte
;EXTRN Moves_bishop:FAR
Public to_idx
; Public GameScreenLocal
Public GameScreenMulti
Public SendByte
Public ReceiveByte
Public PrintNumber
Public chessBoard
Public ValidMoves
Public ValidAttacks
Public ValidMoves2
Public ValidAttacks2
Public B_DeadPiece
Public W_DeadPiece
Public px
Public py
Public Player
Public Mode
Public RMsg
Public SMsg
include Macro.inc
.286
.Model small
.Stack 400h
.Data
Beginning_Board db "B0","B1","B2","B3","B4","B2","B1","B0"
db "B5","B5","B5","B5","B5","B5","B5","B5"
db "00","00","00","00","00","00","00","00"
db "00","00","00","00","00","00","00","00"
db "00","00","00","00","00","00","00","00"
db "00","00","00","00","00","00","00","00"
db "W5","W5","W5","W5","W5","W5","W5","W5"
db "W0","W1","W2","W3","W4","W2","W1","W0"
chessBoard db "B0","B1","B2","B3","B4","B2","B1","B0"
db "B5","B5","B5","B5","B5","B5","B5","B5"
db "00","00","00","00","00","00","00","00"
db "00","00","00","00","00","00","00","00"
db "00","00","00","00","00","00","00","00"
db "00","00","00","00","00","00","00","00"
db "W5","W5","W5","W5","W5","W5","W5","W5"
db "W0","W1","W2","W3","W4","W2","W1","W0"
ValidMoves db 32 dup('$$'), '$' ; assuming that the max no. of possible moves for 1 piece is 32
; idk the correct number
ValidAttacks db 8 dup('$$'), '$'
ValidMoves2 db 32 dup('$$'), '$' ; assuming that the max no. of possible moves for 1 piece is 32
; idk the correct number
ValidAttacks2 db 8 dup('$$'), '$'
;To display dead pieces
B_DeadPiece db 16 dup('$$'),'$'
W_DeadPiece db 16 dup('$$'),'$'
higlight_Pos label byte
px db 1
py db 8
px2 db 1
py2 db 1
selPos label byte ; current selected piece position
hx db 0
hy db 0
hx2 db 0
hy2 db 0
IsKing db ?
W_King_X db 5
W_King_Y db 8
B_King_X db 5
B_King_Y db 1
B_Check db 0
W_Check db 0
;Time variables
prevms db ?
prevs db ?
Prevtime dw ?
frame db ?
timer dw 0
counter db 0
seconds db 0
minutes db 0
CoolDownPieces dw 64 dup(0), '$'
;AnimateArray db 10 dup('$$$$$$$$');00cur pos 00;end pos 0;timer 00;piece symbol
AnimateArray db 10 dup('$$$$$$$');00cur pos 00;end pos 0;timer 00;el symbool
Winner db 0 ;0 no winner 1 i won 2 i lose 3 other player left
; You_Lose_Message db " Black Wins ";'Black Wins'
; You_Win_Message db " White Wins ";'White Wins'
You_Win_Message db " You Win ";'Black Wins' 9
You_Lose_Message db " You Lose ";'White Wins' 10
Player_Left_Message db " Your opponent has left the game ";'White Wins' 33
BTag db "Black:"
WTag db "White:"
IncheckMsg db "Check"
EmptyMsg db " "
RMsg db 4 dup(9)
SMsg db 4 dup(9)
Player db 'W' ; dh el by7aded whether im player1 or player 2
Mode db 0 ; dh el by7aded whether im player1 or player 2
IX db 0
IY db 15d
OX db 33d
OY db 15d
.Code
;The main game loop for local mode
; GameScreenLocal PROC FAR
; MOV AX , @DATA
; MOV DS , AX
; call InitBoard
; call far ptr InitGame
; mov ah, 2Ch
; int 21h
; mov al,dh ; move el seconds
; mov ah,0
; mov bl, 100
; mul bl
; mov bl, cl
; mov bh, 0
; add ax , bx
; mov bx, ax
; mov Prevtime, bx
; mov prevs, dh
; ;======================================================================================
; ;MAIN GAME LOOP
; GameLP:
; call far ptr GetFrameTime
; pusha
; call Animate
; popa
; lea bx, CoolDownPieces
; mov dx, 300 ; => 9 sec for testing purposes. should be 3
; mov si, 0
; mov cx, 0
; mov di,ax ; ax contains the frame time
; UpdateCooldown:
; CD_Lp:
; ;check if piece in this position has a cooldown if not skip it
; cmp [word ptr bx], si ;0
; je NotInCoolDown
; ;if piece is on cooldown check if the cooldown is done
; cmp [word ptr bx], dx ;300
; jae DoneCooldown
; ;cooldown isn't done
; ;check if 37/100 sec has passed since last time, if yes then update the drawing.
; ; there are 8 frames for the cooldown and the cooldown duration is 3 sec
; ; so each frame should be displayed for roughly 37/100 sec
; push dx
; mov ax, [word ptr bx] ; move the time that passed since start of the cooldown timer until the last loop
; mov dl, 37
; div dl
; mov dh,al
; ;dh now has the previous frame index
; ;check if enough time has passed and the frame needs to be updated
; ;calculate new frame index
; add [word ptr bx], di
; mov ax, [word ptr bx]
; mov dl, 37
; div dl
; cmp al,dh ;if frame indexes equal no need to update frame thus skip
; je CD_Lp_Skip
; push cx
; inc ch
; inc cl ;drawing takes position 1 indexed. the loop is 0 indexed since its an array
; call RedrawBoardSq
; call DrawingChecks
; call DrawCooldown
; call RedrawPiece
; pop cx
; CD_Lp_Skip:
; pop dx
; jmp NotInCoolDown
; DoneCooldown:
; mov [word ptr bx], si ;0
; call RedrawPiece
; NotInCoolDown:
; add bx, 2
; inc ch
; cmp ch,8
; jne CD_Lp
; inc cl ; if reaches 8 ie end of row
; mov ch,0
; cmp cl,8
; jne CD_Lp
; mov ch,px
; mov cl,py
; mov ah,1
; int 16h
; jz GameLP1
; mov ah,0
; int 16h
; cmp ah, 01
; je ending
; ;Check if select key pressed
; call far ptr HandleInput
; call far ptr HandleInput2
; cmp winner,0
; je GameLP1
; ; Press any key to exit
; ; mov ah,2
; ; mov dx,1407h
; ; int 10h
; cmp winner,1
; je White_Wins
; lea bp, You_Lose_Message
; jmp DispMsg
; White_Wins:
; lea bp, You_Win_Message
; DispMsg:
; mov al, 1
; mov bh, 0
; mov bl, 4
; mov cx, 12
; mov dl, 14
; mov dh, 12
; push ds
; pop es
; ;mov bp, offset msg
; mov ah, 13h
; int 10h
; MOV AH , 0
; INT 16h
; ret
; GameLP1:
; jmp GameLP
; ending:
; ; ; Press any key to exit
; ; MOV AH , 0
; ; INT 16h
; ; ;Change to Text MODE
; ; MOV AH,0
; ; MOV AL,03h
; ; INT 10h
; ; ; return control to operating system
; ; MOV AH , 4ch
; ; INT 21H
; ret
; GameScreenLocal ENDP
;The main game loop for multiplayer mode
GameScreenMulti PROC
MOV AX , @DATA
MOV DS , AX
call InitBoard
call far ptr InitGame
mov ah, 2Ch
int 21h
mov al,dh ; move el seconds
mov ah,0
mov bl, 100
mul bl
mov bl, cl
mov bh, 0
add ax , bx
mov bx, ax
mov Prevtime, bx
mov prevs, dh
;======================================================================================
;MAIN GAME LOOP
GameLPMulti:
call far ptr GetFrameTime
call Clock
call ReceiveMsg
call Animate
lea bx, CoolDownPieces
mov dx, 300 ; => 9 sec for testing purposes. should be 3
mov si, 0
mov cx, 0
mov di,ax ; ax contains the frame time
UpdateCooldownMulti:
CD_LpMulti:
;check if piece in this position has a cooldown if not skip it
cmp [word ptr bx], si ;0
je NotInCoolDownMulti
;if piece is on cooldown check if the cooldown is done
cmp [word ptr bx], dx ;300
jae DoneCooldownMulti
;cooldown isn't done
;check if 37/100 sec has passed since last time, if yes then update the drawing.
; there are 8 frames for the cooldown and the cooldown duration is 3 sec
; so each frame should be displayed for roughly 37/100 sec
push dx
mov ax, [word ptr bx] ; move the time that passed since start of the cooldown timer until the last loop
mov dl, 37
div dl
mov dh,al
;dh now has the previous frame index
;check if enough time has passed and the frame needs to be updated
;calculate new frame index
add [word ptr bx], di
mov ax, [word ptr bx]
mov dl, 37
div dl
cmp al,dh ;if frame indexes equal no need to update frame thus skip
je CD_Lp_SkipMulti
push cx
inc ch
inc cl ;drawing takes position 1 indexed. the loop is 0 indexed since its an array
call RedrawBoardSq
call DrawingChecks
call DrawCooldown
call RedrawPiece
pop cx
CD_Lp_SkipMulti:
pop dx
jmp NotInCoolDownMulti
DoneCooldownMulti:
mov [word ptr bx], si ;0
call RedrawPiece
NotInCoolDownMulti:
add bx, 2
inc ch
cmp ch,8
jne CD_LpMulti
inc cl ; if reaches 8 ie end of row
mov ch,0
cmp cl,8
jne CD_LpMulti
cmp winner,1
je I_Win
cmp winner,2
je I_Lose
cmp winner, 3
je Player_Left
mov ch,px
mov cl,py
mov ah,1
int 16h
jz GameLP1Multi
mov ah,0
int 16h
cmp ah, 01
je endingMultiMid
;Check if select key pressed
call far ptr HandleInput
; call far ptr HandleInput2
jmp GameLPMulti
I_Lose:
lea bp, You_Lose_Message
jmp DispMsgMulti
Player_Left:
lea bp, Player_Left_Message
mov al, 1
mov bh, 0
mov bl, 4
mov cx, 33
mov dl, 5
mov dh, 12
push ds
pop es
mov ah, 13h
int 10h
AwaitESC2:
mov ah,1
int 16h
jz AwaitESC2
mov ah,0
int 16h
cmp ah,1
jne AwaitESC2
mov SMsg, 201
lea di, SMsg
call far ptr SendByte
ret
GameLP1Multi:
jmp GameLPMulti
endingMultiMid:
jmp endingMulti
I_Win:
lea bp, You_Win_Message
DispMsgMulti:
mov al, 1
mov bh, 0
mov bl, 4
mov cx, 10
mov dl, 14
mov dh, 12
push ds
pop es
;mov bp, offset msg
mov ah, 13h
int 10h
AwaitESC:
call Animate
;display win/lose msg
mov al, 1
mov bh, 0
mov bl, 4
mov cx, 10
mov dl, 14
mov dh, 12
push ds
pop es
mov ah, 13h
int 10h
mov ah,1
int 16h
jz AwaitESC
mov ah,0
int 16h
cmp ah,1
jne AwaitESC
mov SMsg, 201
lea di, SMsg
call far ptr SendByte
mov Ana_El_Tl3t,1
ret
endingMulti:
mov SMsg, 200 ; 200 for end
lea di,SMsg
call far ptr SendByte
mov Ana_El_Tl3t,1
ret
GameScreenMulti ENDP
;Initializes all variables to default values
InitGame PROC Far
pusha
;Initialize array to default values at start of game
mov ax, @data
mov es, ax
lea si, Beginning_Board
lea di,chessBoard
mov cx, 64
REP MOVSW
lea si,B_DeadPiece
call ClearList
lea si,W_DeadPiece
call ClearList
lea si, ValidMoves
call ClearList
lea si, ValidAttacks
call ClearList
lea si, ValidMoves2
call ClearList
lea si, ValidAttacks2
call ClearList
lea si, AnimateArray
mov cx,10*7
mov ah,'$'
CL_Animations:
mov [si],ah
inc si
LOOP CL_Animations
lea si, CoolDownPieces
mov cx, 64
mov ax, 0
IG_Clear:
mov [si], ax
add si,2
loop IG_Clear
lea si, CoolDownPieces
;mov ax, [si + 112]
cmp Player, 'B'
je IAmBlack
lea si, name1
lea di, name2
mov px , 1
mov py , 8
mov CursorColor, 68h
mov MovesColor, 36h
mov AttackColor, 4h
jmp I_G_1
IAmBlack: ;name1 ytktb 3nd el black
lea si, name2
lea di, name1
mov px , 1
mov py , 1
mov CursorColor, 2Ah
mov MovesColor, 2bh
mov AttackColor, 6Bh
I_G_1:
mov px2, 1
mov py2, 1
mov hx , 0
mov hy , 0
mov hx2, 0
mov hy2, 0
mov W_King_X , 5
mov W_King_Y , 8
mov B_King_X , 5
mov B_King_Y , 1
mov B_Check , 0
mov W_Check , 0
mov winner, 0
mov seconds,0
mov minutes,0
mov counter,0
mov IX,0
mov IY,15d
mov OX,33
mov OY,15d
; initialize the board and draws all pieces in place
call InitBoard
DrawSq px, py
MOV ch,px
MOV cl,py
call RedrawPiece
; DrawSq2 px2, py2
; MOV ch,px2
; MOV cl,py2
; call RedrawPiece
PrintNames:
mov al, 1
mov bh, 0
mov bl, 1Eh
mov cx, 6
mov dl, 0
mov dh, 0
push ds
pop es
mov bp, offset WTag
mov ah, 13h
int 10h
mov dh, 1
mov dl, 0
mov bh, 0
mov ah, 2
int 10h
;white name
mov dx, si
mov ah, 9
int 21h
mov al, 1
mov bh, 0
mov bl, 4fh
mov cx, 6
mov dl, 73
mov dh, 0
push ds
pop es
mov bp, offset BTag
mov ah, 13h
int 10h
mov dh, 1
mov dl, 73
mov bh, 0
mov ah, 2
int 10h
;black name
mov dx, di
mov ah, 9
int 21h
push cx
mov cx,10
SetupChat:
call SCROLLInputScreen
call SCROLLOutputScreen
LOOP SetupChat
pop cx
call UpdateCheck
popa
ret
InitGame ENDP
;white / should handle input for black and white but in single player mode in phase 2,
; just need to uncomment some parts. for now it handles white player's input
HandleInput PROC Far ; the user input is in ax => al:ascii ah:scan code
;Handles all game logic
;Including:
; 1-Check for input
; 2-Move piece
; 3-Getting available moves
; MOV ch,px
; MOV cl,py
; cmp al,'q'
; je Player1
; cmp al,'d'
; je RightP1
; cmp al,'a'
; je LeftP1
; cmp al,'w'
; je upP1
; cmp al,'s'
; je downP1
cmp ah, 52h
je Player1
cmp ah, 4Dh
je RightP2
cmp ah, 4Bh
je LeftP2
cmp ah, 48h
je upP2
cmp ah, 50h
je downP2
cmp al,8
je Return
cmp al,20h
jb Return
cmp al,7Eh
ja Return
mov SMsg,al
lea di,SMsg
call far ptr SendByte
mov dh,IY
mov dl,IX
mov bh,0
mov ah,2
int 10h
pusha
call WRITEINPUT
popa
ret
Player1:
mov dl, Player ; W indicates that it is player one that is selecting
jmp select_mid
;==================================
;This part is responsible for updating the selector position on key press
; RightP1:
; cmp px,8
; je Return
; add px,1
; jmp Draw_Highlighted
; LeftP1:
; cmp px,1
; je Return
; sub px,1
; jmp Draw_Highlighted
; upP1:
; cmp py,1
; je Return
; sub py,1
; jmp Draw_Highlighted
; downP1:
; cmp py,8
; je Return
; add py,1
RightP2:
cmp px,8
je Return
add px,1
jmp Draw_Highlighted
LeftP2:
cmp px,1
je Return
sub px,1
jmp Draw_Highlighted
upP2:
cmp py,1
je Return
sub py,1
jmp Draw_Highlighted
downP2:
cmp py,8
je Return
add py,1
jmp Draw_Highlighted
select_mid:jmp select
Return:
ret
; Player2:
; mov dl, 'B' ; B indicates that it is player one that is selecting
; jmp select_mid
;==================================
;This part is responsible for drawing selector position update
Draw_Highlighted:
call RedrawBoardSq ; redaraw the current as a normal board square (not higlighted) before moving
call DrawPossibleMoves ; need to redraw possible moves so that it is not erased if selector gets on a valid move's square
call DrawPossibleAttacks ; need to redraw possible moves so that it is not erased if selector gets on a valid attack's square
call RedrawPiece ; redraw piece if any at the old location
; cmp hx2,0
; je skip2
; ;===== drawing a background behind the selected piece bs need to erase it b3d kda when another piece is selected
; DrawSq2 hx2, hy2
; mov ch, hx2
; mov cl, hy2
; call RedrawPiece
; skip2:
cmp hx,0
je skip
;===== drawing a background behind the selected piece bs need to erase it b3d kda when another piece is selected
DrawSq hx, hy
mov ch, hx
mov cl, hy
call RedrawPiece
skip:
; mov ch,px2
; mov cl,py2
; DrawSq2 px2, py2 ;draw higlighting of new square
; call RedrawPiece ;
mov ch,px
mov cl,py
DrawSq px, py ;draw higlighting of new square
call RedrawPiece ;
ret
;==================================
;This part is responsible for moving and attacking logic
select:
;check if valid move
mov ch,px
mov cl,py
call to_idx
lea si,ValidMoves
call List_Contains
cmp al,0 ; selected pos is not a valid move
je Check_Valid_Attack
; send the move i just made to the other player
lea di,SMsg
mov cl,hx
mov [di], cl
mov cl,hy
mov [di+1], cl
mov cl,px
mov [di+2], cl
mov cl,py
mov [di+3], cl
call SendMsg
call Move_Piece
jmp H_I_ClearValidLists
Check_Valid_Attack:
lea si, ValidAttacks
call List_Contains
cmp al,0 ; selected pos is not a valid attack
jne Skip_Check_Empty
mov al, '0'
cmp [di], al ; check if position is empty and not valid move or attack
je H_I_ClearValidLists_Mid
jmp Sel
;============================
H_I_ClearValidLists_Mid:
jmp H_I_ClearValidLists
;============================
Skip_Check_Empty:
mov al, 'B'
cmp [di], al
je kill_Black
;kill white
lea si, W_DeadPiece
jmp Kill_Piece
kill_Black:
lea si, B_DeadPiece
Kill_Piece:
mov bl,'4' ; king number ex B4 is black king
cmp [di+1],bl
jne HI_AppendDeadPiece
mov Winner,1 ;winner 0 => no winner 1 => I win 2 => Other player wins
HI_AppendDeadPiece:
mov bl,'$' ;get last element in array to append at the end
sub si,2
GetEnd:add si,2
cmp [si],bl
jne GetEnd
mov bh,[di]
mov bl,[di+1]
mov [si],bh
mov [si+1],bl
call DrawDeadP
pusha
; send the move i just made to the other player
lea di,SMsg
mov cl,hx
mov [di], cl
mov cl,hy
mov [di+1], cl
mov cl,px
mov [di+2], cl
mov cl,py
mov [di+3], cl
call SendMsg
popa
call Move_Piece
; cmp hx2,0
; je H_I_ClearValidLists
; mov ch, px
; mov cl, py
; cmp hx2,ch
; jne G3
; cmp hy2,cl
; jne G3
; DeselectPlayer2
; G3:
; call ClearValidLists2
; mov ch,hx2
; mov cl,hy2
; call GetValidMoves
;call DrawPossibleMoves
;==================================
;This part is responsible for re-inializing valid attack/move lists and drawing the updates of attacking/moving
H_I_ClearValidLists:
call ClearValidLists
; cmp hx2,0
; je HI_S1
; DrawSq2 hx2,hy2 ;ba redraw el background of el selected piece bta3t el team el tany
; ;34an lw kan selected w kan valid attack lama ams7 el attack el selector maytms74
; mov ch,hx2
; mov cl,hy2
; call RedrawPiece
; HI_S1:
DeselectPlayer1
; DrawSq2 px2,py2
; call DrawPossibleMoves
; call DrawPossibleAttacks
; call DrawDeadP
ret
;==================================
;This part is responsible for selecting a new piece and drawing its valid moves & attacks
Sel:
mov ch, px
mov cl, py
call to_idx
cmp [di], dl ;dl has the player type W:white or B:black
je Valid_Sel
; should Deslect player1 if Q is pressed and Deselect player2 when Space is pressed
DeselectPlayer1
call ClearValidLists
call DrawPossibleAttacks
ret
Valid_Sel:
;Make sure the piece to be selected isn't on cooldown
;Calculating the current piece's position in the piece cooldown array
mov al, px
dec al ; cause the cooldown array is 0 indexed
mov ah,0
mov bl, 2
mul bl
mov bh, al
mov al, py
dec al ; cause the cooldown array is 0 indexed
mov ah,0
mov bl, 16
mul bl
add al, bh
mov si, ax
;checking if the piece is on cooldown. 0 ==> no cooldown otherwise ==> on cooldown
mov ax, 0
lea bx, CoolDownPieces
cmp [word ptr bx + si], ax
je HI_SelectNewPiece
DeselectPlayer1
call ClearValidLists
ret
HI_SelectNewPiece:
mov ch, hx
mov cl, hy
call RedrawBoardSq
call RedrawPiece
mov ch, px