-
Notifications
You must be signed in to change notification settings - Fork 0
/
chess.asm
5041 lines (4529 loc) · 92.7 KB
/
chess.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
locals
sizeS equ 100d
firstLoc equ 0dh
RankMove Struc
RootAdrs dw 0h ;Tool Source Offset(adress)
DestAdrs dw 0h ;Tool Destini Offset(adress)
moveRank dw 0h ;The Rank For Moving
RankMove EndS
TableS struc
NameP1 db 18d,20d dup('$')
NameP2 db 18d,20d dup('$')
Winner db 18d,20d dup('$') ; winner's name
DNTB db 18d,20d dup('$') ; date & time in the begining
DNTE db 18d,20d dup('$') ; date & time in the end ; DD/MM/YYYY HH:MM:SS
TableS Ends
dseg segment
sqStr db 201d,205d,205d,205d,205d,205d,187d
SQ_COLS = ($-sqStr)/type sqStr
db 186d, 0h, 0h, 0h, 0h, 0h ,186d
db 200d,205d,205d,205d,205d,205d, 188d
SQ_ROWS = (($-sqStr)/type sqStr)/SQ_COLS
brd db 'r','h','b','q','k','b','h','r'
BRD_COLS = ($-brd)/type brd
db 'p','p','p','p','p','p','p','p'
db '0','0','0','0','0','0','0','0'
db '0','0','0','0','0','0','0','0'
db '0','0','0','0','0','0','0','0'
db '0','0','0','0','0','0','0','0'
db 'P','P','P','P','P','P','P','P'
db 'R','H','B','Q','K','B','H','R'
BRD_ROWS = (($-brd)/type brd)/BRD_COLS
BRD_LEN = BRD_ROWS*BRD_COLS
xTurn dw 'A', 'a' ;xTurn[0] = who's turn
castlArr db 0h,0h ;Big/Small Castling Available (0)
promotionMsg db "Pick a Tool:",0ah,0dh,"Q - Queen",0ah,0dh,"R - Rook",0ah,0dh,"H - Horse",0ah,0dh, "B - Bishop$"
promotionDel db " ",0ah,0dh," ",0ah,0dh," ",0ah,0dh," ",0ah,0dh, " $"
SelPlrorCmp db "P - Player",0ah,0dh,"C - Cmp $"
cmpOrPlr dw 0000h ;0h = Player vs Player (else) 'a' = Computer First, 'A' = Player First
selTurnByPlr db "W - White ",0ah,0dh,"B - Blue$"
rnk RankMove SizeS*2 dup(< , , >)
P_OPPMOV db 4h ;1-up, 2-double up,3-eat left, 4- eat right.
R_OPPMOV db 01ch ;7 up + 7 down + 7 left + 7 right = 7*4 = 01ch
B_OPPMOV = R_OPPMOV ;7 upright + 7 upleft + 7 downright + 7 downleft = 7*4 = 01ch = R_OPPMOV
H_OPPMOV db 8h
K_OPPMOV = H_OPPMOV
Q_OPPMOV = R_OPPMOV
openScr db 'ChessTxt.txt', 0
buffer1 db 1000h dup('$') ;OpenScr
buffStr db 6000h dup('$')
fNameStr db 'Tbl.txt',0
fPStr dw ?
buffR db 600h dup('$')
fNameR db 'Results.txt',0
fpr dw ?
p1Winner db 'P1Win.txt', 0
p2Winner db 'P2Win.txt', 0
buffer2 db 1000h dup('$') ;Winner Messeg
menu db " Player Vs Computer "
MEN_LEN = ($-menu)
db " Player1 Vs Player2 "
db " Instruction "
db " Record Table "
db " Quit "
clrMenu db " White "
MEN_CLR_LEN= ($-clrMenu)
db " Blue "
tbl TableS SizeS dup(< , , , , >)
temp TableS < , , , , >
TBL_LEN = type tbl
p1Str db 10,13,"Player One, Enter Your Name, Please: $"
p2Str db 10,13,"Player Two, Enter Your Name, Please: $"
cmpName db "CmpPlayer $"
lineStr db " $"
countStr dw (?)
tempDNT db "00/00/0000 00:00:00$"
msgKeletInst db "Enter 1 For Sort By Name Player 1",10,13,"Enter 2 For Sort By Name Player 2",10,13,"Enter 3 For Sort By Name Winner",10,13,"Enter 4 For Sort By Beggin Date",10,13,"Enter 5 For Sort By End Date",10,10,13,'$'
keletMsg db "Please Enter Input Number(1...5): $"
keletArr db 5h dup(?)
KELET_LEN = ($-keletArr)/type keletArr
startAreas db 5h dup(?)
endAreas db 5h dup (?)
dseg ends
sseg segment stack
dw 100h dup(?)
sseg ends
cseg segment
assume cs:cseg, ds:dseg, ss:sseg
ClrScr Proc
push ax cx dx
mov cx, 30h
mov dl, 0ah
mov ah, 2h
@@Clr: int 21h
loop @@Clr
push 0h
call GoToXY
pop dx cx ax
ret
ClrScr Endp
WriteStr Proc
push bp
mov bp, sp
push ax dx
mov dx, [bp+4] ; offset str
mov ah, 9h
int 21h
pop dx ax bp
ret 2
WriteStr Endp
GoToXY proc
push bp
mov bp, sp
push ax bx dx
mov bh, 0h
mov dx, [bp+4] ;Location
mov ah, 2h
int 10h
pop dx bx ax bp
ret 2
GoToXY endp
Square proc ;Get: Offset Of Square, Cols, Location, Color, Rows - Drawing Square By Settings
push bp
mov bp, sp
push ax bx cx dx si di
mov di, [bp+4] ;Rows Length
mov bl, [bp+6] ;Color
mov cx, [bp+10] ;Cols Length
mov si, [bp+12] ;offset sqStr
mov dx, [bp+8]
WrShu: push cx
mov al, [si]
mov cx, 1h
mov bh, 0h
mov ah, 2h
int 10h
mov ah, 9h
int 10h
inc dl
inc si
pop cx
cmp al, 0h
jz SkipTabs
loop WrShu
mov cx, [bp+10]
inc dh
sub dl, cl
dec di
jnz WrShu
jmp @@Sof
SkipTabs: push ax
mov ax, [bp+10]
sub ax, 3h
add si, ax
add dl, al
pop ax
mov cl, 1h
jmp WrShu
@@Sof: pop di si dx cx bx ax bp
ret 10
Square EndP
DrawBoard proc
push bx cx dx si di
mov di, 1
mov si, 8h ;Board Rows Length
mov dh, 0
DrawC: mov dl, firstLoc ;First Square Location
mov cl, 8h ;Board Cols Length
DrawR: cmp di, 1 ;Color Menager
jnc @@Color2
@@Color1: mov bl, 00001000b
mov di, 1
jmp StSq
@@Color2: mov bl, 00001111b
mov di, 0
StSq: push offset sqStr SQ_COLS dx bx SQ_ROWS
call Square
add dl, SQ_COLS
loop DrawR
dec di
add dh, SQ_ROWS
dec si
jnz DrawC
pop di si dx cx bx
ret
DrawBoard EndP
DrawTools Proc
push bp
mov bp, sp
push ax bx cx dx si di
xor bx, bx
mov si, [bp+4] ;offset brd
mov cx, BRD_COLS
mov di, BRD_ROWS
mov dx, 0h
mov dx, firstLoc ;dl = first location of pointer
add dl, 3h
inc dh
ColsTimes: mov ah, 2h
int 10h
mov al, [si]
mov bl, 00001111b
cmp al, '0'
jnz @@DntDelTl
push cx ax
mov al, ' '
mov cx, 1h
;mov bh, 0h
mov ah, 9h
int 10h
pop ax cx
jmp @@NextTool
@@DntDelTl: push dx ;~~~~1
push 0h 60h ax 07bh
call IfxBetweenAB
pop dx
cmp dx, 1h
pop dx ;~~~~1
jnz @@Con
sub al, 20h ;make capital letter
mov bl, 00001011b
@@Con: push cx
mov cx, 1h
;mov bh, 0h
mov ah, 9h
int 10h
pop cx
@@NextTool: add si, type brd
add dl, 7h
loop ColsTimes
mov dx, firstLoc
add dl, 3h
inc dh
dec di
jz @@Sof
mov cx, 8h
push cx
sub cx, di
SetRow: add dh, 3h
loop SetRow
pop cx
jmp ColsTimes
@@Sof: pop di si dx cx bx ax bp
ret 2
DrawTools EndP
IfxBetweenAB Proc ;if(A<x<B){return 1} else 0
push bp
mov bp, sp
push ax bx cx dx si di
mov bl, [bp+4] ;the B
mov al, [bp+6] ;the x
mov bh, [bp+8] ;the A
cmp al, bl
jnc @@Sof
cmp al, bh
jc @@Sof
mov [bp+10], 1h
@@Sof: pop di si dx cx bx ax bp
ret 6
IfxBetweenAB EndP
PlayChess Proc
push bp
mov bp, sp
push ax bx cx dx si di
mov ax, [bp+4] ;cmpOrPlr
xor bl, bl ;Colour Index - 0 - White; 1 - Gray
xor cl, cl ;SpaceCounter
mov dx, firstLoc
cmp ax, xTurn[0]
jnz Klita
jmp @@CmpTurn
Klita: mov ah, 7h
int 21h
cmp al, 0h
jz DoubleKey
cmp al, 20h
jnz @@Con
jmp SpaceClckd
@@Con: cmp al, 'e'
jz JmpSofi
;push 0h
;call Cheats
;pop ax ;1 = N pressed, 0 = Done
;cmp al, 0h
;jz JmpSofi
;jmp Klita
JmpSofi: jmp @@Sof
DoubleKey: mov ah, 7h
int 21h
push ax ;~~~~PUSH~~~~
mov ax, 00001111b ;White
cmp bl, 1h
jnz @@PntWhite
mov ax, 00001000b ;Gray
@@PntWhite: push ax
call PaintSq
xor bl, 1h
pop ax ;~~~~POP~~~~
cmp al, 04dh
jz RightMove
cmp al, 04bh
jz LeftMove
cmp al, 48h
jz UpMove
cmp al, 50h
jz DownMove
pop ax
jmp Klita
RightMove: add dl, 7h
cmp dl, 045h
jz RByWall
jmp PaintSqu
RByWall: mov dl, 0dh
jmp PaintSqu
LeftMove: sub dl, 7h
cmp dl, 6h
jz LeftByWall
jmp PaintSqu
LeftByWall: mov dl, 03eh
jmp PaintSqu
UpMove: sub dh, 3h
cmp dh, -3h
jz UpByWall
jmp PaintSqu
UpByWall: mov dh, 15h
jmp PaintSqu
DownMove: add dh, 3h
cmp dh, 18h
jz DownByWall
jmp PaintSqu
DownByWall: mov dh, 0h
PaintSqu: mov ax, 00001001b ;Blue
cmp cl, 1h
jnz @@PntBlue
mov ax, 00000100b ;paint red if space was clicked
@@PntBlue: push ax
call PaintSq
jmp Klita
SpaceClckd: cmp cl, 1h
jz SecSpace
push 0h ;For Si Thats Come later... (stam)
push xTurn[0]
call FirstSpace
pop si
cmp si, 0h
jnz Contin ;if ToolSelected
jmp Klita
Contin: xor cl, 1h ;FirstSpace Were Clicked
jmp Klita
SecSpace: push xTurn[0] si dx
call SecondSpace
xor cl, 1h
push 0h xTurn[0]
call CheckMate
pop ax
cmp ax, 1h
jz @@Winner
mov ax, [bp+4] ;cmpOrPlr
cmp ax, xTurn[0]
jz @@CmpTurn
jmp Klita
@@CmpTurn: push xTurn[0] offset rnk offset brd
call ComputerTurn
comment *
push ax ;save ax
push 0h xTurn[2]
call CheckMate
pop ax
cmp ax, 1h
jz @@Winner
pop ax ;load ax
*
call SwitchTurns
jmp Klita
;push 0h ;For ax.. (stam)
;push bx ;xTrun Yano..
;call CheckMate
;pop ax ;1 = Mate! 0 = Nothing, Continue...
;cmp al, 1h
;pop ax
;jnz @@NoMate
;pop ax
;jmp @@Sof
@@Winner:
@@Sof: pop di si dx cx bx ax bp
ret 2
PlayChess EndP
ToolExist Proc ;si(y-1) + x
push bp
mov bp, sp
push ax bx cx dx si di
mov dx, [bp+4] ;location
mov si, [bp+6] ;offset brd
mov cx, BRD_COLS
mov di, BRD_ROWS
mov bx, firstLoc
add bl, 3h
inc bh
@@ColTimes: cmp bx, dx
jz DoneEAsearch
add si, type brd
add bl, 7h
loop @@ColTimes
dec di
jz @@NoExist
mov bx, firstLoc
add bl, 3h
inc bh
mov cx, 8h
push cx
sub cx, di
@@SetRow: add bh, 3h
loop @@SetRow
pop cx
jmp @@ColTimes
DoneEAsearch:
mov bl, [si]
cmp bl, '0'
jz @@NoExist
mov [bp+8], si
@@NoExist: pop di si dx cx bx ax bp
ret 4
ToolExist Endp
FirstSpace Proc
push bp
mov bp, sp
push ax bx cx dx si di
mov bl, [bp+4] ; xTurn[0]
mov cl, 0h ;Selecter , 0 = didnt select yet, 1 = select success
;xor di, 1h
push dx
add dl, 3h
inc dh
push 0h offset brd dx
call ToolExist
pop si
pop dx
cmp si, 0h
jnz TrySelect ;if Tool is exist
jmp SofFirstSpace
TrySelect: push 0h
push 0040h
push [si]
push 005bh
call IfxBetweenAB
pop ax
cmp ax, 1h
jz @@CheckCapital
cmp bl, 'a'
jz SelectSuccess
jmp @@Unsucc
@@CheckCapital:
cmp bl, 'A'
jz SelectSuccess
@@Unsucc: mov si, 0h
jmp SofFirstSpace
SelectSuccess:
mov cl, 1h
push 04h
call PaintSq
push bx dx
mov bh, 0h
add dl, 3h
inc dh
mov ah, 2h
int 10h
mov dl, ' '
mov ah, 2h
int 21h
pop dx bx
SofFirstSpace:
mov [bp+6], si
pop di si dx cx bx ax bp
ret 2
FirstSpace EndP
SecondSpace Proc ; Get: Tool That had been Pressed, Location To Move, xTurn Idexer
push bp
mov bp, sp
push ax bx cx dx si di
mov dx, [bp+4] ;Location
add dl, 3h
inc dh
mov si, [bp+6] ;tool had been pressed
mov ax, [si]
push 0h
push 0060h
push ax
push 0007bh
call IfxBetweenAB
pop cx
cmp cx, 1h
jnz @@ConToP
sub ax, 20h
@@ConToP: cmp al, 'P'
jnz @@ConToR
push dx si xTurn[0]
call PawnRules
jmp @@Con
@@ConToR: cmp al, 'R'
jnz @@ConToB
push dx si
call RookRules
jmp @@Con
@@ConToB: cmp al, 'B'
jnz @@ConToQ
push dx si
call BishopRules
jmp @@Con
@@ConToQ: cmp al, 'Q'
jnz @@ConToH
push dx si
call RookRules
push dx si
call BishopRules
jmp @@Con
@@ConToH: cmp al, 'H'
jnz @@ConToK
push dx si
call HorseRules
jmp @@Con
@@ConToK: cmp al, 'K'
jnz @@ToSof
push dx si
call KingRules
@@ToSof: jmp @@Con
@@Con: push offset brd
call DrawTools
dec dh
sub dl, 3h
mov ah, 10h
int 21h
push 09h
call PaintSq
pop di si dx cx bx ax bp
ret 6
SecondSpace EndP
GetLocByEA Proc
push bp
mov bp, sp
push ax bx cx dx si di
mov si, [bp+4] ;The adress of tool by offset brd
mov di, [bp+6] ;The adress of board
mov [bp+8], 1h ;Error ! - can be crosss !
mov cx, BRD_COLS
mov bx, 0h
mov dx, firstLoc
add dl, 3h
inc dh
@@CmpNow: cmp di, si
jz @@LocFound
add di, type brd
add dl, 7h
loop @@CmpNow
inc bx
cmp bx, BRD_ROWS
jz @@Sof
push bx
mov dx, firstLoc
mov cx, BRD_COLS
add dl, 3h
inc dh
@@BxTimes: add dh, 3h
dec bx
jnz @@BxTimes
pop bx
jmp @@CmpNow
@@LocFound: mov [bp+8], dx
@@Sof: pop di si dx cx bx ax bp
ret 4
GetLocByEA EndP
QueenLoc Proc
push bp
mov bp, sp
push ax bx si
xor bx, bx
mov si, [bp+4] ;offset brd
mov bx, [bp+6] ;xTurn[0]
FQuen: mov al, [si]
cmp bl, 'A'
jnz FSQuen
cmp al, 'Q'
jz @@FindDest
jmp LoopQ
FSQuen: cmp al, 'q'
jz @@FindDest
LoopQ: add si, type brd
jmp FQuen
@@FindDest: mov [bp+8], si
@@Sof: pop si bx ax bp
ret 4
QueenLoc EndP
KingLoc Proc
push bp
mov bp, sp
push ax bx si
xor bx, bx
mov si, [bp+4] ;offset brd
mov bx, [bp+6] ;xTurn[0]
Fking: mov al, [si]
cmp bl, 'A'
jnz FSking
cmp al, 'K'
jz FindDest
jmp LoopK
FSking: cmp al, 'k'
jz FindDest
LoopK: add si, type brd
jmp FKing
FindDest: mov [bp+8], si
@@Sof: pop si bx ax bp
ret 4
KingLoc EndP
comment *
Cheats Proc
push bp
mov bp, sp
push ax bx cx dx si di
@@Again: mov ah, 7h
int 21h
cmp al, 'o'
jz OneWin
cmp al, 't'
jz TwoWin
cmp al, 'n'
mov [bp+4], 1h
jnz @@Jagain
jmp @@Sof
@@Jagain: jmp @@Again
OneWin: push xTurn[0]
pop ax
jmp @@Con
TwoWin: push xTurn[1]
pop ax
@@Con: cmp ax, 0bh
jz @@P1Win
@@P2Win: call ClrScr
push ax bx cx si di
mov cx, 0h
push ax cx dx
mov si, offset tbl
mov cx, countStr
mov al, type tbl
mul cl
add si, ax
pop dx cx ax
lea di, [si].Winner
lea bx, [si].NameP2
mov cl, [bx]
@@WriteWin1:
mov al, [bx]
mov [di], al
inc bx
inc di
loop @@WriteWin1
pop di si cx bx ax
push offset buffer2 offset p2Winner
call Kitov
mov ah, 7h
int 21h
jmp @@Sof
@@P1Win: call ClrScr
push ax bx cx si di
mov cx, 0h
mov si, offset tbl
push ax cx dx
mov si, offset tbl
mov cx, countStr
mov al, type tbl
mul cl
add si, ax
pop dx cx ax
lea di, [si].Winner
lea bx, [si].NameP1
mov cl, [bx]
@@WriteWin2:
mov al, [bx]
mov [di], al
inc bx
inc di
loop @@WriteWin2
pop di si cx bx ax
push offset buffer2 offset p1Winner
call Kitov
mov ah, 7h
int 21h
mov [bp+4], 0h
@@Sof: pop di si dx cx bx ax bp
ret
Cheats EndP
*
PaintSq Proc
push bp
mov bp, sp
push bx
mov bx, [bp+4] ;Paint
mov bh, 0h
push offset sqStr SQ_COLS dx bx SQ_ROWS
call Square
pop bx bp
ret 2
PaintSq EndP
CheckIfAeatB Proc
push bp
mov bp, sp
push ax bx si di
mov si, [bp+6] ;Offset tool Gonna eat (A) --if this
mov di, [bp+4] ;Offset tool gonna be eaten (B) --eat this
mov al, [di]
cmp al, '0'
jnz @@EatCheck
jmp @@Sof
@@EatCheck: push 0h
push 0040h
push [si]
push 005bh
call IfxBetweenAB
pop ax
push 0h
push 0040h
push [di]
push 005bh
call IfxBetweenAB
pop bx
cmp ax, bx
jz @@Sof
mov [bp+8], 1h
@@Sof: pop di si bx ax bp
ret 4
CheckIfAeatB Endp
SwitchTurns Proc
push xTurn[0]
push xTurn[2]
pop xTurn[0]
pop xTurn[2]
ret
SwitchTurns EndP
CheckBorderCross Proc
push bp
mov bp, sp
push dx
mov dx, [bp+4] ;Location to check
mov [bp+6], 1h ;There is a CROSS!
cmp dl, 42h
jnc @@Sof
cmp dl, 10h
jc @@Sof
cmp dh, 1h
jc @@Sof
cmp dh, 17h
jnc @@Sof
mov [bp+6], 0h
@@Sof: pop dx bp
ret 2
CheckBorderCross EndP
CheckBorderCrossByEA Proc
push bp
mov bp, sp
push dx
mov si, [bp+4] ;Location to check
push 0h offset brd si
call GetLocByEA
pop dx
mov [bp+6], 1h ;There is a CROSS!
cmp dl, 42h
jnc @@Sof
cmp dl, 10h
jc @@Sof
cmp dh, 1h
jc @@Sof
cmp dh, 17h
jnc @@Sof
mov [bp+6], 0h
@@Sof: pop dx bp
ret 2
CheckBorderCrossByEA EndP
Promotion Proc
push bp
mov bp, sp
push ax bx dx si
mov si, [bp+4] ;offset tool that moved
mov bl, [bp+6] ;xTurn[0]
mov dx, 0h
mov ah, 2h
int 10h
push offset promotionMsg
call WriteStr
@@Klot: mov ah, 7h
int 21h
cmp al, 'q'
jz @@DoProm
cmp al, 'r'
jz @@DoProm
cmp al, 'b'
jz @@DoProm
cmp al, 'h'
jz @@DoProm
jmp @@Klot
@@DoProm: cmp bl, 'a'
jz @@SmllLet
sub al, 20h
@@SmllLet: mov [si], al
mov dx, 0h
mov ah, 2h
int 10h
push offset promotionDel
call WriteStr
pop si dx bx ax bp
ret 4
Promotion Endp
PawnRules Proc ;Get: Adress Of Tools Array, Location To Move
push bp
mov bp, sp
push ax bx cx dx si di
mov bl, [bp+4] ;xTurn[0]
mov si, [bp+6] ;Offset of tool will be moved (?)
mov dx, [bp+8] ;Location To Move
mov di, si
mov cx, 1h
push 0h offset brd si
call GetLocByEA
pop ax
cmp bl, 'A'
jz @@FromDown
jmp @@FromUp
@@FromDown: cmp ah, 13h
jnz @@MovChk1
inc cx ;two move available
@@MovChk1: sub ah, 3h
sub si, BRD_COLS
mov bl, [si]
cmp bl, '0'
jnz @@FromDEat
cmp dx, ax
jnz @@DoLoop
jmp @@DoMove
@@DoLoop: loop @@MovChk1
@@FromDEat: mov si, di
push 0h offset brd si
call GetLocByEA
pop ax
sub ah, 3h ;Try Eat From Left
sub si, BRD_COLS
jmp @@LeftEat
@@FromUp: cmp ah, 4h
jnz @@MovChk2
inc cx ;two move available
@@MovChk2: add ah, 3h
add si, BRD_COLS
mov bl, [si]
cmp bl, '0'
jnz @@FromUEat
cmp dx, ax
jz @@DoMove
loop @@MovChk2
@@FromUEat: mov si, di
push 0h offset brd si
call GetLocByEA
pop ax
add ah, 3h ;Try Eat From Left
add si, BRD_COLS
@@LeftEat: sub al, 7h
sub si, type brd
cmp ax, dx
jnz @@RightEat
push 0h di si
call CheckIfAeatB
pop ax
cmp al, 1h
jz @@DoMove
@@RightEat: add al, 0eh
add si, type brd*2
cmp ax, dx
jnz @@Sof
push 0h di si
call CheckIfAeatB
pop ax
cmp al, 1h
jz @@DoMove
jmp @@Sof
@@DoMove: cmp dh, 1h
jnz @@Opp
push xTurn[0] si
call Promotion
mov bh, '0'
mov [di], bh
jmp @@SwchTurn
@@Opp: cmp dh, 16h
jnz @@OrigiMov
push xTurn[0] si
call Promotion
mov bh, '0'
mov [di], bh
jmp @@SwchTurn
@@OrigiMov: mov bl, [di]
mov bh, '0'
mov [di], bh
mov [si], bl
@@SwchTurn: push ax ;save ax
push 0h xTurn[0]
call CheckChess
pop ax
cmp al, 1h
pop ax ;load ax
jz @@UndoMove
call SwitchTurns
jmp @@Sof
@@UndoMove: mov [si], bh ;clean the new area
mov [di], bl ;return the tool to its place
@@Sof: pop di si dx cx bx ax bp
ret 6
PawnRules EndP
RookRules Proc
push bp
mov bp, sp
push ax bx cx dx si di
mov si, [bp+4] ;offset of tool will be moved (?)
mov dx, [bp+6] ;Location To Move
mov cx, 4h ;Up/Down/Left/Right
mov di, si
mov bl, [si]
push 0h offset brd si
call GetLocByEA
pop ax
@@WhereJmp: cmp cx, 4h
jnz @@ConTo3
jmp @@RookUM