Many of the RETRO interface layers embed a copy of the image into the binary. This is done by converting the image into a C file that can be included or compiled and linked. The source includes a tool, retro-embedimage, for this. This implements the tool in RETRO.
First up, I need to load the image to a buffer, so I allocate space for this now.
Next is reading in the file. This is slightly complicated by the need to pack the individual bytes into the memory cells.
So, a variable to track the open file ID.
Then read in a byte.
Reading in four bytes, I can shift and merge them back into a single cell.
The next step is a word to return the size of the file in cells.
And then, using the above, read in the data from the file to the image buffer.
Read in the file.
The final part is to export the image as a C array. To keep line length to a reasonible length, I have a counter and add a newline after 18 values.
The rest is easy. Display the relevant header bits, then the cells, then the needed footer.