Table of Contents
THE INFORMATIONS ON THIS PAGE MIGHT BE OBSOLETE. THIS PAGE EXISTS ONLY FOR ARCHIVING PURPOSE. CHECK THE PROJECT README FOR UP TO DATE INFORMATIONS.
Embedding binary data in a ps-exe
So, if you don't know it yet, the fun in PSX development is to be able to upload your exes on real hardware with a USB/Serial cable. This means that the data you'll use in your program ( graphics, sounds, etc.) will have to be embedded in your exe in a binary form, as you won't be able to stream them from the serial port.
Well technically you could load them in memory before uploading your exe or stream them from a cd, but let's keep things simple for now.
With our setup, this is quite easy !
- In
common.mk
, add the lines :
# convert TIM file to bin
%.o: %.tim
$(PREFIX)-objcopy -I binary --set-section-alignment .data=4 --rename-section .data=.rodata,alloc,load,readonly,data,contents -O elf32-tradlittlemips -B mips $< $@
# convert VAG files to bin
%.o: %.vag
$(PREFIX)-objcopy -I binary --set-section-alignment .data=4 --rename-section .data=.rodata,alloc,load,readonly,data,contents -O elf32-tradlittlemips -B mips $< $@
If you pay attention, you can see that's the same command, but for different file types. TIM files are bitmap images and VAG is the sound format used in this example.
Each time you'll want to add a file type, duplicate and change %.vag
to %.filetype
Then, in your project folder, copy the makefile from the cube example :
mkdir new_project && cd new_project
cp ../cube/Makefile ../
All you have to do now is add the files you wish to embed to the SRCS variable, without forgetting the \ :
SRCS = main.c \
../common/crt0/crt0.s \
file_to_embed.ext \
- So this part takes care of converting our data to binary. Now to access them from your program, use this in your sources :
extern ulong _binary_filename_extension_start[];
extern ulong _binary_filename_extension_end[];
extern ulong _binary_bowsht_tim_length[];
The filename variable must begin with _binary_
followed by the full path of your file, with . and / replaced by _ (underscore), and end with _start[];
or _end[];
or _length[];
source
_start
and _end
are pointers, while _length
is a constant.
If you want to go up one level in the folder hierarchy, you can use four underscores : ____
.
This is because /../
are characters that will be replaced with _
.
That's it! When you'll type make
next time, it should convert your files to .o, then include them in your ps-exe.