home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / zendisk2.zip / LST11-17.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  3KB  |  110 lines

  1. ;
  2. ; *** Listing 11-17 ***
  3. ;
  4. ; Demonstrates the calculation of the offset of the word
  5. ; matching a keystroke in a look-up table when SCASW is
  6. ; used, where the 2-byte overrun of SCASW must be
  7. ; compensated for. The offset in the look-up table is used
  8. ; to look up the corresponding address in a second table;
  9. ; that address is then jumped to in order to handle the
  10. ; keystroke.
  11. ;
  12. ; This is a standalone program, not to be used with PZTIME
  13. ; but rather assembled, linked, and run by itself.
  14. ;
  15. stack    segment    para stack 'STACK'
  16.     db    512 dup (?)
  17. stack    ends
  18. ;
  19. code    segment    para public 'CODE'
  20.     assume    cs:code, ds:nothing
  21. ;
  22. ; Main loop, which simply calls VectorOnKey until one of the
  23. ; key handlers ends the program.
  24. ;
  25. start    proc    near
  26.     call    VectorOnKey
  27.     jmp    start
  28. start    endp
  29. ;
  30. ; Gets the next 16-bit key code from the BIOS, looks it up
  31. ; in KeyLookUpTable, and jumps to the corresponding routine
  32. ; according to KeyJumpTable. When the jumped-to routine
  33. ; returns, is will return to the code that called
  34. ; VectorOnKey. Ignores the key if the key code is not in the
  35. ; look-up table.
  36. ;
  37. ; Input: none
  38. ;
  39. ; Output: none
  40. ;
  41. ; Registers altered: AX, CX, DI, ES
  42. ;
  43. ; Direction flag cleared
  44. ;
  45. ; Table of 16-bit key codes this routine handles.
  46. ;
  47. KeyLookUpTable    label    word
  48.     dw    0011bh    ;Esc to exit
  49.     dw    01c0dh    ;Enter to beep
  50. ;*** Additional key codes go here ***
  51. KEY_LOOK_UP_TABLE_LENGTH_IN_WORDS equ (($-KeyLookUpTable)/2)
  52. ;
  53. ; Table of addresses to jump to when corresponding key codes
  54. ; in KeyLookUpTable are found.
  55. ;
  56. KeyJumpTable    label    word
  57.     dw    EscHandler
  58.     dw    EnterHandler
  59. ;*** Additional addresses go here ***
  60. ;
  61. VectorOnKey    proc    near
  62. WaitKeyLoop:
  63.     mov    ah,1    ;BIOS key status function
  64.     int    16h    ;invoke BIOS to see if
  65.             ; a key is pending
  66.     jz    WaitKeyLoop    ;wait until key comes along
  67.     sub    ah,ah    ;BIOS get key function
  68.     int    16h    ;invoke BIOS to get the key
  69.     push    cs
  70.     pop    es
  71.     mov    di,offset KeyLookUpTable
  72.             ;point ES:DI to the table of keys
  73.             ; we handle, which is in the same
  74.             ; segment as this code
  75.     mov    cx,KEY_LOOK_UP_TABLE_LENGTH_IN_WORDS
  76.             ;# of words to scan
  77.     cld
  78.     repnz    scasw    ;look up the key
  79.     jnz    WaitKeyLoop    ;it's not in the table, so
  80.                 ; ignore it
  81.     jmp    cs:[KeyJumpTable+di-2-offset KeyLookUpTable]
  82.             ;jump to the routine for this key
  83.             ; Note that:
  84.             ;   DI-2-offset KeyLookUpTable
  85.             ; is the offset in KeyLookUpTable of
  86.             ; the key we found, with the -2
  87.             ; needed to compensate for the
  88.             ; 2-byte (1-word) overrun of SCASW
  89. VectorOnKey    endp
  90. ;
  91. ; Code to handle Esc (ends the program).
  92. ;
  93. EscHandler    proc    near
  94.     mov    ah,4ch    ;DOS terminate program function
  95.     int    21h    ;exit program
  96. EscHandler    endp
  97. ;
  98. ; Code to handle Enter (beeps the speaker).
  99. ;
  100. EnterHandler    proc    near
  101.     mov    ax,0e07h ;AH=0E is BIOS print character
  102.             ; function, AL=7 is bell (beep)
  103.             ; character
  104.     int    10h    ;tell BIOS to beep the speaker
  105.     ret
  106. EnterHandler    endp
  107. ;
  108. code    ends
  109.     end    start
  110.