⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ps2.lst

📁 CY7C63743 usb键盘的源码
💻 LST
📖 第 1 页 / 共 5 页
字号:
001F            
001F            illegal_int:
001F            sys_reset:
001F 70    [08]     di                                        ;disable interrupts   
0020 19 FF [04]     mov       A,0ffh 
0022 2A 03 [05]     iowr      PORT3_DATA_REG
0024 19 F5 [04]     mov        A,NORMAL                        ;configure GPIO reg
0026 2A 08 [05]     iowr     GPIO_CONFIG_REG
0028 19 FF [04]     mov     A,0ffh                          ;drive connect bit high
002A 2A 03 [05]     iowr    PORT3_DATA_REG
002C            
002C            
002C            
002C 19 00 [04]     mov     a,0                             ;set psp stack to 0
002E 60    [04]     mov     psp,a                           ; 
002F 19 FF [04]     mov     a,0ffh                          ;set dsp stack to 0xff
0031 30    [05]     swap    a,dsp                           ;now we can call functions
0032            
0032 19 00 [04]     mov     A,0                             ;zero endpoint interrupt reg
0034 2A 21 [05]     iowr    ENDPOINT_INTERRUPT_REG            
0036 31 20 [05]     mov     [dual_ifc_keyboard],A           ;set type to ps2 initially
0038 80 43 [05]    jmp      ps2main                        ; go straight to ps2
003A            
003A            .bummer:
003A 80 3A [05]     jmp     .bummer                          ;loop if we ever get here
003C            
003C            
003C            ; the dsp will remain at 0 for both ps2 and usb. Allow 30h bytes for it.
003C            
003C            dsp_stack_size:                 equ     30h
003C            
003C            ; the psp will start at 0xff for ps2 and 0xe0 for usb (to avoid the
003C            ; USB queues)
003C            
003C            psp_stack_size:                 equ     20h
003C            
003C            ram_base:                       equ     psp_stack_size  ;application ram start
003C            dual_ifc_keyboard:              equ     ram_base        ;keyboard type
003C            dual_ifc_1ms:                   equ     ram_base+1      ;1msec counter
003C            ps2main_ram_base:               equ     ram_base+2      ;and ps2 ram also
003C            
003C            ;include all code which resides in lower 4k now.
003C            
003C            ;========================================================================
003C            ;   FILE: ps2main.asm
003C            ;
003C            ;   This file contains the code that implements the ps2 interface to the
003C            ;   host. 
003C            ;
003C            ;REVISION_HISTORY:
003C            ;
003C            ;3/26/99 replaced command processor jump table "calls" with "jmps"
003C            ;
003C            ;2/10/99 Added XPAGEOFF,XPAGEON around command processor jump table
003C            ;
003C            ;8/25/98 Added a 250 usec delay after the reception of a RESET command but
003C            ;prior to the ACK of the command.  Some PC's did not like it without this delay.
003C            ;
003C            ;========================================================================
003C            
003C            
003C                   XPAGEON
003C            
003C            ;RAM use for this module
003C            
003C            ps2_flags:                      equ       ps2main_ram_base+0 ;flag byte
003C            ps2_last_xmit:                  equ       ps2main_ram_base+1 ;last sent byte     
003C            ps2_xmit_holding_reg:           equ       ps2main_ram_base+2 ;next byte to send
003C            ps2_temp0:                      equ       ps2main_ram_base+3 ;temp register 1
003C            ps2_temp1:                      equ       ps2main_ram_base+4 ;temp register 2
003C            ps2_delay:                      equ       ps2main_ram_base+5 ;used for generating delays
003C            ps2_ghost_flagsV:                         equ       ps2main_ram_base+6 ;used to detect PS2 ghost
003C            c750ms_high_byteV:                equ       ps2main_ram_base+7 ;used for generating delay
003C            c750ms_low_byteV:                         equ       ps2main_ram_base+8 ;used for generating delay
003C            PS2MAIN_RAM_SIZE:               equ       9
003C            
003C                                 
003C            ;========================================================================
003C            ;   FUNCTION: ps2main
003C            ;
003C            ;   Main entry point for ps2. Sets up ports, initializes RAM,
003C            ;   calls initialization function for various modules, calls
003C            ;   the BAT function, then enters the main processing loop.
003C            ;
003C            ;
003C            ;
003C            ;========================================================================
003C            soft_reset:
003C 70    [08]     di
003D 19 00 [04]     mov     a,0                             ;set psp stack to 0
003F 60    [04]     mov     psp,a                           ; 
0040 19 FF [04]     mov     a,0ffh                          ;set dsp stack to 0xff
0042 30    [05]     swap    a,dsp                           ;now we can call functions
0043            
0043            ps2main:
0043 2A 26 [05]     iowr    WATCHDOG_REG
0045 19 F5 [04]     mov     A,NORMAL                         ;configure GPIO reg
0047 2A 08 [05]     iowr    GPIO_CONFIG_REG
0049 19 07 [04]     mov     A,CLKH_DATAH
004B 2A 1F [05]     iowr    USB_STATUS_CONTROL_REG          ;initialize control reg    
004D            
004D                ;clear variables local to this module
004D            
**** MACRO ****     CLEARRAM ps2main_ram_base,PS2MAIN_RAM_SIZE
004D 1C 08 [04]     mov     X,PS2MAIN_RAM_SIZE - 1
004F 19 00 [04]     mov     A,0
0051            lp#1:
0051 32 22 [06]     mov     [X + ps2main_ram_base],A
0053 26    [04]     dec     X
0054 D0 51 [05]     jnc     lp#1:
0056            
0056 9B 4F [10]     call    ksc_init_keyscan                    ;initialize the key scanner
0058 96 D0 [10]     call    ps2key_init                         ;and ps2-specific key scanning routines        
005A 19 04 [04]     mov     A,PS2_ENABLED_INTERRUPTS            ;enable ps2 interrupts        
005C 2A 20 [05]     iowr    GLOBAL_INTERRUPT_REG
005E 72    [08]     ei                                          ;enable interrupts                                                       
005F 92 86 [10]     call    ps2_BAT                             ;test the system
0061 31 24 [05]     mov     [ ps2_xmit_holding_reg],A           ;place result in holding register for transmission
**** MACRO ****     SETBIT  PS2_XMIT,ps2_flags                  ;set bit to indicate transmission necessary
0063 19 02 [04]     mov A,PS2_XMIT
0065 33 22 [07]     or  [ps2_flags                  ],A
**** MACRO ****     SETBIT   PS2_SCAN_KBD,ps2_flags              ;enable scanning
0067 19 08 [04]     mov A,PS2_SCAN_KBD
0069 33 22 [07]     or  [ps2_flags              ],A
006B 19 00 [04]     mov     A,0
006D 31 21 [05]     mov     [dual_ifc_1ms],A
006F            .loop:
006F 2A 26 [05]     iowr    WATCHDOG_REG
0071 90 C4 [10]     call    ps2_idle_loop                       ;do all stuff we need to whilst sitting around
0073 90 A4 [10]     call    ps2_get_byte                        ;see if a byte has come in
0075 D0 79 [05]     jnc     .l0
0077 91 05 [10]     call    ps2_do_command                      ;it has, kick off command processor
0079            .l0:
0079 1A 21 [06]     mov     A,[dual_ifc_1ms]                       ;else check for scanning interval  
007B 16 04 [04]     cmp     A,PS2_SCAN_INTERVAL                 ; 
007D C0 8B [05]     jc      .l1                                 ;not time to scan yet, loop
007F            
007F 19 00 [04]     mov     A,0                                 ;reset scanning interval
0081 31 21 [05]     mov     [dual_ifc_1ms],A       
0083            
**** MACRO ****     TSTBIT  PS2_SCAN_KBD,ps2_flags              ;if scanning enabled
0083 19 08 [04]     mov A,PS2_SCAN_KBD
0085 11 22 [06]     and A,[ps2_flags              ]
0087 A0 8B [05]     jz      .l1                                           
0089 93 C5 [10]     call    ps2_scan_keys                       ;  scan the keyboard                       
008B            .l1:
**** MACRO ****     TSTBIT  PS2_XMIT,ps2_flags                  ;  and if we're not sending something else
008B 19 02 [04]     mov A,PS2_XMIT
008D 11 22 [06]     and A,[ps2_flags                  ]
008F B0 9B [05]     jnz     .l2                                 
0091 96 2B [10]     call    ps2_getkey                          ;  see if the keyboard scan resulted in something
0093 C0 9B [05]     jc      .l2                                 
0095 31 24 [05]     mov     [ ps2_xmit_holding_reg],A           ;  get it if so, place in holding register
**** MACRO ****     SETBIT  PS2_XMIT,ps2_flags                  ;  set flag indicating transmission necessary
0097 19 02 [04]     mov A,PS2_XMIT
0099 33 22 [07]     or  [ps2_flags                  ],A
009B            .l2:
009B 80 6F [05]     jmp     .loop                               ;  and loop
009D            
009D            
009D            
009D            
009D            ;========================================================================
009D            ; FUNCTION: ps2_wait_byte
009D            ;
009D            ;
009D            ; waits for reception of a byte from the host. This is called to get
009D            ; extra bytes in a command from the host. While the byte is waited for,
009D            ; the idle loop is called to keep other tasks going.
009D            ;
009D            ; Returns:  A:  received byte from host
009D            ;           C:  1
009D            ;
009D            ;
009D            ;========================================================================
009D            
009D            ps2_wait_byte:
009D 90 C4 [10]     call    ps2_idle_loop                   ;do boring stuff
009F 90 A4 [10]     call    ps2_get_byte                    ;see if host has sent us something
00A1 D0 9D [05]     jnc     ps2_wait_byte                   ;no, continue to wait
00A3 3F    [08]     ret                                     ;yes, return with carry set
00A4            
00A4            
00A4            
00A4            
00A4            ;========================================================================
00A4            ; FUNCTION: ps2_get_byte
00A4            ;
00A4            ;
00A4            ; tries to get a byte from the host
00A4            ;
00A4            ; Returns:  A:  received byte from host
00A4            ;           C:  1 if A is valid, 0 if no byte received
00A4            ;
00A4            ;========================================================================
00A4            
00A4            ps2_get_byte:
00A4 29 1F [05]    iord     USB_STATUS_CONTROL_REG                  ;if host inhibit condition,           
00A6 10 20 [04]    and      A,PS2_CLOCK_BIT                      
00A8 A0 C1 [05]    jz       .no                                     ;skip this whole operation
00AA 29 1F [05]    iord     USB_STATUS_CONTROL_REG                  ;if host holding us off
00AC 10 10 [04]    and      A,PS2_DATA_BIT                          ;skip too
00AE B0 C1 [05]    jnz      .no                                 
00B0            
00B0 29 1F [05]    iord     USB_STATUS_CONTROL_REG                  ;check for inhibit again
00B2 10 20 [04]    and      A,PS2_CLOCK_BIT
00B4 A0 C1 [05]    jz       .no                                 
00B6 93 69 [10]    call     ps2_receive                             ;all ok, try for byte
00B8 C0 BD [05]    jc       .no1                                    ;if byte received
**** MACRO ****    SETC                                             ;set carry and exit
00BA 3A    [04]     cpl   A
00BB 3A    [04]     cpl   A
00BC 3F    [08]    ret
00BD            
00BD            .no1:
**** MACRO ****    SETBIT       PS2_RESEND_REQUESTED,ps2_flags      ;if something went awry during reception,
00BD 19 04 [04]     mov A,PS2_RESEND_REQUESTED
00BF 33 22 [07]     or  [ps2_flags      ],A
00C1                                                                ;flag a resend request
00C1            .no:
**** MACRO ****    CLEARC                                           ;indicate nothing gotten,gained
00C1 0D 00 [04]     or    A,0
00C3            
00C3 3F    [08]    ret
00C4            
00C4            
00C4            ;========================================================================
00C4            ; FUNCTION: ps2_idle_loop
00C4            ;
00C4            ; the idle loop does the things that must be done during times when nothing
00C4            ; else is happening.
00C4            ;
00C4            ; Returns: nothing
00C4            ;========================================================================
00C4            
00C4            ps2_idle_loop:
00C4 29 1F [05]    iord     USB_STATUS_CONTROL_REG              ;if host inhibit                  
00C6 10 20 [04]    and      A,PS2_CLOCK_BIT                     ;don't bother with anything
00C8 A1 04 [05]    jz       .il2                                 
**** MACRO ****    TSTBIT   PS2_RESEND_REQUESTED,ps2_flags      ;if we need last transmission resent
00CA 19 04 [04]     mov A,PS2_RESEND_REQUESTED
00CC 11 22 [06]     and A,[ps2_flags      ]
00CE A0 DC [05]    jz       .il0                             
00D0            
00D0 19 FE [04]    mov      A,PS2_RSND                          ;send a resend request
00D2 92 BC [10]    call     ps2_send
00D4 C1 04 [05]    jc       .il2                             
**** MACRO ****    CLRBIT   PS2_RESEND_REQUESTED,ps2_flags      ;and clear the resend requirement

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -