; MUSDRIVER ver 1.3
; Program av Magnus <8042> 1993
; Senaste {ndring 1994-11-07
  ORG 55000
MUSP]: DI
  LD HL,TGI1
  LD (0FFB4H),HL
  EI
  LD A,62 ; AUTO MODE
  OUT (34),A
  RET
MUSAV: DI
  LD HL,1463 ; B|r kanske kollas f|rst
  LD (0FFB4H),HL
  LD A,63
  OUT (34),A ; St{nger av auto mode p} musen
  EI
  RET
TGI1: PUSH AF
  PUSH HL
  IN A,(22H)
  CP 145 ; X,Y positioner
  JP Z,XYP
  CP 146 ; Knappstatus
  JP Z,KNS
  LD (0FFE3H),A
  CP 3 ; CTRL C
  JR NZ ,CT1
  LD HL,(0FF85H)
  LD A,L
  OR H
  JR Z,CT1
  SET 0,(HL)
CT1: CALL 01B9H
  POP HL
  POP AF
  EI
  RETI
KNS: LD HL,KNS1
 LD (CT1+1),HL
 JP NYI
KNS1: CALL FNM
 LD (KNAPPS),A
 LD HL,01B9H
 LD (CT1+1),HL
 RET
XYP: LD HL,XYP1
 LD (CT1+1),HL
 JP NYI
XYP1: CALL FNM
 CALL MULT64
 LD (XTP),HL
 LD HL,XYP2
 LD (CT1+1),HL
 RET
XYP2: CALL FNM
 PUSH BC
 LD B,0
 LD C,A
 LD HL,(XTP)
 ADD HL,BC
 LD (XPOS),HL
 LD HL,XYP3
 LD (CT1+1),HL
 POP BC
 RET
XYP3: CALL FNM
 CALL MULT64
 LD (YTP),HL
 LD HL,XYP4
 LD (CT1+1),HL
 RET
XYP4: CALL FNM
 PUSH BC
 LD B,0
 LD C,A
 LD HL,(YTP)
 ADD HL,BC
 LD (YPOS),HL
 LD HL,01B9H
 LD (CT1+1),HL
 POP BC
 RET
; -------- Sub rutiner -----------
FNM: LD A,(0FFE3H)
  SUB 32
  AND 63
  PUSH AF
  LD A,0
  LD (0FFE3H),A
  POP AF
  RET
MULT64: LD H,0
  LD L,A
  PUSH BC
  LD B,6 ; A*64 > HL
MLOOP: RL L
  RL H
  DJNZ MLOOP
  POP BC
  RET
NYI: POP HL
  POP AF
  EI
  RETI
;------- VARIABLER ---------------
XTP: NOP
 NOP
YTP: NOP
 NOP
KNAPPS: NOP ; Knapp status
XPOS: NOP ; X-kordinaten
  NOP
YPOS: NOP ; Y-Kordinaten
  NOP
  END 55000
