Classic Computer Magazine Archive COMPUTE! ISSUE 54 / NOVEMBER 1984 / PAGE 10

Atari Numeric I/O

In the course of my Atari programming, I have found the need to store numbers on disk with BASIC. The Atari PUT/GET commands only store numbers from 0 to 255. I'd like to know if there's any way to store larger numbers.

A. J. Allie

All input/output works a character (or byte) at a time. When you PUT a number to disk, you are sending a character in the range 0–255. GET retrieves a character as a number from 0 to 255. PUT and GET are indeed compact ways to store and retrieve numbers in this range, since only one byte is needed for what is printed on the screen as up to three digits. One way to store quantities outside the one-byte range is to break up a number into pieces. A number from 0 to 65535 can be broken into two bytes with a statement like this:


The variable NUMBER (in the range 0–65535) is broken into the two variables HIGHBYTE and LOWBYTE. You can then PUT these numbers to disk as characters. When you want to GET back the numbers, use a statement like this:


There is a much easier way to store and recall numbers. This method does not limit the range of the number. You can store any number the Atari can hold in a variable. Although less memory-efficient, you merely PRINT# (print-file) the number to a file, then use INPUT# (input-file) to read the number back.

PRINT# and INPUT# work exactly like their normal BASIC counterparts, but instead of reading from the keyboard and writing to the screen, input/output is redirected to tape, disk, modem, etc. You must always INPUT# the numbers in the same order they were written to disk. Additionally, when writing the numbers, each number must end with a carriage return, just as you must use the RETURN key to terminate keyboard INPUT.

You can also PRINT# strings to disk and read them back into a string variable. INPUT# can read the data written from one variable into another variable name. VAL and STR$ can be used to con­vert strings to numbers and vice versa. Try this small program to get an idea of how PRINT# and INPUT# work.

FG 100 DIM A$(I), F$(20) GRAPHICS 0
IM 110 PRINT "(C)reate file, or (R)ead file" :INPUT A$
MC 120 PRINT "Enter filename (include D: for disk":?
   "or use C : f or  cassette)"; : INPUT F$
CM 130 IF A$ = "R" THEN OPEN #l, 4, 0, F$ : FOR I =
   1 TO 10 : INPUT #1; A : PRINT  I , A : NEXT  I :
   CLOSE #1 : END
KF 140 PRINT "Enter 10 numbers." : OPEN #1, 8, 0, F$ :
   FOR I = 1 TO 10 : PRINT I; : INPUT A : PRINT #1; A
   : NEXT I : CLOSE #1 : END