home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / uploads / ws4kpd.ark / KEYPAD.TXT next >
Encoding:
Text File  |  1988-07-03  |  12.5 KB  |  236 lines

  1. KEYPAD.TXT - THE CARE AND FEEDING OF THE CP/M KAYPRO PROGRAMMABLE KEYPAD
  2.  
  3. Copyright 1989 by Dale H. Cook
  4.  
  5. This document may be freely distributed provided that it is distributed in
  6. whole with no alteration or modification in form or content, that all
  7. copyright notices remain intact, and that no charge is made other than a
  8. nominal distribution fee. All commercial distribution of this program in part
  9. or in whole without the express written consent of the author is strictly
  10. prohibited. The author may be reached at: CompuServe 71370,2635.
  11.  
  12.  
  13. NOTE: This document involves the use of a number of public domain and/or
  14.       freeware programs such as PROBE and SuperZap. At the end of this text
  15.       is a list of these programs with suggestions on where to find them.
  16.       All are widely and easily available. The only other programs you need
  17.       are on your Kaypro CP/M system disk (like CONFIG and DDT).
  18.  
  19.  
  20.      One of my favorite features on the CP/M Kaypro computers is that the
  21. numeric keypad and cursor keys are fully programmable. The keypad can be
  22. customized for a particular application to become a set of fourteen function
  23. keys. This document explains how the keypad and cursor keys work and how you
  24. can customize them for your own needs.
  25.  
  26.      For simplicity, let's refer to the main keyboard as the "normal" keys,
  27. and to the cursor (arrow) keys and numeric keypad as the "special" keys. When
  28. a normal key is pressed, the key board sends the ASCII value of the key (in
  29. the range 00h to 7Fh) to the BIOS, which passes the value to the calling
  30. program. So when you type an upper case "C", the keyboard and BIOS hand the
  31. calling program the ASCII value 43h. When you type a special key, however,
  32. the keyboard generates a value with the upper bit set (in the range 80h to
  33. FFh) and the BIOS, flagged by the high bit, handles the value differently.
  34. The BIOS passes the value to the monitor ROM which uses the value to enter
  35. a table and look up a new value. This new value, with high bit still set,
  36. is returned to the BIOS. The BIOS uses the new value as an entry into another
  37. table in the BIOS RAM that we will refer to as the "small key table".
  38.  
  39.      Let's take a look at the small key table on your machine. First, you'll
  40. need to know the starting address of your BIOS. Run PROBE.COM and note the
  41. address where your BIOS jump table begins. For example, on my Kaypro 4-84,
  42. it is F600h. (The examples here all use the addresses for my system - just
  43. substitute the addresses you find for your system and follow allong.) Fire up
  44. DDT and instruct it:
  45.  
  46. -dF600 <CR> (to display memory contents starting at F600h)
  47.  
  48.      You'll get a display similar to this:
  49.  
  50. -dF600
  51. F600  C3 A9 F6 C3 1E F7 C3 85 F7 C3 AA F7 C3 06 F8 C3 ................
  52. F610  1F F8 C3 1A F8 C3 15 F8 C3 64 F8 C3 68 F8 C3 6C .........d..h..l
  53. F620  F8 C3 70 F8 C3 74 F8 C3 78 F8 C3 82 F8 C3 3A F8 ..p..t..x.....:.
  54. F630  C3 94 F8 81 00>0B 0A 08 0C 30 31 32 33 34 35 36 .........0123456
  55. F640  37 38 39 2D 2C 0D 2E<05 05 2C 09 0E 18 04 44 03 789-,....,....D.
  56. F650  E1 05 E8 01 00 09 06 18 04 44 03 E1 05 E8 01 00 .........D......
  57. F660  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  58. F670  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  59. F680  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  60. F690  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  61. F6A0  00 00 00 00 00 00 00 00 00 CD 60 F8 AF 32 04 00 ..........'..2..
  62. F6B0  3A 33 F6 32 03 00 21 4A F6 46 23 4E 23 ED B3 7E :3.2..!J.F#N#..~
  63. -
  64.  
  65.      The ASCII display to the right shows a string of 18 bytes (their hex
  66. values are between the > and < symbols) "....0123456789-,.." which
  67. constitute the small key table. The first four - 0Bh, 0Ah, 08h and 0Ch -
  68. are the up, down, left and right cursor key values. The next ten are the
  69. keypad number keys. The last four are the remaining four keys - "-" (2Dh),
  70. "," (2Ch), "ENTER" (0Dh) and "." (2Eh). On some Kaypros the last two keys
  71. seem to have the hex value 00h. (probably due to a BIOS source code error)
  72. If your keypad "ENTER" key doesn't do anything, that's why! Just use CONFIG to
  73. set those keys to their correct values.
  74.  
  75.      Now that we've seen the small key table, what can we do with it? We
  76. could use DDT to change the keys, but Kaypro has provided a seperate program
  77. to make the process easier - CONFIG.COM. If you've never used CONFIG, fire
  78. it up now and play with it. The documentation for this program is pretty
  79. skimpy, but the screens pretty much explain themselves. Try changing the
  80. "ENTER" key to "C" (43h). After you exit CONFIG, the "ENTER" key will print a
  81. "C" on the screen. Changes to the keys made with CONFIG are only good after
  82. the system is cold booted. Since the changes are made on disk, the system
  83. must be rebooted to load the new key values into RAM.
  84.  
  85.      You'll notice that CONFIG lets you program each key with a string of up
  86. to four characters, but the small key table entries are only one byte long.
  87. Let's take a look at that DDT display again:
  88.  
  89. -dF600
  90. F600  C3 A9 F6 C3 1E F7 C3 85 F7 C3 AA F7 C3 06 F8 C3 ................
  91. F610  1F F8 C3 1A F8 C3 15 F8 C3 64 F8 C3 68 F8 C3 6C .........d..h..l
  92. F620  F8 C3 70 F8 C3 74 F8 C3 78 F8 C3 82 F8 C3 3A F8 ..p..t..x.....:.
  93. F630  C3 94 F8 81 00>0B 0A 08 0C 30 31 32 33 34 35 36 .........0123456
  94. F640  37 38 39 2D 2C 0D 2E<05 05*2C*09 0E 18 04 44 03 789-,....,....D.
  95. F650  E1 05 E8 01 00 09 06 18 04 44 03 E1 05 E8 01 00 .........D......
  96. F660  00}00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  97. F670  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  98. F680  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  99. F690  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  100. F6A0  00 00 00 00 00 00 00 00 00{CD 60 F8 AF 32 04 00 ..........'..2..
  101. F6B0  3A 33 F6 32 03 00 21 4A F6 46 23 4E 23 ED B3 7E :3.2..!J.F#N#..~
  102. -
  103.  
  104.      Once again, the hex values of the small key table are indicated between
  105. > and <. I have also marked a string of 72 nuls (00h) between the } and {
  106. symbols. This is the "large key table". Also note the third byte after the
  107. end of the small key table (indicated by the asterisks) - 2Ch on my machine.
  108. This is an offset from the small table to the large table used by the BIOS.
  109. The first byte of the small table is at F635h, and the first byte of the
  110. large table is at F661h. F635h + 2Ch = F661h.
  111.  
  112.      If a byte in the small key table nold a nul (00h) the BIOS will look at
  113. the large key table to find a string of up to four bytes, and pass those
  114. values to the calling program. Try using CONFIG to change the "ENTER" key to
  115. the four characters "C", "a", "t" and "s". Use DDT to examine the changes to
  116. the key tables:
  117.  
  118. -dF600
  119. F600  C3 A9 F6 C3 1E F7 C3 85 F7 C3 AA F7 C3 06 F8 C3 ................
  120. F610  1F F8 C3 1A F8 C3 15 F8 C3 64 F8 C3 68 F8 C3 6C .........d..h..l
  121. F620  F8 C3 70 F8 C3 74 F8 C3 78 F8 C3 82 F8 C3 3A F8 ..p..t..x.....:.
  122. F630  C3 94 F8 81 00 0B 0A 08 0C 30 31 32 33 34 35 36 .........0123456
  123. F640  37 38 39 2D 2C>00<2E 05 05 2C 09 0E 18 04 44 03 789-,....,....D.
  124. F650  E1 05 E8 01 00 09 06 18 04 44 03 E1 05 E8 01 00 .........D......
  125. F660  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  126. F670  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  127. F680  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  128. F690  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
  129. F6A0  00}43 61 74 73{00 00 00 00 CD 60 F8 AF 32 04 00 .Cats.....'..2..
  130. F6B0  3A 33 F6 32 03 00 21 4A F6 46 23 4E 23 ED B3 7E :3.2..!J.F#N#..~
  131. -
  132.  
  133.      Byte F645, formerly 0Dh (carriage return) is now a nul, (00h) and
  134. bytes F6A1 through F6A4 hold the ASCII value of "Cats". Now when you hit
  135. the "ENTER" key, "Cats" will be sent to the screen. To find the four large
  136. key table bytes corresponding to any key, use the table below to perform
  137. a calculation:
  138.  
  139. Offset  Key      Offset  Key      Offset  Key      Offset  Key
  140. ------  ---      ------  ---      ------  ---      ------  ---
  141.  00h    Up        14h    1         28h    6         3Ch    ,
  142.  04h    Down      18h    2         2Ch    7         40h    ENTER
  143.  08h    Left      1Ch    3         30h    8         44h    .
  144.  0Ch    Right     20h    4         34h    9
  145.  10h    0         24h    5         38h    -
  146.  
  147.      Here's the calculation:
  148.  
  149. F635h < First byte of small key table
  150. + 2Ch < Offset from small table to large table mentioned earlier
  151. -----
  152. F661h < First byte of large key table
  153. + 40h < Offset for "ENTER" key
  154. -----
  155. F6A1h < First of the four large table bytes for the "ENTER" key
  156.  
  157.      Now you know how to find your way around the key tables in your Kaypro,
  158. and should understand how CONFIG changes the key table values to customize
  159. your cursor and keypad keys. Let's see how these changes are stored on the
  160. system tracks of a disk.
  161.  
  162.      The Kaypro-distributed version of WordStar 3.3 had a patch that set the
  163. cursor keys "on the fly" to the WordStar cursor commands. (^E, ^X, ^S, ^D)
  164. I wanted to program the keypad for fourteen other common WordStar commands,
  165. so I made a permanent change to the system tracks on my WordStar working
  166. disk. I used CONFIG to make the changes, but we'll use a disk editor. Usually
  167. I use SuperZap, but PATCH18 can do the same thing. (DDT can't do disk
  168. editing easily. Get one of these free programs and save yourself a lot of
  169. work.) Read the documentation for the disk editor of your choice to find out
  170. how to view and change a system track sector. (SuperZap - "Absolute Sector",
  171. PATCH18 - "Record")
  172.  
  173.      Fire up your disk editor, and look at the keytables. (For SuperZap you
  174. want absolute sectors 61 and 62, for PATCH it's track 1, physical sector 21)
  175. Here's what you'll see with SuperZap on two seperate screens: (PROBE puts
  176. both sectors on one screen)
  177.  
  178. Sector 00061 of 03200 A: Trk=001 Sct=021
  179.                   TPA Load = 0000
  180.  
  181.        0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
  182. 0000   C3 A9 F6 C3 1E F7 C3 85 F7 C3 AA F7 C3 06 F8 C3    ................
  183. 0010   1F F8 C3 1A F8 C3 15 F8 C3 64 F8 C3 68 F8 C3 6C    .........d..h..l
  184. 0020   F8 C3 70 F8 C3 74 F8 C3 78 F8 C3 82 F8 C3 3A F8    ..p..t..x.....:.
  185. 0030   C3 94 F8 81 00 0B 0A 08 0C 30 31 32 33 34 35 36    .........0123456
  186. 0040   37 38 39 2D 2C 2E 00 05 05 2C 09 0E 18 04 44 03    789-,....,....D.
  187. 0050   E1 05 E8 01 00 09 06 18 04 44 03 E1 05 E8 01 00    .........D......
  188. 0060   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  189. 0070   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  190.  
  191.  
  192. Sector 00061 of 03200 A: Trk=001 Sct=021
  193.                   TPA Load = 0000
  194.  
  195.        0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F
  196. 0000   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  197. 0010   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
  198. 0020   00 43 61 74 73 00 00 00 00 CD 60 F8 AF 32 04 00    .Cats.....'..2..
  199. 0030   3A 33 F6 32 03 00 21 4A F6 46 23 4E 23 ED B3 7E    :3.2..!J.F#N#..~
  200. 0040   B7 20 F6 3A 47 F6 D3 00 3A 48 F6 D3 08 CD BB F8    . .:G...:H......
  201. 0050   1A 0D 0A 4B 41 59 50 52 4F 20 36 33 4B 20 43 50    ...KAYPRO 63K CP
  202. 0060   2F 4D 20 56 65 72 73 69 6F 6E 20 32 2E 32 46 0D    /M Version 2.2F.
  203. 0070   0A 00 21 00 80 22 4B F9 3E C3 21 03 F6 32 00 00    ..!.."K.>.!..2..
  204.  
  205.      Looks familiar, doesn't it? The "Cats" patch to the "ENTER" key is the
  206. same as the image we saw in the BIOS.
  207.  
  208.      Since the keypad values are in RAM, a program can alter them for a
  209. particular application. For an example of this, see WSKEYPAD.ASM (for 8080)
  210. and WSKEYPAD.AZM (for Z80). These overlays patch the WordStar 4.0 .COM file
  211. to redefine the keypad when WS4 is run, and restore them to their original
  212. value when exiting WS4.
  213.  
  214.      I hope this little discussion has answered your questions on the Kaypro
  215. keypad. If you have further questions, I can be reached on CompuServe in the
  216. CP/M and Computer Club Forums at User I.D. 71370,2635.
  217.  
  218.  
  219.      NOTES ON UTILITIES - These programs can be found on most RCP/M systems
  220. and information systems with CP/M SIGs. Letters in parentheses show where
  221. they can be found on CompuServe. (C - CP/M Forum Lib 2, K - Computer Club
  222. Forum Lib 15)
  223.  
  224.      PROBE - Shows the addresses of important locations in your installation
  225. of CP/M. Look for PROBE.LBR (C) or PROB12.BIN & PROB12.DOC (K).
  226.  
  227.      SuperZap - Commercial disk editor, now freeware. Look for SPZ35.COM
  228. & SPZ25.DOC (K).
  229.  
  230.      PATCH - Versatile disk and memory editor. Look for PATC18.LBR (C) or
  231. PAT18A.BIN & PAT18A.DOC (K).
  232.  
  233.  
  234.    - Dale H. Cook
  235.      July 3, 1989
  236.