And this is the actual routine on the Enterprise128, Z80 4Mh, 1 tic = 250ns:
sub_C3C8:
ld a, (INPUT_DEVICE) ; input device, EXOS variable 189, default 3
cp 1
jp z, EXT1_READ ; go to external joystick 1 reading
cp 2
jp z, EXT2_READ ; go to external joystick 2 reading
or a
jp z, INT_READ ; go to internal joystick reading
;Here begin the Neos mouse reading
ld hl, X_REL ; first byte
ld a, 2 ; RTS low
out (0B7h), a
ld b, 8 ; long delay
call WAIT
call READ_4BIT ; read four higher bits
rld ; push them in (HL)
xor a ; RTS high
out (0B7h), a
ld b, 1 ; short delay
call WAIT
call READ_4BIT ; read four lower bits
rld ; push them in (HL)
ld hl, Y_REL ; second byte
ld a, 2 ; RTS low
out (0B7h), a
ld b, 1 ; short delay
call WAIT
call READ_4BIT ; read four higher bits
rld ; push them in (HL)
xor a ; RTS high
out (0B7h), a
ld b, 1 ; short delay
call WAIT
call READ_4BIT ; read four lower bits
rld ; push them in (HL)
<======Here will be added the future Wheel and three spare buttons reading
xor a
out (0B5h), a
in a, (0B6h) ; read Mouse button. Modified to read left button. Not valid for Neos!!
and 2 ; Mask: 1 for bit 0, 2 for bit 1, 4 for bit 2
; srl a
srl a ; no "srl a" -> data taken from J, one -> from K, two -> from L
xor 1
ld (FIRE_STATUS), a ; EXOS Variable 188
call sub_C4B1 ; this is the "corrections and drawing" routine where the "velocity" 1.1 modification was made
ld a, (X_REL)
ld c, a
ld a, (Y_REL)
or c
ret
; End of function sub_C3C8
--------------------------------------------
WAIT:
nop
nop
nop
dec b
jr nz, WAIT
ret
; End of function WAIT
--------------------------------------------
READ_4BIT:
ld b, 4
ld d, 0
BITREAD:
ld a, b
inc c
out (0B5h), a
in a, (0B6h)
rra ; Two rigth sift ---> data taken from K column
SRL a ;better "srl a" than "rra" as the driver remains the same lenght
rl d
djnz BITREAD
ld a, d
ret
; End of function READ_4BIT