Skip to content

Commit

Permalink
Split rom.ld into smaller files and add a sector linker
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseurae committed Jul 5, 2023
1 parent ca72353 commit a9586eb
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 313 deletions.
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ OBJ_FILES ?= $(SRC_FILES:src/%.c=build/src/%.o)
CFLAGS = -Iinclude -mlong-calls -Wall -Wextra -mthumb -mno-thumb-interwork -fno-inline -fno-builtin -std=gnu11 -mabi=apcs-gnu -mcpu=arm7tdmi -march=armv4t -mtune=arm7tdmi -x c -c -MMD -g -mthumb-interwork -Wimplicit -Wparentheses -Wno-unused -Werror -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast -Wno-stringop-overflow $(EXTRA_CFLAGS)

LD = $(PREFIX)ld
LDFLAGS = --relocatable -T rom.ld $(EXTRA_LDFLAGS)
LDFLAGS = -i rom.ld -T linker.ld $(EXTRA_LDFLAGS)

ARMIPS := armips

Expand All @@ -28,13 +28,15 @@ test.gba: snakewood.gba build/linked.o
clean:
rm -rf build

build/src/%.o: src/%.c Makefile
build/src/%.o: src/%.c Makefile rom.ld
@mkdir -p build/src
$(CC) $(CFLAGS) -c $< -o $@

build/linked.o: $(OBJ_FILES) rom.ld
build/linked.o: $(OBJ_FILES) rom.ld linker.ld
@mkdir -p build
@echo "$(LD) $(LDFLAGS) -Map build/linked.map -o $@ <objects> <libs>"
@$(LD) $(LDFLAGS) -Map build/linked.map -o $@ $(OBJ_FILES)

rom.ld: linker/*.ld

-include $(SRC_FILES:src/%.c=build/src/%.d)
19 changes: 19 additions & 0 deletions linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SECTIONS {
.text :
ALIGN(4)
{
*(.text);
}

.rodata :
ALIGN(4)
{
*(.rodata);
}

/* Discard everything not specifically mentioned above. */
/DISCARD/ :
{
*(*);
}
}
67 changes: 67 additions & 0 deletions linker/ram.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
gBattleStruct = 0x2000000;
gBattleFlags = 0x2017100;
sMonSummaryScreen = 0x2018000;
gPartyMenu2 = 0x201B000;
gPartyMenu = 0x201C000;
gSprites = 0x2020004;
gBGTilemapBuffers = 0x20211cc;
gStringVar1 = 0x20231cc;
gStringVar2 = 0x20232cc;
gStringVar3 = 0x20233cc;
gStringVar4 = 0x20234cc;
gBattleTypeFlags = 0x20239f8;
gActiveBattler = 0x2024a60;
gBattleControllerExecFlags = 0x2024a64;
gBattleMons = 0x2024a80;
gCurrentMove = 0x2024be6;
gBattleMoveDamage = 0x2024bec;
gHpDealt = 0x2024bf0;
gTakenDmg = 0x2024bf4;
gBattlerAttacker = 0x2024c07;
gBattlerTarget = 0x2024C08;
gCritMultiplier = 0x2024c0d;
gBattlescriptCurrInstr = 0x2024c10;
gMoveResultFlags = 0x2024c68;
gHitMarker = 0x2024c6c;
gTakenDmgByBattler = 0x2024c74;
gDisableStructs = 0x2024ca8;
gProtectStructs = 0x2024d28;
gSpecialStatuses = 0x2024d68;
gBattleWeather = 0x2024db8;
gEnigmaBerries = 0x2024df0;
gBattleMovePower = 0x2024e80;
gCreatingSpriteTemplate = 0x2024e8c;
gPlayerName = 0x2024ea4;
gPlayTimeHours = 0x2024eb2;
gPlayTimeMinutes = 0x2024eb4;
gExpandedItemPockets = 0x2025420;
gRegisteredItems = 0x2025520;
gMapHeader = 0x202e828;
gPlayerAvatar = 0x202e858;
gSpecialVar_0x8004 = 0x202e8cc;
gSpecialVar_Result = 0x202e8dc;
gPartyMenuUseExitCallback = 0x202e8f4;
gMenuWindowPtr = 0x202e9c8;
gMenuTextTileOffset = 0x202e9ce;
gPlttBufferUnfaded = 0x202eac8;
gPlttBufferFaded = 0x202eec8;
gTrainerBattleOpponent = 0x202ff5e;
gFieldEffectArguments = 0x202ff84;
sPokeMenuCursorPos = 0x202ffa8;
sPokeMenuOptionsNo = 0x202ffa9;
sPokeMenuOptionsOrder = 0x202ffaa;
gUnknown_02038558 = 0x2038558;
sCurrentBagPocket = 0x2038559;
gSpecialVar_ItemId = 0x203855e;
gRepelMenuChoices = 0x203a400;
gLastUsedRegisteredItem = 0x203a404;

gMartInfo = 0x3000708;
gMain = 0x3001770;
gPlayerParty = 0x3004360;
gObjectEvents = 0x30048a0;
gTasks = 0x3004b20;
gLastFieldPokeMenuOpened = 0x3005ce0;
gBagPocketScrollStates = 0x3005d10;
gCurrentBagPocketItemSlots = 0x3005d24;
gScriptContext1 = 0x3007440;
33 changes: 33 additions & 0 deletions linker/rodata.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Event_NoRegisteredItem = 0x81a14af;
BattleScript_SubstituteFade = 0x81d99ab;
gFontDefaultPalette = 0x81e66b2;
gWindowTemplate_81E6C3C = 0x81E6C3C;
gMenuTextWindowTemplate = 0x81e6ce4;
gMonFrontPicCoords = 0x81e7c74;
gMonFrontPicTable = 0x81e8354;
gMonPaletteTable = 0x81ea5b4;
gMoveNames = 0x81f8320;
gMonSpriteGfx_Sprite_ptr = 0x81faf4c;
gBattleMoves = 0x81fb12c;
gNatureStatTable = 0x81fd070;
gHoldEffectToType = 0x8208263;
gFieldEffectObjectTemplatePointers = 0x836dfc0;
gWeatherPtr = 0x8396fc4;
gWeatherFuncs = 0x8396fc8;
gWeatherPalStateFuncs = 0x83970b8;
sPokeMenuFieldMoves = 0x839f554;
gItems = 0x83c5564;
gContestMoves = 0x83cf594;
gDecorations = 0x83eb6c4;
gShadowEffectTemplateIds = 0x8401e32;
gShadowVerticalOffsets = 0x8401e36;
gOtherText_CancelNoTerminator = 0x840e645;
gOtherText_OneDash = 0x840e680;
gOtherText_TwoDashes = 0x840e682;
gOtherText_QuitShopping = 0x840eca1;
gOtherText_WontHaveAnyEffect = 0x840ef85;
gOtherText_Player = 0x842c983;
gOtherText_Badges = 0x842c98a;
gOtherText_Pokedex = 0x842c992;
gOtherText_PlayTime = 0x842c99a;
gStatStageRatios = 0x8208244;
9 changes: 9 additions & 0 deletions linker/syscalls.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
memcpy = 0x815b890 | 1;
memset = 0x815bb08 | 1;
CpuFastSet = 0x81e07e8 | 1;
CpuSet = 0x81e07ec | 1;
LZ77UnCompVram = 0x81e07f0 | 1;
__divsi3 = 0x81e0868 | 1;
__modsi3 = 0x81e0978 | 1;
__udivsi3 = 0x81e0e90 | 1;
__umodsi3 = 0x81e0f08 | 1;
189 changes: 189 additions & 0 deletions linker/text.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
CreateSprite = 0x8000bdc | 1;
CreateSpriteAtEnd = 0x8000c30 | 1;
SpriteCallbackDummy = 0x8001210 | 1;
StartSpriteAnim = 0x8001f58 | 1;
AllocSpritePalette = 0x8002690 | 1;
IndexOfSpritePaletteTag = 0x80026c0 | 1;
LoadFontDefaultPalette = 0x8002a1c | 1;
Text_LoadWindowTemplate = 0x8002a34 | 1;
PrintStringWithNewlines = 0x8004fd0 | 1;
StringCopy = 0x8006ab0 | 1;
ConvertIntToDecimalStringN = 0x8006bc4 | 1;
ConvertIntToDecimalString = 0x8006ddc | 1;
BtlController_EmitSetMonData = 0x800c664 | 1;
LoadCompressedObjectPalette = 0x800d2a4 | 1;
DecompressPicFromTable_2 = 0x800d308 | 1;
GetBattlerForBattleScript = 0x8015150 | 1;
MarkBattlerForControllerExec = 0x8015554 | 1;
BattleScriptPushCursor = 0x801584c | 1;
AbilityBattleEffects = 0x8018324 | 1;
CountAliveMons = 0x803c348 | 1;
SetMonSpriteTemplate = 0x803c56c | 1;
GetMonData = 0x803cb60 | 1;
CalculatePPWithBonus = 0x803ddec | 1;
GetNature = 0x803f464 | 1;
CanMonLearnTMHM = 0x8040374 | 1;
InitMapView = 0x8053220 | 1;
LoadMapTilesetPalettes = 0x8056d84 | 1;
MetatileBehavior_IsPokeGrass = 0x8056e14 | 1;
MetatileBehavior_IsReflective = 0x8056e5c | 1;
MetatileBehavior_IsReflective = 0x8056e5c | 1;
MetatileBehavior_IsIce = 0x8056e84 | 1;
MetatileBehavior_IsSurfableWaterOrUnderwater = 0x8056f38 | 1;
MetatileBehavior_IsPuddle = 0x80573bc | 1;
PlayerFreeze = 0x80594C0 | 1;
StopPlayerAvatar = 0x80597F4 | 1;
GetPlayerAvatarGraphicsIdByStateId = 0x805986c | 1;
SetPlayerAvatarStateMask = 0x80599f4 | 1;
GetObjectEventIdByLocalIdAndMap = 0x805ab84 | 1;
TryGetObjectEventIdByLocalIdAndMap = 0x805aba8 | 1;
ObjectEventSetGraphicsId = 0x805b980 | 1;
ObjectEventTurn = 0x805bac0 | 1;
GetObjectEventGraphicsInfo = 0x805bc10 | 1;
ObjectEventGetLocalIdAndMap = 0x805bcac | 1;
CameraObjectReset2 = 0x805c42c | 1;
ObjectEventIsMovementOverridden = 0x806051c | 1;
ObjectEventClearHeldMovementIfActive = 0x80605b4 | 1;
ObjectEventClearHeldMovementIfFinished = 0x8060614 | 1;
ObjectEventUpdateMetatileBehaviors = 0x80636e0 | 1;
GetGroundEffectFlags_Reflection = 0x8063708 | 1;
GetGroundEffectFlags_TallGrassOnSpawn = 0x8063764 | 1;
GetGroundEffectFlags_TallGrassOnBeginStep = 0x8063784 | 1;
GetGroundEffectFlags_LongGrassOnSpawn = 0x80637a4 | 1;
GetGroundEffectFlags_LongGrassOnBeginStep = 0x80637c4 | 1;
GetGroundEffectFlags_Tracks = 0x80637e4 | 1;
GetGroundEffectFlags_SandPile = 0x8063824 | 1;
GetGroundEffectFlags_ShallowFlowingWater = 0x8063874 | 1;
GetGroundEffectFlags_Puddle = 0x80638d8 | 1;
GetGroundEffectFlags_Ripple = 0x8063908 | 1;
GetGroundEffectFlags_ShortGrass = 0x8063928 | 1;
GetGroundEffectFlags_HotSprings = 0x8063978 | 1;
GetGroundEffectFlags_Seaweed = 0x80639c8 | 1;
GetGroundEffectFlags_JumpLanding = 0x80639e8 | 1;
GroundEffect_SpawnOnTallGrass = 0x8063e48 | 1;
GroundEffect_MoveOnTallGrass = 0x8063e94 | 1;
GroundEffect_SpawnOnLongGrass = 0x8063ee0 | 1;
GroundEffect_MoveOnLongGrass = 0x8063f2c | 1;
GroundEffect_WaterReflection = 0x8063f78 | 1;
GroundEffect_IceReflection = 0x8063f84 | 1;
GroundEffect_FlowingWater = 0x8063f90 | 1;
GroundEffect_SandTracks = 0x8063fa0 | 1;
GroundEffect_DeepSandTracks = 0x8063fcc | 1;
GroundEffect_Ripple = 0x806409c | 1;
GroundEffect_StepOnPuddle = 0x80640a8 | 1;
GroundEffect_SandPile = 0x80640b8 | 1;
GroundEffect_JumpOnTallGrass = 0x80640c8 | 1;
GroundEffect_JumpOnLongGrass = 0x8064120 | 1;
GroundEffect_JumpOnShallowWater = 0x8064148 | 1;
GroundEffect_JumpOnWater = 0x8064178 | 1;
GroundEffect_JumpLandingDust = 0x80641a8 | 1;
GroundEffect_ShortGrass = 0x80641d8 | 1;
GroundEffect_HotSprings = 0x80641e8 | 1;
GroundEffect_Seaweed = 0x80641f8 | 1;
FreezeObjectEvents = 0x8064434 | 1;
StartFieldEffectForObjectEvent = 0x80649f4 | 1;
DoShadowFieldEffect = 0x8064a1c | 1;
ShowFieldMessage = 0x8064b68 | 1;
HideFieldMessageBox = 0x8064c58 | 1;
TextWindow_LoadStdFrameGraphicsOverrideStyle = 0x8064f6c | 1;
SetupNativeScript = 0x80653dc | 1;
ScriptContext2_Enable = 0x8065530 | 1;
ScriptContext2_IsEnabled = 0x8065548 | 1;
ScriptContext1_SetupScript = 0x80655b8 | 1;
ScriptContext1_Stop = 0x80655f0 | 1;
VarSet = 0x8069270 | 1;
FlagGet = 0x8069340 | 1;
PrintPartyMenuPromptText = 0x806d538 | 1;
PartyMenuEraseMsgBoxAndFrame = 0x806d5a4 | 1;
TryPrintPartyMenuMonNickname = 0x806e07c | 1;
GetMonNickname = 0x806e0ec | 1;
DisplayPartyMenuMessage = 0x806e834 | 1;
sub_806E8D0 = 0x806E8D0 | 1;
ItemIdToBattleMoveId = 0x806f024 | 1;
MonKnowsMove = 0x806f03c | 1;
IsHMMove = 0x806f7b8 | 1;
sub_806F8AC = 0x806f8ac | 1;
Task_ClosePartyMenuAfterText = 0x806fb0c | 1;
IsHPRecoveryItem = 0x806fb7c | 1;
PartyMenuUpdateLevelOrStatus = 0x806fbb4 | 1;
GetMedicineItemEffectMessage = 0x806fbd0 | 1;
IsMedicineIneffective = 0x806fd90 | 1;
ExecuteTableBasedItemEffect__ = 0x806fdc4 | 1;
IsBlueYellowRedFlute = 0x807002c | 1;
GetItemEffectType = 0x8070e48 | 1;
AppendToList = 0x8071c3c | 1;
InitMenuWindow = 0x8071c4c | 1;
Menu_PrintText = 0x8071e50 | 1;
Menu_EraseWindowRect = 0x8071e84 | 1;
Menu_BlankWindowRect = 0x8071ebc | 1;
Menu_DrawStdWindowFrame = 0x8071f08 | 1;
Menu_PrintTextPixelCoords = 0x80729d8 | 1;
MenuPrint_RightAligned = 0x8072b4c | 1;
MenuPrint_Centered = 0x8072bd8 | 1;
AlignInt1InMenuWindow = 0x8072c14 | 1;
AlignStringInMenuWindow = 0x8072c74 | 1;
Menu_GetTextColors = 0x8072cd4 | 1;
LoadPalette = 0x8073a58 | 1;
TransferPlttBuffer = 0x8073ae0 | 1;
BeginNormalPaletteFade = 0x8073bf4 | 1;
PlaySE = 0x8075494 | 1;
GetBattlerSide = 0x8078814 | 1;
CreateTask = 0x807aa88 | 1;
DestroyTask = 0x807ab74 | 1;
TaskDummy = 0x807ac50 | 1;
FuncIsActiveTask = 0x807acbc | 1;
FindTaskIdByFunc = 0x807acf4 | 1;
Task_WeatherInit = 0x807c9e4 | 1;
Task_WeatherMain = 0x807ca34 | 1;
BuildGammaShiftTables = 0x807cb10 | 1;
ApplyGammaShift = 0x807cebc | 1;
Weather_SetBlendCoeffs = 0x807db64 | 1;
SetRainStrengthFromSoundEffect = 0x807dd5c | 1;
PlayRainSoundEffect = 0x807ddb8 | 1;
PreservePaletteInWeather = 0x807de38 | 1;
FieldEffectStop = 0x808583c | 1;
CreateTrainerSprite = 0x80859bc | 1;
FreeResourcesAndDestroySprite = 0x8085c44 | 1;
CreateFlyBirdSprite = 0x8088f60 | 1;
StartFlyBirdSwoopDown = 0x8088fc0 | 1;
SetFlyBirdPlayerSpriteId = 0x8088ffc | 1;
HandleItemUsePartyMenu = 0x808B0C0 | 1;
ReturnToBagFromPartyMenu = 0x808B224 | 1;
GetBadgeCount = 0x8094890 | 1;
GetPokedexSeenCount = 0x80948c4 | 1;
FormatPlayTime = 0x80948e4 | 1;
GetMonMove = 0x809f760 | 1;
GetMonMovePP = 0x809f798 | 1;
SummaryScreen_PlaceTextTile_White = 0x809fa74 | 1;
SummaryScreen_SetSpriteInvisibility = 0x80a1918 | 1;
SummaryScreen_DrawTypeIcon = 0x80a198c | 1;
GetMonStatusAndPokerus = 0x80a1cd8 | 1;
SummaryScreen_SetTextColor = 0x80a1e58 | 1;
SummaryScreen_CopyColoredString = 0x80a1e9c | 1;
SummaryScreen_PrintColoredText = 0x80a1ff8 | 1;
ItemIsMail = 0x80a2f2c | 1;
HideMapNamePopup = 0x80a30a4 | 1;
sub_80A37C0 = 0x80A37C0 | 1;
DrawSelectIcon = 0x80a4030 | 1;
MoveSelectIcon = 0x80a405c | 1;
EraseSelectIcon = 0x80a40ac | 1;
; RemoveSelectIconFromRegisteredItem = 0x80a40d0 | 1;
; AddSelectIconToRegisteredItem = 0x80a413c | 1;
sub_80A41D4 = 0x80A41D4 | 1;
HighlightSelectedOption = 0x80a425c | 1;
PrintCancelOption = 0x80a42b0 | 1;
ItemListMenu_InitMenu = 0x80a736c | 1;
sub_80A7528 = 0x80A7528 | 1;
CheckBagHasItem = 0x80a92d4 | 1;
RemoveBagItem = 0x80a9538 | 1;
SanitizeItemId = 0x80a98bc | 1;
ItemId_GetName = 0x80a98d4 | 1;
ItemId_GetHoldEffect = 0x80a993c | 1;
ItemId_GetHoldEffectParam = 0x80a9960 | 1;
ItemId_GetDescription = 0x80a9984 | 1;
ItemId_GetFieldFunc = 0x80a9a98 | 1;
DrawMultichoiceMenu = 0x80b5138 | 1;
CopyMapName = 0x80fbff8 | 1;
UpdateShadowFieldEffect = 0x8126d10 | 1;
SetSurfBlob_BobState = 0x8127ed0 | 1;
CB2_ShowDiploma = 0x8145d88 | 1;
Loading

0 comments on commit a9586eb

Please sign in to comment.