📄 ps2d_cmd.asm
字号:
;;*****************************************************************************
;;*****************************************************************************
;; FILENAME: PS2D_cmd.asm
;; Version: 1.2, Updated on 2005/07/06 at 13:49:25
;; Generated by PSoC Designer ver 4.2 b1013 : 02 September, 2004
;;
;; DESCRIPTION: PS2D User Module command implementation file
;; for the enCoRe II family of devices
;;
;; NOTE: User Module APIs conform to the fastcall convention for marshalling
;; arguments and observe the associated "Registers are volatile" policy.
;; This means it is the caller's responsibility to preserve any values
;; in the X and A registers that are still needed after the API
;; function returns. Even though these registers may be preserved now,
;; there is no guarantee they will be preserved in future releases.
;;-----------------------------------------------------------------------------
;; Copyright (c) Cypress Semiconductor 2004. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************
include "m8c.inc"
include "PS2D.inc"
;-----------------------------------------------
; Global Symbols
;-----------------------------------------------
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:
;
;-----------------------------------------------------------------------------
.SECTION
PS2D_DoCommand:
_PS2D_DoCommand:
push x
; * Get a host byte
; * Bail if none to receive
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 .no_cmd ; Bail on no host byte
; Flow here to process a command
.proc_cmd:
; Check if we are in wrap/echo mode, if so we need to
; determine if the command code is one that terminates wrap/echo mode
swap a,x ; Get the command back
cmp [PS2D_bMode], PS2D_CMD_MODE_WRAP_AROUND
jnz .dispatch_cmd
; Flow here if we are in wrap/echo mode.
cmp a,PS2_CMD_RESET_WRAP_MODE ; Wrap Reset?
jz .dispatch_cmd ; Simply let the dispatch routine do it.
cmp a,PS2_CMD_RESET ; Reset?
jz .dispatch_cmd ; Simply let the dispatch routine do it.
; Flow here to wrap/echo the command
call PS2D_SendResponseByte
jmp .proc_cmd_exit ; Done
; Jump here to dispatch a command
.dispatch_cmd:
cmp a, PS2_CMD_FIRST_CMD ; The command code against the lower limit
jnc .valid_cmd
call PS2D_CmdError ; Respond with a resend/error
jmp .proc_cmd_exit ; Done
; Jump here for a valid command code
.valid_cmd:
; Index into the response table
; * ACK if needed
; * Dispatch to the command handler
SUB a, (PS2_CMD_FIRST_CMD) ; Index into the ack dispatch table
push a ; Save the index
index PS2D_CMD_RESPONSE ; Get the response
cmp a, PS2_CMD_NO_ACK ; Respond or not?
jz .no_rsp
call PS2D_SendResponseByte
.no_rsp:
pop a ; Restore the index
asl a ; Now it is a word offset for the JACC
call .dispatch
jmp .ret_addr
.dispatch:
jacc PS2D_CMD_DISPATCH
.ret_addr:
.proc_cmd_exit:
mov a, 0x01 ; Signal a command was processed
jmp .exit
.no_cmd:
mov a, 0x00 ; Signal no command was processed
.exit:
pop x ; Restore X, return flag is in A
ret
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdError
; DESCRIPTION: Report a transmission error to the host
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; 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)
;-----------------------------------------------------------------------------
PS2D_CmdError:
; Mouse only
IF (PS2D_DEVICE_TYPE & PS2D_DEVICE_TYPE_MOUSE)
inc [PS2D_ErrorCnt] ; Tally the error
cmp [PS2D_ErrorCnt], 1 ; First error?
jz .resend ; Ask for a resend
; Flow here on the second error
mov [PS2D_ErrorCnt], 0 ; Restart the error counting
ljmp PS2D_SendResponseError ; Send and error
; Jump here on a resend
.resend:
ENDIF
ljmp PS2D_SendResponseResend ; Send a resend
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdReset
; DESCRIPTION: Reset the PS/2 Interface
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
PS2D_CmdReset:
CALL PS2D_BAT ; Do the BAT again
RET
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdDisable
; DESCRIPTION: Disable Reporting
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdDisable:
DISABLE_DEVICE ; Device specific disable actions
mov [PS2D_bIsEnabled], 0x00 ; Disable the interface
call PS2D_AbortTransfer ; Abort the transfer
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdEnable
; DESCRIPTION: Enable reporting
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdEnable:
mov [PS2D_bIsEnabled], 0x01 ; Enable the interface
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_CmdResend
; DESCRIPTION: Resend the current buffer. Simply set the packet index to 0
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_CmdResend:
mov [PS2D_bTxPktIndex], 0 ; Reset the index to zero
ret
; End of File PS2D_cmd.asm
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -