@echo off
IF [%2]==[] (SET lang=JP) ELSE (SET lang=%2)
SET pfx=%~p1%~n1
:: compile
SET fn=%1
IF "%fn:~-2%"==".c" C:\devkitPro\devkitPPC\bin\powerpc-eabi-gcc.exe -D "SMS_LANG_%lang%" -I "%~p0\include" "%1" -S -o "%pfx%.s" -Os -std=gnu99 -fno-asynchronous-unwind-tables
IF ERRORLEVEL 1 GOTO END
C:\devkitPro\devkitPPC\bin\powerpc-eabi-gcc.exe -I "%~p0\include" -x assembler-with-cpp "%pfx%.s" -c -o "%pfx%.o"
:: link
IF EXIST "%pfx%.ld" SET LDFLAGS=-T "%pfx%.ld"
C:\devkitPro\devkitPPC\bin\powerpc-eabi-ld.exe -Os -T "%~p0\linker\SMS-%lang%.ld" -T "%~p0\linker\alias.ld" -T "%~p0\linker\extra.ld" %LDFLAGS% -T "%~p0\linker\gecko.ld" -o "%pfx%_obj.o" "%pfx%.o" -Map "%pfx%.map"
:: print
C:\devkitPro\devkitPPC\bin\powerpc-eabi-objdump.exe "%pfx%_obj.o" --full-content
C:\devkitPro\devkitPPC\bin\powerpc-eabi-objcopy.exe "%pfx%_obj.o" "%pfx%.bin" -O binary -R .eh_frame -R .comment -R .sdata -R .gnu.attributes -g -S
:: bin2gecko
IF "%lang%"=="EU" GOTO bin2gecko_EU
IF "%lang%"=="JP" GOTO bin2gecko_JP
IF "%lang%"=="US" GOTO bin2gecko_US
echo bin2gecko for language [%lang%] is not implemented
GOTO END
:bin2gecko_EU
"%~p0\bin2gecko.exe" "%pfx%.bin" -m "%pfx%.map" -c OnUpdate:0x8029e070:3 -c OnSetup:0x80291750:0 -c OnDraw2D:0x80138b50:0 -c OnWaterHitsGround:0x80277568:0 -c OnObjectTouchMario:0x801a81b4:3 -c OnAllNPCsUpdate:0x8003e140:0 -c OnSmallEnemyHitMario:0x80065e0c:3 -r OnEMarioControl:0x8003ff5c -r IsMario:0x80245898
:bin2gecko_JP
"%~p0\bin2gecko.exe" "%pfx%.bin" -m "%pfx%.map" -c OnUpdate:0x800f9b64:3 -c OnSetup:0x800ece3c:0 -c OnDraw2D:0x80206734:0 -c OnWaterHitsGround:0x8015ebf8:0 -c OnObjectTouchMario:0x801886d8:3 -c OnAllNPCsUpdate:0x80251d50:0 -c OnSmallEnemyHitMario:0x8027f64c:3 -r OnEMarioControl:0x80253ac0 -r IsMario:0x8012cfe0
:bin2gecko_US
"%~p0\bin2gecko.exe" "%pfx%.bin" -m "%pfx%.map" -c OnUpdate:0x802a6160:3 -c OnSetup:0x802998b8:0 -c OnDraw2D:0x80143f14:0 -c OnWaterHitsGround:0x8027f7dc:0 -c OnObjectTouchMario:0x801b02fc:3 -c OnAllNPCsUpdate:0x8003e2f0:0 -c OnSmallEnemyHitMario:0x8006c76c:3 -r OnEMarioControl:0x8004010c -r IsMario:0x8024db0c
:END
:: pause