📄 ps2d_cmd.lis
字号:
0000 mov [PS2D_bTxPktIndex], 0 ;
export PS2D_DoCommand
export _PS2D_DoCommand
export PS2D_CmdError
export PS2D_CmdReset
export PS2D_CmdDisable
export PS2D_CmdEnable
export PS2D_CmdResend
;-----------------------------------------------
; Persistent RAM Allocation
;-----------------------------------------------
AREA bss (RAM,REL)
AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_DoCommand
;
; DESCRIPTION: Process a host command if the host is requesting to send one
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: A = 0 if no command was processed
; A = 1 if a command was processed
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
0000 .SECTION
0000 PS2D_DoCommand:
0000 _PS2D_DoCommand:
0000 10 push x
0001 ; * Get a host byte
0001 ; * Bail if none to receive
0001 9000 call PS2D_GetHostByte ; Get the host byte if one is available
0003 4B swap a,x ; Swap bytes to make the check
0004 3900 cmp a, 0x00 ; Zero signals we have a byte
0006 B032 jnz .no_cmd ; Bail on no host byte
0008
0008 ; Flow here to process a command
0008 .proc_cmd:
0008 ; Check if we are in wrap/echo mode, if so we need to
0008 ; determine if the command code is one that terminates wrap/echo mode
0008 4B swap a,x ; Get the command back
0009 3C0002 cmp [PS2D_bMode], PS2D_CMD_MODE_WRAP_AROUND
000C B00D jnz .dispatch_cmd
000E
000E ; Flow here if we are in wrap/echo mode.
000E 39EC cmp a,PS2_CMD_RESET_WRAP_MODE ; Wrap Reset?
0010 A009 jz .dispatch_cmd ; Simply let the dispatch routine do it.
0012
0012 39FF cmp a,PS2_CMD_RESET ; Reset?
0014 A005 jz .dispatch_cmd ; Simply let the dispatch routine do it.
0016
0016 ; Flow here to wrap/echo the command
0016 9000 call PS2D_SendResponseByte
0018 801C jmp .proc_cmd_exit ; Done
001A
001A ; Jump here to dispatch a command
001A
001A .dispatch_cmd:
001A 39E6 cmp a, PS2_CMD_FIRST_CMD ; The command code against the lower limit
001C D005 jnc .valid_cmd
001E
001E 901D call PS2D_CmdError ; Respond with a resend/error
0020 8014 jmp .proc_cmd_exit ; Done
0022
0022 ; Jump here for a valid command code
0022 .valid_cmd:
0022 ; Index into the response table
0022 ; * ACK if needed
0022 ; * Dispatch to the command handler
0022 11E6 SUB a, (PS2_CMD_FIRST_CMD) ; Index into the ack dispatch table
0024
0024 08 push a ; Save the index
0025 F000 index PS2D_CMD_RESPONSE ; Get the response
0027 3900 cmp a, PS2_CMD_NO_ACK ; Respond or not?
0029 A003 jz .no_rsp
002B 9000 call PS2D_SendResponseByte
002D
002D .no_rsp:
002D 18 pop a ; Restore the index
002E
002E 64 asl a ; Now it is a word offset for the JACC
002F 9002 call .dispatch
0031 8003 jmp .ret_addr
0033 .dispatch:
0033 E000 jacc PS2D_CMD_DISPATCH
0035 .ret_addr:
0035 .proc_cmd_exit:
0035 5001 mov a, 0x01 ; Signal a command was processed
0037 8003 jmp .exit
0039
0039 .no_cmd:
0039 5000 mov a, 0x00 ; Signal no command was processed
003B
003B .exit:
003B 20 pop x ; Restore X, return flag is in A
003C 7F ret
003D .ENDSECTION
003D ;-----------------------------------------------------------------------------
003D ; FUNCTION NAME: PS2D_CmdError
003D ; DESCRIPTION: Report a transmission error to the host
003D ;
003D ;-----------------------------------------------------------------------------
003D ;
003D ; ARGUMENTS: None
003D ;
003D ; RETURNS: None
003D ;
003D ; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
003D ;
003D ; THEORY of OPERATION or PROCEDURE:
003D ;
003D ; This lets _SendResponseXXXX do the return to the call (saves stack and code)
003D ;-----------------------------------------------------------------------------
003D PS2D_CmdError:
003D
003D ; Mouse only
IF (PS2D_DEVICE_TYPE & PS2D_DEVICE_TYPE_MOUSE)
003D 7600 inc [PS2D_ErrorCnt] ; Tally the error
003F 3C0001 cmp [PS2D_ErrorCnt], 1 ; First error?
0042 A007 jz .resend ; Ask for a resend
0044
0044 ; Flow here on the second error
0044 550000 mov [PS2D_ErrorCnt], 0 ; Restart the error counting
0047 7D0000 ljmp PS2D_SendResponseError ; Send and error
004A
004A ; Jump here on a resend
004A .resend:
ENDIF
004A 7D0000 ljmp PS2D_SendResponseResend ; Send a resend
004D ;-----------------------------------------------------------------------------
004D ; FUNCTION NAME: PS2D_CmdReset
004D ; DESCRIPTION: Reset the PS/2 Interface
004D ;
004D ;-----------------------------------------------------------------------------
004D ;
004D ; ARGUMENTS: None
004D ;
004D ; RETURNS: None
004D ;
004D ; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
004D ;
004D ; THEORY of OPERATION or PROCEDURE:
004D ;
004D PS2D_CmdReset:
004D 9000 CALL PS2D_BAT ; Do the BAT again
004F 7F RET
0050 ;-----------------------------------------------------------------------------
0050 ; FUNCTION NAME: PS2D_CmdDisable
0050 ; DESCRIPTION: Disable Reporting
0050 ;
0050 ;-----------------------------------------------------------------------------
0050 ;
0050 ; ARGUMENTS: None
0050 ;
0050 ; RETURNS: None
0050 ;
0050 ; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
0050 ;
0050 ; THEORY of OPERATION or PROCEDURE:
0050 ;
0050 ;-----------------------------------------------------------------------------
0050 PS2D_CmdDisable:
0050 550000 mov [PS2D_bIsEnabled], 0x00 ; Disable the interface
0053 9000 call PS2D_AbortTransfer ; Abort the transfer
0055
0055 7F ret
0056 ;-----------------------------------------------------------------------------
0056 ; FUNCTION NAME: PS2D_CmdEnable
0056 ; DESCRIPTION: Enable reporting
0056 ;
0056 ;-----------------------------------------------------------------------------
0056 ;
0056 ; ARGUMENTS: None
0056 ;
0056 ; RETURNS: None
0056 ;
0056 ; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
0056 ;
0056 ; THEORY of OPERATION or PROCEDURE:
0056 ;
0056 ;-----------------------------------------------------------------------------
0056 PS2D_CmdEnable:
0056 550001 mov [PS2D_bIsEnabled], 0x01 ; Enable the interface
0059 7F ret
005A ;-----------------------------------------------------------------------------
005A ; FUNCTION NAME: PS2D_CmdResend
005A ; DESCRIPTION: Resend the current buffer. Simply set the packet index to 0
005A ;
005A ;-----------------------------------------------------------------------------
005A ;
005A ; ARGUMENTS: None
005A ;
005A ; RETURNS: None
005A ;
005A ; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
005A ;
005A ; THEORY of OPERATION or PROCEDURE:
005A ;
005A ;-----------------------------------------------------------------------------
005A PS2D_CmdResend:
005A 550000 mov [PS2D_bTxPktIndex], 0 ; Reset the index to zero
005D 7F ret
005E ; End of File PS2D_cmd.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -