home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / kbguid11.zip / KEYBTEST.ASM < prev   
Assembly Source File  |  1994-05-23  |  3KB  |  180 lines

  1. ;-----------------------------------------------------------------------------
  2. ;                Keyboard test program
  3. ;-----------------------------------------------------------------------------
  4. comment ^
  5.  
  6. I wrote this to check out some facts in the keyboard guide. I think it's
  7. pretty self-explanatory. It works only with Tasm, I suppose, but converting
  8. shouldn't be that hard.
  9.  
  10. Copyright (c) Wout Mertens 1994. Read the legal information in the accompany-
  11. ing text. (kbguide.txt)
  12.  
  13. ^
  14. ;-----------------------------------------------------------------------------
  15. ;                    Coding
  16. ;-----------------------------------------------------------------------------
  17.  
  18. .286
  19. jumps
  20. locals
  21. dosseg
  22.  
  23. .model small
  24.  
  25. ;-----------------------------------------------------------------------------
  26. ;                Macros/equs
  27. ;-----------------------------------------------------------------------------
  28.  
  29. WaitKBFlag    macro Mask
  30.         local Wait
  31. Wait:
  32.     in    al, 64h
  33.     and    al, Mask
  34.     jnz    Wait
  35. endm
  36.  
  37. GotKey    macro
  38.     in    al, 61h
  39.     or    al, 80h
  40.     out    61h, al
  41.     and    al, 7fh
  42.     out    61h, al
  43. endm
  44.  
  45. WaitForKey macro Key
  46.     local Here
  47.  
  48. Here:
  49. ifnb <Key>
  50.     cmp    Yo, Key
  51.     jne    Here
  52. else
  53.     cmp    Yo, 0
  54.     je    Here
  55.     cmp    Yo, ACK
  56.     je    Here
  57. endif
  58.     mov    Yo, 0
  59. endm
  60.  
  61. Send    macro b
  62.  
  63.     mov    al, b
  64.     out    60h, al
  65.     WaitKBFlag 2
  66.  
  67. endm
  68.  
  69. ACK        equ 0fah
  70.  
  71. ;-----------------------------------------------------------------------------
  72. ;                Stack segment
  73. ;-----------------------------------------------------------------------------
  74.  
  75. .stack
  76.  
  77. ;-----------------------------------------------------------------------------
  78. ;                 Data segment
  79. ;-----------------------------------------------------------------------------
  80.  
  81. .data
  82.  
  83. Yo    db    0            ;Current key
  84. Place    dw    0            ;See int09
  85.  
  86. ;-----------------------------------------------------------------------------
  87. ;                 Code segment
  88. ;-----------------------------------------------------------------------------
  89.  
  90. .code
  91.  
  92. Program proc
  93.  
  94. ;* Begin
  95. Start:                    ;Major dirty code ahead!
  96. ; * Init regs
  97.     startupcode            ;Set ds, ss etc.
  98.  
  99.     mov    ax, 3509h        ;Save old int 9 vector
  100.     int    21h
  101.     push    es
  102.     push    bx
  103.  
  104.     push    ds            ;Set the new one
  105.     mov    ax, seg int09
  106.     mov    ds, ax
  107.     mov    dx, offset int09
  108.     mov    ax, 2509h
  109.     int    21h
  110.     pop    ds
  111.  
  112.     Send 0f0h            ;Set scanset 1
  113.     Send 1
  114.     Send 0f0h            ;Read out scanset no.
  115.     Send 0
  116.     WaitForKey            ;Wait for non-ACK results
  117.  
  118.     Send 0f0h            ;Ditto, for 2
  119.     Send 2
  120.     Send 0f0h
  121.     Send 0
  122.     WaitForKey
  123.  
  124.     Send 0f0h            ;Ditto, for 3
  125.     Send 3
  126.     Send 0f0h
  127.     Send 0
  128.     WaitForKey
  129.  
  130.     Send 0f0h            ;Set old no 2 back
  131.     Send 2
  132.     WaitForKey 1            ;Wait for Escape
  133.  
  134.     Send 0edh            ;Set all LEDs
  135.     Send 7
  136.     WaitForKey 1            ;Wait for Escape
  137.  
  138.     pop    dx            ;Get int 9 back
  139.     pop    ds
  140.     mov    ax, 2509h
  141.     int    21h
  142.  
  143. ;* Einde
  144. Einde:
  145.     exitcode
  146.  
  147. Program endp
  148.  
  149. int09    proc    far
  150.     pusha
  151.     push    ds
  152.     push    es
  153.  
  154.     mov    ax, 0b800h        ;es->videoseg
  155.     mov    es, ax
  156.     mov    ax, @Data        ;ds->data
  157.     mov    ds, ax
  158.     mov    bx, Place        ;Where to put the next key
  159.     mov    ah, 70h
  160.     in    al, 60h
  161.     mov    [es:bx], ax
  162.  
  163.     mov    Yo, al
  164.  
  165. Go:    GotKey                ;Thank keyboard
  166.  
  167.     add    bx, 2            ;Set next place
  168.     mov    Place, bx
  169.  
  170.     mov    al, 20h         ;End-Of-Interrupt
  171.     out    20h, al
  172.  
  173.     pop    es
  174.     pop    ds
  175.     popa
  176.     iret
  177.  
  178. endp
  179.  
  180. end     Program