Files
sylverb-game-and-watch-retr…/linux/update_gb_rom.sh
sylverb a0eab3646c Default GB/GBC emulator is now tgb-dual
Several additions to add support for C++ emulators
2023-12-12 13:38:59 +01:00

32 lines
699 B
Bash
Executable File

#!/bin/bash
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <gb_rom.gb> [gb_rom.c]"
echo "This will convert the gb rom into a .c file and update all the references"
exit 1
fi
INFILE=$1
OUTFILE=loaded_gb_rom.c
if [[ ! -e "$(dirname $OUTFILE)" ]]; then
mkdir -p "$(dirname $OUTFILE)"
fi
if [[ $# -gt 1 ]]; then
OUTFILE=$2
fi
SIZE=$(wc -c "$INFILE" | awk '{print $1}')
echo "const unsigned char ROM_DATA[] = {" > $OUTFILE
xxd -i < "$INFILE" >> $OUTFILE
echo "};" >> $OUTFILE
echo "unsigned int ROM_DATA_LENGTH = $SIZE;" >> $OUTFILE
echo "unsigned int cart_rom_len = $SIZE;" >> $OUTFILE
extension="${INFILE##*.}"
echo "const char *ROM_EXT = \"$extension\";" >> $OUTFILE
echo "Done!"