Page 1 of 1
Including binaries in Pure C
Posted: 26 Jun 2025 20:53
by PhilC
Hi All,
Struggling a bit with something simple in Pure C of all things.
I need to import a raw image file into either the C or ASM. Now I'm used to using something like:
Code: Select all
Filelocation:
incbin "name of file.raw"
but in PureC asm that doesn't exist.I've tried using .incbin in the C section but all the examples I've found don't seem to work.
Could someone give me some examples on how to do this using Pure C. Preferably in ASM but C will also do as long as its globally available.
Re: Including binaries in Pure C
Posted: 27 Jun 2025 01:04
by chronicthehedgehog
PhilC wrote: 26 Jun 2025 20:53
Hi All,
Struggling a bit with something simple in Pure C of all things.
I need to import a raw image file into either the C or ASM. Now I'm used to using something like:
Code: Select all
Filelocation:
incbin "name of file.raw"
but in PureC asm that doesn't exist.I've tried using .incbin in the C section but all the examples I've found don't seem to work.
Could someone give me some examples on how to do this using Pure C. Preferably in ASM but C will also do as long as its globally available.
There's no mention of incbin in the PureC doc I have. Does an INCLUDE within a DATA section work?
In C, I'd use a tool like xxd to convert it into C array format. Here's a TOS version that might work (not tested it tbh) if you don't want to use it on linux :)
XXD.zip
Re: Including binaries in Pure C
Posted: 27 Jun 2025 08:06
by JezC
Not related to the Atari ecosystem in any way, but for our ARM-based products at work, we often use a utility from Segger (
www.segger.com) that converts a binary file into a C array (source & header file) - so maybe that is an option?
It's bin2c.exe - and it's listed as a free utility on their website.
Re: Including binaries in Pure C
Posted: 27 Jun 2025 08:17
by PhilC
Thanks @chronicthehedgehog & @JezC . I'll give the bin 2c a go later on.
Re: Including binaries in Pure C
Posted: 27 Jun 2025 09:08
by mrbombermillzy
If your file was e.g. a bitmap image, I think you can use:
FILE* name = fopen("path/imagename.bmp", "rb");
and then reference 'name' where you need to.
So you could e.g. read the image header with:
fread(imageHeader, sizeof(unsigned char), 54, name);
(you would also have to define 'imageHeader' in the above example)
For reference, I found more info:
Code: Select all
[ fopen ]
#include <stdio.h>
FILE* fopen( const char *filename, const char *mode);
<filename> is a string containing a filename (see Pathnames).
If no file by that name exists, a new one is created.
<mode> is a string containing the read/write options.
Function opens a file and returns a FILE pointer to be used by other
I/O functions. It returns NULL if unsuccesful.
Note: Streams stdin, stdout, stderr, stdaux and stdprn are opened
automatically.
See also Standard I/O, freopen() and tmpfile.
from Thorsten Ottos site here:
https://tho-otto.de/hypview/hypview.cgi ... 8&index=37
Re: Including binaries in Pure C
Posted: 27 Jun 2025 11:46
by mikro
xxd is the way to go (there were also Atari tools for that task available, if you insist on real hardware usage).
Good practice (when cross compiling) is to make 'xxd' as part of the 'make' process -- so when you update your binary, it will get automatically converted and included.
Re: Including binaries in Pure C
Posted: 27 Jun 2025 12:53
by PhilC
Thanks for the suggestion @mikro, I'll likely use that method when I've got a proper project to share