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

📄 int09.asm

📁 实时多重作业操作系统内核(RTMK)。简单实时多重作业操作系统内核源程序。RTMK支持消息和事件
💻 ASM
字号:
;************************************************************************
;*
;* Module name         : INT09.ASM
;*
;* Module description  :
;*    Keyboard interrupt handler.
;*
;* Project             : RTMK
;*
;* Target platform     : DOS
;*
;* Compiler & Library  : TASM
;*
;* Author              : Richard Shen
;*
;* Creation date       : 25 August, 95
;*
;************************************************************************
                  title    Interrupt 09
                  .model   large

                  public   _Int09Handler
                  public   _SaveInt09

                  extrn    _servingInt
                  extrn    _ApplCheckFunc:CODEPTR
                  extrn    _ackProcess:far
                  extrn    _armEvent:far
                  extrn    _RtmkSend:CODEPTR
                  extrn    _ClearKeyHitEvent:CODEPTR

;************************************************************************
;*                S E G M E N T    D E C L A R A T I O N S              *
;************************************************************************

;int09_text       segment byte public 'CODE'
;int09_text       ends

DGROUP            group    _DATA,_BSS
                  assume   cs:int09_text, ds:DGROUP

_DATA             segment  word public 'DATA'
   d@             label    byte
   d@w            label    word
_DATA             ends

_BSS              segment word public 'BSS'
   b@             label    byte
   b@w            label    word
_BSS              ends

;************************************************************************
;*                      D A T A    S E G M E N T                        *
;************************************************************************
_DATA             segment  word public 'DATA'
   _SaveInt09     dd       0           ; Original INT 09H interrupt handler
_DATA             ends

; Keyboard scan codes
scSpaceKey        equ      39h
scInsKey          equ      52h
scDelKey          equ      53h

scCtrlKey         equ      1dh
scShiftLeftKey    equ      2ah
scShiftRightKey   equ      36h
scAltKey          equ      38h
scCapKey          equ      3ah
scNumLockKey      equ      45h
scScrollLockKey   equ      46h

; ROM BIOS data area (offset)
keyFlags          equ     (byte ptr 17h)     ; Keyboard status bits
keyBufHead        equ     (word ptr 1ah)     ; Address of keyboard buffer head
keyBufTail        equ     (word ptr 1ch)     ; Address of keyboard buffer tail
keyBufOrg         equ     (word ptr 1eh)     ; Address of keyboard buffer tail
keyBufEnd         equ     (word ptr 3eh)     ; Address of keyboard buffer end

;************************************************************************
;*                      C O D E    S E G M E N T                        *
;************************************************************************

;int09_text       segment  byte public 'CODE'
                  .CODE

discardKeyTab     label    byte
                  db       scCtrlKey, scShiftLeftKey, scShiftRightKey
                  db       scAltKey,  scCapKey,       scNumLockKey
                  db       scScrollLockKey

discardKeyCnt     equ      ($ - discardKeyTab)

;***********************************************************************
;  Function name   : Int09Handler
;  Description     : Interrupt 09 (keyboard hardware interrupt) handler
;                  :
;  Parameters      : -
;  Returns         : -
;  Author          : Richard Shen
;----------------------------------------------------------------------
;  Date     By      Description
;----------------------------------------------------------------------
;  25Aug95  RCS     Created
;**********************************************************************/
_Int09Handler     proc far
         cli                           ; Disable interrupt
         push     ax                   ; Save registers
         push     bx
         push     cx
         push     dx
         push     es
         push     ds
         push     si
         push     di
         push     bp
         mov      bp, DGROUP
         mov      ds, bp
         mov      bp, sp

         mov      ax, 40h              ; ROM BIOS area segment
         mov      es, ax
         mov      di, es:keyBufTail
         in       al, 60h              ; Read keyboard port
         mov      ah, es:keyFlags
         pushf
         call     dword ptr DGROUP:_SaveInt09 ; Let original handler to do
         cli                        ; Interrupt flag might have been cleared
         test     al, 80h           ; Key hit detected (not released) ?
         jne      @@9               ; If no, ==> return
         mov      ah, al            ; Save key scan code
         mov      si, offset cs:discardKeyTab   ; Check whether the key is
         mov      cx, discardKeyCnt             ; Shift, Alt, Ctrl, CapsLock
@@8:     mov      al, cs:[si]                   ; or ScrollLock.
         cmp      ah, al                        ; If yes, ignore it
         je       @@9
         inc      si
         loop     @@8

         mov      ax, es:[di]       ; Key pressed
         push     ax
         mov      ax, di
         mov      es:keyBufHead, ax
         pop      ax
   ;
   ;     if (ApplCheckFunc != 0)
   ;     {
   ;        if (ApplCheckFunc(key))
   ;        {
   ;           if (ackProcess != NULL)
   ;              RtmkSend(ackProcess, armEvent);  /* Key hit event arrived */
   ;        } /* end of if */
   ;     } /* end of if */
   ;
         mov      dx, word ptr DGROUP:_ApplCheckFunc
         or       dx, word ptr DGROUP:_ApplCheckFunc + 2
         je       short @@9
         push     ax                   ; Pass in parameter
         call     dword ptr DGROUP:_ApplCheckFunc
         or       ax, ax               ; Check return code
         pop      ax                   ; Adjust stack pointer
         je       @@9

         mov      ax, word ptr DGROUP:_ackProcess  ; if (ackProcess)
         or       ax, word ptr DGROUP:_ackProcess + 2
         je       short @@9
         push     word ptr DGROUP:_armEvent
         push     word ptr DGROUP:_ackProcess + 2
         push     word ptr DGROUP:_ackProcess
         inc      word ptr DGROUP:_servingInt      ; servingInt++;
         call     far ptr  _RtmkSend
         add      sp, 6
         call     far ptr  _ClearKeyHitEvent       ;    ClearKeyHit();
         dec      word ptr DGROUP:_servingInt      ; servingInt--;
@@9:     in       al, 61h           ; Get current value of keyboard control line
         mov      ah, al            ; Save it
         or       al, 80h           ; Set "enable keyboard" bit
         out      61h, al           ; and write it out the control port
         xchg     ah, al            ; Fetch the original control port value
         out      61h, al           ; and write it back
         mov      al, 20h
         out      20h, al

         pop      bp                               ; Restore registers
         pop      di
         pop      si
         pop      ds
         pop      es
         pop      dx
         pop      cx
         pop      bx
         pop      ax
         sti                           ; Enable interrupt
         iret
_Int09Handler     endp

;int09_text       ends

         end

⌨️ 快捷键说明

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