01.03.2014 Views

Section 2 - Commodore Computers

Section 2 - Commodore Computers

Section 2 - Commodore Computers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

May, May. 1982. Issue 24 2A<br />

COMPUTE!<br />

COMPUTEI 163<br />

The reason that only the values from 0 to 127<br />

are acceptable is that a byte with its most significant<br />

bit (MSB, (MSB: $80$ 0 or 128) turned on is our signal that<br />

this byte is IS to be the last character in the soft key<br />

string. Obviously, ObvIOusly, you can rewrite this part, if you<br />

desire, so that some other means is used to designate<br />

the end of string stnng (a preceding length byte or trailing<br />

zero byte are obvious alternatives). However, the<br />

method chosen is simple and seems adequate for<br />

most purposes. pu For the BASIC user, the soft<br />

keys can be made truly 'soft'...<br />

For the BASIC user, the soft<br />

keys can be made truly 'soft'...<br />

One more note before we get into implementation<br />

details: since there are times when you u might<br />

really<br />

y want the graphics character "hidden" by a<br />

soft key, I have designed an "escape" sequence.<br />

Pressi ng "control-comma" (normally the graphics<br />

Pressing "control-comma" (normally the graphics<br />

heart character) signals to the soft key routine that<br />

the next character is not /101 to be translated. Thus,<br />

even the heart may be generated by pressing<br />

even the heart may be generated by pressing<br />

control-comma twice.<br />

The NIHy·GrIHy<br />

Nitty-Gritty<br />

Program I shows the complete source of Easykey,<br />

Program 1 shows the complete source of Easykey,<br />

the program which implements all the features<br />

mentioned above. The program is composed of<br />

five primary parts.<br />

mentioned above. The program is composed of<br />

five primary parts.<br />

The first part, with line numbers in the 2000-<br />

2999 range, is used to hook the routine into Atari's<br />

OS. First, rirst, we search the Handler Table looking for<br />

the E: device. When we find it, we hold onto its<br />

address and put the address of our replacement<br />

driver in the table instead. Recall that the address<br />

in HATABS H must be the address of the Handler<br />

Routine Table. We copy the current table (presum<br />

Routine Table. We copy the current table (presumably<br />

the Atari default table, from ROM) to our<br />

ably the Atari default table, from ROM) to our<br />

NEWETBL (new E. table) and replace the entry<br />

point for the get-a-single-character routine with<br />

poi nt for the get-a-single-character routine with<br />

the address of our new routine (NEWEGETCH)<br />

less one (always required, see commentary on the<br />

M: driver in my January column). We then change<br />

LOM EM so BASIC won 't wipe us out and exit.<br />

LOMEM so BASIC wont wipe us out and exit.<br />

The second part of this process is the new geta-single-character<br />

routine for the screen editor (E:)<br />

device. Most of this code is copied directly from the<br />

OS ROMs, the only exceptions being the branches<br />

to locations in RON! and the call to the<br />

get-<br />

keyboard<br />

to locations in ROM and the call to the keyboard<br />

get-a-character routine (KGETCH).<br />

The third part, NEWKGETCH (NEW Keyboard<br />

GET single CHaracter routine), is the heart<br />

of this whole process. Here is where individual<br />

keystrokes are actually interpreted from their<br />

hardware codes and characteristics charaCleristics to a more palatable<br />

ATASCIIA TASCll code. But here, also, is where the<br />

system is vulnerable to our machinations. Since<br />

nothing "downstream" of the keyboard handler<br />

(e.g., the rest of the E: driver, CIO, BASIC, etc.)<br />

knows what happened at the physical keyboard<br />

level, the calling routines will believe the keyboard<br />

handler no matter what it tells them. thcm.<br />

Actually, NEWKGETCH t is fairly simple. First<br />

it checks to see if it is already processing a soft key.<br />

If I f so, it simply hands the caller the next key of the<br />

soft key's string. IfI f not, it goes and gets a real key<br />

from the keyboard. If that key is a heart, it simply<br />

gets the next real keyboard key and passes that<br />

back to the caller (our "escape" clause). Otherwise,<br />

if the keyboard key was not control-A through<br />

Control-Z, then the key is returned to the caller<br />

unchanged.<br />

If the keyboard key was one of the definable<br />

soft keys, its value is used to index into a table of<br />

soft key string pointers. Here one last validity<br />

check is made: if the string pointer is zero, the<br />

keyboard key is returned to the thc caller and no soft<br />

key string handling occurs. IfI I' a string pointer is<br />

encountered, its address is placed in KPTR and<br />

used to access all the characters in the string.<br />

Note that zero bytes are translated to $9B (CR)<br />

characters and that any character with its most<br />

significant bit on terminates the string (by zeroing<br />

the high order byte of KPTR).<br />

The fourth part of this routine is simply the<br />

above-mentioned table of soft key string pointers.<br />

Note that we take advantage of the fact that the<br />

assembler places zeroes into .WORDs (or .BYTEs)<br />

which are undefined.<br />

The last part, of course, consists of the actual<br />

strings. Note the flexibility here. Control-D (label<br />

SO), SD), for example, includes the modified CR character<br />

($00) as also its last character by simply turning<br />

onn the MSBit, producing a code of $80.<br />

Soft Keys: Using Them From BASIC<br />

Soft Keys: Using Them From BASIC<br />

To conserve space and to show the flexibility of the<br />

soft key system, I included strings for onlyy three<br />

keys: control-D, which causes a disk directory<br />

listing, control-S for "SETCOLOR," and control-P<br />

for "PRI NT#." The simplest way to add more soft<br />

for "PRI NT#." The simplest way to add more soft<br />

key strings is to plllthem put into the source givenn<br />

(with labels "SA" through "SZ," as appropriate)<br />

and assemble the whole thing at an address<br />

appropriate for your system.<br />

But youu can add or change soft key strings

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!