• Please review our updated Terms and Rules here

DATA Command in Applesoft BASIC

WMH

Experienced Member
Joined
Dec 26, 2011
Messages
425
Location
Florida
Hello there!

I know this is a very simple question, but for some reason I just can't find the information I need.

What is the DATA command in Applesoft BASIC? I've seen it in many programs, including some programs to help output sound and many Beagle Bros two-liners, but I just don't know what it does.

Any info is appreciated.

Thanks,
WMH
 
predefine sets of data (duh)
what you read are probably machine language code/data that is poke'd into memory during run time, then call'ed from applesoft.
very popular technique to embed machine language routine(s) into applesoft program.
 
predefine sets of data (duh)
what you read are probably machine language code/data that is poke'd into memory during run time, then call'ed from applesoft.
very popular technique to embed machine language routine(s) into applesoft program.

Well, I assumed it has to do with defining data... :)

Just didn't know if it was machine code or not, because it seems that the USR command does that (or at least was meant to do that.)
 
It doesn't have to be machine code; it can be strings or numbers which can be used for any purpose. Storing the various constants/addresses that will be used in PEEKs or POKEs was quite common. But it could also replace the input command; programs written for school needed to be reproducable and 20 Input statements were likely to yield a wrong result because of a incorrect entry.
 
I think it was sort of the equivalent of an array in basic. You can access the data at any byte point or just use it as an object (drawing a sprite was often stored in data form).
 
Actually, DATA statements hold a set of values, to be used by the READ statement.
So while you can certainly use them to populate arrays, you can just as easily use them to assign values to scalars or strings.
 
Actually, DATA statements hold a set of values, to be used by the READ statement.
So while you can certainly use them to populate arrays, you can just as easily use them to assign values to scalars or strings.

I see. You place multiple values in memory with DATA to be read into variables later.

For some reason, I just can't get it to work. Oh well, I guess I'll eventually figure it out.
 
For some reason, I just can't get it to work. Oh well, I guess I'll eventually figure it out.
It's not as hard as all that. What you trying?

Here's an example.
Code:
10 FOR A=1 TO 10
20  READ N
30  PRINT N
40 NEXT A
50 DATA 1,3,5,7,9,2,17,25,99,4
Ok
run
 1
 3
 5
 7
 9
 2
 17
 25
 99
 4
Ok
Change the numbers on the DATA line and the program will print the new values.
 
It's not as hard as all that. What you trying?

Here's an example.
Code:
10 FOR A=1 TO 10
20  READ N
30  PRINT N
40 NEXT A
50 DATA 1,3,5,7,9,2,17,25,99,4
Ok
run
 1
 3
 5
 7
 9
 2
 17
 25
 99
 4
Ok
Change the numbers on the DATA line and the program will print the new values.

OK, thanks. I'm not really trying anything specific, I was just wondering how to use the command and what it does.

Now I know. :)
 
Start off small ;-) Write some bad spaghetti code and enjoy writing your own tutorials on how the commands work. Great way to learn and to reiterate your knowledge to yourself. I never learned trigonometry but goofed around with those commands (COS, SIN, TAN) in qbasic graphically to figure out what they did. Basically was just goofing with putting a pixel at x,y of random color on the screen and kept drawing a circle. Then I added the code to apply cos,sin, or tan to the coordinates and saw their interesting effects.
 
Start off small ;-) Write some bad spaghetti code and enjoy writing your own tutorials on how the commands work. Great way to learn and to reiterate your knowledge to yourself. I never learned trigonometry but goofed around with those commands (COS, SIN, TAN) in qbasic graphically to figure out what they did. Basically was just goofing with putting a pixel at x,y of random color on the screen and kept drawing a circle. Then I added the code to apply cos,sin, or tan to the coordinates and saw their interesting effects.

I must say, that's great advice! :)

That's what I'm doing right now, and it's how I taught myself other modern languages (Visual Basic .NET, C#) and a few oldies (QBasic being one, VB for MS-DOS, and a few others.)

I've gotten to the point in Applesoft where I'm writing text-based command interpreters. I wanted to write an ASCII "GUI," and I saw the DATA command was often used for those.

I have a mouse, maybe I'll write up a simple graphical GUI soon. :)
 
DATA statements can be seen as an alternative to loading a data file of fixed content. Apart from being used to load machine code snippets into memory (in combination with POKE), as mentioned you can store all sorts of data structures there. For example a text adventure, you would probably want to keep locations and pointers to other locations in DATA statements that are loaded into variable arrays upon execution:

10 DATA"A LAWN OUTSIDE A HOUSE",0,2,0,0,"AN APPLE ORCHARD",1,0,3,0
12 DATA"A FISHING POND",0,0,0,2,"END"
15 I=1: DIM L$(3),M(3,4),D$(4)
17 D$(1)="NORTH": D$(2)="SOUTH": D$(3)="EAST": D$(4)="WEST"
20 READ A$
22 IF A$<>"END" THEN L$(I)=A$:READ M(I,1),M(I,2),M(I,3),M(I,4):I=I+1:GOTO 20
25 I=1
30 PRINT"YOU ARE AT ";L$(I):pRINT"YOU CAN GO:";
35 FOR J=1 TO 4:IF M(I,J)>0 THEN PRINT " ";D$(J);
37 NEXTJ:INPUT B$:J=1
40 IF B$=D$(J) AND M(I,J)>0 THEN I=M(I,J):GOTO 30
45 J=J+1:IF J<5 THEN 40
50 PRINT"CAN'T GO THERE!":pRINT:GOTO 30

(runnable on Commodore Basic, probably runnable on Applesoft Basic too)
 
Yeah that basic chess game thread I was tempted to point out is one of those annoying data (ML) based basic programs. Basically the loader is in basic but the game gets put into memory in ML using data statements so debugging is quite a PITA.
 
Back
Top