home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / PROG / BWSB120B.ZIP / TTP / KBDAEMON.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-12-23  |  3.7 KB  |  138 lines

  1. ; KBDEAMON.ASM - Keyboard schtuff for gAMeS... ugh, GAMES; durn caps
  2. ;                lock key..
  3. ; Written by Edward Schlunder aka Zilym Limms/OverThrowMachine
  4.  
  5. .Model Large, Pascal
  6. .386P
  7. .Code
  8.  
  9. OldInt9         dd      ?              ;Old Int 9h handler address
  10.  
  11. EE              db      0
  12.  
  13. KUp             db      0              ;1-Up is down, 0-Up is up
  14. KDown           db      0              ;1-Down is down, 0-Down is up
  15. KLeft           db      0              ;1-Left is down, 0-Left is up
  16. KRight          db      0              ;1-Right is down, 0-Right is up
  17.  
  18. ;Kicks the KB daemon into action..
  19. KickKBDaemon        Proc    Uses ds es
  20.     Mov     ax, 3509h                  ;Get original Int 9h handler
  21.     Int     21h
  22.     Mov     Word PTR cs:OldInt9, bx       ;Save old IRQ vector
  23.     Mov     Word PTR cs:OldInt9+2, es
  24.  
  25.     Mov     dx, Offset Int9Handler     ;Load DX with our KB handler offset
  26.     Mov     ax, 2509h                  ;DOS function to change int vectors
  27.     Mov     bx, cs                     ;Put segment of our DMA IRQ handler in
  28.     Mov     ds, bx                     ;DX for DOS's use.
  29.     Int     21h                        ;Go call DOS and have the interrupt
  30.  
  31.     Ret
  32. KickKBDaemon        EndP
  33.  
  34. ;Returns the current key krap..
  35. KBDaemon            Proc        Uses es, Up:dword,Down:dword,Lft:dword,Rgt:dword
  36.     Mov     al, cs:KUp
  37.     Les     bx, Up
  38.     Mov     es:[bx], al
  39.  
  40.     Mov     al, cs:KDown
  41.     Les     bx, Down
  42.     Mov     es:[bx], al
  43.  
  44.     Mov     al, cs:KRight
  45.     Les     bx, Rgt
  46.     Mov     es:[bx], al
  47.  
  48.     Mov     al, cs:KLeft
  49.     Les     bx, Lft
  50.     Mov     es:[bx], al
  51.  
  52.     Ret
  53. KBDaemon            EndP
  54.  
  55. FreeKBDaemon        Proc        Uses ds
  56.     Mov     ax, 2509h                  ;DOS function to change int vectors
  57.     Mov     dx, word ptr cs:OldInt9
  58.     Mov     ds, word ptr cs:OldInt9+2
  59.     Int     21h                        ;Go call DOS and have the interrupt
  60.  
  61.     Ret
  62. FreeKBDaemon        EndP
  63.  
  64. Int9Handler         Proc
  65.     Push    ax
  66.  
  67.     In      al, 60h                    ;Get current scan code
  68.     Cmp     al, 0E0h                   ;Is it a good one?
  69.     Je      EEXiT
  70.  
  71.     Cmp     cs:EE, 1
  72.     Jne     BIOSJump
  73.     Mov     cs:EE, 0
  74.  
  75.     Cmp     al, 48h                    ;UP?
  76.     Jne     @F
  77.     Mov     byte ptr cs:KUp, 1
  78.     Jmp     Exit
  79.  
  80. @@: Cmp     al, 48h OR 80h             ;Is it an UP is up code?
  81.     Jne     @F
  82.     Mov     byte ptr cs:KUp, 0         ;Yep
  83.     Jmp     Exit
  84.  
  85. @@: Cmp     al, 50h                    ;DOWN?
  86.     Jne     @F
  87.     Mov     byte ptr cs:KDown, 1
  88.     Jmp     Exit
  89.  
  90. @@: Cmp     al, 50h OR 80h
  91.     Jne     @F
  92.     Mov     byte ptr cs:KDown, 0
  93.     Jmp     Exit
  94.  
  95. @@: Cmp     al, 4Dh                    ;RIGHT?
  96.     Jne     @F
  97.     Mov     byte ptr cs:KRight, 1
  98.     Jmp     Exit
  99.  
  100. @@: Cmp     al, 4Dh OR 80h
  101.     Jne     @F
  102.     Mov     byte ptr cs:KRight, 0
  103.     Jmp     Exit
  104.  
  105. @@: Cmp     al, 4Bh                    ;LEFT?
  106.     Jne     @F
  107.     Mov     byte ptr cs:KLeft, 1
  108.     Jmp     Exit
  109.  
  110. @@: Cmp     al, 4Bh or 80h             ;LEFT?
  111.     Jne     Exit
  112.     Mov     byte ptr cs:KLeft, 0
  113.     Jmp     Exit
  114.  
  115. EEXiT:
  116.     Mov     cs:EE, 1
  117.  
  118. Exit:
  119.     In      al, 61h                    ;Get value of keyboard control lines
  120.     Mov     ah, al                     ;Save it
  121.     Or      al, 80h                    ;Set the "enable kbd" bit
  122.     Out     61h, al                    ; And write it out the control port
  123.     Xchg    ah, al                     ;Fetch the original control port value
  124.     Out     61h, al                    ; And write it back
  125.  
  126.     Mov     al, 20h
  127.     Out     20h, al
  128.  
  129.     Pop     ax
  130.     Iret
  131.  
  132. BIOSJump:
  133.     Pop     ax
  134.     Jmp     cs:OldInt9
  135. Int9Handler             EndP
  136.  
  137. End
  138.