This is a quick tool to generate an image.js from the ngaImage for use with the JavaScript and Typescript implementations of the VM.
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.