📄 ps2d_mouse_cmd.asm
字号:
mov [PS2D_bMode],[PS2D_bLastMode] ; Restore the previous mode
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdSetWrapMode
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdSetWrapMode:
cmp [PS2D_bLastMode], PS2D_CMD_MODE_WRAP_AROUND ; Are we already in Wrap Mode/
jz .exit ; Jump if we are already there
; Flow here to enter Wrap Mode
mov [PS2D_bLastMode],[PS2D_bMode] ; Save the current mode
mov [PS2D_bMode], PS2D_CMD_MODE_WRAP_AROUND ; Set Wrap Mode
; Jump or flow here to exit
.exit:
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdSetScaling_1_1
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdSetScaling_1_1:
mov [PS2D_bMouseScaling], 0x00 ; Set the scaling to 1:1
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdSetScaling_2_1
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdSetScaling_2_1:
mov [PS2D_bMouseScaling], 0x01 ; Set the scaling to 2:1
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdSetResolution
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
; This lets _SendResponseXXXX do the return to the call (saves stack and code)
;-----------------------------------------------------------------------------
.LITERAL
PS2D_cValidResolutions: DB 1, 2, 4, 8
PS2D_cEndOfValidResolutions:
PS2D_cSizeOfValidResolutions: equ PS2D_cEndOfValidResolutions - PS2D_cValidResolutions
.ENDLITERAL
PS2D_CmdSetResolution:
.get_byte:
call PS2D_GetHostByte ; Get the host byte if one is available
swap a,x ; Swap bytes to make the check
cmp a, 0x00 ; Zero signals we have a byte
jnz .get_byte ; Keep trying to get the rate byte
; Validate the sample rate
; Build a little stack frame
swap a,x ; Get the sample index back
cmp a,PS2D_cSizeOfValidResolutions
jc .valid
; Flow here if the index is invalid
ljmp PS2D_SendResponseError ;
; Jump here when we valiate the resolution
.valid:
mov [PS2D_bMouseResolution], a ; And save it
ljmp PS2D_SendResponseACK ;
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdMouseStatusReport
; DESCRIPTION:
; Byte 0
; bit 7:7 0 Must be zero
; bit 6:6 Mode 1=Stream/0=Report
; bit 5:5 Enable 1=Enabled/0=Disabled
; bit 4:4 Scaling 1=2:1/0=1:1
; bit 3:3 0 Must be zero
; bit 0:0 Left btn 1=down/0=up
; bit 2:2 Mid btn 1=down/0=up
; bit 1:1 Right btn 1=down/0=up
; bit 0:0 Left btn 1=down/0=up
; Byte 1 Resolution
; Byte 2 Sample Rate
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdMouseStatusReport:
mov a,0 ; Initialize the report
mov [PS2D_aTxBuffer+0],a ; Initialize the report
mov [PS2D_aTxBuffer+1],a ; Initialize the report
mov [PS2D_aTxBuffer+2],a ; Initialize the report
;------------------------------------------------------------------------------
; Byte 0
;------------------------------------------------------------------------------
mov a,0x40 ; bit 6:6 Mode 1=Stream
cmp [PS2D_bMode],PS2D_CMD_MODE_STREAM
jz .s1
mov a,0x00 ; bit 6:6 Mode 0=Stream
.s1:
or [PS2D_aTxBuffer+0],a ; bit 6:6 Mode
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
mov a,0x20 ; bit 5:5 Enable 1=Enabled
cmp [PS2D_bIsEnabled], 0x01
jz .s2
mov a,0x00 ; bit 5:5 Enable 0=Disabled
.s2:
or [PS2D_aTxBuffer+0],a ; bit 5:5 Enable
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
mov a,0x10 ; bit 4:4 Scaling 1=2:1
cmp [PS2D_bIsEnabled], 0x01
jz .s3
mov a,0x00 ; bit 4:4 Scaling 0=1:1
.s3:
or [PS2D_aTxBuffer+0],a ; bit 4:4 Scaling
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; bit 0:0 Left btn 1=down/0=up
; bit 2:2 Mid btn 1=down/0=up
; bit 1:1 Right btn 1=down/0=up
; bit 0:0 Left btn 1=down/0=up
;------------------------------------------------------------------------------
; Byte 1 Resolution
;------------------------------------------------------------------------------
mov a,[PS2D_bMouseResolution]
mov [PS2D_aTxBuffer+1],a
;------------------------------------------------------------------------------
; Byte 2 Sample Rate from the table
;------------------------------------------------------------------------------
mov a,[PS2D_bSampleRateIndex]
index PS2D_cValidSampleRates
mov [PS2D_aTxBuffer+2],a
;------------------------------------------------------------------------------
; Start the packet transfer
;------------------------------------------------------------------------------
mov [PS2D_bTxPktSize], 3
mov [PS2D_bTxPktIndex], 0
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CheckWheelUnlock
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.LITERAL
WheelUnlockSequence: DB 6, 5, 4
.ENDLITERAL
PS2D_CheckWheelUnlock:
_PS2D_CheckWheelUnlock:
mov a, [PS2D_bWheelUnlock]
cmp a, 3 ; Range Check
jnc .exit ;
index WheelUnlockSequence ; Get the current sequence item
cmp a, [PS2D_bSampleRateIndex]
jnz .reset ; Jump on no match
; Flow here if we matched on this attempt
inc [PS2D_bWheelUnlock] ; Bump the unlock index
cmp [PS2D_bWheelUnlock], 3 ; Have we completed the sequence?
jnz .exit
; Flow here if we should unlock the scroll wheel
mov [PS2D_bDeviceID], 3 ; Unlock it through the device ID
mov [PS2D_bWheelUnlock], 0x00 ; Reset unlock index
; Flow or jump here to exit
.exit:
ret
; Jump here to reset the counters
.reset:
mov [PS2D_bWheelUnlock], 0 ; Reset the counter/index
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdGetDeviceID
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdGetDeviceID:
mov [PS2D_aTxBuffer+0], [PS2D_bDeviceID] ; Return the ID to the host
;------------------------------------------------------------------------------
; Start the packet transfer
;------------------------------------------------------------------------------
mov [PS2D_bTxPktSize], 1
mov [PS2D_bTxPktIndex], 0
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_StartDevice
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
; This function is called by PS2D_Start
;
;-----------------------------------------------------------------------------
PS2D_StartDevice:
mov [PS2D_bDeviceID], 0x00 ; Disable
mov [PS2D_bSampleRateIndex], 0x05 ; Sample rate : 100
mov [PS2D_bMouseResolution], 0x02 ; Resolution: 4 cnt/mm
mov [PS2D_bMouseScaling], 0x00 ; scaling: 1:1
mov [PS2D_bIsEnabled], 0x00 ; Disable
mov [PS2D_bWheelUnlock], 0x00 ; Reset unlock index
mov [PS2D_bMode], PS2D_CMD_MODE_STREAM ; Stream Mode
mov [PS2D_bLastMode], PS2D_CMD_MODE_STREAM ; Stream Mode
ret
;-----------------------------------------------------------------------------
; Mouse command dispatch table
;-----------------------------------------------------------------------------
export PS2D_CMD_DISPATCH:
PS2D_CMD_DISPATCH:
JMP PS2D_CmdSetScaling_1_1 ; E6
JMP PS2D_CmdSetScaling_2_1 ; E7
JMP PS2D_CmdSetResolution ; E8
JMP PS2D_CmdMouseStatusReport ; E9
JMP PS2D_CmdError ; EA
JMP PS2D_CmdError ; EB
JMP PS2D_CmdResetWrapMode ; EC
JMP PS2D_CmdError ; ED
JMP PS2D_CmdSetWrapMode ; EE
JMP PS2D_CmdError ; EF
JMP PS2D_CmdError ; F0
JMP PS2D_CmdError ; F1
JMP PS2D_CmdGetDeviceID ; F2
JMP PS2D_CmdSetSampleRate ; F3
JMP PS2D_CmdEnable ; F4
JMP PS2D_CmdDisable ; F5
JMP PS2D_CmdError ; F6
JMP PS2D_CmdError ; F7
JMP PS2D_CmdError ; F8
JMP PS2D_CmdError ; F9
JMP PS2D_CmdError ; FA
JMP PS2D_CmdError ; FB
JMP PS2D_CmdError ; FC
JMP PS2D_CmdError ; FD
JMP PS2D_CmdResend ; FE
JMP PS2D_CmdReset ; F0
;-----------------------------------------------------------------------------
; End of File PS2D_mouse_cmd.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -