This is the most simple EnterMice reading routine, only 118 bytes. It only reads the two first bytes, strictly MSX protocol, but has the possibility of a secondary "wired" button.
It must be driven by a 50 Hz interrupt, embedded on the internal joystick reading routine of the target program or game.
Sorry for the badly formatted comments.
EnterMice simple reading routine:
ld hl, X_REL ;first byte, X displacement since last lecture
ld a, 2 ;RTS low
out (0B7h), a
ld b, 3 ;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, 2 ;short delay
call WAIT
call READ_4BIT ;read four lower bits
rld ;push them in (HL)
ld hl, Y_REL ;second byte, Y displacement since last lecture
ld a, 2 ;RTS low
out (0B7h), a
ld b, 2 ;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, 2 ;short delay
call WAIT
call READ_4BIT ;read four lower bits
rld ;push them in (HL)
xor a
ld c, a
out (0B5h), a
in a, (0B6h)
and 6
srl a ; here the status of J column is on carry, but is discarded
srl a
rl c ; K column is saved on c
xor 1
ld (SECBUTT_STATUS), a ; L column is the Right Mouse Button
ld a, c
xor 1
ld (MAINBUTT_STATUS), a ; K column is the Left Mouse Button
ld a, (X_REL)
ld c, a
ld a, (Y_REL)
or c ;If a=0, no movement
ret
WAIT:
nop
nop
nop
dec b
jr nz, WAIT
ret
READ_4BIT:
ld b, 4
ld d, 0
READ_LOOP:
ld a, b
out (0B5h), a
in a, (0B6h)
rra ;data is read from K column
rra
rl d
djnz READ_LOOP
ld a, d
ret