Warning

You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Last revisionBoth sides next revision
data [2019/05/07 08:05] neilsdata [2019/05/07 08:12] neils
Line 9: Line 9:
     data varname![] = incbin "path/to/binary_file"     data varname![] = incbin "path/to/binary_file"
  
-The ''DATA'' directive allocates a one-dimensional static array in memory filled with pre-initialized data //in compile time//. The array can be used as a regular array in runtimeExample:+The ''DATA'' directive allocates a one-dimensional static array in memory filled with pre-initialized data //in compile time//. The length of the array will equal to the number of elements in the list of values..
  
- rem ** this will print: 9 +If the right-hand side of the assignment is an ''INCBIN'' directive, the length of the array will equal to the length of the file and each byte in the file will become one array element. Only //byte type// arrays can be initialized this way. 
- data squares[] = 0, 1, 4, 9, 16 + 
- print squares[3]+Example with value list: 
 + 
 +    rem -- this will print: 9 
 +    data squares[] = 0, 1, 4, 9, 16 
 +    print squares[3] 
 + 
 +Example with ''INCBIN'': 
 + 
 +    rem -- load a sprite 
 +    data sprite![] = incbin "sprite.bin"
   
 ''DATA'' statements can be written anywhere in your program. The following will also work: ''DATA'' statements can be written anywhere in your program. The following will also work: