Commit 0313a270 authored by Jeffrey Lee's avatar Jeffrey Lee Committed by ROOL

Implement scroll mouse support

This adds support for the MS Intellimouse & Intellimouse Explorer
extensions, as documented by:

https://isdaman.com/alsos/hardware/mouse/ps2interface.htm
https://www.scs.stanford.edu/10wi-cs140/pintos/specs/kbd/scancodes-12.html

Wheel state changes & extra buttons are signalled to the OS via
PointerReason_WheelChange
parent 0c6f57c1
......@@ -43,10 +43,17 @@ command_SETRATE * &F3
command_RESEND * &FE
command_RESET * &FF
; Mouse commands.
command_SETCOUNT * &E8 ;AKA Set Resolution
command_ENABLE * &F4 ; Start transmission if in Incremental Stream mode
command_DISABLE * &F5 ; Stop transmission of mouse position reports
command_DEFAULT * &F6
command_GETDEVICEID * &F2
; mouse types (command_GETDEVICEID response)
mousetype_STANDARD * &00 ; 3 button
mousetype_INTELLIMOUSE * &03 ; MS Intellimouse, 3 button + wheel
mousetype_INTELLIMOUSEX * &04 ; MS Intellimouse Explorer, 5 button + wheel
resend_count * 10 ; Maximum number of resends in sequence.
......@@ -80,6 +87,10 @@ DeviceType # 1 ;
RXStateHandler # 4 ; Address of current state handler.
[ ScrollMouse
ProbeStatePtr # 0 ; Overlay next 4 bytes
MouseType # 1 ; mousetype_*
]
Byte1 # 1 ; First byte of serial mouse report.
Byte2 # 1 ; Second byte of serial mouse report.
Byte3 # 1 ; Third byte of serial mouse report.
......@@ -112,6 +123,13 @@ MouseData # 0 ; Mouse data record.
DeltaX # 4 ; X movement since last query from Kernel.
DeltaY # 4 ; Y movement since last query from Kernel.
Buttons # 4 ; Button states.
[ ScrollMouse
ScrollData # 0
DeltaYS # 4 ; Y then X to match PointerReason_WheelChange
DeltaXS # 4
ExtraButtons # 1
LastExtraButtons # 1
]
LastButtons # 1 ; Button states on last poll.
# 3:AND:(-:INDEX:@)
......
......@@ -67,14 +67,15 @@ key SETD false
int SETD false
drv SETD false
table SETD false
scroll SETD false
; Note: There seems to be some kind of timing issue with the
; two below options which can cause either mouse support to
; break (constant reset loop), or the machine to lock up
; completely. I've seen this on RPCEmu, when softloading the
; module. Running in recompiler mode for max speed sometimes
; gets it working properly!
rxtx SETD false ; Interface RX/TX bytes
proto SETD false ; Protocol/state machine
rxtx SETD false ; Interface RX/TX bytes
proto SETD false ; Protocol/state machine
[ :LNOT: :DEF: standalone
GBLL standalone
......@@ -108,6 +109,9 @@ CaptureInput SETL false
GBLL MapWinRToPower ; this should be true for Funai (1?) build. Off for everyone else
MapWinRToPower SETL false
GBLL ScrollMouse ; support MS Intellimouse extensions
ScrollMouse SETL true
;---------------------------------------------------------------------------
; Get the sources.
;
......
......@@ -68,7 +68,7 @@ Init
;
LDR r2, [r12] ; Have we already some workspace?
CMP r2, #0
BNE %FT01
BNE %FT05
MOV r0, #ModHandReason_Claim
LDR r3, =max_running_work
......@@ -76,7 +76,13 @@ Init
EXIT VS
STR r2, [r12] ; Store workspace pointer.
MOV r0, #0
01
SUBS r3, r3, #4
STR r0, [r2, r3]
BNE %BT01
05
MOV r12, r2
[ TMLDebug
......
......@@ -225,6 +225,11 @@ PointerInit
STR lr, DeltaX
STR lr, DeltaY
STR lr, Buttons
[ ScrollMouse
STR lr, DeltaYS
STR lr, DeltaXS
STRB lr, ExtraButtons
]
EXIT
......@@ -319,6 +324,31 @@ PointerRequest
Push "r10,r11"
[ ScrollMouse
; Update scroll state
ADR r10, ScrollData
LDMIA r10, {r1,r3}
MOV r10, #0
STR r10, DeltaYS
STR r10, DeltaXS
LDRB r2, ExtraButtons
LDRB r10, LastExtraButtons
STRB r2, LastExtraButtons
EOR r10, r10, r2
ORR r10, r10, r1
ORRS r10, r10, r3 ; Any changes?
BEQ %FT05
Debug scroll, "WheelChange", r1, r2, r3
Push "r0,r9,lr"
MOV r0, #PointerReason_WheelChange
MOV r9, #PointerV
SWI XOS_CallAVector
Pull "r0,r9,lr"
05
MOV r1, #PointerDevice_PS2Mouse
]
ADR lr, MouseData ; Get DeltaX, DeltaY and Buttons.
LDMIA lr, {r2,r3,r10}
......@@ -940,7 +970,13 @@ PS2_GetZero
MOV r2, #type_Mouse
STRB r2, DeviceType
[ ScrollMouse
ADREQ r1, ProbeData
STREQ r1, ProbeStatePtr
ADREQ r2, PS2_MouseProbe
|
ADREQ r2, PS2_GetACKforSETRATE
]
BEQ continue
B unexpected
......@@ -948,6 +984,66 @@ PS2_GetZero
; State routines for mouse
; ------------------------
[ ScrollMouse
ProbeData
; mousetype_INTELLIMOUSEX sequence (minus first command_SETRATE byte)
DCB 200
DCB command_SETRATE
DCB 200
DCB command_SETRATE
DCB 80
DCB command_GETDEVICEID
DCB command_RESET, mousetype_INTELLIMOUSEX ; End
; mousetype_INTELLIMOUSE sequence
DCB command_SETRATE
DCB 200
DCB command_SETRATE
DCB 100
DCB command_SETRATE
DCB 80
DCB command_GETDEVICEID
DCB command_RESET, mousetype_INTELLIMOUSE ; End
; Everything else is assumed to be a standard mouse
DCB command_RESET, mousetype_STANDARD
ALIGN
PS2_MouseProbe
TEQ r0, #keybd_ACK
BNE unexpected ; Assume this is a transient error
; What byte to send next?
LDR r2, ProbeStatePtr
LDRB r1, [r2], #1
STR r2, ProbeStatePtr
TEQ r1, #command_RESET ; Sequence end?
ADRNE r2, PS2_MouseProbe
BNE send_continue
ADR r2, PS2_MouseProbeRead
B continue
PS2_MouseProbeRead
LDR r2, ProbeStatePtr
LDRB r1, [r2], #1
TEQ r0, r1 ; Did we get the expected response?
BEQ %FT10
; Try the next sequence, if there is one
LDRB r1, [r2], #1
TEQ r1, #command_RESET
STRNE r2, ProbeStatePtr
ADRNE r2, PS2_MouseProbe
BNE send_continue
; Ran out of test sequences. Load the default type.
LDRB r1, [r2], #1
10
Debug scroll, "PS2_MouseProbe detected mouse type", r1
STRB r1, MouseType
; Set our default sample rate
MOV r1, #command_SETRATE
ADR r2, PS2_GetACKforSETRATE
B send_continue
]
;
; sent command_SETRATE (&F3)
; expect keybd_ACK (&FA)
......@@ -1043,8 +1139,63 @@ PS2_GetByte3
Debug proto,"PS2_GetByte3 &",r0
STRB r0, Byte3
[ ScrollMouse
LDRB r2, MouseType
TEQ r2, #mousetype_STANDARD
STREQB r3, KBState ; already stored???
BEQ PS2_GotAllBytes
TEQ r0, #keybd_BAT
ADREQ r2, PS2_GetByte4_afterBAT
ADRNE r2, PS2_GetByte4
B continue
PS2_GetByte4_afterBAT
TEQ r0, #00
BEQ ForceRESET ;Looks like a mouse power-on-reset
PS2_GetByte4
Debug proto,"PS2_GetByte4 &",r0
STRB r0, Byte4
[ debugscroll
TEQ r0, #0
DebugIf NE, scroll, "Byte4", r0
]
; Process scroll data + buttons
STRB r3, KBState ; already stored???
LDRB r2, MouseType
TEQ r2, #mousetype_INTELLIMOUSEX
MOVEQ r2, r0, LSR #4
ANDEQ r2, r2, #3
MOVNE r2, #0
STRB r2, ExtraButtons
MOVNE r2, r0, LSL #24
MOVNE r2, r2, ASR #24
MOV r3, #0
[ {TRUE}
MOVEQ r2, r0, LSL #28
MOVEQ r2, r2, ASR #28
|
; WIP horizontal scrolling. Needs extra detection/activation logic,
; since not all INTELLIMOUSEX support it.
BNE PS2_UpdateScroll
MOV r2, r0, LSL #28
CMP r2, #&E0000000 ; Horizontal scroll?
CMPNE r2, #&20000000 ; (Assume only one tick at a time!)
MOVEQ r3, r2, ASR #29
MOVEQ r2, #0
MOVNE r2, r2, ASR #28
PS2_UpdateScroll
]
ADR lr, ScrollData
LDMIA lr, {r0, r1}
ADD r0, r0, r2
ADD r1, r1, r3
STMIA lr, {r0, r1}
LDRB r0, Byte3
PS2_GotAllBytes
|
STRB r3, KBState ; already stored???
]
LDRB r2, Byte1
;Build Y movement into r1
AND r1, r2, #&20 ; extract Y data sign
......@@ -1100,7 +1251,7 @@ ForceRESET
MOV r0, #command_RESET ;Reset the device
BL SendByte
ADR r2, PS2_GetACKforRESET
ADRL r2, PS2_GetACKforRESET
B continue
;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment