;OSICHESS
;this version was modified for UK101 48x30 screen with graphics character set
;backported to OSI C4P
;program loads at $0000, starts/restarts at $0263 (03AC)

;The computer can play at three levels, super fast, fast and normal
;Normal is up to 2 minutes per move, fast is 15 seconds, and superfast is 5
;speed is controlled with two bytes. Set location "SPEED1" to 00 for fast and superfast, 08 for normal
;set location "SPEED2" to FF for superfast, FB for fast and Normal
;
*=0000
    .BYTE $40,$0A,$50,$0A,$00,$8D,$0A,$FF,$0A,$00,$24,$0E,$D0,$0B,$D0,$0B
    .BYTE $FF,$FF,$FF,$FF,$FF,$24,$0E,$24,$FF,$FF,$FF,$FF,'MATE'
    .BYTE $00,$45,$A3,$A4,$94,$42,$17,$A5,'ILLEGAL!'
    ;$30-$3F - chess pieces
    ;.BYTE 'QKRRNNBBPPPPPPPP' ;ASCII version instead of next line
    .BYTE $E6,$04,$DB,$DB,$BC,$BC,$18,$18,$F0,$F0,$F0,$F0,$F0,$F0,$F0,$F0 ;gfx version

    .BYTE $73,$E9,$95,$1F,$10,'COMPUTING!',$CC
    ;$50-6F - current board
    ;.BYTE $03,$04,$00,$07,$46,$05,$22,$06,$10,$17,$11,$16,$12,$25,$CC,$33
    ;.BYTE $73,$74,$70,$77,$45,$75,$40,$55,$60,$67,$61,$66,$62,$65,$64,$34
    .BYTE $03,$04,$00,$07,$02,$05,$01,$06,$10,$17,$11,$16,$12,$15,$14,$13
    .BYTE $73,$74,$70,$77,$72,$75,$71,$76,$60,$67,$61,$66,$62,$65,$64,$63
    ;$70-8F - default board
    .BYTE $03,$04,$00,$07,$02,$05,$01,$06,$10,$17,$11,$16,$12,$15,$14,$13
    .BYTE $73,$74,$70,$77,$72,$75,$71,$76,$60,$67,$61,$66,$62,$65,$64,$63
    ;
    .BYTE $F0,$FF,$01,$10,$11,$0F,$EF,$F1,$DF,$E1,$EE,$F2,$12,$0E,$1F,$21
    .BYTE $0A,$09,$06,$06,$04,$04,$03,$03,$01,$01,$01,$01,$01,$01,$01,$01
    .BYTE $05,$05,$C8,$FB,$F9,$04,$00,$01,$00,$05,$00,$02,$35,$34,$DA,$7A
    ;$C0-DB = opening plays
    .BYTE $99,$25,$0B,$25,$01,$00,$33,$25,$07,$36,$34,$0D,$34,$34,$0E,$52
    .BYTE $25,$0D,$45,$35,$04,$55,$22,$06,$43,$33,$0F,$CC,$FF,$74,$CC,$74
    .BYTE $00,$00,$00,$18,$00,$00,$00,$00,$00,$00,$00,$1A,$00,$00,$00,$18
    .BYTE $63,$02,$CB,$0C,$00,$00,$00,$00,$00,$CC,$CC,$CC,$00,$00,$00,$00


;To make UK101 version(48x30), set SCRNROW to 64, SCRNINDENT=19
;To make OSIC2/C4/C8 version (64x32), set SCRNROW to 64, SCRNINDENT=2
;To make OSIC1 version (32x32), set SCRNROW to 32, SCRNINDENT=2

SCRNBASE=$D000
SCRNROW=64

;OSI
SCRNINDENT=2
MESSAGE=SCRNROW*3+SCRNBASE+SCRNINDENT+10
COORDS=SCRNROW*2+SCRNBASE+SCRNINDENT+5
ALERT=SCRNROW*5+SCRNBASE+SCRNINDENT+11

;UK101 coordinates 2K vid 48x30
;SCRNINDENT=19
;MESSAGE=SCRNROW*3+SCRNBASE+SCRNINDENT-6
;COORDS=SCRNROW*16+SCRNBASE+SCRNINDENT+22;
;ALERT=SCRNROW*5+SCRNBASE+SCRNINDENT-6

*=$0263
    .EXE *  ;as6502 emit run address
L0263       JMP L03AC

L0266       LDA $FA
            CMP #$FF
            BNE L0270
            LDA #$00
            STA $E3
L0270       JMP L0680

S0273       JSR S0840
            TAX
            SBC $FFC9,Y
            BNE L027E
            BEQ L0286
L027E       LDA $E3
            BNE L0290
            LDA $B4
            BMI L0290
L0286       LDX #$03
L0288       LDA $1C,X
            STA ALERT+2,x  ;draw MATE
            DEX
            BPL L0288
L0290       RTS

L0291       LDX $FB
            BMI L02B2
            JMP L02AC

            .BYTE $B1

L0299       JSR S054B
            JSR S04B2
            JSR L04F5
            JSR S04B2
            JSR S0531
            LDA $B4
            BPL L02B2

L02AC       JSR S054B
            JMP L039D

L02B2       LDX #$07
L02B4       LDA $28,X
            STA ALERT,X ;draw ILLEGAL
            DEX
            BPL L02B4
            JMP L03B7

            NOP
S02C0       CLD
            LDA #$00
            STA $43
            LDX #$1F
L02C7       LDA $50,X
            BMI L02CD
            INC $43
L02CD       DEX
            BPL L02C7
            LDA $43
            CMP #$18
            BPL L02DD
            LDA #$FB
            STA L038A+1
            BNE L02E2
L02DD       LDA #$FD
            STA L038A+1
L02E2       LDA $43
            CMP #$14
            BPL L02FC
            CMP #$10
            BPL L02F8
            LDA #$03
L02EE       LDX #$07
L02F0       STA $A8,X
            DEX
            BPL L02F0
            LDX #$FF
            RTS

L02F8       LDA #$02
            BNE L02EE
L02FC       LDA #$01
            BNE L02EE
S0300       LDX $B5
            BMI L0360
            LDA $B0
            BEQ L0310
            CPX #$08
            BNE L0310
            CMP $E6
            BEQ L033E
L0310       INC $E3,X
            NOP
            NOP
            NOP
            JSR S089A
            JMP L09A5

            .BYTE $0F

L031C       LDA $B1
L031E       CMP $0060,Y
            BEQ L0326
            DEY
            BPL L031E
L0326       LDA $00A0,Y
            CMP $E4,X
            BCC L0331
            STY $E6,X
            STA $E4,X

L0331       CLC
            PHP
            ADC $E5,X
            STA $E5,X
            PLP
L0338       CPX #$04
            BEQ L033F
            BMI L036F
L033E       RTS

L033F       LDA $E8
            STA $DD
            LDA #$00
            STA $B5
            JSR S054B
            JSR S04B2
            JSR S0400
            JSR S04B2
L0353       LDA #$08
            STA $B5
            JSR S0409
            JSR S0531
            JMP L05FA

L0360       CPX #$F9
            BNE L036F
            LDA $60
            CMP $B1
            BNE L036E
            LDA #$00
            STA $B4
L036E       RTS

L036F       BVC L036E
            LDY #$07
            LDA $B1
L0375       CMP $0060,Y
            BEQ L037F
            DEY
            BEQ L036E
            BPL L0375
L037F       LDA $00A0,Y
            CMP $E2,X
            BCC L0388
            STA $E2,X
L0388       DEC $B5
SPEED2=*+1
L038A       LDA #$FB  ;change for speed FB=NORMAL/FAST FF=SUPERFAST
            CMP $B5
            BEQ L0393
            JSR S0525
L0393       INC $B5
            RTS

L0396       CMP #$08
            BCS L03AC
            JSR S05EA
L039D       LDX #$1F
L039F       LDA $50,X
            CMP $FA
            BEQ L03A8
            DEX
            BPL L039F
L03A8       STX $FB
L03AA       STX $B0
RESTARTLOC=*
L03AC       JSR S02C0
            TXS
            LDX #$C8
            STX $B2
            JSR S0273
L03B7       JSR $FEED
            JSR S0663
            STA $F3
            CMP #$0C
            BNE L03D2
            LDX #$1F
L03C5       LDA $70,X
            STA $50,X
            DEX
            BPL L03C5
            STX $DC
            LDA #$CC
            BNE L03E4
L03D2       CMP #$0E
            BNE L03DD
            JSR S04B2
            LDA #$EE
            BNE L03E4
L03DD       CMP #$14
            BNE L03EC
            JSR S05A2
L03E4       STA $FB
            STA $FA
            STA $F9
            BNE L03AA
L03EC       CMP #$0F
            BNE L03F6
            JMP L0291

            JMP L039D
L03F6       CMP #$0D
            BNE L03FD
            JMP $FE00

L03FD       JMP L0396

S0400       LDX #$10
S0402       LDA #$00
L0404       STA $DE,X
            DEX
            BPL L0404
S0409       LDA #$10
            STA $B0
L040D       DEC $B0
            BPL L0412
            RTS

L0412       JSR S051E
            LDY $B0
            LDX #$08
            STX $B6
            CPY #$08
            BPL L0460
            CPY #$06
            BPL L0451
            CPY #$04
            BPL L0446
            CPY #$01
            BEQ L0434
            BPL L043B
L042D       JSR S048E
            BNE L042D
            BEQ L040D
L0434       JSR S049C
            BNE L0434
            BEQ L040D
L043B       LDX #$04
            STX $B6
L043F       JSR S049C
            BNE L043F
            BEQ L040D
L0446       JSR S049C
            LDA $B6
            CMP #$04
            BNE L0446
            BEQ L040D
L0451       LDX #$10
            STX $B6
L0455       JSR S048E
            LDA $B6
            CMP #$08
            BNE L0455
            BEQ L040D
L0460       LDX #$06
            STX $B6
L0464       JSR S04CA
            BVC L046E
            BMI L046E
            JSR S0300
L046E       JSR S051E
            DEC $B6
            LDA $B6
            CMP #$05
            BEQ L0464
L0479       JSR S04CA
            BVS L040D
            BMI L040D
            JSR S0300
            LDA $B1
            AND #$F0
            CMP #$20
            BEQ L0479
            JMP L040D

S048E       JSR S04CA
            BMI L0496
            JSR S0300
L0496       JSR S051E
            DEC $B6
            RTS

S049C       JSR S04CA
            BCC L04A3
            BVC S049C
L04A3       BMI L04AC
            PHP
            JSR S0300
            PLP
            BVC S049C
L04AC       JSR S051E
            DEC $B6
            RTS

S04B2       LDX #$0F
L04B4       SEC
            LDY $60,X
            LDA #$77
            SBC $50,X
            STA $60,X
            STY $50,X
            SEC
            LDA #$77
            SBC $50,X
            STA $50,X
            DEX
            JMP L0A5F

S04CA       LDA $B1
            LDX $B6
            CLC
            ADC $8F,X
            STA $B1
            AND #$88
            BNE L0519
            LDA $B1
            LDX #$20
L04DB       DEX
            BMI L04EC
            CMP $50,X
            BNE L04DB
            CPX #$10
            BMI L0519
            LDA #$7F
            ADC #$01
            BVS L04ED
L04EC       CLV
L04ED       LDA $B5
            BMI L0515
SPEED1=*+1
            CMP #$08        ;change for speed 08=NORMAL 00=FAST/SUPERFAST
            BPL L0515
L04F5       PHA
            PHP
            LDA #$F9
            STA $B5
            STA $B4
            JSR S054B
            JSR S04B2
            JSR S0409
            JSR S052E
            PLP
            PLA
            STA $B5
            LDA $B4
            BMI L0515
            SEC
            LDA #$FF
            RTS

L0515       CLC
            LDA #$00
            RTS

L0519       LDA #$FF
            CLC
            CLV
            RTS

S051E       LDX $B0
            LDA $50,X
            STA $B1
            RTS

S0525       JSR S054B
            JSR S04B2
            JSR S0409
S052E       JSR S04B2
S0531       TSX
            STX $B3
            LDX $B2
            TXS
            PLA
            STA $B6
            PLA
            STA $B0
            TAX
            PLA
            STA $50,X
            PLA
            TAX
            PLA
            STA $B1
            STA $50,X
            JMP L0570

S054B       TSX
            STX $B3
            LDX $B2
            TXS
            LDA $B1
            PHA
            TAY
            LDX #$1F
L0557       CMP $50,X
            BEQ L055E
            DEX
            BPL L0557
L055E       LDA #$CC
            STA $50,X
            TXA
            PHA
            LDX $B0
            LDA $50,X
            STY $50,X
            PHA
            TXA
            PHA
            LDA $B6
            PHA
L0570       TSX
            STX $B2
            LDX $B3
            TXS
            RTS

L0577       LDX $E4
            CPX $A0
            BNE L0581
            LDA #$00
            BEQ L058B
L0581       LDX $E3
            BNE L058B
            LDX $EE
            BNE L058B
            LDA #$FF
L058B       LDX #$04
            STX $B5
            CMP $FA
            BCC L059F
            BEQ L059F
            STA $FA
            LDA $B0
            STA $FB
            LDA $B1
            STA $F9
L059F       JMP L0266

S05A2       JMP L0AE4

            NOP
L05A6       LDA $F9
L05A9=*+1
            CMP ($00),Y
            JMP L0B0C

L05AD       LDA ($00),Y
            STA $FB
            DEY
L05B3=*+1
            LDA ($00),Y
            STA $F9
            DEY
            STY $DC
            BNE L05D5
L05BB       STA $DC
L05BD       LDX #$0C
            STX $B5
            STX $FA
            LDX #$14
            JSR S0402
            LDX #$04
            STX $B5
            JSR S0400
            LDX $FA
            CPX #$0F
            BCC L05E7
L05D5       LDX $FB
            LDA $50,X
            STA $FA
            STX $B0
            LDA $F9
            STA $B1
            JSR S054B
            JMP L03AC

L05E7       LDA #$FF
            RTS

S05EA       LDX #$04
L05EC       ASL $F9
            ROL $FA
            DEX
            BNE L05EC
            ORA $F9
            STA $F9
            STA $B1
            RTS

L05FA       CLC
            LDA #$80
            ADC $ED
            ADC $EC
            ADC $EB
            ADC $E1
            ADC $DF
            SEC
            SBC $E4
            SBC $E0
            SBC $E2
            SBC $E0
            SBC $DE
            SBC $E5
            SBC $E3
            NOP
            JSR S08A5
            LSR A
            CLC
            ADC #$60
            ADC $E1
            ADC $ED
            LSR A
            SEC
            SBC $E4
            CLC
            ADC #$58
            ADC $DD
            ADC $B8
            ADC $B8
            ADC $E8
            ADC $E1
            JSR S08BE
            SBC $E4
            SBC $E5
            SBC $E5
            SBC $E2
            LDX $B1
            CPX #$33
            BEQ L065A
            CPX #$34
            BEQ L065A
            CPX #$43
            BEQ L065A
            CPX #$44
            BEQ L065A
            LDX $B0
            BEQ L065D
            LDY $50,X
            CPY #$10
            BPL L065D
L065A       CLC
            ADC #$01
L065D       JMP L08C4

            NOP
            NOP
            NOP
S0663       CMP #$30
            BMI L067C
            CMP #$3A
            BEQ L067D
            CMP #$3B
            BMI L067A
            CMP #$43
            BMI L067C
            CMP #$47
            BPL L067C
            SEC
            SBC #$07
L067A       AND #$0F
L067C       RTS

L067D       LDA #$14
            RTS

L0680       LDX #$02
            LDY #$06
L0684       LDA $F9,X
            LSR A
            LSR A
            LSR A
            LSR A
            JSR S069E
            LDA $F9,X
            JSR S069E
            NOP
            INY
            DEX
            BPL L0684
            JSR S06B0
            NOP
            NOP
            NOP
            RTS

S069E       AND #$0F
            ORA #$30
            CMP #$3A
            BMI L06A9
            CLC
            ADC #$07
L06A9       STA COORDS,Y
            INY
            RTS

L06AE       NOP
            NOP
S06B0       LDX #$09
L06B2       LDA $45,X
            STA MESSAGE,X ; $D0CB,X ;display COMPUTING! message
            DEX
            BPL L06B2
L06BA       LDY #$05
L06BC       LDX #$20
L06BE       DEX
            BNE L06BE
            DEY
            BNE L06BC
            CLC
            ADC #$FF
            BNE L06BA
            LDX #$09
L06CB       LDA #$20
            STA MESSAGE,X ;$D0CB,X erase message
            DEX
            BPL L06CB
            RTS

S06D4       LDA #$20
            LDY #$08
            LDX #$00
L06DA       STA SCRNBASE,X
            INX
            BNE L06DA
            INC L06DA+2
            DEY
            BNE L06DA
            LDA #>SCRNBASE
            STA L06DA+2
            STA $DE00,X
            LDX #$07
            LDY #$03
            LDA #$30
            CLC         ;display column labels
L06F5       STA SCRNROW*4+SCRNINDENT+SCRNBASE+1,Y ; $D114,Y
            INY
            INY
            INY
            ADC #$01
            DEX
            BPL L06F5
            LDA #$30    ;display row labels
            STA SCRNROW*7+SCRNINDENT+SCRNBASE ;$D1D3
            ADC #$01
            STA SCRNROW*10+SCRNINDENT+SCRNBASE ;$D293
            ADC #$01
            STA SCRNROW*13+SCRNINDENT+SCRNBASE ;$D353
            ADC #$01
            STA SCRNROW*16+SCRNINDENT+SCRNBASE ;$D413
            ADC #$01
            STA SCRNROW*19+SCRNINDENT+SCRNBASE ;$D4D3
            ADC #$01
            STA SCRNROW*22+SCRNINDENT+SCRNBASE ;$D593
            ADC #$01
            STA SCRNROW*25+SCRNINDENT+SCRNBASE ;$D653
            ADC #$01
            STA SCRNROW*28+SCRNINDENT+SCRNBASE ;$D713
            NOP
            JMP L0768
;data for 1 row of chessboard display
L072C       .BYTE $9D,$A1,$A1,$9C,$20,$20,$9D,$A1,$A1
L0735       .BYTE $9C,$20,$20,$9D,$A1,$A1,$9C,$20,$20,$9D,$A1
            .BYTE $A1,$9C,$20,$20,$20
            NOP
            NOP
            NOP
VAL=SCRNROW*6+SCRNINDENT+SCRNBASE+2 ;D195
S0748       LDX #$00
L074A       LDA L072C,X
L074E = *+1
L074F = *+2
            STA VAL,X ;$D195,X
            INX
            CPX #$19
            BNE L074A
            LDA L074E
            CLC
            ADC #SCRNROW
S075B       BCC L0760
            INC L074F
L0760       STA L074E
            RTS

            NOP
            NOP
            NOP
            NOP

L0768       LDY #$08  ;reset chessboard draw board
            LDA #<VAL
            STA L074E
            LDA #>VAL
            STA L074F
L0774       TYA
            CLC
            LSR A
            BCC L0782
            INC L074E
            INC L074E
            INC L074E
L0782       JSR S0748
            JSR S0748
            JSR S0748
            TYA
            CLC
            LSR A
            BCC L0799
            DEC L074E
            DEC L074E
            DEC L074E
L0799       DEY
            BEQ L079F
            JMP L0774

L079F       RTS


L07A0       BEQ L0735
            JSR S075B
            RTS

L07A6       NOP
            NOP
            LDA $FA
            CMP #$CC
            BNE L07B1
            JMP S0840

L07B1       CMP #$EE
            BNE L07B8
            JMP S0840

L07B8       CMP #$78
            BMI L07BD
            RTS

L07BD       JMP S0840

S07C0       CLC
            LDX #$0F
L07C3       JSR S07D4
            DEX
            BPL L07CA
            RTS

L07CA       JMP L07C3

L07CD       NOP
            NOP
            NOP
            NOP
            NOP
            NOP
            NOP
S07D4       LDA $50,X
            CMP #$90
            BCC L07DD
            JMP L07F5

L07DD       JSR S080A
            CLC
L07E2=*+1
            LDA #$57  ;42 "B
            JSR S07E9
            JMP L07F2

S07E9       STA VAL2 ;$D721
            INC S07E9+1
            LDA $30,X
            RTS

L07F2       JSR S07E9
L07F5       CLC
            LDA $60,X
            CMP #$90
            BCC L07FD
            RTS

L07FD       JSR S080A
            CLC
L0802=*+1
            LDA #$42 ;57 "W
            JSR S07E9
            JSR S07E9
            RTS

VAL2=SCRNROW*4+SCRNINDENT+SCRNBASE ;D113
S080A       STA $40
            AND #$70
            LSR A
            LSR A
            LSR A
            LSR A
            CLC
            TAY
            LDA #>VAL2
            STA S07E9+2
            LDA #<VAL2
            STA S07E9+1
            CLC
L081F       ADC #SCRNROW*3
            STA S07E9+1
            BCC L0829
            INC S07E9+2
L0829       CLC
            DEY
            BPL L081F
            CLC
            LDA $40
            AND #$07
            TAY
L0833       INC S07E9+1
            INC S07E9+1
            INC S07E9+1
            DEY
            BPL L0833
            RTS

S0840       JSR S06D4
            JMP L0893

            .BYTE $03
L0847       LDA #$3A
            JSR S084F
            JMP L0880

S084F       STA SCRNROW*6+SCRNINDENT+SCRNBASE+3,X ;$D196,X  ;draw
            STA SCRNROW*7+SCRNINDENT+SCRNBASE+3,X ;$D1D6,X
            STA SCRNROW*9+SCRNINDENT+SCRNBASE+3,X ;$D259,X
            STA SCRNROW*10+SCRNINDENT+SCRNBASE+6,X ;$D299,X
            STA SCRNROW*12+SCRNINDENT+SCRNBASE+3,X ;$D316,X
            STA SCRNROW*13+SCRNINDENT+SCRNBASE+3,X ;$D356,X
            STA SCRNROW*15+SCRNINDENT+SCRNBASE+6,X ;$D3D9,X
            STA SCRNROW*16+SCRNINDENT+SCRNBASE+6,X ;$D419,X
            STA SCRNROW*18+SCRNINDENT+SCRNBASE+3,X ;$D496,X
            STA SCRNROW*19+SCRNINDENT+SCRNBASE+3,X ;$D4D6,X
            STA SCRNROW*21+SCRNINDENT+SCRNBASE+6,X ;$D559,X
            STA SCRNROW*22+SCRNINDENT+SCRNBASE+6,X ;$D599,X
            STA SCRNROW*24+SCRNINDENT+SCRNBASE+3,X ;$D616,X
            STA SCRNROW*25+SCRNINDENT+SCRNBASE+3,X ;$D656,X
            STA SCRNROW*27+SCRNINDENT+SCRNBASE+6,X ;$D6D9,X
            STA SCRNROW*28+SCRNINDENT+SCRNBASE+6,X ;$D719,X
            RTS

L0880       CLC
            INX
            JSR S084F
            INX
            INX
            INX
            INX
            INX
            DEY
            BMI L0893
            JSR S084F
            JMP L0880

L0893       JSR S07C0
            JSR L0680
            RTS

S089A       CMP #$02
            BMI L08A4
            CMP #$08
            BPL L08A4
            INC $E3,X
L08A4       RTS

S08A5       BCS L08B5
            STA $42
            LDA #$FF
            SEC
            SBC $42
            LSR A
            LSR A
            STA $42
            LDA #$00
            RTS

L08B5       STA $41
            LDA #$00
            STA $42
            LDA $41
            RTS

S08BE       SEC
            SBC $42
            SBC $E4
            RTS

L08C4       STA $43
            LDA $B1
            AND #$70
            STA $20
            CMP #$20
            BMI L08E7
            CMP #$60
            BPL L08E7
            LDA $B1
            AND #$07
            CMP #$02
            BMI L08E7
            CMP #$06
            BPL L08E7
            CLC
            LDA #$05
            ADC $43
            STA $43
L08E7       LDA $70,X
            CMP $50,X
            BNE L08F6
            CLC
            LDA #$00
            ADC #$06
            ADC $43
            BNE L08F8
L08F6       LDA $43
L08F8       CPX #$07
            BEQ L090B
            CPX #$06
            BEQ L090B
            CPX #$05
            BEQ L0917
            CPX #$04
            BEQ L0917
            JMP L0924

L090B       LDY $B1
            CPY #$22
            BEQ L0921
            CPY #$25
            BNE L0924
            BEQ L0921
L0917       LDY $B1
            CPY #$11
            BEQ L0921
            CPY #$16
            BNE L0924
L0921       CLC
            ADC #$06
L0924       STA $42
            LDA $B8
            SEC
            SBC $E4
            BMI L0936
            LDA $B8
            CLC
            ADC $42
            STA $42
            BNE L093D
L0936       LDA $42
            SEC
            SBC $E4
            STA $42
L093D       LDA $B8
            SEC
            SBC $E4
            BMI L0983
            LDA #$00
            STA $BC
            STA $BD
            LDX #$0F
L094C       LDA $50,X
            BMI L0957
            LDA $A0,X
            CLC
            ADC $BD
            STA $BD
L0957       DEX
            TXA
            NOP
            BPL L094C
            LDX #$0F
L095E       LDA $60,X
            BMI L0969
            LDA $A0,X
            CLC
            ADC $BC
            STA $BC
L0969       DEX
            TXA
            NOP
            BPL L095E
            LDA $BD
            SEC
            SBC $BC
            BMI L097C
            LDA $42
            CLC
            ADC #$08
            BNE L0981
L097C       LDA $42
            SEC
            SBC #$08
L0981       STA $42
L0983       LDA $B8
            CLC
            ADC $E1
            SEC
            SBC $E4
            SBC $E0
            BMI L0996
            LDA $42
            CLC
            ADC $B8
            BNE L099B
L0996       LDA $42
            SEC
            SBC $E2
L099B       LDX $BA
            BEQ L09A2
            JMP L0A0D

L09A2       JMP L0A1E

L09A5       CPX #$04
            BNE L09BB
            LDY $B0
            CPY #$02
            BEQ L09B5
            CPY #$03
            BEQ L09B5
            BNE L09BB
L09B5       STY $B7
            LDY $B1
            STY $BB
L09BB       BVC L09ED
            LDY #$0F
            LDA $B1
L09C1       CMP $0060,Y
            BEQ L09C9
            DEY
            BPL L09C1
L09C9       LDA $00A0,Y
            CPX #$00
            BNE L09D2
            STY $B9
L09D2       CMP $E4,X
            BCC L09DA
            STY $E6,X
            STA $E4,X
L09DA       CPX #$04
            BNE L09E4
            LDY $B0
            STY $B7
            STA $B8
L09E4       CPX #$00
            BNE L09EA
            STY $B9
L09EA       JMP L09F7

L09ED       CPX #$04
            BNE L09F7
            LDY #$00
            STY $B8
            STY $BA
L09F7       BVC L0A0A
            CPX #$00
            BNE L0A07
            LDY $B7
            CPY $B9
            BNE L0A07
            LDY #$01
            STY $BA
L0A07       JMP L0331

L0A0A       JMP L0338

L0A0D       STA $42
            LDX $B7
            LDA $A0,X
            CMP $E1
            BMI L0A1E
            LDA $42
            SEC
            SBC $A0,X
            SBC #$06
L0A1E       LDY $B7
            CPY #$02
            BEQ L0A2B
            CPY #$03
            BEQ L0A2B
            JMP L0A49

L0A2B       STA $42
            LDY #$01
            LDA $BB
L0A31       CLC
            ADC #$10
            BMI L0A49
            LDX #$0F
L0A38       CMP $50,X
            BEQ L0A49
            DEX
            BPL L0A38
            DEY
            BPL L0A31
            LDA $42
            CLC
            ADC #$05
            STA $42
L0A49       LDA $B8
            SEC
            SBC $E2
            BMI L0A57
            LDA $42
            CLC
            ADC #$05
            BNE L0A5C
L0A57       LDA $42
            SEC
            SBC #$05
L0A5C       JMP L0A82

L0A5F       BMI L0A64
            JMP L04B4

L0A64       LDY L07E2	;toggle White & Black
            CPY #$57
            BNE L0A77
            LDA #$42
            STA L07E2
            LDA #$57
            STA L0802
            BNE L0A81
L0A77       LDA #$57
            STA L07E2
            LDA #$42
            STA L0802
L0A81       RTS

L0A82       STA $42
            LDX $B7
            CPX #$08
            BMI L0AAF
            LDA $B1
            AND #$F0
            CMP #$40
            BMI L0AAF
            BNE L0A98
            LDA #$08
            BNE L0AAA
L0A98       CMP #$50
            BNE L0AA0
            LDA #$09
            BNE L0AAA
L0AA0       CMP #$60
            BNE L0AA8
            LDA #$0A
            BNE L0AAA
L0AA8       LDA #$0B
L0AAA       CLC
            ADC $42
            STA $42
L0AAF       LDA $42
            JMP L0577

L0AB4       PHP
L0AB5       .BYTE $0C
L0AB6       STX $B5
            LDA #$00
            LDX #$03
L0ABC       STA $EF,X
            DEX
            BPL L0ABC
            JSR S0409
            JSR S04B2
            JMP L0353

            .BYTE $00,$00,$00,$00,$00,$00
L0AD0       NOP
            NOP
            LDA #$0C
            STA $B5
            JSR S0409
            NOP
            NOP
            NOP
            JSR S0531
            LDA #$00
            STA $B5
            RTS

L0AE4       LDA #$40
            STA $00
            LDA #$50
            STA $02
            LDY $DC
            BPL L0B09
            LDA L07E2
            CMP #$57
            BEQ L0AFB
            LDA #$02
            BNE L0AFD
L0AFB       LDA #$00
L0AFD       STA L05A9
            STA L05AD+1
            STA L05B3
            JMP L05A6

L0B09       JMP L05BD

L0B0C       BNE L0B12
            DEY
            JMP L05AD

L0B12       CLC
            LDA $00
            ADC #$20
            STA $00
            LDA $02
            ADC #$20
            STA $02
            LDA $00
            CMP #$D0
            BCS L0B28
            JMP L05A6

L0B28       LDA #$00
            JMP L05BB
			
;moves table?
            .BYTE $00,$00,$00
L0B30       .BYTE $99,$43,$0F,$63,$41,$05,$52,$25,$07,$44,$34,$0E,$53,$33,$0F,$CC
            .BYTE $99,$13,$06,$34,$14,$04,$36,$25,$06,$52,$33,$0E,$43,$24,$0F,$44
            .BYTE $99,$11,$04,$66,$21,$0A,$56,$22,$06,$53,$35,$0D,$52,$34,$0E,$CC
            .BYTE $99,$14,$04,$66,$11,$05,$56,$21,$0B,$55,$24,$0F,$42,$25,$06,$43
            .BYTE $99,$34,$0E,$33,$01,$00,$52,$46,$04,$55,$22,$06,$43,$33,$0F,$CC
            .BYTE $99,$14,$04,$43,$44,$06,$75,$25,$06,$31,$22,$07,$55,$34,$0F,$44
            .BYTE $99,$01,$00,$36,$46,$04,$52,$25,$07,$55,$22,$06,$43,$33,$0F,$CC
            .BYTE $99,$06,$00,$75,$41,$04,$31,$25,$06,$52,$22,$07,$55,$34,$0F,$44
            .BYTE $99,$34,$0E,$52,$25,$0D,$45,$35,$04,$55,$22,$06,$43,$33,$0F,$CC
            .BYTE $99,$43,$0F,$43,$25,$06,$52,$32,$04,$42,$22,$07,$55,$34,$0F,$44
            .BYTE $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$BD,$43,$38,$9F,$C0
            .BYTE $02,$37,$63,$6C,$7B,$98,$58,$96,$5A,$92,$B2,$B6,$AA,$92,$DD,$A5
            .BYTE $CA,$71,$7B,$38,$7A,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24,$24
            .BYTE $00
			