Topic : The GFA-Basic Compendium Author : GFA Systemtechnik GmbH Version : GFABasic.HYP v2.98 (12/31/2023) Subject : Documentation/Programming Nodes : 899 Index Size : 28056 HCP-Version : 3 Compiled on : Atari @charset : atarist @lang : @default : Document not found @help : Help @options : +g -i -s +z @width : 75 @hostname : STRNGSRV @hostname : CAB @hostname : HIGHWIRE @hostname : THING View Ref-FileDATA const [,const1,const2,...] READ var [,var1,var2,...] RESTORE [label] _DATA _DATA= x const, const1, const2: numerical or string constants var, var1, var2: avar or svar label: user-defined label x: iexp (suitable for an address) DATA statements are used to store numeric or string constants which can then be accessed with READ. Numeric values can be specified in hexadecimal, octal, or binary form, but string constants must be enclosed in inverted commas if they contain commas, as commas are normally used to separate items in the DATA statement. Internally associated with DATA and READ is the so-called data pointer, which always points to the next item to be READ. When a program is RUN, this is the first item in the first DATA statement. The RESTORE instruction allows the data pointer to be moved so as to point to any DATA statement, provided the DATA statement is preceded by a label. If no label is specified by RESTORE, the data pointer is moved to the first DATA statement in the program. See GOTO for the rules for defining a label. The variable _DATA returns the position of the DATA pointer. _DATA returns 0 if the next READ would result in an 'out of data' error. _DATA= permits the setting of the DATA pointer to a value which has been previously determined with _DATA. Comments cannot be placed behind DATA statements. Examples: FOR i=1 TO 3 READ a PRINT a' NEXT i ' RESTORE roman_numbers READ a$,b$,c$,d$ PRINT PRINT a$'b$'c$'d$ ' DATA 1,2,3,4 DATA a,b,c,d ' roman_numbers: DATA I,II,III,IV --> In the loop the numeric values 1, 2, and 3 are read in and printed on the screen. After that, by means of RESTORE, the data pointer is moved to the line containing the roman numerals as data. They are also read in and printed. DATA 10,&A,$A,&HA,&O12,&X1010,%1010 FOR i%=1 to 7 READ a% PRINT a% NEXT i% --> The number 10 is read in seven times. Like INPUT, VAL() etc., READ can interpret Hexadecimal numbers if they are prefixed with '$' or '&H', and Binary numbers if they are prefixed with '%' or '&X'. DIM dp%(100) DATA 1,2,3,4,5,6,7,8,9 DATA 13,24,328,3242,1,0 ' i%=0 DO WHILE _DATA dp%(i%)=_DATA INC i% READ a LOOP ' DEC i% ' FOR j%=i% DOWNTO 0 _DATA=dp%(j%) READ a PRINT a NEXT j% ~INP(2) --> Displays: 0 1 3242 328 24 13 9 8 7 6 5 4 3 2 1 A key is then waited for. Note: Using _DATA to detect the 'out of data' state is only useful if you have one set of DATA statements. If you have more that one set of DATA statements used for different purposes, then _DATA cannot be used to detect the end of the first set. Memo: If a string contains a comma or double quotes or spaces on either end, the entire string must be enclosed in double quotes. Certain characters cannot be placed in DATA statements. They are ASCII 4, 10, and 13. Example: DATA " spaces, "quotes", and commas in the string " Adding quotes does not increase the size of the compiled binary. The _DATA pointer truely is a pointer, as it actually returns the address of the item in the DATA statement itself. Thus, this can be done in the Editor: DATA test,this BYTE{_DATA}=ASC("T") READ t$ PRINT t$ The word "Test" will appear. This will actually change your source code if executed in the Editor! When compiled, the commas between data items become nulls which would allow the use of CHAR{} to fetch data items. Thus, this can be done in a compiled program: DATA Hello world,hi PRINT CHAR{_DATA} The words "Hello world" will appear. _DATA seems to work in the interpreter, but I had problems with it in compiled programs. I think this is why: RESTORE test READ a$ PRINT a$'_DATA !interpreter prints 'bug 0' (fails compiled!) EDIT test: DATA "bug" Typing '_DATA=x' results in '_DATA= x', detokenizer inserts a space. Considered a visual bug. The editor issues error #72 for _DATA=x if these problems happen: _DATA=x and there are no DATA statements at all in the listing _DATA=x and x is below the first DATA statement _DATA=x and x is above the last DATA statement However, it appears as 'Undefined error #72'. It seems Frank forgot to include some human readable text for this error code. The compiler issues no error and will even allow one to set it to zero. If the label used with RESTORE is undefined, the compiler will not issue an error message. Instead the data pointer will be set incorrectly to the first data statement in the program. Version 2 would issue an error reading strings with unpaired quotes. This was changed in version 3 and error code #36 was retired. Example____ v2___ v3___ DATA "test" test test DATA "test error "test DATA test" error test"