home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / ASMCODE.ZIP / KEY.ASM < prev    next >
Assembly Source File  |  1994-11-02  |  6KB  |  245 lines

  1. { ────────────────────────────────────────────────────────────────────────
  2.  
  3.   This code is Copyright (c) 1994 by Jonathan E. Wright and AmoebaSoft.
  4.  
  5.   To communicate with the author, send internet mail to: NELNO@DELPHI.COM
  6.  
  7.   About this code:
  8.     written for Turbo Assembler and links with NEWCRT.PAS.
  9.  
  10.   ──────────────────────────────────────────────────────────────────────── }
  11.  
  12. .286
  13.  
  14. DATA    SEGMENT WORD PUBLIC USE16
  15.  
  16.         public  KeyPrsd, RKey, NewInt9
  17.  
  18.         EXTRN   KeyFlags  : BYTE;
  19.         EXTRN   KeyBuff   : BYTE;
  20.         EXTRN   KeyBuffOn : BYTE;
  21.  
  22.         EXTRN   KeyHead   : WORD;
  23.         EXTRN   KeyTail   : WORD;
  24.         EXTRN   KeyChange : BYTE;
  25.  
  26.         EXTRN   KeyTran   : BYTE;
  27.         EXTRN   ShiftTran : BYTE;
  28.         EXTRN   KillFlag  : BYTE;
  29.         EXTRN   IOCount   : WORD;
  30.  
  31.         EXTRN   Quit      : BYTE;
  32.  
  33. DATA    ENDS
  34.  
  35. CODE    SEGMENT WORD PUBLIC USE16
  36.         ASSUME  CS:CODE,DS:DATA
  37.  
  38. ; ╔═══════════════════════════════════════════════════════════════════════╗
  39. ; ║                                                                       ║
  40. ; ║ returns true if a key is in the buffer, false if not                  ║
  41. ; ║ always returns false if the buffer is not active                      ║
  42. ; ║                                                                       ║
  43. ; ╚═══════════════════════════════════════════════════════════════════════╝ }
  44.  
  45. KeyPrsd PROC    FAR
  46.  
  47.         push    bp
  48.         mov     bp,sp
  49.  
  50.     xor     ax,ax
  51.         cmp     al,KeyBuffOn
  52.         je      ENDKeyPrsd
  53.  
  54.     mov     bx,KeyTail
  55.     cmp     bx,KeyHead
  56.     je      ENDKeyPrsd
  57.  
  58.     mov     ax,1
  59.  
  60. ENDKeyPrsd:
  61.         mov     sp,bp
  62.         pop     bp
  63.  
  64.     ret
  65.  
  66. KeyPrsd ENDP
  67.  
  68. ;╔═══════════════════════════════════════════════════════════════════════╗
  69. ;║                                                                       ║
  70. ;║ Returns first key in buffer and updates head and tail pointers        ║
  71. ;║ returns 0 if KeyBuffOn = 0                                            ║
  72. ;║                                                                       ║
  73. ;╚═══════════════════════════════════════════════════════════════════════╝ }
  74.  
  75. RKey    PROC    FAR
  76.  
  77.         push    bp
  78.         mov     bp,sp
  79.  
  80.     xor     ax,ax
  81.     cmp     KeyBuffOn,0
  82.     je      ENDRKey
  83.  
  84. WaitForKey:
  85.     mov     bx,KeyTail
  86.     cmp     bx,KeyHead
  87.         je      WaitForKey
  88.  
  89.     cli
  90.     mov     bx,KeyTail
  91.     mov     al,[bx]
  92.     inc     bx
  93.  
  94.     cmp     bx,OFFSET KeyBuff+255
  95.     jne     NoWrap
  96.         mov     bx,OFFSET KeyBuff
  97.  
  98. NoWrap:
  99.         cmp     bx,KeyHead
  100.     jne     KeysLeft
  101.  
  102.     mov     KeyChange,0
  103.  
  104. KeysLeft:
  105.         mov     KeyTail,bx
  106.  
  107. ENDRKey:
  108.         sti
  109.     xor     ah,ah
  110.  
  111.         mov     sp,bp
  112.         pop     bp
  113.  
  114.     ret
  115.  
  116. RKey    ENDP
  117.  
  118. ;╔═══════════════════════════════════════════════════════════════════════╗
  119. ;║                                                                       ║
  120. ;║ reads a key from the keyboard and modifies the KeyFlags table.  If    ║
  121. ;║ KeyBuffOn <> 0 then the key is also placed in KeyBuff.  Up to 255     ║
  122. ;║ keys can be placed in the buffer.                                     ║
  123. ;║                                                                       ║
  124. ;║ Flags table is set as follows:  the high bit of the flag is set to    ║
  125. ;║ 1 if the key is pressed and set to 0 when it is released.  The low    ║
  126. ;║ bit is set to 1 if it is pressed and unchanged when it is released    ║
  127. ;║                                                                       ║
  128. ;╚═══════════════════════════════════════════════════════════════════════╝ }
  129.  
  130. NewInt9 PROC    FAR
  131.  
  132.         push    ax
  133.         push    bx
  134.         push    cx
  135.         push    dx
  136.         push    es
  137.     push    di
  138.         push    ds
  139.         push    si
  140.         pushf
  141.  
  142.     mov     ax,DATA
  143.     mov     ds,ax
  144.  
  145.         mov     cx,IOCount
  146.  
  147. IODelayLoop2:
  148.         loop    IODelayLoop2
  149.  
  150.         in      al,60h
  151.         mov     bx,ax
  152.  
  153. ;        mov     ax,bx
  154.         and     bx,007Fh
  155.  
  156.     test    al,10000000b       ; Check if key was Released
  157.     jnz     KeyReleased
  158.  
  159.     mov     byte ptr [OFFSET KeyFlags+BX],10000000b
  160.  
  161.     cmp     KeyBuffOn,0        ; is the buffer on?
  162.     je      ENDNewInt9
  163.  
  164.         mov     di,KeyHead
  165.     cmp     di,OFFSET KeyBuff+255
  166.         jne     HeadNot255
  167.  
  168.         cmp     KeyTail,OFFSET KeyBuff
  169.     jne     TailNot0
  170.         jmp     ENDNewInt9
  171.  
  172. HeadNot255:
  173.         inc     di
  174.  
  175.         cmp     KeyTail,di
  176.     je      ENDNewInt9
  177.  
  178.     dec     di
  179.  
  180. TailNot0:
  181.         cmp     byte ptr [OFFSET KeyFlags+2Ah],080h
  182.         je      Shift
  183.         cmp     byte ptr [OFFSET KeyFlags+36h],080h
  184.         je      Shift
  185.  
  186.         cmp     byte ptr [OFFSET KeyFlags+38h],080h
  187.         jne     NoShift
  188.  
  189.         cmp     bl,2Dh              ; Alt-X pressed?
  190.         jne     NoShift             ; if no then jump
  191.  
  192.         mov     Quit,1              ; store TRUE in Quit
  193.         jmp     ENDNewInt9
  194.  
  195. Shift:
  196.         mov     bl,byte ptr [OFFSET ShiftTran+BX]
  197.         jmp     Check0
  198.  
  199. NoShift:
  200.         mov     bl,byte ptr [OFFSET KeyTran+BX]
  201.  
  202. Check0:
  203.         cmp     bl,0
  204.         je      ENDNewInt9
  205.  
  206.         cmp     KeyBuffOn,2
  207.         jne     StoreBuff
  208.  
  209.         test    bl,10000000b       ; is this a function key or
  210.         jnz     ENDNewInt9         ; keypad key?
  211.  
  212. StoreBuff:
  213.         mov     [di],bl            ; Put key in buffer
  214.     inc     KeyHead
  215.     cmp     KeyHead,OFFSET KeyBuff+255
  216.     jne     ENDNewInt9
  217.     mov     KeyHead,OFFSET KeyBuff
  218.     jmp     ENDNewInt9
  219.  
  220. KeyReleased:
  221.         mov     byte ptr ds:[OFFSET KeyFlags+BX],00000000b
  222.  
  223. ENDNewInt9:
  224.         mov     KeyChange,1
  225.  
  226.     mov     al,20h             ; send EOI
  227.      out     20h,al
  228.  
  229.         popf
  230.         pop     si
  231.     pop     ds
  232.     pop     di
  233.         pop     es
  234.         pop     dx
  235.         pop     cx
  236.     pop     bx
  237.     pop     ax
  238.  
  239.         iret
  240.  
  241. NewInt9 ENDP
  242.  
  243. CODE    ENDS
  244.  
  245.         END