home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / pps110.zip / PPSSRC.ZIP / KEYTASK.ASM < prev    next >
Assembly Source File  |  1992-07-12  |  4KB  |  207 lines

  1. ;   FILENAME: KEYTASK.ASM
  2. ;
  3. ;   DESCRIPTION: This file includes all the keyboard interrupt routines.
  4. ;
  5.  
  6. %tabsize 4
  7.  
  8. ifndef  MDL
  9.     display "Error: This module requires that you provide a memory model"
  10.     display "       definition on the command line. I.E. /dMDL=SMALL."
  11.     err ; Force a fatal error
  12. else
  13.  
  14.     ideal                   ; Use TASM's Ideal mode
  15.     model   MDL,Pascal        ; Define the memory model
  16.     P286
  17.  
  18. include "globals.inc"  ; Public symbol declarations
  19. include "stdlib.inc"
  20. include "keytask.inc"
  21.  
  22. dataseg
  23.  
  24. kb              db      KB_STATE_ARRAY_SIZE dup (0)
  25. Int09           dd      0
  26. KbdSet        db    0    ; Is the keyboard interrupt set?
  27. Key        dw    0    ; Used in program
  28. Buttons     dw    0    ; Number of mouse buttons
  29. MouseX        dw    0    ; Mouse cursor loc and button info
  30. MouseY        dw    0
  31. Button        dw    0
  32. GotMouse    dw    0
  33. NKey        dw    0
  34.  
  35. codeseg
  36.  
  37. proc    ms_init
  38.     mov    ax,@data
  39.     mov    ds,ax
  40.     mov    ax,0
  41.     int    33h
  42.     mov    [Word GotMouse],1
  43.     mov    [Word Buttons],bx
  44.     cmp    ax,0
  45.     jne    @@PassedTest
  46.     mov    [Word GotMouse],0      ; No mouse present or detected
  47.     mov    [Word Buttons],0
  48.     ret
  49.  
  50. @@PassedTest:
  51.     ret
  52. endp    ms_init
  53.  
  54. proc    ms_show
  55.     uses    ds
  56.     mov    ax,@data
  57.     mov    ds,ax
  58.     mov    ax,1
  59.     int    33h
  60.     mov    ax,3
  61.     int    33h
  62.     shr    cx,3
  63.     shr    dx,3
  64.     mov    [Button],bx
  65.     mov    [MouseX],cx
  66.     mov    [MouseY],dx
  67.     ret
  68. endp    ms_show
  69.  
  70. proc    ms_hide
  71.     mov    ax,2
  72.     int    33h
  73.     ret
  74. endp    ms_hide
  75.  
  76. proc    Keys
  77.     push    ds
  78.     mov    ax,@data
  79.     mov    ds,ax
  80. ;     call     K_ConvertKey
  81. ;     mov     [Word cs:KeyTaskKey],0FFFFh
  82.     cmp    [Word GotMouse],1
  83.     je    @@CheckMouse
  84.     mov    [Word MouseX],0
  85.     mov    [Word MouseY],0
  86.     mov    [Word Button],0
  87.     jmp    @@TestAfterMouse
  88.  
  89. @@CheckMouse:
  90.     mov    ax,3            ; Read mouse stuff
  91.     int    33h
  92.     shr    cx,3
  93.     shr    dx,3
  94.     mov    [Button],bx
  95.     mov    [MouseX],cx
  96.         mov     [MouseY],dx
  97.  
  98. @@TestAfterMouse:
  99.     cmp    [Button],0
  100.     je    @@DoneWithItall
  101.     cmp    [GotMouse],1
  102.     jne    @@DoneWithItAll
  103.     mov    ax,5
  104.     mov    bx,0
  105.     int    33h
  106.  
  107. @@DoneWithItAll:
  108.     mov    ax,[Key]
  109.     mov    bx,[MouseY]
  110.     mov    cx,[MouseX]
  111.     mov    dx,[Button]
  112.     pop    ds
  113.     cmp    ax,0
  114.     ret
  115. endp    Keys
  116.  
  117. proc    sd_KbdTask near
  118.         push    ax bx cx dx si di ds es
  119.  
  120.         mov     ax, seg KB
  121.         mov     ds, ax
  122.         in      al, 60h                         ;get scan code
  123.         mov     dl, al
  124.         and     ax, 7fh                         ;mask off upper bit of al, clear ah
  125.         mov     bx, offset KB
  126.         add     bx, ax                          ;ds:dx points to KBState[ scancode ]
  127.         and     dl, 80h
  128.         jz      @@keyDown
  129.                                                 ;key was released
  130.         mov     [Byte bx], 0
  131.         jmp     @@done
  132. @@keyDown:                                      ;key was pressed
  133.         mov     [Byte bx], 1
  134. @@done:
  135.         ;reset keyboard
  136.         in      al, 61h
  137.         or      al, 80h
  138.         nop
  139.         nop
  140.         out     61h, al
  141.         and     al, 7fh
  142.         nop
  143.         nop
  144.         out     61h, al
  145.  
  146.     ;tell the Programmable Interrupt Controller
  147.     ;that the interrupt has been processed
  148.         cli
  149.         mov     al, 20h
  150.         out     20h, al
  151.  
  152.         pop     es ds di si dx cx bx ax
  153.         iret
  154. endp    sd_KbdTask
  155.  
  156. proc    SetKbdTask
  157.     push    ds
  158.     mov    ax,@data
  159.     mov    ds,ax
  160.     cmp    [Byte KbdSet],1
  161.         jne     @@1
  162.     pop    ds
  163.         ret
  164. @@1:    mov    [Byte KbdSet],1
  165.  
  166.     ; Install the keyboard handler
  167.     mov    ax,3509h
  168.     int    21h
  169.  
  170.     mov    [Word Int09+2],es
  171.     mov    [Word Int09],bx
  172.  
  173.     push    ds
  174.     mov    ax,2509h
  175.     push    cs
  176.     pop    ds
  177.     mov    dx,offset sd_KbdTask
  178.     int    21h
  179.     pop    ds
  180.  
  181.     pop    ds
  182.         ret
  183. endp    SetKbdTask
  184.  
  185. proc    OffKbdTask
  186.     push    ds
  187.     mov    ax,@data
  188.     mov    ds,ax
  189.     cmp    [Byte KbdSet],0
  190.         jne     @@1
  191.     pop    ds
  192.     ret
  193. @@1:    mov    [Byte KbdSet],0
  194.     mov    ax,2509h
  195.     mov    dx,[Word Int09]
  196.     mov    ds,[Word Int09+2]
  197.         int     21h
  198.     pop    ds
  199.     ret
  200. endp    OffKbdTask
  201.  
  202. endif   ; ifndef MDL
  203.  
  204. end
  205.  
  206.  
  207.