Skip to content

Commit 8ea6ad8

Browse files
committed
Allow strings and addresses into byte DATA arrays.
1 parent 7f95842 commit 8ea6ad8

4 files changed

Lines changed: 38 additions & 5 deletions

File tree

manual.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,29 @@ General Statements
13871387
Note that the array can be modified
13881388
afterwards like a normal array.
13891389

1390+
*Advanced Usage*
1391+
1392+
Byte DATA arrays can be used to
1393+
include assembler routines (to call
1394+
via `USR`, see the example above),
1395+
display lists and any other type of
1396+
binary data.
1397+
1398+
To facilitate this, you can include
1399+
constant strings and the address of
1400+
other byte DATA array by name.
1401+
1402+
All the bytes of the string, including
1403+
the initial length byte are included
1404+
into the DATA array.
1405+
1406+
Example:
1407+
1408+
DATA str() B. = "Hello", "World"
1409+
X = ADR(str)
1410+
? $(X), $(X+6)
1411+
DATA ad() B. = $AD,str,$A2,0,$60
1412+
? USR(ADR(ad)), str(0)
13901413

13911414
**Decrements variable by 1**
13921415
**DEC _var_ / DE.**

src/basic.syn

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,18 @@ DATA_WORDS: data word
555555
"," E_NUMBER_WORD DATA_WORDS
556556
pass
557557

558+
DATA_BYTE:
559+
"\"" E_CONST_STRING
560+
E_NUMBER_BYTE
561+
emit { VT_ARRAY_BYTE } E_LABEL
562+
558563
DATA_BYTES: data byte
559564
# To store bytes, simply remove upper part
560-
"," E_NUMBER_BYTE DATA_BYTES
561-
pass
565+
DATA_BYTE "," DATA_BYTES
566+
DATA_BYTE
562567

563568
DATA_TYPE: data type
564-
# Note: E_VAR_SET_TYPE skips white space, this allows spaces between
565-
# the data type and the "=".
566-
TYPE_BYTE EQUAL E_LABEL_SET_TYPE E_NUMBER_BYTE DATA_BYTES
569+
TYPE_BYTE EQUAL E_LABEL_SET_TYPE DATA_BYTES
567570
TYPE_WORD EQUAL E_LABEL_SET_TYPE E_NUMBER_WORD DATA_WORDS
568571

569572
DATA_END:

testsuite/tests/stmt-data.bas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ a = adr(arr2)
2222
? : ? "2: "; dpeek(a);
2323
for i=1 to 8 : a = a + 2: ? ", "; dpeek(a); : next
2424
?
25+
26+
data arr4() b. = "String", arr1, "Code"
27+
? $(ADR(arr4))
28+
? adr(arr1) - dpeek(ADR(arr4)+1+LEN($(ADR(arr4))))
29+

testsuite/tests/stmt-data.chk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ Start
66
2: -7, -5, -3, -1, 0, 7, 123, 22136, -1
77
1: 1, 2, 3, 4, 254, 255, 0, 123, 134, 65, 255, 10
88
2: -7, -5, -3, -1, 0, 7, 123, 22136, -1
9+
String
10+
0

0 commit comments

Comments
 (0)