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

📄 ps2key.asm

📁 用cy7c66113开发的HUB
💻 ASM
📖 第 1 页 / 共 4 页
字号:
    call    put_code                        ;and return
    ret

.break:                                     ;key was a break situation
                                            ;we need to append shift-make codes
    CLRBIT  PS2KEY_MAKE_FLAG,ps2key_flags   ;put a break code for the character in question
    mov     A,X
    call    put_code

    mov     A,[ksc_mod0]
    and     A,LEFT_SHIFT_BIT                ;if a left shift
    jz      .rightmake

    SETBIT  PS2KEY_MAKE_FLAG,ps2key_flags   ;append a left-make code
    mov           A,AT101KB_LEFTSHIFT
    call    put_code

.rightmake:
    mov     A,[ksc_mod0]                 ;if a right shift
    and     A,RIGHT_SHIFT_BIT
    jz      .exit

    SETBIT  PS2KEY_MAKE_FLAG,ps2key_flags   ;prepend a right-make code
    mov           A,AT101KB_RIGHTSHIFT
    call    put_code
.exit:
    ret

;========================================================================
; FUNCTION: numlock_case
;
; generates altered scan code for numlock'ed character
;
;========================================================================

 numlock_case:
                                            ;numlock codes use extended byte
    SETBIT PS2KEY_EXTENDED_FLAG,ps2key_flags   ;so set flag
    TSTMAKE
    jz      .break
                                             ;key was a make
    SETBIT  PS2KEY_MAKE_FLAG,ps2key_flags   ;so prepend a left-shift make
    mov           A,AT101KB_LEFTSHIFT
    call    put_code

    mov     A,X
    call    put_code
    ret                                     ;and return

.break:                                     ;key was a break
    CLRBIT  PS2KEY_MAKE_FLAG,ps2key_flags   ;generate make code for the character
    mov     A,X
    call    put_code

    mov     A,AT101KB_LEFTSHIFT
    call    put_code
    ret
    
    
;========================================================================
; FUNCTION: put_code
;
; generates  scan code
;
; uses the value in the local variables extended_flag and make_flag
;
;========================================================================


put_code:
    push    X                                ;save X register
    mov     X,A                              ;save character in X
    TSTBIT PS2KEY_EXTENDED_FLAG,ps2key_flags
    jz     .next

    mov           A,0e0h                     ; prepend an 0xe0
    call     putch
.next:                                       ;check for make/break
    TSTBIT PS2KEY_MAKE_FLAG,ps2key_flags
    jz     .break

.make:                                       ;it is a make
    mov    A,[ps2key_scan_set]
    cmp    A,SCAN_SET_1                      ;if scan set 1,
    jnz     .makescan2

    mov    A,X
    index  scan_set_1_table                  ;    look up using set 1's table
    call   putch                             ;    put character, and exit
    jmp    .exit
.makescan2:
    cmp     A,SCAN_SET_2
    jnz    .makescan3                       ;if scan set 2,
    mov    A,X                              ;    look up using set 2's table
    index  scan_set_2_table
    call   putch                            ;    put character, and exit
    jmp    .exit

.makescan3:                                 ;scan set 3
    mov     A,X                             ;just do it
    index   scan_set_3_table
    call    putch
    jmp     .exit

.break:                                     ;it is a break
   mov     A,[ps2key_scan_set]
    cmp    A,SCAN_SET_1                     ;
    jnz    .breakscan2
    mov    A,X                              ;if scan set 1,
    index  scan_set_1_table                 ;    look up code and set bit 7
    or     A,080h
    call   putch                            ;    put code and exit
    jmp    .exit
.breakscan2:
    cmp     A,SCAN_SET_2
    jnz     .breakscan3

    mov    A,0f0h                           ;if scan set 2,
    call   putch                            ;    prepend an 0xf0 byte and exit

    mov    A,X
    index  scan_set_2_table
    call   putch

    jmp     .exit
.breakscan3:
    mov    A,0f0h                           ;if scan set 3,
    call   putch                            ;    prepend an 0xf0 byte and exit

    mov    A,X
    index  scan_set_3_table
    call   putch
    
.exit:
    pop     X
    ret

;========================================================================
; FUNCTION: ps2_getkey
;
; gets a character from ring buffer.
;
; Returns:
;    C = 1 if no characters are
;   available, otherwise, C = 0 and character returned in acc.
;
;========================================================================



ps2_getkey:

    mov     A,[ps2key_key_count]                 ;if key count is zero, return
    cmp     A,0
    jnz     .yes
    SETC
    ret
.yes:
    push    X
    dec     [ps2key_key_count]                   ;else decrement key count
    mov     X,[ps2key_outptr]                    ;get char pointed to
    mov     A,[X + 0]                            ;by out pointer
    mov     X,A                                  ;save it in X
    inc     [ps2key_outptr]                      ;increment out pointer
    mov     A,key_buffer_end                     ;check for wrap
    cmp     A,[ps2key_outptr]
    jnz     .loop
    mov     A,PS2KeyBuffer                  ;wrap, restore pointer to beginning
    mov     [ps2key_outptr],A
.loop:
    mov     A,X
    pop     X
    CLEARC                                       ;return with carry clear
    ret



;========================================================================
; FUNCTION: put_error
;
; inserts an overrun error code into the ring buffer
;
; Returns:
;
;
;========================================================================




put_error:
    mov     A,[ps2key_key_count]                ;get current buffer size
    cmp     A,BUFFER_LEN                        ;if == to max
    jnz     .put                                ;quit now
    ret                                         ;else
.put:
    push    X                                   ;save X
    mov     X,0ffh                              ;if scan set 1, use 0xff for error code
    mov     A,[ps2key_scan_set]
    cmp     A,SCAN_SET_1
    jz     .l1
    mov      X,0                                 ;sets 2 and 3 use a 0 for overrun
.l1:
    mov     A,X
.l2:
    call     put                                ;put the character into the ring buffer
    pop     X                                   ;restore X
    ret

;========================================================================
; FUNCTION: putch
;
; putch inserts a character into the ring buffer. if the ring buffer
; is full or has only room for 1 byte, putch will set the overflow flag
; and return. In other words, putch always leaves room, if possible,
; in the key buffer for insertion of an error code if an overflow occurs.
;
; Returns:
;
;
;========================================================================




putch:
    push    A                                   ;save the character
    mov     A,[ps2key_key_count]                ;get current buffer length
    cmp     A,BUFFER_LEN-1                        ;if not full,
    pop     A                                   ;  retrieve the character
    jc      put                                 ;  and put it it buffer
    SETBIT  PS2KEY_OVERFLOW_FLAG,ps2key_flags   ;else

    ret                                         ;  quit now
put:
    push    X
    inc     [ps2key_key_count]                  ;increment the key count
    mov     X,[ps2key_inptr]                    ;get current in pointer
    mov     [X +0],A                            ;put character there
    pop     X
    inc     [ps2key_inptr]                      ;increment the pointer
    mov     A,key_buffer_end                    ;check for wraparound
    cmp     A,[ps2key_inptr]
    jnz     .l1
    mov     A,PS2KeyBuffer                 ;buffer wrap -- restore pointer to beginning
    mov     [ps2key_inptr],A
.l1:
    ret


;========================================================================
; FUNCTION: ps2key_disable_typematic_action
;
; Disables a typematic key function
;
;
; Returns: nada
;
;
;========================================================================




ps2key_disable_typematic_action:
    push    A                           ;save A
    mov     A,0                         ;clear out typematic key and delay
    mov     [ps2key_last_key_made],A
    mov     [ps2key_delay_ctr],A
    pop     A
    ret

;========================================================================
; FUNCTION: ps2key_enable_typematic_action
;
;
;   Stores the contents of A as the typematic key, and initializes
;   the delay counter to the initial typematic delay.
;
; Returns:
;
;
;========================================================================
 ps2key_enable_typematic_action:
    push    A                               ;save key code
    mov     [ps2key_last_key_made],A        ;store it
    mov     A,[ps2key_flags]
    mov     [ps2key_last_flags],A           ;save the flags associated with it
    mov     A,[ps2key_type_delay]           ;initialize delay counter
    mov     [ps2key_delay_ctr],A            ;to typematic delay
.exit:
    pop     A
    ret

;========================================================================
; FUNCTION: ps2key_check_typematic
;
;
; Checks for expiration of the typematic delay counter and generates
; a key make for the typematic key, if the delay has expired.
;
; Returns:
;
;
;========================================================================


ps2key_check_typematic:
    push    A                               ;save A
    TSTBIT  PS2_SCAN_KBD,ps2_flags          ;  if scanning enabled
    jz      .exit
    mov     A,[ps2key_last_key_made]        ;if we've got a key make in the typematic buffer
    cmp     A,0
    jz      .exit
    mov     A,[ps2key_delay_ctr]            ;check the delay counter
    cmp     A,0                             ;if not zero
    jz      .exit
    dec     [ps2key_delay_ctr]              ;    decrement it
    jnz     .exit
    mov     A,[ps2key_type_period]          ; if now zero, reinitialize to
                                            ; typematic interval
    mov     [ps2key_delay_ctr],A             ;  and generate a key code

    ;we're generating a make code. Set the make flag, and if the
    ;key we must "repeat" requires an extension byte (E0), set the flag for
    ;that too
    SETBIT  PS2KEY_MAKE_FLAG,ps2key_flags           ;set make flag
    CLRBIT  PS2KEY_EXTENDED_FLAG,ps2key_flags       ;clear extension flag
    TSTBIT  PS2KEY_EXTENDED_FLAG,ps2key_last_flags  ;if typematic key was extended
    jz      .noextend
    SETBIT  PS2KEY_EXTENDED_FLAG,ps2key_flags       ;set extention flag
.noextend:
    mov     A,[ps2key_last_key_made]                ;get the key to be generated
    call    put_code                                ;and make it
.exit:
    pop     A
    ret
    
;========================================================================
; FUNCTION: check_typematic_break
;
;
; Checks to see if the key in A is the same as the current typematic key.
; If it is, it disables typematic action. this routine is typically called
; on key breaks to see if the current typematic key has been released.
;
; Returns:
;
;========================================================================

check_typematic_break:
    cmp     A,[ps2key_last_key_made]            ;if this key is the same as the last key make
    jnz     .exit
    call    ps2key_disable_typematic_action     ;turn off the typematic action
.exit:
    ret




;========================================================================
; ps2key_init
;
; initializes variables maintained by this module
;
;
;========================================================================


ps2key_init:
    CLEARRAM (ps2key_ram_base-PS2KEY_RAM_SIZE),PS2KEY_RAM_SIZE  ;clear ram
    call    ps2key_clear_key_buffer
    mov     A,SCAN_SET_2                            ;initialize to scan set 2
    mov     [ps2key_scan_set],A
    call    ps2key_set_default_key_types               ;set default ss3 types
    mov     A,0
    mov     [ps2key_numlock],A                      ;disable numlock
   ret
   
;========================================================================
; ps2key_clear_key_buffer
;
; clears the key buffer
;
;
;========================================================================

ps2key_clear_key_buffer:
    push    A

⌨️ 快捷键说明

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