01.03.2014 Views

Section 2 - Commodore Computers

Section 2 - Commodore Computers

Section 2 - Commodore Computers

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

"6 1-18 COMPUTEI May. May, 1982. Issue 24<br />

to NEWSTT.<br />

What Happens When Applesoft Applesott Runs Into An &<br />

The & symbol is tokenized in the same way thai that<br />

BASICC commands are tokenized, so, even though<br />

& IS is not a proper BASIC "command" (see the<br />

Applesoft AIJ/Jlesofl ReferenceR Manual), the interpreter will<br />

treat it as if it were one. T he & address in the toke n<br />

treat it as if it were one. The & address in the token<br />

lookup table is $03F5 (less {less I). That is, the CHRGET<br />

routine jumped to by the interpreterr will return to<br />

location $3F5 whenn it has fetched the next characterr<br />

following the 8c. At S3F5, there are three free<br />

followi ng the &. At $3F5 , there a re three free<br />

locations, which typically contain an instruction to<br />

jump to some other address, say $0300, where the<br />

actual &- ^--interpreter begins. The &- it-interpreter interpreter will<br />

then typically examinee the contents of the accumu­<br />

lator, which holds the latest character fetched by<br />

C HRGET. and will o pe rate on these in much the<br />

CHRGET, and will operate on these in much the<br />

same mannerr as the Applesoft interpreterr did for<br />

the character it got from CHRGET. H There are<br />

various ways to accomplish this, but the effect will<br />

be to eventually find yet another address (the start<br />

of the command flagged by the &:) &) aand to force a<br />

J M MI* P to that address. The return at the eend off the<br />

subroutine jumped to will be a return back to the<br />

Applesoft IInterpreter and, thence, to NEWSTT,<br />

as described above.<br />

How To Get Rid Of The & in ROM Applesott<br />

How To Get Rid Of The A in ROM Applesoft<br />

QOur UI' goal is to write a command mand token interpreter<br />

which will handle modified Applesoft commands.<br />

We are not worried about things flagged by the 8c<br />

We are not wo rried about things fl agged by the &<br />

which would not otherwise be treated as commands.<br />

We could extend the routine below so that it would<br />

handle these, but, givenn the implementation, (i.e.<br />

as a patch to CHRGET, H which is veryy frequently<br />

called), this would noticeably slow down Applesoft,<br />

called), this would noticeably slow down Applesoft,<br />

so we do not recommend il. it. Further, Funher, we could<br />

extend the interpreter so that it would handle<br />

tokens<br />

which are not commands, allowing modification<br />

of functions.<br />

Again, , we do not recommend<br />

this. Applesoft provides a USR R function with the<br />

explicit intention of allowingg user defined functions.<br />

Our experience ence with functions is that they<br />

are not really y modified at all. Rather, they are<br />

replaced by something quite different, which the<br />

user considers better.<br />

user considers better.<br />

I Inn this case, we feel l thatt the appropriate vehicle<br />

for re place ment is the one d elibe rately built into<br />

for replacement is the one deliberately built into<br />

Applesoft, i.e. USR. An &-based alternative, or an<br />

alternative using this routine, would be inappropriate<br />

as we ll as quite clumsy. Given these limited<br />

riate as well as quite clumsy. Given these limited<br />

objectives, along with a desire (if onlyy to ease our<br />

memory burden) to mimic the Applesoft token<br />

interpretation approach, the modification to ROM<br />

Applesoft in order to allow compatibility witli<br />

flag modified commands is surprisingly straight<br />

memory burden) to mimic the Applesoft token<br />

interpretation approach, the modification to ROM<br />

Applesoft in order to all ow com patability with<br />

RAM Applesoft without requiring ampersands to<br />

flag modified commands is surprisingly straightforward.<br />

Nearl y a ll of ROM Applesoft resides in ROM<br />

Nearly all of ROM Applesoft resides in ROM<br />

and so cannot cannOt be changed. One important rOll routine,<br />

CHRGET, does not reside in ROM. GHRGET is<br />

C H RGET, does not reside in ROM. C HRGET is<br />

loaded into memory whenever A pplesoft is initial­<br />

loaded into memory whenever Applesoft is initial<br />

Ized ized (e.g. by the FP command if youu have a disk).<br />

T his is exactl y the routine ca ll ed by the Applesoft<br />

This is exactly the routine called by the Applesoft<br />

interpreter whenever it wants a new command. We<br />

modify CHRGET so that it jumps to a routine we<br />

call NEWGET, located at $300, which will replace<br />

CHRGET. Along with doing everything CHRGET<br />

used to do, , this routine checks whether the characte<br />

r it fetches is a token in a li st of modified command<br />

ter it fetches is a token in a list of modified command<br />

tokens. If so, it executes that command before<br />

returning to the Applesoft interpeter.<br />

All properly wrillen written Applesoft commands and ·<br />

programs will<br />

leave the TeXT PoinTeR (TXTPTR)<br />

pointing to an eend of ol line following ow g the command,<br />

once the command has been executed. User wriuen<br />

written<br />

commands must conform to this as well. If they d o,<br />

commands must conform to this as well. If they do,<br />

then, when NEWGET finally y returns control to<br />

BASIC, it will pass th e Applesoft interpreter an<br />

BASIC, it will pass the Applesoft interpreter an<br />

"end of line." This forces, as we have seen above, a<br />

branch to NEWSTT, which isjust what we want in<br />

order to avoid confusion in Applesoft over what<br />

order to avoid confusion in Applesoft ove r what<br />

should be executed next.<br />

Further Notes<br />

Here are a few further notes on tl,e the ROM Applesoft<br />

LOke tokenn interpreter In subroutine listed at the end off<br />

thiss article, which may not otherwise be clear From from<br />

the discllssion discussion above.<br />

1. I. The CHRGET routine conceptuallyy divides into<br />

two subsections. The first increments TXTPTR, to<br />

point to the next character. r. The next section is<br />

often called CHRGOT, aand this is the routine<br />

which actuallyy fetches the contents off the locationn<br />

pointed to by TXTPTRR ancl and sets up various internal<br />

flags. By 10adingJMP loading $300 into the first three<br />

bytes o f CHRGET, we effectively destroy the 6-byte<br />

bytes of CHRGET, we effectively destroy the 6-byte<br />

segment of codee which increments nts TXTPTR, and<br />

thus have to repeat this as the first 6 bytes of<br />

NEWGET. In the process, we free the three page 0<br />

NEWGET. In the process, we free the three page 0<br />

locations, $ $B4, $B5, $ $B6, which follow the e J JMPM P<br />

$300. These are used as temporary locations by<br />

NEWGET. The CHRGOT C routine e is completelyy<br />

unaffected by the jump, so we can still use it to<br />

unaffected by the j ump, so we can still use it to<br />

actually fetch the characterr and to set the appropriate<br />

flags (eg. Zero).<br />

2. C H RGET has no effect o n registe rs X a nd Y.<br />

2. CHRGET has no effect on registers X and Y.<br />

We will use both in searching the token table. If we<br />

do not return the original values off X and Y when<br />

we return from frotn NEWGET, WGE1 ~ ,<br />

we will induce errors rs in<br />

the many roUlines routines which call CHRGET and which<br />

assume that this call will not affect tl,ese these registers. rs.<br />

3. Variable FLAG checks whetherr or not a command<br />

is currently being executed. If FLAG is 0, we

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

Saved successfully!

Ooh no, something went wrong!