Skip to content

Instantly share code, notes, and snippets.

@m0rb
Created January 31, 2023 03:03
Show Gist options
  • Save m0rb/fd98dffbba2e1a5101bd488ba57f75bf to your computer and use it in GitHub Desktop.
Save m0rb/fd98dffbba2e1a5101bd488ba57f75bf to your computer and use it in GitHub Desktop.
Quick and dirty NES ROM binifier
#!/bin/bash
# yet another NES ROM to BIN script
# got tired of doing this all by hand
# - morb
TITLE=$1
ROMSIZE=65536
RSIZES=($(file "$TITLE" | cut -f2- -d: | awk '{print $5"\n"$7}'))
BIN=${TITLE/.nes/.bin}
CHR=${BIN/.*/_chr.bin}
PRG=${BIN/.*/_prg.bin}
PS=${RSIZES[0]/x16k/}
CS=${RSIZES[1]/x8k/}
PF=$(( $ROMSIZE / ( $PS * 16384 ) ))
CF=$(( $ROMSIZE / ( $CS * 8192 ) ))
dd if=${TITLE} of=${BIN} bs=1 skip=16 #iNES Header
dd if=${BIN} of=${PRG} bs=16384 count=${PS} #PRG ROM
dd if=${BIN} of=${CHR} bs=16384 skip=${PS} #CHR ROM
for ((i=0;i<$PF;i++)) { cat ${PRG} >> ${PRG/.bin/_x${PF}.bin} ; }
for ((i=0;i<$CF;i++)) { cat ${CHR} >> ${CHR/.bin/_x${CF}.bin} ; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment