        MAIN "*.*",134

;MOUSE DRIVER (C) 1999 LOKI/CLEVERS/TMH

MOUSDR  RET 
        CALL MDRV
        CALL MCOORD
        LD A,(MDIRECT)
        LD (DIRECT),A
        RET 

;mdrv   LD A,(MOUSDR)
;       AND A
;       RET NZ
;       LD HL,(MDR1+1)
;       PUSH HL
;       CALL MDRV
;       POP HL
;       LD (MDR1+1),HL
;       LD A,(DIRECT)
;       AND A
;       RET NZ
;       LD A,(MDIRECT)
;       LD (DIRECT),A
;       RET

MDRV    LD HL,#0000
        LD (MSHIFTX),HL
        LD (MSHIFTY),HL
        LD (FIRE),HL
MDR1    LD HL,#0000
        LD D,#00
        LD BC,#FBDF
        IN A,(C)
        LD (MDR1+#01),A
        SUB L
        JR Z,DIRY
        JP P,MRIGHT
        NEG 
        SET #01,D              ; LEFT
        LD (MSHIFTX+#00),A
        JR DIRY
MRIGHT  SET #00,D              ; RIGTH
        LD (MSHIFTX+#01),A
DIRY    LD B,#FF
        IN A,(C)
        NEG 
        LD (MDR1+#02),A
        SUB H
        JR Z,MBUTT
        JP P,MDOWN
        NEG 
        SET #03,D              ; UP
        LD (MSHIFTY+#00),A
        JR MBUTT
MDOWN   SET #02,D              ; DOWN
        LD (MSHIFTY+#01),A
MBUTT   CALL MBUTTON
        LD A,D
        LD (MDIRECT),A
        RET 

CHBUTT  LD A,(MB)
        AND A
        JR Z,LMB
RMB     LD HL,0
        LD (MBUT1),HL
        LD HL,#E2CB
        LD (MBUT2),HL
        LD HL,CANCEL
        LD (ffire+1),HL
        LD HL,FIRE
        LD (ccancel+1),HL
        RET 

LMB     LD HL,#E2CB
        LD (MBUT1),HL
        LD HL,0
        LD (MBUT2),HL
        LD HL,FIRE
        LD (ffire+1),HL
        LD HL,CANCEL
        LD (ccancel+1),HL
        RET 

MBUTTON LD A,(MOUSDR)
        AND A
        RET NZ
        LD BC,#FADF
        IN A,(C)
        RRA 
BUTDEF  IN A,(C)
        RRA 
        JR C,M04
MBUT1   SET #04,D              ; FIRE
        EX AF,AF'
        LD A,1
ffire   LD (FIRE),A
        EX AF,AF'
M04     RRA 
        JR C,MO4
MBUT2   DW 0           ; SET #05,D - CANCEL
        LD A,1
ccancel LD (CANCEL),A
MO4     RET 

MSHIFTX DW #0000; СМЕЩЕНИЕ (LEFT,RIGHT)
MSHIFTY DW #0000; СМЕЩЕНИЕ (UP,DOWN)

;Тут к координатам стрелки добавляются
;координаты крысы
MCOORD  LD A,(ARWXMX)
        LD C,A
        LD A,(ARWYMX)
        LD B,A
        LD HL,(MSHIFTX)
        LD A,(ARW_X)
        SUB L
        JR NC,$+#03
        XOR A
        ADC A,H
        JR C,$+#05
        CP C
        JR C,$+#03
        LD A,C
        LD (ARW_X),A
        LD HL,(MSHIFTY)
        LD A,(ARW_Y)
        SUB L
        JR NC,$+#03
        XOR A
        ADC A,H
        JR C,$+#05
        CP B
        JR C,$+#03
        LD A,B
        LD (ARW_Y),A
        RET 

TEST    LD A,(MICE)
        AND A
        JR Z,NOMO
YESMO   CALL CHBUTT
        XOR A
test    LD (MOUSDR),A
        RET 

NOMO    XOR A
        LD (FIRE),A
        LD (CANCEL),A
        LD (MDIRECT),A
        LD A,#C9
        JR test

