/
ChessY2K.ASM
3807 lines (3241 loc) · 85.7 KB
/
ChessY2K.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
.title ChessY2K
;
; Chess assembler ASM code for MSX
;
; DOS command lines to compile:
; TASM -80 -b ChessPI.ASM ChessPI.co2
; TASM -80 -b ChessY2K.ASM ChessY2K.com
; TASM -80 -b ChessPG.ASM ChessPG.co2
; Then run ChessY2K.com on MSX-DOS1
;
; Date: sep.,oct. 2012, upd. feb.2016
;
;Performance testing: 256 movement generations per minute on MSX machine -
; not enaugh for chess but ok for pgn-viewer project.
#include "options.asm" ; generated by compile-bat files
;
; *define PGN_COMPILE to compile separate module for pgn viewer replays
; It can not be done in one .COM unfortunately because of limited length.
; ChessPZ.COM is a compilation with no PGN version.
;
; Memory 0x4400-0x8000 is free and usable. Stack at ~0xD500
;
.org $100
AA_startProgram:
call Copy_VdpRegs ; save VDP regs
call ChessMN ; process menu
; chess logic is in this file
call Rest_VdpRegs ; restore VDP regs
call SetScreen0By30h
jp JMP_0000 ; return to MSXDOS
ret
startFEN:
.byte "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",0
; STATUSES OF CURRENT CHESS GAME
; Current chess position
BOARD: .byte "a1 h1" ;64 bytes of board
.byte "a2 h2"
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte "a8 h8"
.byte 0
SIDE: .byte 0 ; side to move 0-white, 1-black
CASTLES: .byte 0 ; castling allowance flags
; if bits are set: 0 wK, 1 wQ, 2 bK, 3 bQ sides
ENPSQ: .byte $ff ; en-passant square none
WKSQ: .byte 0 ; square of white king
BKSQ: .byte 0 ; square of black king
NEXT_MVCNT: .byte 0 ;count, values, and string to output
NEXT_MOVES: .word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.word 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
; list of moves from the root
; bytes:
; square from,
; square to,
; promoted piece with flags
; en-passant square move before
MOVE_CNT .byte 0 ; count of moves (below 127 chess both-side-moves)
MOVE_HIST .ds 1024; Kb for history of chess moves (4bytes per 1-side-move)
; Container for UCI-string-of-moves in form "e2e4 e7e5 ... e1g1 ... b7b8q ... "
; (set before MOVE_byString usage), it is for data passing
MOVE_str: .byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.ds $700
;above 2Kb of moves
;
; variables and arrays for next possible chess movements
; (for printing and displaying)
NEXT_MVSTR: .byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
.byte " "
; We use own memory of .COM file till now
;
; So, we are able to generate next chess moves, detect check and checkmate in 1.
; And print it out. No reasonable chess evaluation searches possible here!
GenMovesAndString:
call GenMoves
call MovesToStr ; to print after
ret
;BEGIN of ========== MAKE MOVES BY UCI-MOVE-STRING
; use UndoAllMoves before or setFEN
;
MOVE_byString:
push af
push bc
push de
ld de, MOVE_str
MbyStrLoop:
call GenMoves
ld a,(de) ; find separator
cp ' '
jr z,MbySover
cp 0
jr z,MbySover
call MbyStrMove ; single move
inc de
inc de ; skip promoted and blank too
jr MbyStrLoop ; and process next move
MbySover:
pop de
pop bc
pop af
ret
; "move by string" in DE register
; restore registers after
MbyStrMove:
call MbySgetSQ
ld (SQi),a
call MbySgetSQ
ld (SQt),a
ld a,(de)
cp ' '
jr nz,MbyPromPiece
dec de
jr MbyNoN
MbyPromPiece:
cp 'q'
jr nz,MbyNoQ
ld a,4
jr MbyProm
MbyNoQ: cp 'r'
jr nz,MbyNoR
ld a,3
jr MbyProm
MbyNoR: cp 'b'
jr nz,MbyNoB
ld a,2
jr MbyProm
MbyNoB: cp 'n'
jr nz,MbyNoN
ld a,1
jr MbyProm
MbyNoN: ld a,0 ; not promoted
MbyProm:
ld (PromoPcId),a
call MakeMove
ret
MbySgetSQ:
ld a,(de)
inc de
sub 'a'
ld b,a
ld a,(de)
inc de
sub '1'
sla a
sla a
sla a
or b
ret ; a-reg contains square on return
;END
;BEGIN of ========== SIMPLY UNDO ALL MOVES
UndoAllMoves:
push af
UndoAllLoop:
ld a,(MOVE_CNT)
cp 0
jr z,UndoAllBrk
call UnMakeMove
jr UndoAllLoop
UndoAllBrk:
pop af
ret
;END
;BEGIN of ========== MOVE GEN - movement generation routine
; Very proper - according to chess rules.
; Scanning all board squares 0..63, trying to move pieces by type, then by directions.
; If move seems good then adds to the list with verification on own king attacks after movement
; to avoid illegal cases.
SQi: .byte 0 ;current square
SQt: .byte 0 ;square to move to
MateDetect: .byte 0 ; if 1 then just find the first legal move and return
GenMoves:
push af
push bc
push de
push hl
push ix
push iy
call BOsave
ld a,0
ld (CastlMove),a
ld (PromoPcId),a
ld (CaptPiece),a
ld a, (MateDetect)
cp 1
jr z,GenMvNoClr ; if we are not gona save
ld ix, NEXT_MVCNT
ld (ix), 0
GenMvNoClr:
ld a, 0 ; square counter 0..63
ld (SQi), a
ld hl, BOARD
GenMvSqScan:
ld a, (hl) ; piece
push hl
pop iy ; set to remember square-from
ld a, (hl) ; get piece standing there
cp 0
jr z, OverMGSq ; empty square
cp 'a' ; pieces
jr nc, BlackPiece
WhitePiece: ; A-Z
ld a,(SIDE)
cp 0
jr nz, OverMGSq ; not turn
ld a, (hl)
jr WhichPiece
BlackPiece:
ld a,(SIDE)
cp 1
jr nz, OverMGSq ; not turn
ld a, (hl)
sub 32 ; to uppercase
WhichPiece:
cp 'P'
jr z, Pmoves
cp 'N'
jr z, Knmoves
cp 'B'
jr z, Bsmoves
cp 'R'
jr z, Rkmoves
cp 'Q'
jr z, Qnmoves
cp 'K'
jr z, Kgmoves
jr OverMGSq
Pmoves:
ld a,(SIDE)
cp 1
jr z, blackPmoves
call MoveGenWPawn
jr OverMGSq
blackPmoves:
call MoveGenBPawn
jr OverMGSq
Knmoves:
call MoveGenKnight
jr OverMGSq
Bsmoves:
call MoveGenBishop
jr OverMGSq
Rkmoves:
call MoveGenRook
jr OverMGSq
Qnmoves:
call MoveGenBishop ; simply
call MoveGenRook ; the same
jr OverMGSq
Kgmoves:
call MoveGenKing
jr OverMGSq
OverMGSq:
inc hl
ld a, (MateDetect)
cp 2
jr nz, GenMVscn
jr GenMVexit
GenMVscn:
ld a, (SQi)
inc a
ld (SQi),a
sub 64 ; Loop 0-63
jr nz, GenMvSqScan
GenMVexit:
call LookForCheckmates ; verifies checkmates
call BOrest
pop iy
pop ix
pop hl
pop de
pop bc
pop af
ret
; helping procedure to obtain current X,Y on board and store to d,e regs.
StoreXYtoDE:
ld a, (SQi)
and 7
ld d,a ; X- a..h
ld a, (SQi)
srl a
srl a
srl a
ld e,a ; Y- 1..8
ret
; sets new SQt to move and calculates new hl position
StoreSqToMove:
ld a,e
sla a
sla a
sla a
or d
ld (SQt),a ;a-reg. contains the new square to jump
ld b,0
ld a,(SQi)
ld c,a
ld a,(SQt)
sub c
jr c, StDistNeg
ld c,a
add hl,bc ;new hl position sq-forward
jr StNSqOver
StDistNeg:
ld a,(SQt)
ld c,a
ld a,(SQi)
sub c
ld c,a
scf
ccf
sbc hl,bc ;new hl position sq-backward
StNSqOver:
ret
;END
;BEGIN of ========== MOVE GEN for WHITE PAWN goes up
MoveGenWPawn:
push af
push de
ld a,0
ld (CaptPiece),a
ld a, (ENPSQ)
ld d,a
ld a,(SQi)
add a, 8
ld (SQt),a
ld bc,8 ;1-7 vert. try next sq forward
add hl, bc ;new square-to
call IsEmpty
jr nc, wpNoFWmoves
call AddMovPromo
ld a, (SQi)
cp 16 ;below row 3
jr nc, wpNoFWmoves
add a, 8+8
ld (SQt),a
ld bc, 8 ;another (double) move
add hl, bc ;new square-to
call IsEmpty
jr nc, wpNoFWmoves
call AddMove
wpNoFWmoves:
push iy
pop hl ; restore
ld a,1
ld (CaptPiece),a
ld a, (SQi)
and 7
cp 0
jr z, wpTryCaptRight
ld a, (SQi)
add a, 8-1 ; try capture left
ld (SQt),a
ld bc, 8-1
add hl, bc
call IsBlack
jr nc, wpTryLeftEnPs
call AddMovPromo
jr wpTryCaptRight
wpTryLeftEnPs:
ld a,(SQt)
cp d
jr nz, wpTryCaptRight
call AddMovPromo
jr wpTryCaptRight
wpTryCaptRight:
push iy
pop hl ; restore
ld a, (SQi)
and 7
cp 7
jr z, wpMGend
ld a, (SQi)
add a, 8+1 ; try capture right
ld (SQt),a
ld bc, 8+1
add hl, bc
call IsBlack
jr nc, wpTryRightEnPs
call AddMovPromo
jr wpMGend
wpTryRightEnPs:
ld a,(SQt)
cp d
jr nz, wpMGend
call AddMovPromo
jr wpMGend
wpMGend:
push iy
pop hl ; restore
ld a,0
ld (PromoPcId),a
pop de
pop af
ret
;END
;BEGIN of ========== MOVE GEN for BLACK PAWN goes down
MoveGenBPawn:
push af
push de
ld a,0
ld (CaptPiece),a
ld a, (ENPSQ)
ld d,a
ld a,(SQi)
sub 8
ld (SQt),a
scf
ccf
ld bc,8 ;1-7 vert. try next sq forward
sbc hl, bc ;new square-to
call IsEmpty
jr nc, bpNoFWmoves
call AddMovPromo
ld a, (SQi)
cp 48 ;above row 6
jr c, bpNoFWmoves
sub 8+8
ld (SQt),a
scf
ccf
ld bc, 8 ;another (double) move
sbc hl, bc ;new square-to
call IsEmpty
jr nc, bpNoFWmoves
call AddMove
bpNoFWmoves:
push iy
pop hl ; restore
ld a,1
ld (CaptPiece),a
ld a, (SQi)
and 7
cp 7
jr z, bpTryCaptRight
ld a, (SQi)
sub 8-1 ; try capture left
ld (SQt),a
scf
ccf
ld bc, 8-1
sbc hl, bc
call IsWhite
jr nc, bpTryLeftEnPs
call AddMovPromo
jr bpTryCaptRight
bpTryLeftEnPs:
ld a,(SQt)
cp d
jr nz, bpTryCaptRight
call AddMovPromo
jr bpTryCaptRight
bpTryCaptRight:
push iy
pop hl ; restore
ld a, (SQi)
and 7
cp 0
jr z, bpMGend
ld a, (SQi)
sub 8+1 ; try capture right
ld (SQt),a
scf
ccf
ld bc, 8+1
sbc hl, bc
call IsWhite
jr nc, bpTryRightEnPs
call AddMovPromo
jr bpMGend
bpTryRightEnPs:
ld a,(SQt)
cp d
jr nz, bpMGend
call AddMovPromo
jr bpMGend
bpMGend:
push iy
pop hl ; restore
ld a,0
ld (PromoPcId),a
pop de
pop af
ret
;END
;BEGIN of ========== MOVE GEN for ROOKS
rookMoves: .byte '+',1,'=',0 ,'-',1,'=',0 ,'=',0,'+',1 ,'=',0,'-',1
.byte 0
MoveGenRook:
push af
push bc
push ix
call StoreXYtoDE ; d= X [a..h] e= Y [1..8]
ld ix,rookMoves
ld b, 4
RookScan4directions:
push de
RookLoop:
call RookTryMove
cp 0
jr z,RookLoop
pop de
inc ix
inc ix
inc ix
inc ix
djnz RookScan4directions
pop ix
pop bc
pop af
ret
; try move to that direction
RookTryMove:
push bc
push ix
ld a,0
ld (CaptPiece),a
ld a, (ix) ;given directions for a..h -1,+1,=0
inc ix
cp '='
jr z, RkZero1
cp '-'
jr z, RkNegX
ld a,d
inc a ;a=direction +1 of X
cp 8
jr nc, RkNo
jr RkCanOk1
RkNegX:
ld a,0 ;a=direction -1 of X
cp d
jr c, RkCanSubtrX
jr RkNo
RkCanSubtrX:
ld a,d
dec a
RkCanOk1:
ld d,a
RkZero1: inc ix
ld a, (ix) ;given directions for 1..8 -1,+1,=0
inc ix
cp '='
jr z, RkZero2
cp '-'
jr z, RkNegY
ld a,e
inc a ;a=direction +1 of Y
cp 8
jr nc, RkNo
jr RkCanOk2
RkNegY:
ld a,0 ;a=direction -1 of Y
cp e
jr c, RkCanSubtrY
jr RkNo
RkCanSubtrY:
ld a, e
dec a
RkCanOk2:
ld e,a
RkZero2: inc ix
call StoreSqToMove ;new SQt,hl
ld a, (SIDE)
cp 1
jr z,RkThisBlack
call IsBlack ; enemy?
jr c,RkCaptMove
call IsWhite ; our?
jr c,RkNo
ld a,0 ; continue after to this direction
jr RkAdd
RkThisBlack:
call IsWhite ; enemy?
jr c,RkCaptMove
call IsBlack ; our?
jr c,RkNo
ld a,0 ; continue after to this direction
jr RkAdd
RkCaptMove:
ld a,1
ld (CaptPiece),a ; and stop to this direction
RkAdd:
call AddMove
jr RkOver
RkNo: ld a,1 ; stop to this direction
RkOver:
push iy
pop hl
pop ix
pop bc
ret
;END
;BEGIN of ========== MOVE GEN for BISHOPS
bishopMoves: .byte '+',1,'+',1 ,'+',1,'-',1 ,'-',1,'+',1 ,'-',1,'-',1
.byte 0
MoveGenBishop:
push af
push bc
push ix
call StoreXYtoDE ; d= X [a..h] e= Y [1..8]
ld ix,bishopMoves
ld b, 4
BishopScan4directions:
push de
BishopLoop:
call BishopTryMove
cp 0
jr z,BishopLoop
pop de
inc ix
inc ix
inc ix
inc ix
djnz BishopScan4directions
pop ix
pop bc
pop af
ret
; try move to that direction
BishopTryMove:
push bc
push ix
ld a,0
ld (CaptPiece),a
ld a, (ix) ;given directions for a..h -1,+1
inc ix
cp '-'
jr z, BsNegX
ld a,d
inc a ;a=direction +1 of X
cp 8
jr nc, BsNo
jr BsCanOk1
BsNegX:
ld a,0 ;a=direction -1 of X
cp d
jr c, BsCanSubtrX
jr BsNo
BsCanSubtrX:
ld a,d
dec a
BsCanOk1:
ld d,a
inc ix
ld a, (ix) ;given directions for 1..8 -1,+1
inc ix
cp '-'
jr z, BsNegY
ld a,e
inc a ;a=direction +1 of Y
cp 8
jr nc, BsNo
jr BsCanOk2
BsNegY:
ld a,0 ;a=direction -1 of Y
cp e
jr c, BsCanSubtrY
jr BsNo
BsCanSubtrY:
ld a, e
dec a
BsCanOk2:
ld e,a
inc ix
call StoreSqToMove ;new SQt,hl
ld a, (SIDE)
cp 1
jr z,BsThisBlack
call IsBlack ; enemy?
jr c,BsCaptMove
call IsWhite ; our?
jr c,BsNo
ld a,0 ; continue after to this direction
jr BsAdd
BsThisBlack:
call IsWhite ; enemy?
jr c,BsCaptMove
call IsBlack ; our?
jr c,BsNo
ld a,0 ; continue after to this direction
jr BsAdd
BsCaptMove:
ld a,1
ld (CaptPiece),a ; and stop to this direction
BsAdd:
call AddMove
jr BsOver
BsNo: ld a,1 ; stop to this direction
BsOver:
push iy
pop hl
pop ix
pop bc
ret
;END
;BEGIN of ========== MOVE GEN for KNIGHTS
knightMoves: .byte '+',1,'+',2 ,'+',2,'+',1 ,'+',2,'-',1 ,'+',1,'-',2
.byte '-',1,'-',2 ,'-',2,'-',1 ,'-',2,'+',1 ,'-',1,'+',2
.byte 0
MoveGenKnight:
push af
push bc
push de
push ix
call StoreXYtoDE ; d= X [a..h] e= Y [1..8]
ld ix, knightMoves
ld b, 8
KnightScan8moves:
call KnightTryMove
inc ix
inc ix
inc ix
inc ix
djnz KnightScan8moves
pop ix
pop de
pop bc
pop af
ret
; try move to that square
KnightTryMove:
push bc
push de
push ix
ld a,0
ld (CaptPiece),a
ld a, (ix) ;given directions for a..h -1,+1,-2,+2
inc ix
cp '-'
jr z, KnNegX
ld a, (ix) ; a=direction +1 or +2 of X
add a,d
cp 8
jr nc, KnNo
jr KnCanOk1
KnNegX:
ld a, (ix) ; a=direction -1 or -2 of X
dec a
cp d
jr c, KnCanSubtrX
jr KnNo
KnCanSubtrX:
ld a, d
sub (ix)
KnCanOk1:
ld d,a
inc ix
ld a, (ix) ;given directions for 1..8 -1,+1,-2,+2
inc ix
cp '-'
jr z, KnNegY
ld a, (ix) ; a=direction +1 or +2 of Y
add a,e
cp 8
jr nc, KnNo
jr KnCanOk2
KnNegY:
ld a, (ix) ; a=direction -1 or -2 of Y
dec a
cp e
jr c, KnCanSubtrY
jr KnNo
KnCanSubtrY:
ld a, e
sub (ix)
KnCanOk2:
ld e, a
inc ix
call StoreSqToMove ;new SQt,hl
ld a, (SIDE)
cp 1
jr z, KnThisBlack
call IsBlack ; enemy?
jr c,KnCaptMove
call IsWhite ; our?
jr c,KnNo
jr KnAdd
KnThisBlack:
call IsWhite ; enemy?
jr c,KnCaptMove
call IsBlack ; our?
jr c,KnNo
jr KnAdd
KnCaptMove:
ld a,1
ld (CaptPiece),a
KnAdd:
call AddMove
KnNo:
push iy
pop hl