Last active
March 4, 2020 22:20
-
-
Save raxoft/f70995bb53f6880bd2a7 to your computer and use it in GitHub Desktop.
Kempston mouse driver for ZX Spectrum.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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 http://www.worldofspectrum.org/forums/discussion/43026/mouse-systems-for-zx-spectrum | |
updatemouse | |
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) | |
cpl | |
.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 | |
ret | |
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 | |
mouseinput | |
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 ; |
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
This driver use incorrect address of slave mouse ports. All slave mouse ports use 4 higher address lines in log.0 (A15-A12=log.0). Mouse drivers and software on my webpage use slave ports 0ADF,0BDF,0FDF.