📄 ps2main.asm
字号:
;========================================================================
; FILE: ps2main.asm
;
; This file contains the code that implements the ps2 interface to the
; host.
;
;REVISION_HISTORY:
;
;3/26/99 replaced command processor jump table "calls" with "jmps"
;
;2/10/99 Added XPAGEOFF,XPAGEON around command processor jump table
;
;8/25/98 Added a 250 usec delay after the reception of a RESET command but
;prior to the ACK of the command. Some PC's did not like it without this delay.
;
;========================================================================
XPAGEON
;RAM use for this module
ps2_flags: equ ps2main_ram_base+0 ;flag byte
ps2_last_xmit: equ ps2main_ram_base+1 ;last sent byte
ps2_xmit_holding_reg: equ ps2main_ram_base+2 ;next byte to send
ps2_temp0: equ ps2main_ram_base+3 ;temp register 1
ps2_temp1: equ ps2main_ram_base+4 ;temp register 2
ps2_delay: equ ps2main_ram_base+5 ;used for generating delays
ps2_ghost_flagsV: equ ps2main_ram_base+6 ;used to detect PS2 ghost
c750ms_high_byteV: equ ps2main_ram_base+7 ;used for generating delay
c750ms_low_byteV: equ ps2main_ram_base+8 ;used for generating delay
PS2MAIN_RAM_SIZE: equ 9
;========================================================================
; FUNCTION: ps2main
;
; Main entry point for ps2. Sets up ports, initializes RAM,
; calls initialization function for various modules, calls
; the BAT function, then enters the main processing loop.
;
;
;
;========================================================================
soft_reset:
di
mov a,0 ;set psp stack to 0
mov psp,a ;
mov a,0ffh ;set dsp stack to 0xff
swap a,dsp ;now we can call functions
ps2main:
iowr WATCHDOG_REG
mov A,NORMAL ;configure GPIO reg
iowr GPIO_CONFIG_REG
mov A,CLKH_DATAH
iowr USB_STATUS_CONTROL_REG ;initialize control reg
;clear variables local to this module
CLEARRAM ps2main_ram_base,PS2MAIN_RAM_SIZE
call ksc_init_keyscan ;initialize the key scanner
call ps2key_init ;and ps2-specific key scanning routines
mov A,PS2_ENABLED_INTERRUPTS ;enable ps2 interrupts
iowr GLOBAL_INTERRUPT_REG
ei ;enable interrupts
call ps2_BAT ;test the system
mov [ ps2_xmit_holding_reg],A ;place result in holding register for transmission
SETBIT PS2_XMIT,ps2_flags ;set bit to indicate transmission necessary
SETBIT PS2_SCAN_KBD,ps2_flags ;enable scanning
mov A,0
mov [dual_ifc_1ms],A
.loop:
iowr WATCHDOG_REG
call ps2_idle_loop ;do all stuff we need to whilst sitting around
call ps2_get_byte ;see if a byte has come in
jnc .l0
call ps2_do_command ;it has, kick off command processor
.l0:
mov A,[dual_ifc_1ms] ;else check for scanning interval
cmp A,PS2_SCAN_INTERVAL ;
jc .l1 ;not time to scan yet, loop
mov A,0 ;reset scanning interval
mov [dual_ifc_1ms],A
TSTBIT PS2_SCAN_KBD,ps2_flags ;if scanning enabled
jz .l1
call ps2_scan_keys ; scan the keyboard
.l1:
TSTBIT PS2_XMIT,ps2_flags ; and if we're not sending something else
jnz .l2
call ps2_getkey ; see if the keyboard scan resulted in something
jc .l2
mov [ ps2_xmit_holding_reg],A ; get it if so, place in holding register
SETBIT PS2_XMIT,ps2_flags ; set flag indicating transmission necessary
.l2:
jmp .loop ; and loop
;========================================================================
; FUNCTION: ps2_wait_byte
;
;
; waits for reception of a byte from the host. This is called to get
; extra bytes in a command from the host. While the byte is waited for,
; the idle loop is called to keep other tasks going.
;
; Returns: A: received byte from host
; C: 1
;
;
;========================================================================
ps2_wait_byte:
call ps2_idle_loop ;do boring stuff
call ps2_get_byte ;see if host has sent us something
jnc ps2_wait_byte ;no, continue to wait
ret ;yes, return with carry set
;========================================================================
; FUNCTION: ps2_get_byte
;
;
; tries to get a byte from the host
;
; Returns: A: received byte from host
; C: 1 if A is valid, 0 if no byte received
;
;========================================================================
ps2_get_byte:
iord USB_STATUS_CONTROL_REG ;if host inhibit condition,
and A,PS2_CLOCK_BIT
jz .no ;skip this whole operation
iord USB_STATUS_CONTROL_REG ;if host holding us off
and A,PS2_DATA_BIT ;skip too
jnz .no
iord USB_STATUS_CONTROL_REG ;check for inhibit again
and A,PS2_CLOCK_BIT
jz .no
call ps2_receive ;all ok, try for byte
jc .no1 ;if byte received
SETC ;set carry and exit
ret
.no1:
SETBIT PS2_RESEND_REQUESTED,ps2_flags ;if something went awry during reception,
;flag a resend request
.no:
CLEARC ;indicate nothing gotten,gained
ret
;========================================================================
; FUNCTION: ps2_idle_loop
;
; the idle loop does the things that must be done during times when nothing
; else is happening.
;
; Returns: nothing
;========================================================================
ps2_idle_loop:
iord USB_STATUS_CONTROL_REG ;if host inhibit
and A,PS2_CLOCK_BIT ;don't bother with anything
jz .il2
TSTBIT PS2_RESEND_REQUESTED,ps2_flags ;if we need last transmission resent
jz .il0
mov A,PS2_RSND ;send a resend request
call ps2_send
jc .il2
CLRBIT PS2_RESEND_REQUESTED,ps2_flags ;and clear the resend requirement
jmp .il2
.il0:
TSTBIT PS2_RESEND,ps2_flags ;if host wants last byte resent
jz .il1
mov A,[ps2_last_xmit] ;get it
call ps2_send ;resent it
jc .il2
CLRBIT PS2_RESEND,ps2_flags ;reset flag
jmp .il2
.il1:
TSTBIT PS2_XMIT,ps2_flags ;if we've got something interesting to send
jz .il2
mov A,[ps2_xmit_holding_reg] ;get it
call ps2_send ;send it
jc .il2
CLRBIT PS2_XMIT,ps2_flags ;clear flag saying we've got something
mov A,[ps2_xmit_holding_reg] ;save last transmission
mov [ ps2_last_xmit],A
.il2:
ret ;that is it
;========================================================================
; FUNCTION: ps2_do_command
;
; host command processor switch statement
;
; Returns: nothing
;========================================================================
ps2_do_command:
sub A,0EDh ;subtract off base of command
jc ps2_invalid_command ;whoops, bad command
mov X,A ;else save zero-based command in X
;clear all resend requirementd
CLRBIT (PS2_RESEND_REQUESTED + PS2_RESEND),ps2_flags
mov A,X ;get back zero-based command
rlc ;prepare for case jump
;to proper routine
jacc .switch
XPAGEOFF
.switch:
jmp ps2_set_status_indicators
jmp ps2_echo_enable
jmp ps2_invalid_command
jmp ps2_select_alternate_scan_code
jmp ps2_invalid_command
jmp ps2_read_id
jmp ps2_set_typematic_rate_delay
jmp ps2_enable
jmp ps2_default_disable
jmp ps2_set_default
jmp ps2_set_keys
jmp ps2_set_keys
jmp ps2_set_keys
jmp ps2_set_keys
jmp ps2_set_key_type
jmp ps2_set_key_type
jmp ps2_set_key_type
jmp ps2_resend
jmp ps2_reset
endswitch:
jc ps2_do_command ;if command failed,
ret
XPAGEON
;========================================================================
; FUNCTION: ps2_invalid_command
;
; handles invalid commands
;
;
; Returns:
; C = 0 for success
;========================================================================
ps2_invalid_command:
SETBIT PS2_RESEND_REQUESTED,ps2_flags ;flag that we need a resend
CLEARC ;clear C indicating we're done
jmp endswitch ;and return
;========================================================================
; FUNCTION: ps2_set_status_indicators
;
; sets indicator leds
;
; Returns:
;
; C: 0 if command was sucessful
; C: 1 if command failed
;
;========================================================================
ps2_set_status_indicators:
call ps2_ack_byte ;ack this command
call ps2_wait_byte ;wait for 2nd byte
cmp A,8 ;if 2nd byte invalid
jc .ed0
SETC ;indicate it
jmp endswitch ;and return
.ed0: ;else
and A,7 ;mask off all but 3 ls bits
index ps2_led_tbl ;use translation table
push A ;save it
call ksc_writeLED ;write the leds
pop A ;get it back
and A,NUM_LOCK_LED ;save state of numlock
mov [ps2key_numlock],A ;locally
call ps2_ack_byte ;ack this byte too
CLEARC ;indicate we are done
jmp endswitch
;table to translate ps2-command enumeration of leds into our own bits
XPAGEOFF
ps2_led_tbl:
db 0
db SCROLL_LOCK_LED
db NUM_LOCK_LED
db SCROLL_LOCK_LED + NUM_LOCK_LED
db CAPS_LOCK_LED
db CAPS_LOCK_LED + SCROLL_LOCK_LED
db CAPS_LOCK_LED + NUM_LOCK_LED
db CAPS_LOCK_LED + NUM_LOCK_LED + SCROLL_LOCK_LED
XPAGEON
;========================================================================
;
; FUNCTION: ps2_echo_enable -- burps back an echo byte
;
; Returns:
;
; C: 0 command can't fail
;========================================================================
ps2_echo_enable:
mov A,PS2_ECHO ;send echo response
call ps2_put_byte ;and respond
CLEARC
jmp endswitch
;========================================================================
; FUNCTION: ps2_select_alternate_scan_code
;
; Returns:
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -