#! /usr/bin/env bash

set -e

OS=$(uname | tr [:upper:] [:lower:])
HOST_ENV=${OS}-$(uname -m)

BIN=./dist/${HOST_ENV}-$(cat .current_build)/bin/
PATH=$BIN:${DEVKITPRO}/tools/bin/:${DEVKITARM}/bin/:$PATH
NOSTALGIA_BIN=build/gba-*/src/nostalgia/player/nostalgia.bin
NOSTALGIA_MEDIA=nostalgia_media.oxfs
NOSTALGIA_PROJECT=$1
NOSTALGIA_GBA=nostalgia.gba
MEDIA_HEADER=media_header.txt

echo NOSTALGIA_MEDIA_HEADER_________ > $MEDIA_HEADER

nost-pack -src $NOSTALGIA_PROJECT -dst $NOSTALGIA_MEDIA

padbin 32 $NOSTALGIA_BIN
ls -lh $NOSTALGIA_BIN
cat $NOSTALGIA_BIN $MEDIA_HEADER $NOSTALGIA_MEDIA > $NOSTALGIA_GBA
rm -f $MEDIA_HEADER #$NOSTALGIA_MEDIA
gbafix $NOSTALGIA_GBA
