        MAIN "",134

STOP_ARW
INITMV  LD HL,STEP
        LD DE,STPCNT
        LDI 
        LDI 
        LDI 
        RET 

MOVES   CALL moves
        LD HL,(ARW_X)
        DUP 3
        SRL H
        SRL L
        EDUP 
        LD (ARW_XC),HL
        RET 

moves   LD A,(MDIRECT)
        AND A
        RET NZ
        LD A,(DIRECT)
        PUSH AF
        CALL MVEXAM
        POP AF
        LD C,A
        RRCA 
        AND 5
        XOR C
        LD B,A
        RRCA 
        LD HL,ARWXMN
        LD DE,ARW_X
        PUSH BC
        CALL C,XYMOVE
        POP BC
        RRC C
        RRC C
        LD A,B
        RRCA 
        RRCA 
        RRCA 
        INC DE
        LD HL,ARWYMN
        JR C,XYMOVE
        RET 

MVEXAM  LD BC,(DIROLD)
        LD (DIROLD),A
        AND #0F
        JR Z,INITMV
        LD HL,STPCNT
        DEC (HL)
        RET NZ
        LD A,(STEP)
        LD (HL),A
        INC HL
        LD A,(HL)
        DEC A
        RET Z
        LD (HL),A
        INC HL
        INC (HL)
        RET 

XYMOVE  LD A,C
        RRCA 
        LD A,(SPDCNT)
        LD C,A
        LD A,(DE)
        JR C,XYINC
        SUB C
        JR C,XYMNX
        LD (DE),A
        CP (HL)
        JR C,XYMNX
        RET 

XYINC   ADD A,C
        INC HL
        JR C,XYMNX
        LD (DE),A
        CP (HL)
        RET C
XYMNX   LD A,(HL)
        LD (DE),A
        RET 

ARW_OLD LD HL,PutArw
        LD DE,GetArw
; HL - PUTARW
; DE - GETARW
ARW_NEW LD (PUTARW+1),HL
        LD (GARW+1),DE
        RET 

PUT_INT LD (putarw+1),HL
        RET 

GET_INT LD (getarw+1),HL
        RET 

PUTARW  CALL PutArw
putarw  JP Ret

GETARW
getarw  CALL Ret
GARW    CALL GetArw
        RET 

PutArw  LD DE,(ARW_X)
        LD A,D
        OR A
        JR Z,ZERO_1
        DEC D
ZERO_1  LD A,E
        OR A
        JR Z,ZERO_2
        DEC E
ZERO_2  LD A,D
        RRA 
        SCF 
        RRA 
        RRA 
        AND #5F
        LD H,A
        XOR E
        AND 7
        XOR E
        RRCA 
        RRCA 
        RRCA 
        LD L,A
        LD A,D
        XOR H
        AND 7
        XOR H
        LD H,A
        LD (XPLACE),HL
        PUSH HL
        LD DE,PLACE
        DEFB 1,#FF,ARW_YR
LP1     LDI 
        LDI 
        DEC HL
        DEC HL
        CALL INC_Y
        DJNZ LP1
        POP HL
        LD A,(ARW_X)
        SUB 1
        JR C,ZERO_3
        AND 7
ZERO_3  SUB 8
        NEG 
        LD B,A

        LD DE,(ARW_ADR)
        LD C,ARW_YR
        LD A,(ARW_Y)
        OR A
        JR NZ,LP2
        INC DE
        INC DE
        DEC C
LP2     EX DE,HL
        PUSH BC
        PUSH HL
        PUSH DE
        LD E,(HL)
        LD D,#FF
        INC HL
        LD L,(HL)
        LD H,0
LP3     SLI E
        RL D
        ADD HL,HL
        DJNZ LP3
        LD B,H
        LD C,L
        POP HL
        LD A,(HL)
        AND D
        XOR B
        LD (HL),A
        INC L
        LD A,L
        AND #1F
        JR Z,ZERO_4
        LD A,(HL)
        AND E
        XOR C
        LD (HL),A
ZERO_4  DEC L
        DHL_
        POP DE
        POP BC
        INC DE
        INC DE
        LD A,H
        CP #58
        RET NC
        DEC C
        JR NZ,LP2
        RET 

GetArw  LD HL,(XPLACE)
        LD DE,PLACE
        LD B,ARW_YR
LP4     LD A,(DE)
        LD (HL),A
        INC HL
        INC DE
        LD A,(DE)
        LD (HL),A
        INC DE
        DEC HL
        DHL_
        DJNZ LP4
        RET 

DIRSCN  CALL dirscn
        AND A
        CALL Z,MOUSDR
;       LD A,(DIRECT)
        RET 

KEMPST  LD A,(KJOY)
        LD E,A
        AND A
        RET Z
        IN A,(#1F)
        AND #1F
        LD E,A
        LD (DIRECT),A
        RET 

dirscn  CALL KEMPST
        LD A,#FE
        IN A,(#FE)
        RRCA 
        JR NC,NODCT
        CALL SINC_L
        OR E
        LD E,A
        CALL SINC_R
NOSINC  OR E
        LD E,A
        CALL QAOPSP
        OR E
        LD E,A
EXDIR0  AND #1F
TODCT   LD (DIRECT),A
        RET 

NODCT   XOR A
        JR TODCT

QAOPSP  LD   A,#7F
        IN   A,(#FE)
        RRCA 
        RL   C
        LD   A,#FB
        IN   A,(#FE)
        RRCA 
        RL   C
        LD   A,#FD
        IN   A,(#FE)
        RRCA 
        RL   C
        LD   A,#DF
        IN   A,(#FE)
EXDIR1  RRCA 
        RRCA 
        RL   C
        RLCA 
        RLCA 
EXDIR2  RL   C
EXDIR3  LD   A,C
        CPL 
        JR   EXDIR0

SINC_L  LD   A,#F7
        IN   A,(#FE)
     ;   LD A,#DF;    *************************** Dart Alver ???????????????
        RRCA 
        PUSH AF
        RRCA 
        LD   C,A
        POP  AF
        RL   C
        RRCA 
        JR   EXDIR2
SINC_R  LD   A,#EF
        IN   A,(#FE)
        LD   B,3
LPSINC  RRCA 
        RL   C
        DJNZ LPSINC
        JR   EXDIR1

ARW_YR  EQU 10   ;высота стр. в пикс.
STPCNT  DEFB 0
LVLCNT  DEFB 0
SPDCNT  DEFB 0
DIROLD  DEFB 0
PLACE   DEFS 10*2     ;буфер (2*ARW_YR)

