Skip to content

Including binary data in your program

dmsc edited this page Oct 22, 2020 · 1 revision

Sometimes you need to include binary data in your program, for example a title screen or a font for a game.

There are basically three ways to do this in FastBasic.

Include the data into the FastBasic program.

This has the advantage of generating a single Atari executable, making the program easier to distribute, and you can include arbitrary data at any location. The disadvantage is that you can't set the exact memory location of the included data, so if you need aligned data (for example, in a font), you need to copy it at runtime to the target location, making the program consume more memory.

To do this, you use the DATA statement. In the IDE, you need to include the data as multiple values, like DATA myFont() byte = 1, 2, 3, 4,

In the cross compiler, you can include data from a file using DATA myFont() bytefile "myfile.bin" .

Note that the data should be in raw format, and will be copied into the program as is.

Concatenate two binary files.

This also generates a single Atari executable, and you can also specify the exact memory address of the data. The disadvantage is that this is harder to do and you can't test your program as easily.

You need the data in Atari binary format, not RAW. This means the data should be a loadable file, with the standard FF FF header.

To use the data in the IDE, while testing your program, simply load your binary data in DOS first, and then the IDE. If the data is loaded high enough in memory, the IDE won't overwrite it and you can use the data assuming it is there. When you need to generate a new executable, from the IDE write the compiled program to disk and then, in DOS, use the COPY command with /A to concatenate the two parts:

  D1:COPY MYDATA.BIN FULLPROG.COM
  D1:COPY MYPROG.COM FULLPROG.COM/A

Note that the loadable data should be before your program, and you can include multiple files the same way.

When using the cross compiler, can do the same using standard Unix or Windows commands (cat on Unix, copy on Windows)

Load the data from your program at run-time.

This has the advantage of simpler programming and testing, and also that you could load different files on the same memory (for example, different backgrounds for each stage on a game). The disadvantage is that you will need to distribute a full disk image with your program, including the executable and all the data files.

To do this, you need to include code for loading the RAW data in you program, the following code would work:

PROC LoadFile
  OPEN #1, 4, 0, "D:FONT.BIN"
  BGET #1, $A000, 1024
  CLOSE #1
ENDPROC

Note that the file must have RAW data, and the load address is specified in the BGET statement.