Authors
Publication
Pub Details
Date
Pages
This article shows you how you can use a full size IBM compatible keyboard with your computer and create a new channel to link it to your own Basic programs. My new cartridge version of Pro/File 2068 has the software part of this project built into the cartridge, and it can be used with any Basic program–not just with Pro/File. However, if you do not have the cartridge, or if you’d like to experiment with this on your TS1000, you can use this article to upgrade your cassette based programs to take advantage of a keyboard which is far better than the Timex keyboard.
The TS2068’s marvelous channeling feature lets you hook the IBM keyboard right into your own Basic. This means that the INPUT and INKEY$S commands can be taught to respond to the IBM keyboard instead of the 2068 keys. Unfortunately, the TS1000 is not this flexible, however the principals for reading the keyboard are the same for both computers. I’ll leave further experimenting with the TS1000 to you.
This project is fairly simple to build. All that’s required besides a standard replacement keyboard for the IBM PC (such as the Keytronics Model 5151) is one of my Experimenter’s I/O ports and a few miscellaneous electronic components.
If you use a program which requires a lot of input from the keyboard, you’ll be amazed by the improvement this project offers. The hardware shown here can be used with the TS1000/1500 too.
General Principals: What IS the IBM Keyboard?
Besides being a sturdy keyboard with a good feel to it, the IBM type keyboard is termed an “intelligent” keyboard because it has built-in circuitry which automatically scans the keys to see which one you press. When it finds you pressing a key, a serial steam of pulses is sent out through its data line (pin 2 of its 5 pin DIN connector) which represents a “scan code” for the key you press. This stream of electrical pulses is very similar to the stream of dits and dahs which represent a letter in Morse Code. Each key has its own unique scan code. It is the job of the interface hardware and software to intercept the pulse stream and translate it into a character which. can. be understood by the computer.
A clock line comes out through pin 1 of the keyboard connector. This line also sends a serial stream of pulses at a fixed rate much like the ticks of a clock… only faster. The clock line makes it possible to “synchronize” the reading. of the data line. It only ticks when data is being sent through pin 2. Each scan code consists of 8 serial pulses (or bits). Therefore, the clock ticks 8 times for each keypress.
Another characteristic of the IBM type keyboard is that each key actually produces two different scan codes depending on whether you press down on a key (commonly called the DOWN CODE) or release a key (called the UP CODE). The only difference between any given DOWN or UP code is that the 8th bit of the stream of pulses will always be low for a DOWN CODE and will always be high for an UP CODE.
This means that when the serial stream is converted to an 8 bit number, the UP CODE for a specific key will always be 128 (that’s 80 hex) more than the corresponding DOWN CODE. Because of this, it is very easy for the software to tell if you are pressing down on a key or if you have released it (pressing up?). If the scan code is less than 128, your finger is on a key. If it is greater than 128 you have released it.
The last important feature of the keyboard is that it will automatically send repetitive scan codes if you press a key and hold it down. While this bit of “intelligence” may work just find on an IBM computer, it turns out to be a major headache for the Timex, but the keyboard software gets around this problem and still manages to provide for auto repeating keys.
Interface Hardware Requirements
In order for the computer to make sense out of the serial stream of keyboard data, some means of converting it into a parallel byte is necessary. The electronic circuitry shown here does this. The schematic shows the keyboard data and clock lines on pins 2 and 1 of the DIN connector respectively. The serial data stream is fed to pin 2 of the 7164 serial to parallel converter chip. The clock is inverted (highs become lows and lows become highs) by the 7404 and then is sent to the clock input pin (pin 8) of the 74164. These two lines are all that is necessary for the 74164 to convert the stream into 8 parallel bits. These outputs (D7 through D0) must then be connected to their respective places on the IN/OUT board’s input lines.
The power supply lines (+5v and GND) necessary to run both the converter and the keyboard can be taken directly from the I/O Port.
Wiring this circuit is easy. There’s nothing critical about the way lines are laid out. Just make sure all the connections go to the right places.
Whenever I build circuits like this, I like to do them on solderless breadboards which are available at Radio Shack. Once I have everything working properly, I take it apart and rebuild it on perfboard with soldered connections.
Once you get your circuit built, connect it to your computer and test it out. Enter the test listing (Basic line 10 which immediately follows the keyboard table) on the next page.
Address Value
64770 205
64771 30
64772 253
64773 121
64774 12
64775 32
64776 2
64777 207
64778 12
64779 167
64780 202
64781 14
64782 12
64783 33
64784 59
64785 92
64786 203
64787 238
64788 50
64789 8
64790 92
64791 55
64792 195
64793 14
64794 12
64795 209
64796 16
64797 253
64798 1
64799 223
64800 80
64801 96
64802 175
64803 237
64804 120
64805 245
64806 16
64807 250
64808 68
64809 209
64810 186
64811 32
64812 239
64813 16
64814 250
64815 79
64816 33
64817 194
64818 253
64819 254
64820 170
64821 40
64822 15
64823 254
64824 182
64825 40
64826 11
64827 254
64828 184
64829 40
64830 20
64831 190
64832 32
64833 26
64834 1
64835 0
64836 0
64837 201
64838 175
64839 119
64840 33
64841 195
64842 253
64843 203
64844 86
64845 32
64846 243
64847 203
64848 142
64849 24
64850 239
64851 175
64852 119
64853 33
64854 195
64855 253
64856 203
64857 134
64858 24
64859 230
64860 119
64861 203
64862 127
64863 32
64864 225
64865 33
64866 195
64867 253
64868 254
64869 70
64870 40
64871 87
64872 254
64873 42
64874 40
64875 50
64876 254
64877 54
64878 40
64879 46
64880 254
64881 58
64882 40
64883 63
64884 254
64885 59
64886 40
64887 46
64888 254
64889 56
64890 40
64891 38
64892 126
64893 203
64894 71
64895 32
64896 24
64897 33
64898 197
64899 253
64900 203
64901 79
64902 40
64903 5
64904 197
64905 14
64906 84
64907 9
64908 193
64909 9
64910 126
64911 50
64912 196
64913 253
64914 78
64915 6
64916 0
64917 58
64918 194
64919 253
64920 201
64921 33
64922 120
64923 254
64924 24
64925 230
64926 203
64927 206
64928 24
64929 160
64930 203
64931 198
64932 24
64933 156
64934 175
64935 50
64936 194
64937 253
64938 58
64939 196
64940 253
64941 6
64942 0
64943 16
64944 254
64945 79
64946 201
64947 203
64948 86
64949 32
64950 4
64951 203
64952 214
64953 24
64954 227
64955 203
64956 150
64957 24
64958 144
64959 14
64960 255
64961 201
64962 0
64963 0
64964 0
64965 0
64966 199
64967 49
64968 50
64969 51
64970 52
64971 53
64972 54
64973 55
64974 56
64975 57
64976 48
64977 45
64978 61
64979 12
64980 9
64981 113
64982 119
64983 101
64984 114
64985 116
64986 121
64987 117
64988 105
64989 111
64990 112
64991 91
64992 93
64993 13
64994 94
64995 97
64996 115
64997 100
64998 102
64999 103
65000 104
65001 106
65002 107
65003 108
65004 59
65005 39
65006 39
65007 0
65008 92
65009 122
65010 120
65011 99
65012 118
65013 98
65014 110
65015 109
65016 44
65017 46
65018 47
65019 0
65020 203
65021 0
65022 32
65023 0
65024 0
65025 205
65026 226
65027 7
65028 4
65029 8
65030 10
65031 11
65032 9
65033 15
65034 0
65035 0
65036 55
65037 56
65038 57
65039 45
65040 52
65041 53
65042 54
65043 43
65044 49
65045 50
65046 51
65047 48
65048 46
65049 0
65050 199
65051 33
65052 64
65053 35
65054 36
65055 37
65056 94
65057 38
65058 42
65059 40
65060 41
65061 95
65062 43
65063 12
65064 9
65065 81
65066 87
65067 69
65068 82
65069 84
65070 89
65071 85
65072 73
65073 79
65074 80
65075 123
65076 125
65077 13
65078 94
65079 65
65080 83
65081 68
65082 70
65083 71
65084 72
65085 74
65086 75
65087 76
65088 58
65089 34
65090 39
65091 0
65092 92
65093 90
65094 88
65095 67
65096 86
65097 66
65098 78
65099 77
65100 60
65101 62
65102 63
65103 0
65104 203
65105 0
65106 32
65107 0
65108 0
65109 205
65110 226
65111 7
65112 4
65113 8
65114 10
65115 11
65116 9
65117 15
65118 0
65119 0
65120 55
65121 56
65122 57
65123 45
65124 52
65125 53
65126 54
65127 43
65128 49
65129 50
65130 51
65131 48
65132 46
65133 198
65134 11
65135 197
65136 45
65137 8
65138 0
65139 9
65140 43
65141 195
65142 10
65143 195
10 PRINT AT 1,0; IN 223;" ";GO TO 10: REM Note 3 spaces between the quotes
Press different keys on the IBM keyboard. Line 10 will continuously read the keyboard port and print the keyboard scan code. Notice that each key produces its own unique pair of UP codes and DOWN codes, and that the UP code will equal the DOWN code plus 128.
Keyboard Software
To use the IBM keyboard with your 2068, poke the values shown in table 1 into addresses 64770 through 65143. Use your favorite loader program to do this or enter and run the simple loader shown below:
10 CLEAR 64769
20 FOR X=64770 TO 65143
30 INPUT "VALUE FOR ";(X);"?";Y
40 POKE X,Y: PRINT X5"=";Y
50 NEXT X
After all the bytes have been poked, save it off to tape with the command,
SAVE "IBM"CODE 64770,375
Now, any time you want to use the software, load it into your computer by using the command,
LOAD "IBM"CODE
Then add these lines to the basic program you wish to use the IBM keyboard with:
1 REM xxxxK
2 POKE 26715,0: POKE 26716,5: POKE 24717,2: POKE 26718,253: POKE 23582,28
Line 1 is the “channel table”. It is vitally important that it be the first line of your basic program. This software also assumes that your program starts at the normal starting address of 26710 decimal. Line 2, pokes the “x’s” in line 1 with the values necessary so the computer will know how to find the keyboard software. The first two pokes are the address of the channel OUTPUT routine. The second two pokes are the address of the channel INPUT routine–the address of our keyboard software. The last poke which goes to the streams table gives the distance from the new keyboard channel table to the start of normal channel table. You can change line 2’s line number if necessary, but the line MUST be executed BEFORE you try to read the IBM keyboard.
And how do you read the keyboard? Well, the keyboard can be read by any Basic Input or Inkey$ command which specifies channel #4. For example:
INPUT #4;"MAKE YOUR SELECTION";A$
LET YS$=INKEYS#4
INPUT "HOW MUCH"s#4;X
Therefore, what you must do is go through your basic listing and change every occurance of INPUT and INKEY$ to INPUT #4 and INKEYS#4.
The IBM keyboard will function only when the program is being run. When you stop to edit program lines you must use the 2068 keyboard.
The INPUT #4 command accepts keypresses from both the IBM and the 2068 keyboards. The INKEYS#4 command is different in that it reads only the IBM keyboard. If you want to make it possible to read BOTH keyboards using INKEY$, enter a program line something like this:
LET K$=INKEYS+INKEY$#4:IF LEN K$>1 THEN LET KS$=KS(1)
This line will read both the 2068 keyboard and the IBM keyboard into k$. If no keys are pressed, or if just one keyboard or the other is being used, KS$ will be empty or will equal the character being pressed. If you press keys on both keyboards simultaneously, KS will assume the value of the 2068 keyboard only.
Features of the Keyboard Software
All standard ASCII characters (letters, numbers, and punctuation marks) work according to the symbol printed on the key. There are 10 special function keys which I have pre-defined. Because this software was written primarily for use with Pro/File 2068, these function keys are set to perform various functions within that program.
- F1-Auto Repeat. Hold this key down to repeat the last keypress.
- F2-STEP Token (Step to next file in Pro/File)
- F3-STOP token (Close file in Pro/File)
- F4-CHR$ 7 (INSERT/OVER switch in Pro/File)
- F5-CHR$ 4 (Line Delete in Pro/File)
- F6-Cursor LEFT
- F7-Cursor DOWN
- F8-Cursor UP
- F9-Cursor RIGHT
- F10-CHR$ 15 (More Commands in ADD/EDIT mode)
The shift and caps lock keys work as you would expect. Holding shift and some other key will produce upper case. The caps lock key is an upper/lower case switch. Press it once to make all keypresses upper case. Press it again to make all keypresses lower case.
Defining Alternate Keys on the IBM
The ALT key is an ALTernate shift key, however its function is not to produce upper case characters. ALT can be pressed along with some other key to produce your own custom defined character. At the start, pressing ALT and some other key will have no effect because you haven’t defined any keys yet. Here’s how to do it.
The table below shows memory addresses which store the key code to be used when you press ALT with some other key. If you poke a key address with the code for the character you wish the key to represent, you can obtain that character when you simultaneously press ALT and the desired key.
Address IBM Key
65145 ESC
65146 1
65147 2
65148 3
65149 4
65150 5
65151 6
65152 7
65153 8
65154 9
65155 0
65156 -
65157 =
65158 Back Sp
65159 TAB
65160 q
65161 w
65162 e
65163 r
65164 t
65165 y
65166 u
65167 i
65168 o
65169 p
65170 [
65171 ]
65172 RETURN
65173 CTRL
65174 a
65175 s
65176 d
65177 f
65178 g
65179 h
65180 j
65181 k
65182 l
65183 ;
65184 '
65185 `
65186 not used
65187 \
65188 z
65189 x
65190 c
65191 v
65192 b
65193 n
65194 m
65195 ,
65196 .
65197 /
65198 not used
65199 Pr Scr
65200 not used
65201 Space
65202 not used
65203 not used
65204 F2
65205 F3
65206 F4
65207 F5
65208 F6
65209 F7
65210 F8
65211 F9
65212 F10
65213 NUM LOCK
65214 not used
65215 HOME
65216 Cur UP
65217 Pg up
65218 -
65219 Cur LEFT
65220 Alt 5
65221 Cur RIGHT
65222 +
65223 End
65224 Cur DOWN
65225 Pg DOWN
65226 Ins
65227 Del
The addresses on the next page give keys in UPPER CASE mode. Access them by pressing SHIFT and ALT simultaneously with one of the other keys.
Address IBM Key
65229 ESC
65230 !
65231 @
65232 #
65233 $
65234 %
65235 ^
65236 &
65237 *
65238 (
65239 )
65240 _
65241 +
65242 Back Sp
65243 TAB
65244 Q
65245 W
65246 E
65247 R
65248 T
65249 Y
65250 U
65251 I
65252 O
65253 P
65254 {
65255 }
65256 RETURN
65257 CTRL
65258 A
65259 S
65260 D
65261 F
65262 G
65263 H
65264 J
65265 K
65266 L
65267 :
65268 "
65269 ~
65270 not used
65271 ;
65272 Z
65573 X
65274 C
65275 V
65276 B
65277 N
65278 M
65279 <
65280 >
65281 ?
65282 not used
65283 PR SCR
65284 not used
65285 SPACE
65286 not used
65287 not used
65288 F2
65289 F3
65290 F4
65291 F5
65292 F6
65293 F7
65294 F9
65295 F9
65296 F10
65297 NUM LOK
65298 not used
65299 HOME
65300 CUR UP
65301 PAGE UP
65302 -
65303 CUR LEFT
65304 5
65305 CUR RIGHT
65306 +
65307 END
65308 CUR DOWN
65309 PG DOWN
65300 INSERT
65310 DELETE
Here is an example of how you might define a key. Say you want to make it possible to produce the AND token whenever you press ALT and F10 together. What you must do is determine the code for the AND token. You’ll find the code listed on page 244 of the 2068 owner’s manual. The table printed there shows that the number 198 is the code for AND. Now refer to the table above and change the address representing F10 so that it stores the value 198. Enter the command:
POKE 65212,198
to change the value representing the F10 key. Now, any time you press F10 and ALT together, you will get the token AND. This works as long as you are in lower case. If you want F10 to respond the same way in upper case as well, you must also POKE 65296 with a 198.
Keyboard Routine Disassembly
FD02 CD1EFD KEY? CALL IBM$
FD05 79 LD A,C
FD06 0C INC C
FD07 2002 JR NZ,FD0Bh
FD09 CF RST 08h
FD0A 0C INC C
FD0B A7 AND A
FD0C CA0E0C JP Z,0C0Eh
FD0F 213B5C LD HL,5C3Bh
FD12 CBEE SET 5,(HL)
FD14 32085C LD (5C08h),A
FD17 37 SCF
FD18 C30E0C JP 0C0Eh
FD1B D1 STAK POP DE
FD1C 10FD CLER DJNZ STAK
FD1E 01DF50 IBM$ LD BC,50DFh
FD21 60 LD H,B
FD22 AF SAMP XOR A
FD23 ED78 IN A,(C)
FD25 F5 PUSH AF
FD26 10FA DJNZ SAMP
FD28 44 LD B,H
FD29 D1 POP DE
FD2A BA CP D
FD2B 20EF JR NZ,CLER
FD2D 10FA DJNZ FD29h
FD2F 4F LD C,A
FD30 21C2FD LD HL,LSCN
FD33 FEAA CP AAh
FD35 280F JR Z,UNSH
FD37 FEB6 CP B6h
FD39 280B JR Z,UNSH
FD3B FEB8 CP B8h
FD3D 2814 JR Z,UNAL
FD3F BE CP (HL)
FD40 201A JR NZ,CHAR
FD42 010000 QUIT LD BC,0000h
FD45 C9 RET
FD46 AF UNSH XOR A
FD47 77 LD (HL),A
FD48 21C3FD LD HL,KFLG
FD4B CB56 BIT 2,(HL)
FD4D 20F3 JR NZ,QUIT
FD4F CB8E RES 1,(HL)
FD51 18EF JR QUIT
FD53 AF UNAL XOR A
FD54 77 LD (HL),A
FD55 21C3FD LD HL,KFLG
FD58 CB86 RES 0,(HL)
FD5A 18E6 JR QUIT
FD5C 77 CHAR LD (HL),A
FD5D CB7F BIT 7,A
FD5F 20E1 JR NZ,QUIT
FD61 21C3FD LD HL,KFLG
FD64 FE46 CP 46h
FD66 2857 JR Z,BRAK
FD68 FE2A CP 2Ah
FD6A 2832 JR Z,SHFT
FD6C FE36 CP 36h
FD6E 282E JR Z,SHFT
FD70 FE3A CP 3Ah
FD72 283F JR Z,CAPS
FD74 FE3B CP 3Bh
FD76 282E JR Z,REPE
FD78 FE38 CP 38h
FD7A 2826 JR Z,ALT_
FD7C 7E DCOD LD A,(HL)
FD7D CB47 BIT 0,A
FD7F 2018 JR NZ,SPEC
FD81 21C5FD LD HL,TBL0
FD84 CB4F BIT 1,A
FD86 2805 JR Z,LOWR
FD88 C5 UPPR PUSH BC
FD89 0E54 LD C,54h
FD8B 09 ADD HL,BC
FD8C C1 POP BC
FD8D 09 LOWR ADD HL,BC
FD8E 7E LD A,(HL)
FD8F 32C4FD LD (LASK),A
FD92 4E LD C,(HL)
FD93 0600 LD B,00h
FD95 3AC2FD LD A,(LSCN)
FD98 C9 RET
FD99 2178FE SPEC LD HL,TBL1
FD9C 18E6 JR FD84h
FD9E CBCE SHFT SET 1,(HL)
FDA0 18A0 JR QUIT
FDA2 CBC6 ALT_ SET 0,(HL)
FDA4 189C JR QUIT
FDA6 AF REPE XOR A
FDA7 32C2FD LD (LSCN),A
FDAA 3AC4FD LD A,(LASK)
FDAD 0600 LD B,00h
FDAF 10FE DJNZ FDAFh
FDB1 4F LD C,A
FDB2 C9 RET
FDB3 CB56 CAPS BIT 2,(HL)
FDB5 2004 JR NZ,FDBBh
FDB7 CBD6 SET 2,(HL)
FDB9 18E3 JR SHFT
FDBB CB96 RES 2,(HL)
FDBD 1890 JR FD4Fh
FDBF 0EFF BRAK LD C,FFh
FDC1 C9 RET
FDC2 00 LSCN NOP
FDC3 00 KFLG NOP
FDC4 00 LASK NOP
FDC5 00 TBL0 NOP