📄 637mouse.asm
字号:
;
;========================================================================
ps2SetResolution:
cmp A, RES1
jz validRes ; go if 1 count per millimeter (mm)
cmp A, RES2
jz validRes ; go 2 counts/mm
cmp A, RES4
jz validRes ; go if 4 counts/mm
cmp A, RES8
jz validRes ; go if 8 counts/mm
mov A, PS2_RESEND
ret
validRes:
mov [ps2Resolution], A
mov A, PS2_ACK
ret
;========================================================================
; FUNCTION: ps2StatusRequest
;
; Form a 3-byte status according to IBM Specs
;
; Byte 1:
; Bit 7: Reserved
; 6: 0 = Stream Mode, 1 = Remote Mode
; 5: 0 = Disabled, 1 = Enabled
; 4: 0 = Scaling 1:1, 1 = Scaling 2:1
; 3: Reserved
; 2: 1 = Left Button Pressed
; 1: Reserved
; 0: 1 = Right Button Pressed
; Byte 2:
; Bits 7-0: Current Resolution Setting
; Byte 3:
; Bits 7-0: Current Sampling Rate
;
;========================================================================
ps2StatusRequest:
mov A, 00h
mov [temp], A
mov A, [currentButtonState]
and A, RIGHT_BUTTON_MASK
jnz sr1
mov A, BIT0 ; set right button pressed
or [temp], A ;
sr1:
mov A, [currentButtonState]
and A, LEFT_BUTTON_MASK
jnz sr2
mov A, BIT2 ; set left button pressed
or [temp], A ;
sr2:
mov A, [ps2Scale]
cmp A, SCALE2_1
jnz sr3
mov A, BIT4 ; set scaling 2:1
or [temp], A ;
sr3:
mov A, [ps2MouseEnabled]
cmp A, 01h
jnz sr4
mov A, BIT5 ; set mouse enabled
or [temp], A ;
sr4:
mov A, [ps2StreamMode]
cmp A, 01h
jz sr5
mov A, BIT6 ; set remote mode
or [temp], A ;
sr5:
mov A, [temp] ; load packet onto xmit buffer
mov [ps2XmitBuffer0], A ;
mov A, [ps2Resolution] ;
mov [ps2XmitBuffer1], A ;
mov A, [ps2ReportRate] ;
mov [ps2XmitBuffer2], A ;
mov A, 03h ; indicate 3-byte packet length
mov [ps2XmitBufferLen], A ;
mov [ps2XmitLen], A ;
ret
;========================================================================
; FUNCTION: ps2SetStreamMode
;
;========================================================================
ps2SetStreamMode:
mov A, 01h ; turn on stream mode
mov [ps2StreamMode], A ;
call ps2ResetMouseReportInterval
ret
;========================================================================
; FUNCTION: ps2ReadData
; Sends a mouse packet back even if there has been no mouse
; movement since the last report or the switch status is unchanged
;
;========================================================================
ps2ReadData:
mov A, EVENT_PENDING ; force it to send a mouse packet
mov [eventMachine], A ;
call loadMousePacket ; load xmit buffer with mouse packet
call ps2ResetMouseReportInterval
ret
;========================================================================
; FUNCTION: ps2ResetWrapMode
; Resets the wrap mode. Note that, if stream mode is on, the
; mouse is disabled when the wrap mode is reset.
;
;========================================================================
ps2ResetWrapMode:
mov A, 00h ; turn off wrap mode
mov [ps2WrapMode], A ;
mov A, [ps2StreamMode]
cmp A, 01h ; is stream mode on?
jnz ps2RWMExit ; no - exit
mov A, 00h ; yes - disable mouse
mov [ps2MouseEnabled], A ;
ps2RWMExit:
ret
;========================================================================
; ps2SetWrapMode
; Any byte of data sent by the system, except 0ech and 0ffh,
; is returned by the mouse
;
;========================================================================
ps2SetWrapMode:
mov A, 01h ; turn on wrap mode
mov [ps2WrapMode], A ;
ret
;========================================================================
; FUNCTION: ps2SetRemoteMode
; Data is transmitted only in response to a Read Data command
;
;========================================================================
ps2SetRemoteMode:
mov A, 00h ; turn off streaming mode
mov [ps2StreamMode], A ;
ret
;========================================================================
; FUNCTION: ps2ReadDeviceType
; Returns device ID = 03h if wheel supported, else 0
;
;========================================================================
ps2ReadDeviceType:
mov A, [ps2Wheel]
cmp A, 01h
mov A, 03h ; set up for wheel support (ID = 3)
jz wheelSupported
mov A, 00h ; set up for no wheel support (ID = 0)
wheelSupported:
mov [ps2XmitBuffer0], A
mov A, 01h ; indicate one byte for sending
mov [ps2XmitBufferLen], A ;
mov [ps2XmitLen], A ;
ret
;========================================================================
; FUNCTION: ps2SetSampleRate
; Sets the sample rate for the mouse
; On entry:
; A = sample rate
; On exit:
; A = PS2_RESEND if invalid sample rate
; A = PS2_ACK if valid sample rate
;
;========================================================================
XPAGEOFF
ps2ValidRates:
db 10, 20, 40, 60, 80, 100, 200 ; 10, 20, ... reports/sec
ps2ValidIntervals:
db 100, 50, 25, 17, 13, 10, 5 ; 100, 50, ... msec/report
XPAGEON
ps2SetSampleRate:
mov X, 07h
mov [ps2Temp0], A ; save sample rate
nextSampleRate:
dec X
jc endSampleRate ; go if end of sample rates
mov A, X ; get valid rate
index ps2ValidRates ;
cmp A, [ps2Temp0] ; does sample rate match?
jnz nextSampleRate ; go if no
mov [ps2ReportRate], A ; save report rate
mov A, X ; get corresponding interval
index ps2ValidIntervals ;
mov [ps2ReportInterval], A ; and save it
call ps2ResetMouseReportInterval
mov A, PS2_ACK ; indicate valid sample rate
; send back ACK byte (PS2 protocol)
ret
endSampleRate:
mov A, PS2_RESEND ; indicate invalid sample rate
; request host to resend data
ret
;========================================================================
; FUNCTION: ps2EnableMouse
; Enables the mouse
;
;========================================================================
ps2EnableMouse:
mov A, 01h
mov [ps2MouseEnabled], A
ret
;========================================================================
; FUNCTION: ps2DisableMouse
; Disables the mouse
;
;========================================================================
ps2DisableMouse:
mov A, 00h ; disable mouse
mov [ps2MouseEnabled], A ;
ret
;========================================================================
; FUNCTION: ps2SetDefault
; Set default settings
;
;========================================================================
ps2SetDefault:
mov A, 100 ; 100 reports per second
mov [ps2ReportRate], A ;
mov A, 10 ; 1 report/10 msec
mov [ps2ReportInterval], A ;
mov A, 01h ; 1-to-1 scaling
mov [ps2Scale], A ;
mov [ps2StreamMode], A ; stream mode on
mov A, 02h ; 4 counts/mm resolution
mov [ps2Resolution], A ;
mov A, 00h ; disable mouse
mov [ps2MouseEnabled], A ;
mov [ps2Wheel], A ; wheel off
mov [ps2WrapMode], A ; turn off wrap mode
ret
;========================================================================
; FUNCTION: ps2Resend
; Resends the last transmission from the mouse
;
;========================================================================
ps2Resend:
mov A, [ps2XmitBufferLen] ; get message length
mov [ps2XmitLen], A ; update remaining bytes to be sent
ret
;========================================================================
; FUNCTION: ps2Reset
; Simply waits in a loop and wait for a watchdog reset to occur
;
;========================================================================
ps2Reset:
mov A, 00h
iowr GLOBAL_INTERRUPT_REG
ps2ResetSelf:
jmp ps2ResetSelf
ret
;********************************************************************
;
; PS2 Subroutines
;
;********************************************************************
;
;========================================================================
; FUNCTION: ps2ResetMouseReportInterval
;
; Resets the mouse's report interval to the value last sent
; by the host. The report interval is counted down in the main loop
; to provide a time base for sending mouse data packets.
;
;========================================================================
ps2ResetMouseReportInterval:
mov A, [ps2ReportInterval]
mov [ps2IntervalCount], A
ret
;========================================================================
; FUNCTION: loadMousePacket
; Load transmit buffer with mouse packet
;
;========================================================================
loadMousePacket:
;
; Notes: we do not apply scaling and resolution to the (x,y)
; coordinates
;
mov A, [ps2Wheel]
cmp A, 01h
jz lmp4Bytes ; go if wheel enabled
mov A, MOUSE_PACKET_3 ; set up for 3-byte transfer
mov [ps2XmitBufferLen], A ;
mov [ps2XmitLen], A ;
mov A, [buttonValue] ; get button state already in
; proper IBM format
and A, 03h ; only keep left & right buttons
jmp lmp0
lmp4Bytes:
mov A, MOUSE_PACKET_4 ; set up for 4-byte transfer
mov [ps2XmitBufferLen], A ;
mov [ps2XmitLen], A ;
mov A, [buttonValue] ; get button state already in
; proper IBM format
and A, 07h ; only keep (L,R,M) bits
or A, BIT3 ; always set to 1
lmp0:
mov [temp], A
mov A, [xCount]
and A, BIT7
jz lmp1
mov A, BIT4 ; set X sign bit
or [temp], A ;
lmp1:
mov A, [yCount]
and A, BIT7
jz lmp2
mov A, BIT5 ; set Y sign bit
or [temp], A ;
lmp2:
mov A, [temp] ; save mouse packet
mov [ps2XmitBuffer0], A ;
mov A, [xCount] ;
mov [ps2XmitBuffer1], A ;
mov A, [yCount] ;
mov [ps2XmitBuffer2], A ;
mov A, [zCount] ;
cpl A ;
inc A ;
mov [ps2XmitBuffer3], A ;
mov A, 00h ; reset (X,Y,Z) coordinates
mov [xCount], A ;
mov [yCount], A ;
mov [zCount], A ;
ret
;========================================================================
; FUNCTION: ps2BAT
;
;========================================================================
ps2BAT:
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -