30.12.2013 Views

May June 1980 - Commodore Computers

May June 1980 - Commodore Computers

May June 1980 - 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/JUNE. I <strong>1980</strong> I960. . ISSUE 4. 4 COMPUTE. 9Q<br />

Atari Tape Data Files<br />

Atari Tape Data Files<br />

A Consumer Oriented Approach<br />

Introduction<br />

This article is based on a major axiom of consumer<br />

computing:<br />

Easier is Better<br />

The specific coroll ary when writing a program which<br />

The specific corollary when writing a program which<br />

saves data between program runs is:<br />

Use only one tape. Program and data should be on the<br />

same tape. They should, in fact, be the same thing.<br />

A consumer should be able to load his program, run<br />

it 10 to update hiss checkbook and balance hiss budget, and<br />

then save the program on tape when done. The next<br />

day, he can load his program and all data changes<br />

from the previous day should be there.<br />

" Impossible", you say? Well , perhaps. It is cer­<br />

"Impossible", you say? Well, perhaps. It is cer<br />

tainly y impossible on some of the computers on the<br />

market. But it is not impossible on the Alari. Atari. The trick<br />

is to fool Atari Basic into saving all dimensioned<br />

variables when a program is saved to tape. We won't<br />

try 10 save the simple variables. Since I am not a<br />

try to save the simple variables. Since I am not a<br />

revered expert, I won't make the mistake of saying<br />

this is impossible. (But, I think it's impossible.)<br />

this is impossible. (But, I think it's impossible.)<br />

Saving the dimensioned variables with a program is<br />

relatively easy.<br />

Write your program<br />

Listing 1 is a simple program. Nothing tricky. But<br />

Listing 1 is a simple program. Nothing tricky. But<br />

notice that I print the dimensioned variables in Lines<br />

70-130 and then assign values to them in Lines 140-<br />

190. I am assuming the variables have valid contents<br />

before changing them! The only important restriction<br />

here is to type the line containing the DIM<br />

statement firsl. It doesn't have to be the first line<br />

statement first. It doesn't have to be the first line<br />

in the program. Just make sure it is the first line<br />

typed.<br />

The Atari Basic variable sy mbol table is con­<br />

The Atari Basic variable symbol table is con<br />

structed when each line is typed in, , not when the program<br />

is run. Later we will need to find the locations<br />

of the string variables in the table . This is<br />

tions of the string variables in the table. This is<br />

easier if they are the first variables present. For a<br />

more complete discussion of the symbol table, see the<br />

text in the box.<br />

text in the box.<br />

50 DIM A$(10),B(2 , 3)<br />

50 DIM A?(10),B(2,3)<br />

70 ? A$ AS<br />

80 FOR 1=0 TO 2<br />

80 FOR 1=0 TO 2<br />

90 FOR J =0 TO 3<br />

90 FOR J = 0 TO 3<br />

1100 PRINT B{I,J), B( 110 NEXT J<br />

120 PRINT<br />

130 NEXT I<br />

14~ ? "STRING=";:INPUT A$<br />

140 ? "STRING=";:INPUT AS<br />

150 15~ ? "I=";:INPUT I<br />

160 IF 1=9 THEN 200<br />

160 IF 1=9 THEN 200<br />

170 17~ ? "J=";:INPUT "; : I A:B(I,J)=A<br />

, 190 GOTO 150<br />

190 GOTO 150<br />

200 END<br />

50 DIM A$(10),B(2,3)<br />

70 ? A$<br />

110 NEXT J<br />

1120 PRINT<br />

130 NEXT I<br />

140 14~ ? "STRING=";:INPUT ";: INPUT AS A$<br />

1501 5~ ? "I=";:INPUT I<br />

160 IF 1=9 THEN 200<br />

Al Baker<br />

2327 S S. Westminster<br />

Wheaton, IL 6O187<br />

210 A=A+82<br />

220 POKE 141,INT(A/256):POKE , 140,A-PEEK(141)*256141 230 CSAVE<br />

procedure won't work.<br />

AI Baker<br />

Wheaton, IL 60187<br />

Suppose the program is already written and you<br />

didn't type the DIM statement first. Write your<br />

program 10 to tape using the command LIST"C". Type<br />

NEW. Now type the DIM statement from your program<br />

with the string variables first. Finally, reload<br />

the program from tape with the command ENTER<br />

"e". "C". Now the string variables are at the beginning<br />

of the variable tables.<br />

Protect the Dimensioned Variables<br />

The next step is to fool Basic into treating the<br />

dimensioned variables as part of the program. Also,<br />

you have to add the code to let the program save<br />

itself to tape. In an application, saving the program<br />

to tape will be the final program option selected by<br />

the user. In Listing 2 this is added to the program<br />

in lines 200 through 230.<br />

50 Dnt A$( 1 0) ,B (2 ,3)<br />

80 FOR 1=0 TO 2<br />

90 FOR J=0 TO 3<br />

100 l~ ~ PRINT B(I,J),<br />

110 NEXT J<br />

130 NEXT I<br />

1 60 IF 1=9 THEN 200<br />

170 ? "J=" "J=";:INPUT ; :INPUT A: A:B(I,J)=A B(I , J)=A<br />

190 GOTO 150<br />

200 A=PEEK(140)+PEEK(141)*256<br />

)*256<br />

210 A=A+82<br />

230 CSAVE<br />

Locations 140 and 141 contain the address of the<br />

end of the computer program. Program line 200 places<br />

this address in the variable A. In line 210 we add the<br />

size of the dimensioned variables. Each string variable<br />

containss as many bytes as its dimension. Each<br />

numeric array contains 6 times the number of<br />

members of the array. The B array is 6x(2 + l)x(3 + 1)<br />

= ~ 6x3x4 = ~ 72 bytes. Thus we had to add 10 + 72 or<br />

82 to the end of the program in the example.<br />

Now run the program and let the internal CSAVE<br />

create a tape. Turn the computer off and then on.<br />

Now reload the newly created program from tape.<br />

For some reason this step is important. (I don't 't<br />

know why.) If you do not use the new tape, this<br />

procedure won't work.<br />

Finish the program<br />

We now have a program in memory which has an<br />

invalid program - end pointer. See Sec the third listing.<br />

Add lines 10 through 40 to your program. Make sure<br />

that you use the correct number instead of 4' -82"<br />

that you use the correct number instead of "-82"

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

Saved successfully!

Ooh no, something went wrong!