Skip to content

Instantly share code, notes, and snippets.

Last active Mar 4, 2020
What would you like to do?
Kempston mouse driver for ZX Spectrum.
; Kempston mouse driver with master/slave support.
; Written by Patrik Rak in 2013, and revised in 2016.
; Based on a driver originally written for testing ZXDS, see the original WoS post
; in the thread at
ld hl,ports
ld de,mouseinput
ld c,0xDF
.loop ld b,(hl)
inc hl
in a,(c)
ld (de),a
inc de
ld a,(mouseinput+6)%256
cp e
jr nz,.loop
ex de,hl
call .pair
.pair ld c,255
ld a,(de)
call .update
ld c,191
ld a,(de)
.update inc de
ld b,a
sub (hl)
ld (hl),b
inc hl
jp m,.dec
add a,(hl)
jr c,.clamp
cp c
jr c,.ok
.clamp ld a,c
jr .ok
.dec add a,(hl)
jr c,.ok
xor a
.ok ld (hl),a
inc hl
ports db 0xFB ; mouse 1 X port
db 0xFF ; mouse 1 Y port
db 0x0B ; mouse 2 X port
db 0x0F ; mouse 2 Y port
db 0xFA ; mouse 1 button port
db 0x0A ; mouse 2 button port
mouse1x db 0
mouse1y db 0
mouse2x db 0
mouse2y db 0
mouse1b db 0 ; mouse 1 buttons
mouse2b db 0 ; mouse 2 buttons
old1x db 0
pos1x db 0 ; mouse 1 X
old1y db 0
pos1y db 0 ; mouse 1 Y
old2x db 0
pos2x db 0 ; mouse 2 X
old2y db 0
pos2y db 0 ; mouse 2 Y
; EOF ;
Copy link

raxoft commented Apr 19, 2017

OK, updated to use the ports Velesoft suggested, so it works with interfaces which use another line(s) from A12-15 range than just A15 for master/slave selection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment