📄 ps2d.asm
字号:
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_TransferInProgress
;
; DESCRIPTION: API Function returns the current transfer status of the UM
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: A: 0 if no transfer is in progress
; 1 if a transfer is in progress
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
PS2D_TransferInProgress:
_PS2D_TransferInProgress:
mov a,[PS2D_bTxPktIndex] ; Compare the current index
cmp a,[PS2D_bTxPktSize] ; verses the packet size
jz .no_more
; Flow here with more to transfer
mov a,0x01 ; More bytes to go
jmp .exit
; Jump here if no more bytes to transfer
.no_more:
mov a,0x00 ; More bytes to go
.exit:
ret
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_AbortTransfer
;
; DESCRIPTION: API function to abort the current transfer
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
PS2D_AbortTransfer:
_PS2D_AbortTransfer:
mov [PS2D_bTxPktIndex],[PS2D_bTxPktSize] ; Simply set the index to the packet length
ret
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_SendNextByte
;
; DESCRIPTION: Sends the next byte in the transfer buffer
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: None
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
PS2D_SendNextByte:
_PS2D_SendNextByte:
; Anything to send?
mov a, [PS2D_bTxPktIndex] ; Get the index
cmp a, [PS2D_bTxPktSize] ; Compared to the packet length
jz .exit ; Anything left to send?
; Check for a host RTS
M8C_DisableGInt ; Disable interrupts
call PS2D_HostRequestToSend ; Host RTS?
cmp a,0x01 ;
jz .exit ; Exit if so
mov x, [PS2D_bTxPktIndex] ; Get the index
mov a, [x+PS2D_aTxBuffer] ; Get the next byte
call PS2D_Send ; Send it
cmp a,0x00 ; Successful?
jnz .exit ; Jump if not
inc [PS2D_bTxPktIndex] ; Bump the index
.exit:
M8C_EnableGInt ; Enable interrupts
ret
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_GetHostByte
; DESCRIPTION: Gets a byte from the host, if the host has requested to
; send data
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None
;
; RETURNS: A: Data byte
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_GetHostByte:
_PS2D_GetHostByte:
M8C_ClearWDT
mov x, 0x80 ; Assume no host byte available
mov a, 0x00
M8C_DisableGInt ; Disable interrupts
call PS2D_HostRequestToSend ; Is the host requesting to send?
cmp a, 0x00 ; 0x00 Indicates no RTS
jz .exit ; Bail out if no RTS
call PS2D_Receive ; Receive the host byte
.exit:
M8C_EnableGInt ; Enable interrupts
ret
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_HostRequestToSend
;-----------------------------------------------------------------------------
;
; DESCRIPTION:
; Check to see if the PS/2 Host is issuing a request to send
;
; ARGUMENTS:
; none.
;
; RETURNS:
; 1 = Host RTS
; 0 = No Host RTS
;
; SIDE EFFECTS:
; REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION OR PROCEDURE:
; TOP goes here
;
;-----------------------------------------------------------------------------
.SECTION
PS2D_HostRequestToSend:
_PS2D_HostRequestToSend:
M8C_ClearWDT
MOV A, REG[PS2D_DR] ; Get the clock and data signals
AND A, (PS2D_MASK) ; Alone
CMP A, PS2D_SCLK ;
JNZ .no_rts ; RTS if only the SDATA is low and SCLK high
.rts:
MOV A, 1 ; Signal rts
RET
.no_rts:
MOV A, 0 ; Signal no rts
RET
.ENDSECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_SendResponseByte
; PS2D_SendResponseACK (Alternate entry)
; PS2D_SendResponseError (Alternate entry)
; PS2D_SendResponseResend (Alternate entry)
;
; DESCRIPTION: Send a single byte in response to some command
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: A: Contains the byte to send
;
; RETURNS: A: Contains the completeion status
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_SendResponseResend:
_PS2D_SendResponseResend:
MOV A, PS2_CMD_RESEND ; Send a Resend
JMP PS2D_SendResponseByte ;
PS2D_SendResponseError:
_PS2D_SendResponseError:
MOV A, PS2_CMD_ERROR ; Send an Error
JMP PS2D_SendResponseByte ;
PS2D_SendResponseACK:
_PS2D_SendResponseACK:
MOV A, PS2_CMD_ACK ; Send an ACK
PS2D_SendResponseByte:
_PS2D_SendResponseByte:
M8C_ClearWDT
M8C_DisableGInt ; Disable interrupts
.send:
CALL PS2D_Send ; Simply send what's in A
M8C_EnableGInt ; Enable interrupts
RET
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_Release
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_Release:
_PS2D_Release:
OR [Port_1_Data_SHADE], PS2D_CLKH_DATAH ; Release C=H, D=H
MOV A, [Port_1_Data_SHADE] ;
MOV reg[PS2D_DR], A ; Update the port
RET
;-----------------------------------------------------------------------------
; FUNCTION NAME: PS2D_Delay
; DESCRIPTION:
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
PS2D_Delay:
_PS2D_Delay:
; we got here with a fixed delay caused by the call, and we will incur
; more due to the sub A, jc, and return. This is equal to 10+4+5+8, or
; 27 cycles of delay.
; our fixed delay is now 278 cycles.
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_24MHz
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_12MHz
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_6MHz
PSOC_ERROR PS2D User Module - Only supports 6, 12, or 24 Mhz
ELSE
; 6 Mhz
SUB A, ((((27*167)/1000)*2)/3)+1 ; subtract current overhead
JC .delay_done ; exit if carry set, time has already expired
ENDIF
ELSE
; 12 Mhz
SUB A, ((((27*83)/1000)*4)/7) ; subtract current overhead
JC .delay_done ; exit if carry set, time has already expired
ENDIF
ELSE
; 24 Mhz
SUB A, ((((27*42)/1000)*8)/11)+1 ; subtract current overhead
JC .delay_done ; exit if carry set, time has already expired
ENDIF
; now eat up the rest of the us in this loop.
.delay_loop:
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_24MHz
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_12MHz
IF CPU_CLOCK_SPEED - OSC_CR0_CPU_6MHz
PSOC_ERROR PS2D User Module - Only supports 6, 12, or 24 Mhz
ELSE
; 6 Mhz - 1.5us per loop
SUB A, 1
JNC .delay_loop
ENDIF
ELSE
; 12 Mhz - 1.667us per loop
NOP
NOP
NOP
SUB A, 1
JNC .delay_loop
ENDIF
ELSE
; 24 Mhz - 1.375us per loop
NOP
NOP
NOP
NOP
NOP
NOP
SUB A, 1
JNC .delay_loop
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -