You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
154 COMPUTE! May. 1Q82.lssue 1982. Issue24<br />
24<br />
1000 :<br />
1500 RETURN<br />
And RUN it. Well, it doesn't do anything. AS A$ is a<br />
useless string, a long chain of blanks, nOt not exactlyy<br />
our intention. ntion.<br />
(3) Let's position the cursor over the string.<br />
Move It it back lO to ':0" "0" oon n "ONE" by inserting three<br />
left cursors wlthlll within the quotes after "E". RUN it.<br />
There is hope, but note the unacceptable length of<br />
the string.<br />
. (4) "Ve We cann limit it PET's wish for characters by<br />
pnntlllg printing a comma ma after the "ONE". But that's the<br />
last thing I need in my neat display. Let's convince<br />
the PET, instead, that its screen width is not 40<br />
characters (or 80 in 80xx), but onlyy three. Butterfield's<br />
memory map indicates that information is<br />
held in 213. I don't know what it is in Original<br />
PETs, those maps were never printed in COMPUTE!.<br />
(Perhaps an equivalent of 213 does not exist. I If I'<br />
Butter-<br />
anyone would like to contribute an accurate crossreference<br />
type map for all these systems, please<br />
send one in).<br />
Type two lines:<br />
1020 POKE213,3 (0 to squeeze the screen width<br />
1080 POKE213,39 (0 to restore it back.<br />
(PET counts from zero)<br />
This works. Incidentally, line e 1080 may not be<br />
cross-<br />
needed, but out of overabundance of caution<br />
I'll<br />
keep it. PET's self preservation instinct seems lO to<br />
restore reSlOre 213 for subsequent screen work. Query<br />
whether 80-column window facility might be useful.<br />
(5) We're not out of the woods yet. What will<br />
happen if "ONE" were followed by a string of<br />
blanks, a typical sight in a left adjusted alphabetic<br />
information? rmation' Modify two twO lines to lo be:<br />
100 ?LEFT$("ONE" + +" "10 I 0 sp'\10) sp", I + +" "10 t 0 left";:<br />
GOSUB1000<br />
GOSUBIOOO<br />
1020 POKE213.10<br />
POKE213,10<br />
RUN it. Trailing g blanks are handled correctly.<br />
y.<br />
(6) What at about leading blanks you might see<br />
in a right-justified number? number' Change one line:<br />
100 ?RIGHT$("IO sp"+"472", IO)+ "lO left";!<br />
100 ?RIGHT$("10 sp" + "472",10> + "10 left";:<br />
GOSUBI000<br />
GOSUBIOOO<br />
and RUN it. Oops! The value is intact, but PET<br />
and RUN it. Oops! The va lu e is il~tact, but PET<br />
stripped the leading spaces, spaces. as it always does,in<br />
INPUT. I This T result may be satisfactory tisfaclOry for many<br />
applications, lOa sloppy for others. Let's handle it.<br />
applications, loo sloppy for others. Let's handle it.<br />
(7) One fix x might involve printing a phony<br />
character r in the e first position. But BUllhen, then, if we wanted<br />
to use the value in a numeric variable, able, we'd have to LO<br />
strip the character. Instead, we'll use a harmless<br />
strip the character. Instead. we'll use a harmless<br />
quote by typing 100 PRINT CHR$(34) + RIGHT$<br />
GHTS<br />
... etc. and in crease the screen width lo I I in line<br />
... etc. and increase the screen width to 11 in line<br />
1020. Unfortunately y this places a character on the<br />
screen. Unavoidable. RUN it. Not bad. . The T leading<br />
blanks are there, the value is all right, but the origi<br />
blanks are there, the value is all right, but the original<br />
string is useless with the in-quote cursors.<br />
In fa ct, any formatting command o n the same<br />
lin e, i. e. prio r lo goin g into 1000, wi ll print this<br />
nal string is useless with the in-quote cursors.<br />
In fact, any formatting command on the same<br />
line, i.e. prior to going into 1000, will print this<br />
way. TAB(x) will yield x right cursors. That's the<br />
way. TAB(x) will yield x right cursors. That's the<br />
way PET is built. We could POKEE 205 lo to disable<br />
the quote mode, but that gets messy in some applicall<br />
cations. We could close the quote, but that increases<br />
the space penalty on the line by another character.<br />
A less limiting way is needed.<br />
(8) Remember that all we reallyy wa want is lo to<br />
move the cursorr left. PET docsn't doesn't care how. TThe<br />
~n memory elllo r.y map ind~ indicates G~tes the current cursor positionn<br />
IS is heldm in 198 (Original n gln 226?). 22(5?). To move the cursor<br />
into the first position we'll put a zero there. I Inn line<br />
100 delete 10 left cursors and its surrounding unding<br />
quotes. Type 1005 POKE 198,0 lo to put cursor in the<br />
first posltlon, position, and 1040 POKE 198,1111 sothata<br />
a<br />
subsequent field prints in a correct position. RUN<br />
It. it. It reallyy works now. We can handle leading g and<br />
trailIn trailing g blanks and anything in between. Right)<br />
Right?<br />
(9) I Not Ot qU quite. Ite: How about a null string? I Itt cann<br />
happen. If a condition is true you might be printing<br />
h ~,~ ,~~n. I f a con~ llI on is true you might be printing<br />
a "*", '.: II if false you'lI you'll pnnt print nothlllg nothing and use TAB lo to<br />
position to the next item, or skip line if it is at the<br />
end. Our 1000 subroutine can't predict the future,<br />
and will allemptlO attempt to process a null string with all its<br />
IIlherent inherent troubles. Let's see what happens. Type<br />
WO 100 PRINl PRINT "" ;:GOS~ ;:GOSUB1000andB don't type, type/but<br />
Imagllle, imagine, 11100 PRINT INl TAB(!O)"whatever". TAB(!0)"whatever". RUN it.<br />
Very nasty. There is actually more wrong than the<br />
eye can see. If I fthe PET is alive you u have just learned,<br />
lor ror instance, IIl stancc, (he the easiest way of causing g active files<br />
to vanish into thin air (look at the table in $0251-<br />
026E 026F on the Upgrade and 4.0 systems). Tragic<br />
results, to lo say the least.<br />
(10) ( A quote may help. TypeT 100 PRINT<br />
CHR$(34) + "M;:GOSUB "";:GOSUB 1000. Once O again, this I.his<br />
gives a correct result, ult. but subsequent TAB or<br />
cursor characters will cause trouble. This was not Il ot<br />
very important illl porlant with numbers. It's vital that it doesn't<br />
happen here.<br />
(11) ( II ) While we correct this mishap, mishap.let·s let's make<br />
the routine a bit more general for furl further testing.<br />
Type NEW and the code in lines 10-260, adjusting<br />
198, 213 and screen width of 39 to lo your u r system. systcm. PI<br />
is the first position ot of the field. . P2 is the final linal posi<br />
tion n after a string, string. null or otherwise, is primed. printed.<br />
You can n try the code on various things within the<br />
quotes in line 30. When en done, type two quotes<br />
there (" '*) ") and convince yourself that it it can't work.<br />
rk.<br />
Then remove REM from line e 190 and try it. This<br />
works. Replace REM in 190 and remove REM in<br />
200. This also works with some space penalty.<br />
Either method methocl should work for a particular<br />
application tion - the choice is is a function of further use<br />
for r the field. . Lines 190 or 200 simply check if the<br />
cursor has moved. If I r not, t, the subroutine utine detects a<br />
null string g and makes the needed adjustments by<br />
faking a different screen width. In I n case of 200, it it<br />
must also reset 198, since the PR I IT statement<br />
must also reset 198, since the PRINT statement