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.

156 COMPUTEI COMPUTE! May, 1Q82.lssue 1982. Issue 2-d 24<br />

changes it. Unless 1urphy has other pl ans, this<br />

changes it. Unless Murphy has other plans, this<br />

completes the tests.<br />

You .should be able to guess now what would<br />

happen if the PRINT 'Tstatemelll statement colllained contained cursor<br />

controls, forced quotes, commas, colons, a clear<br />

colllrols, forced quotes, commas, colons, a clear<br />

screen command, orr reverse lields fields (both at the<br />

beginning and the end of the space) within the<br />

quotes. All the info rmati on needed to answer the<br />

quotes. All the information needed to answer the<br />

questions is here and in the known facts off an<br />

ordinary I INPUT T statemenl. statement. I Iff you can't guess youu<br />

may walll want LO to try these things by repeating step II 11. .<br />

We don't need those answers for the simple applicalio<br />

cationn below, butt we may need lhem them forr other tasks.<br />

The Problem Solved<br />

Sin ce we noll' understand some of the PET's rules<br />

in this ibis game we can try a slightly more ambitious<br />

project: correctly picking up multifield records,<br />

our original illlenl. intent. A routine in lines 510-1060 1060 is<br />

used. By way of illustration, we use unformatted<br />

data from DATA lines. Two PRINT PRJ 'T statemellls<br />

statements<br />

fo rmat the data on the screen, avoiding garbage<br />

Since we now understand some of the PE'Fs rules<br />

format the data on the screen, avoiding garbage<br />

collection problems in thee string construction.<br />

(The strings are acwall actuallyy constructed in high me­<br />

mory, but that does not contribute to the garbage.)<br />

mory, but that does not cOlllribute to the garbage.)<br />

PRJ NT C$ does not format the data, therefore a<br />

PRINT C$ does not format the data, therefore a<br />

null string will result on output/input, a slight<br />

complication if you u wantla to leave the e program<br />

intact. The shifted-space method is used. I leave it<br />

intacl. The shifted-space method is used. I leave il<br />

as an exercise to the reader to try null strings else­<br />

as an exercise to the reader to try null strings else<br />

where on a line, while positioning ing subsequent<br />

fields correctly. An example is given in the two<br />

RF.M REM lines,<br />

es. which introduce illlroduce another variable.<br />

Admiuedly Admittedly these complications are unnecessary,<br />

unnecessary.<br />

they are included to make the task harder.<br />

As each part of a line is printed, prillled, the subroutine<br />

in 1010 I 0 places its image into an element of an array alTay<br />

AS(line,field A$(line,field). Note that in some applications you<br />

may not even have to go after each field. . You u may<br />

wish to pick up one, two, three, three. or all al) four fields in<br />

a single procedure by placing g GOSUB1010 I 0 I 0 where<br />

you u want it. I TThere are no new concepts in the code. TheT key variables ab are: arc:<br />

AS(I,j)<br />

A$(I,J)<br />

I<br />

j<br />

destination array<br />

record or screen line number<br />

field number, counted in subroutine from left<br />

to right<br />

cursor position before the fi eld is printed<br />

P(J-1) PU-I ) cursor position before the field is printed<br />

P(J) PU)<br />

cursor position after the field is printed<br />

Ww<br />

screen width varying with P(J) PU><br />

WS<br />

system screen width address where we adjust<br />

CP<br />

PS<br />

P<br />

screen size<br />

syste m address of cursor position on a line<br />

system address of cursor position on a line<br />

forces tabbing on a null string if such must<br />

exist. PS default is 1.<br />

flags when we're dealing with a null string.<br />

T he two P arrays could have been coded as si ngle<br />

The two P arrays could have been coded as single<br />

variables. They The)' are provided in array arra), form, for we<br />

may need those values for something else.<br />

may need those values for something else.<br />

When you run this demo program, you will<br />

see thallhe that the method works and is not all that complicated.<br />

Here, we have purposely set up certain<br />

roadblocks to see how far we can push the PET.<br />

There are more uses of screen input,just as<br />

there are more aspects to the method. Wejust<br />

scratched thee surface. But once we have thee basics<br />

we can go On on to bigger things.<br />

Screen input is userul useful ror for working with strings<br />

without th e usual penalty. I thank Jim Butterfield<br />

without the usual penalty. I thank Jim Buttcrfield<br />

for hinting at this in the POWER documentation<br />

and. more impo nalllly, fOI" ofrering a va luable<br />

and, more importantly, for offering a valuable<br />

warning abollt about lrollble trouble spots.<br />

10 REM SCREEN INPUT ELIZABETH I DEAL<br />

20 P1;POS(0)<br />

P1=POS(0)<br />

30 PRINT"ANYTHING";:GOSUB180<br />

40 PRINT"'":PRINT<br />

50 PRINTA$,LEN(A$)ASC(A$+CHR$(0»<br />

PRINTA$,LEN(A$)ASC(A$+CHR$(0))<br />

60 END<br />

180 P2;POS(0):P;0<br />

P2=POS(0):P=0<br />

19 1900 :REM IFP2;P1THENP;1<br />

IFP2=P1THENP=1<br />

2002 :REM IFP2;P1THENP;1:PRINTCHR$(1<br />

IFP2=PlTHENP=l:PRINTCHR$(1<br />

60); ;<br />

210 POKE198,P1<br />

220 POKE213,P2+P<br />

230 OPEN3,3:INPUT#3,A$:CLOSE3 : 240 POKE213,39<br />

250 POKE198,P2+P<br />

260 RETURN<br />

500<br />

:<br />

5100 W=39:WS=213:CP=198<br />

W;39:WS;213:CP;198<br />

520 R=3:NV=5:DIM R;3:NV;5: A$(R,NV),P(NV)<br />

,P(NV)<br />

530 BL$=" BL$;" ":PF$=CHR$(160):PS=1<br />

:PS=l<br />

540 FORI=1TOR:J=0:READ FORI;lTOR:J=0:READ A$,B,C$<br />

550 : REM PRINT"";:IFI=2THENPRINT"*<br />

ii " ,.<br />

560 : REM PS=2:GOSUB1010<br />

0 10<br />

570 PRINT LEFT$(A$+BL$,8); ; :GOSUB1010<br />

580 PRINT PF$+RIGHT$(BL$+STR$(B),6)<br />

(B) +" ";:GOSUB1010<br />

590 PRINT C$;:PS=1:GOSUB1010<br />

:PS;1:GOSUB1010<br />

600 PRINT:NEXTI:PRINT<br />

610 FORI=1TOR:FORJ=1TONV<br />

FORI;lTOR:FORJ=lTONV<br />

620 PRINTA$(I,J);<br />

630 NEXTJ:PRINT:NEXTI:PRINT:END<br />

: END<br />

640 DATA FIRST,12345,TEXT 1<br />

650 DATA SECOND,12rTEXT D,12,TEXT 11<br />

660 DATA THIRD,,,<br />

THIRD",<br />

1000 :<br />

1010 J ;J+1:P (J);POS(0) :P;0<br />

1010 J=J+1:P(J)=POS(0):P=0<br />

1020 IFP(J)=P(J-1)THENP=1:PRINT IFP(J);P(J-1)THENP;1:PRINT PF$;<br />

1030 P0KECP,P(J-l):P0KEWS,P(J)+P*PS<br />

1030 POKECP,P(J-1) :POKEWS,P(J)+P*PS<br />

1 040 P(J) ;P (J)+P*PS<br />

1040 P(J)=P(J)+P*PS<br />

10500PEN3,3:INPUT#3,A$(I,J):CLOSE3<br />

OPEN3,3:INPUT#3,A${I,J):CLOSE3<br />

1060 POKEWS,W:POKECP,P(J):RETURN ©<br />

1060 POKEWS,W:POKECP,P(J):RETURN ©

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

Saved successfully!

Ooh no, something went wrong!