home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / at / kbmap.asm < prev    next >
Assembly Source File  |  1994-03-04  |  5KB  |  193 lines

  1. From: ppa@hpldola.HP.COM (Paul P. Austgen)
  2. Newsgroups: comp.sys.ibm.pc
  3. Subject: Re: One more time....
  4. Date: 2 Feb 89 21:30:05 GMT
  5.  
  6. I'm sure there are programs to do just exactly what you want, but this
  7. one allows you to change any keys to anything else that you want to.
  8. If you have access to a BB, try to find kbmap.  If yoiu have the .COM
  9. file, you can edit the table with DEBUG and you don't have to
  10. reassemble.  I find it especially useful to map keys on old games for
  11. the XT over to my AT cursor keys.  I have included a source listing
  12. below:
  13.  
  14.  
  15. ;*******************************************
  16. ;*                                         *
  17. ;*  KBMAP -- A program to translate scan   *
  18. ;*           codes on the PC/AT keyboard.  *
  19. ;*                                         *
  20. ;*        Written by: Alan D. Jones        *
  21. ;*                                         *
  22. ;*        Released to the public domain    *
  23. ;*        on Feb 27,1988.                  *
  24. ;*                                         *
  25. ;*******************************************
  26.  
  27. ;This program must be converted to a "COM"
  28. ; file after linking.
  29.  
  30.  
  31. .286c
  32.  
  33. XCODE    segment para public 'CODE'
  34.  
  35.     assume    cs:XCODE,ds:NOTHING,es:NOTHING,ss:NOTHING
  36.  
  37.     org    100h
  38.  
  39. start:    jmp    load
  40.  
  41. ;This is a complete scan code translation table.
  42. ;The scan code received from the keyboard is used
  43. ; as an index into this table, and the byte found
  44. ; at "scantbl+<scan code>" is substituted and
  45. ; passed to the keyboard interrupt handler.
  46. ;CAUTION: if this table is modified, be sure to
  47. ; swap or substitute MATCHING PAIRS! Both the "make"
  48. ; code and the "break" code ( = make code + 80h )
  49. ; must be changed.
  50.  
  51. ;<ctrl> key:       make = 1Dh, break = 9Dh
  52. ;<caps lock> key:  make = 3Ah, break = 0BAh
  53. ;The table as it stands exchanges the <ctrl> and
  54. ; <caps lock> key functions.
  55.  
  56.     org    104h
  57.  
  58. scantbl    DB 000H,001H,002H,003H,004H,005H,006H,007H
  59.     DB 008H,009H,00AH,00BH,00CH,00DH,00EH,00FH
  60.     DB 010H,011H,012H,013H,014H,015H,016H,017H
  61.     DB 018H,019H,01AH,01BH,01CH,03AH,01EH,01FH
  62.     DB 020H,021H,022H,023H,024H,025H,026H,027H
  63.     DB 028H,029H,02AH,02BH,02CH,02DH,02EH,02FH
  64.     DB 030H,031H,032H,033H,034H,035H,036H,037H
  65.     DB 038H,039H,01DH,03BH,03CH,03DH,03EH,03FH
  66.     DB 040H,041H,042H,043H,044H,045H,046H,047H
  67.     DB 048H,049H,04AH,04BH,04CH,04DH,04EH,04FH
  68.     DB 050H,051H,052H,053H,054H,055H,056H,057H
  69.     DB 058H,059H,05AH,05BH,05CH,05DH,05EH,05FH
  70.     DB 060H,061H,062H,063H,064H,065H,066H,067H
  71.     DB 068H,069H,06AH,06BH,06CH,06DH,06EH,06FH
  72.     DB 070H,071H,072H,073H,074H,075H,076H,077H
  73.     DB 078H,079H,07AH,07BH,07CH,07DH,07EH,07FH
  74.     DB 080H,081H,082H,083H,084H,085H,086H,087H
  75.     DB 088H,089H,08AH,08BH,08CH,08DH,08EH,08FH
  76.     DB 090H,091H,092H,093H,094H,095H,096H,097H
  77.     DB 098H,099H,09AH,09BH,09CH,0BAH,09EH,09FH
  78.     DB 0A0H,0A1H,0A2H,0A3H,0A4H,0A5H,0A6H,0A7H
  79.     DB 0A8H,0A9H,0AAH,0ABH,0ACH,0ADH,0AEH,0AFH
  80.     DB 0B0H,0B1H,0B2H,0B3H,0B4H,0B5H,0B6H,0B7H
  81.     DB 0B8H,0B9H,09DH,0BBH,0BCH,0BDH,0BEH,0BFH
  82.     DB 0C0H,0C1H,0C2H,0C3H,0C4H,0C5H,0C6H,0C7H
  83.     DB 0C8H,0C9H,0CAH,0CBH,0CCH,0CDH,0CEH,0CFH
  84.     DB 0D0H,0D1H,0D2H,0D3H,0D4H,0D5H,0D6H,0D7H
  85.     DB 0D8H,0D9H,0DAH,0DBH,0DCH,0DDH,0DEH,0DFH
  86.     DB 0E0H,0E1H,0E2H,0E3H,0E4H,0E5H,0E6H,0E7H
  87.     DB 0E8H,0E9H,0EAH,0EBH,0ECH,0EDH,0EEH,0EFH
  88.     DB 0F0H,0F1H,0F2H,0F3H,0F4H,0F5H,0F6H,0F7H
  89.     DB 0F8H,0F9H,0FAH,0FBH,0FCH,0FDH,0FEH,0FFH
  90.     
  91. old15        dd    0
  92.  
  93. ;-------------------------------------------
  94.  
  95. ;Interrupt 15h function 4Fh is called (on MOST AT bios's)
  96. ; by the keyboard interrupt handler, with the scan code
  97. ; passed in the AL register. A program may trap int 15h
  98. ; function 4Fh and examine or alter the scan code BEFORE
  99. ; it is processed by the handler. If int 15h returns with
  100. ; carry set, processing proceeds. If it returns with carry
  101. ; clear, processing is skipped and the bios routine ignores
  102. ; the key press.
  103.  
  104. int15        proc    far
  105.  
  106.         pushf
  107.  
  108. ;is this the scan code call?
  109.  
  110.         cmp    ah,4Fh
  111.         je    scancode
  112.  
  113. ;no, act as if we were not here
  114.  
  115.         popf
  116.         jmp    cs:old15
  117.  
  118. ;it is the scan code call, run it thru the translator
  119.  
  120. scancode:    popf
  121.         push    ds
  122.         push    bx
  123.         push    cs
  124.         pop    ds
  125.         lea    bx,scantbl
  126.         xlatb
  127.         pop    bx
  128.         pop    ds
  129.  
  130. ;set carry so scan code is processed
  131.  
  132.         stc
  133.         iret
  134.  
  135. int15        endp
  136.  
  137. ;-------------------------------------------
  138.  
  139. ;Initialization code -- not needed after program
  140. ; becomes memory-resident.
  141.  
  142. cutoff        label    byte
  143.  
  144. msg1        db    'This program only runs '
  145.         db    'on PC/AT type machines.'
  146.         db    0Dh,0Ah,24h
  147.  
  148. load:
  149.  
  150. ;Make sure this is a PC/AT
  151.  
  152.         push    sp
  153.         pop    ax
  154.         cmp    ax,sp
  155.         jne    wrongmachine
  156.         mov    ax,0F000h
  157.         mov    es,ax
  158.         cmp    byte ptr es:[0FFFEh],0FCh
  159.         jne    wrongmachine
  160.  
  161.  
  162. ;Get old interrupt vector
  163.  
  164.         mov    ax,3515h
  165.         int    21h
  166.         mov    word ptr old15,bx
  167.         mov    word ptr old15+2,es
  168.  
  169. ;Install new interrupt vector
  170.  
  171.         mov    ax,2515h
  172.         mov    dx,offset int15
  173.         int    21h
  174.  
  175. ;Terminate and stay resident
  176.  
  177.         mov    ax,3100h
  178.         lea    dx,cutoff
  179.         add    dx,0Fh
  180.         shr    dx,4
  181.         int    21h
  182.  
  183. ;Display "wrong machine" error message and exit
  184.  
  185. wrongmachine:    lea    dx,msg1
  186.         mov    ah,9
  187.         int    21h
  188.         mov    ax,4C01h
  189.         int    21h
  190.  
  191. XCODE    ends
  192.     end    start
  193.