#!/bin/sh # Configuration options PURESTART=8323072 # Start offset ROMSTART=2961113088 # Start offset + 0xB??????? prefix ROM="./MARIO64.Z64" # ROM file ROM_MODEL="./MARIO-MODEL.Z64" # Unmodified ROM file BINDIR="./bin" ## ## Prerequisites ## # Create a clean copy of our ROM cp ${ROM_MODEL} ${ROM} ## ## Checks ## # Check for `f2c` if [ ! -f ./f2c ] then echo "Can't find \"f2c\" binary." exit 1 fi # Check for `putbin` if [ ! -f ./putbin ] then echo "Can't find \"putbin\" binary." exit 1 fi ## ## User binary ## # Build user binary make -C ${BINDIR} # Error checking... if [ "$?" != 0 ] then echo "Problem building binary." exit 1 fi ## ## Stage 2 ## # Copy the game's entry point to be replaced dd if=${ROM} bs=1 skip=4096 count=1024 | ./f2c entry_point > stage2/game-ep.c # Move user binary to stage2 cp -vf ${BINDIR}/bin.a ./stage2/bin.a # Clean & build make -C stage2 clean make -C stage2 # Error checking if [ "$?" != 0 ] then echo "Problem building stage2." exit 1 fi ## ## Stage 1 ## # Get filesize of stage 2 binary STAGE2SIZE=`stat --printf="%s" stage2/nbl-stage2.bin` # Calculate ROM ending address ROMEND=`echo ${ROMSTART} ${STAGE2SIZE} + p | dc` # Generate config.h rm -fv ./stage1/config.h echo "#ifndef __N64BL_CONF_H__" >> ./stage1/config.h echo "#define __N64BL_CONF_H__" >> ./stage1/config.h echo "#define BL_STACK_TMP 0x807FFFF0" >> ./stage1/config.h echo "#define BL_ROM_START `printf "0x%08X" ${ROMSTART}`" >> ./stage1/config.h echo "#define BL_ROM_END `printf "0x%08X" ${ROMEND}`" >> ./stage1/config.h echo "#define BL_RAM_START 0xA0400000" >> ./stage1/config.h echo "#endif /* __N64BL_CONF_H__ */" >> ./stage1/config.h # Clean & build make -C stage1 clean make -C stage1 ## ## Finishing touches ## # Copy the binaries to their respective locations ./putbin ./stage1/nbl-stage1.bin ${ROM} 1000 ./putbin ./stage2/nbl-stage2.bin ${ROM} `printf "%08X" ${PURESTART}` # Fix the ROM CRC ucon64 --n64 --chk ${ROM}