Merge remote-tracking branch 'pret/master' into pret-merge

This commit is contained in:
cawtds
2025-02-12 18:15:52 +01:00
48 changed files with 13073 additions and 12426 deletions

View File

@@ -470,7 +470,6 @@ $(ROM): $(ELF)
firered: ; @$(MAKE) GAME_VERSION=FIRERED
leafgreen: ; @$(MAKE) GAME_VERSION=LEAFGREEN
# Symbol file (`make syms`)
$(SYM): $(ELF)
$(OBJDUMP) -t $< | sort -u | grep -E "^0[2389]" | $(PERL) -p -e 's/^(\w{8}) (\w).{6} \S+\t(\w{8}) (\S+)$$/\1 \2 \3 \4/g' > $@

View File

@@ -48,7 +48,7 @@ TwoIsland_House_EventScript_AskTutorMon::
TwoIsland_House_EventScript_ChooseMonToTutor::
msgbox TwoIsland_House_Text_TutorWhichMon
special SelectMoveTutorMon
special ChooseMonForMoveRelearner
waitstate
goto_if_ge VAR_0x8004, PARTY_SIZE, TwoIsland_House_EventScript_EndTutorMove
special IsSelectedMonEgg
@@ -59,7 +59,7 @@ TwoIsland_House_EventScript_ChooseMonToTutor::
TwoIsland_House_EventScript_ChooseMoveToTeach::
msgbox TwoIsland_House_Text_TeachWhichMove
special DisplayMoveTutorMenu
special TeachMoveRelearnerMove
waitstate
goto_if_eq VAR_0x8004, 0, TwoIsland_House_EventScript_ChooseMonToTutor
goto_if_set HAS_BOTH_MUSHROOMS, TwoIsland_House_EventScript_ChooseMushroom

View File

@@ -234,12 +234,12 @@ gSpecials::
def_special GetElevatorFloor
def_special NullFieldSpecial @ Lottery Corner specials
def_special NullFieldSpecial
def_special SelectMoveTutorMon
def_special ChooseMonForMoveRelearner
def_special SelectMoveDeleterMove
def_special MoveDeleterForgetMove
def_special BufferMoveDeleterNicknameAndMove
def_special GetNumMovesSelectedMonHas
def_special DisplayMoveTutorMenu
def_special TeachMoveRelearnerMove
def_special NullFieldSpecial @ Hoenn Cycling Road specials
def_special NullFieldSpecial
def_special GetPlayerAvatarBike

3
include/constants/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
# Will be moved to build/ eventually
map_groups.h
layouts.h

View File

@@ -1039,7 +1039,7 @@ static const struct PokedudeBattlePartyInfo *const sPokedudeBattlePartyPointers[
[TTVSCR_CATCHING] = sParties_Catching,
};
struct PokedudeBattlerState *gPokedudeBattlerStates[MAX_BATTLERS_COUNT];
COMMON_DATA struct PokedudeBattlerState *gPokedudeBattlerStates[MAX_BATTLERS_COUNT] = {0};
static void PokedudeSimulateInputChooseAction(u32 battler)
{

View File

@@ -32,10 +32,10 @@ enum {
STATE_RETRY,
};
const void *gMultibootStart;
int gMultibootStatus;
size_t gMultibootSize;
struct MultiBootParam gMultibootParam;
COMMON_DATA const void *gMultibootStart = NULL;
COMMON_DATA int gMultibootStatus = 0;
COMMON_DATA size_t gMultibootSize = 0;
COMMON_DATA struct MultiBootParam gMultibootParam = {0};
static void CB2_BerryFix(void);
static void Task_BerryFixMain(u8 taskId);

View File

@@ -43,7 +43,7 @@ static struct BgConfig2 sGpuBgConfigs2[4];
static u32 sDmaBusyBitfield[4];
static u8 gpu_tile_allocation_map_bg[0x100];
bool32 gWindowTileAutoAllocEnabled;
COMMON_DATA bool32 gWindowTileAutoAllocEnabled = 0;
static const struct BgConfig sZeroedBgControlStruct = { 0 };

View File

@@ -28,7 +28,7 @@
#include "constants/field_weather.h"
#include "constants/maps.h"
u32 UnusedVarNeededToMatch[8];
COMMON_DATA u32 UnusedVarNeededToMatch[8] = {0};
static void Task_LinkupStart(u8 taskId);
static void Task_LinkupAwaitConnection(u8 taskId);

View File

@@ -41,7 +41,7 @@ struct EReaderData
static void Task_EReader(u8);
struct EReaderData gEReaderData;
COMMON_DATA struct EReaderData gEReaderData = {0};
extern const u8 gMultiBootProgram_EReader_Start[];
extern const u8 gMultiBootProgram_EReader_End[];

View File

@@ -11,8 +11,11 @@ static bool8 IsFlagOrVarStoredInQuestLog(u16 idx, u8 a1);
#define SPECIAL_FLAGS_SIZE (NUM_SPECIAL_FLAGS / 8) // 8 flags per byte
#define TEMP_FLAGS_SIZE (NUM_TEMP_FLAGS / 8)
#define DAILY_FLAGS_SIZE (NUM_DAILY_FLAGS / 8)
#define TEMP_VARS_SIZE (NUM_TEMP_VARS * 2) // 1/2 var per byte
#define NUM_DAILY_FLAGS (DAILY_FLAGS_END - DAILY_FLAGS_START + 1)
EWRAM_DATA u16 gSpecialVar_0x8000 = 0;
EWRAM_DATA u16 gSpecialVar_0x8001 = 0;
EWRAM_DATA u16 gSpecialVar_0x8002 = 0;
@@ -35,10 +38,7 @@ EWRAM_DATA u16 gSpecialVar_PrevTextColor = 0;
EWRAM_DATA u16 gSpecialVar_0x8014 = 0;
EWRAM_DATA u8 sSpecialFlags[SPECIAL_FLAGS_SIZE] = {};
#define NUM_DAILY_FLAGS (DAILY_FLAGS_END - DAILY_FLAGS_START + 1)
#define DAILY_FLAGS_SIZE (NUM_DAILY_FLAGS / 8)
u16 gLastQuestLogStoredFlagOrVarIdx;
COMMON_DATA u16 gLastQuestLogStoredFlagOrVarIdx = 0;
extern u16 *const gSpecialVars[];

View File

@@ -43,7 +43,7 @@ static EWRAM_DATA struct EvoInfo *sEvoStructPtr = NULL;
static EWRAM_DATA u16 *sBgAnimPal = NULL;
// IWRAM common
void (*gCB2_AfterEvolution)(void);
COMMON_DATA void (*gCB2_AfterEvolution)(void) = NULL;
#define sEvoCursorPos gBattleCommunication[1] // when learning a new move
#define sEvoGraphicsTaskId gBattleCommunication[2]

View File

@@ -56,8 +56,8 @@ static EWRAM_DATA struct FameCheckerData * sFameCheckerData = NULL;
static EWRAM_DATA struct ListMenuItem * sListMenuItems = NULL;
static EWRAM_DATA s32 sLastMenuIdx = 0;
struct ListMenuTemplate gFameChecker_ListMenuTemplate;
u8 gIconDescriptionBoxIsOpen;
COMMON_DATA struct ListMenuTemplate gFameChecker_ListMenuTemplate = {0};
COMMON_DATA u8 gIconDescriptionBoxIsOpen = 0;
static void MainCB2_LoadFameChecker(void);
static void LoadUISpriteSheetsAndPalettes(void);

View File

@@ -39,9 +39,9 @@ static s16 sVerticalCameraPan;
static u8 sBikeCameraPanFlag;
static void (*sFieldCameraPanningCallback)(void);
struct CameraObject gFieldCamera;
u16 gTotalCameraPixelOffsetY;
u16 gTotalCameraPixelOffsetX;
COMMON_DATA struct CameraObject gFieldCamera = {0};
COMMON_DATA u16 gTotalCameraPixelOffsetY = 0;
COMMON_DATA u16 gTotalCameraPixelOffsetX = 0;
// text
static void move_tilemap_camera_to_upper_left_corner_(struct FieldCameraOffset *cameraOffset)

View File

@@ -74,7 +74,7 @@ static void UpdateLetsGoEvolutionTracker(void);
static bool8 UpdatePoisonStepCounter(void);
#endif // OW_POISON_DAMAGE
struct FieldInput gFieldInputRecord;
COMMON_DATA struct FieldInput gFieldInputRecord = {0};
void FieldClearPlayerInput(struct FieldInput *input)
{

View File

@@ -57,8 +57,8 @@ static EWRAM_DATA u16 sListMenuLastScrollPosition = 0;
static EWRAM_DATA u8 sPCBoxToSendMon = 0;
static EWRAM_DATA u8 sBrailleTextCursorSpriteID = 0;
struct ListMenuTemplate sFieldSpecialsListMenuTemplate;
u16 sFieldSpecialsListMenuScrollBuffer;
COMMON_DATA struct ListMenuTemplate sFieldSpecialsListMenuTemplate = {0};
COMMON_DATA u16 sFieldSpecialsListMenuScrollBuffer = 0;
static void Task_AnimatePcTurnOn(u8 taskId);
static void PcTurnOnUpdateMetatileId(bool16 flag);

View File

@@ -15,7 +15,7 @@ struct ConnectionFlags
u8 east:1;
};
struct BackupMapLayout VMap;
COMMON_DATA struct BackupMapLayout VMap = {0};
EWRAM_DATA u16 ALIGNED(4) sBackupMapData[VIRTUAL_MAP_SIZE] = {0};
EWRAM_DATA struct MapHeader gMapHeader = {0};
EWRAM_DATA struct Camera gCamera = {0};

View File

@@ -51,8 +51,8 @@ struct HelpSystemState
u8 scrollSub;
};
struct HelpSystemState gHelpSystemState;
u16 gHelpContextIdBackup;
COMMON_DATA struct HelpSystemState gHelpSystemState = {0};
COMMON_DATA u16 gHelpContextIdBackup = 0;
static bool32 IsCurrentMapInArray(const u16 * mapIdxs);
static void BuildMainTopicsListAndMoveToH00(struct HelpSystemListMenu * a0, struct ListMenuItem * a1);

View File

@@ -10,7 +10,7 @@
#define ZERO 0
bool8 gHelpSystemEnabled;
COMMON_DATA bool8 gHelpSystemEnabled = 0;
struct HelpSystemVideoState
{

View File

@@ -364,7 +364,7 @@ static void VBlankCB_MoveRelearner(void)
TransferPlttBuffer();
}
void DisplayMoveTutorMenu(void)
void TeachMoveRelearnerMove(void)
{
LockPlayerFieldControls();
CreateTask(Task_InitMoveRelearnerMenu, 10);

View File

@@ -75,9 +75,9 @@ static u32 sRfuAPIBuffer[RFU_API_BUFF_SIZE_RAM / 4];
static u8 sResendBlock8[CMD_LENGTH * 2];
static u16 sResendBlock16[CMD_LENGTH];
struct RfuGameData gHostRfuGameData;
struct RfuManager gRfu;
u8 gHostRfuUsername[PLAYER_NAME_LENGTH + 1];
COMMON_DATA struct RfuGameData gHostRfuGameData = {0};
COMMON_DATA struct RfuManager gRfu = {0};
COMMON_DATA u8 gHostRfuUsername[PLAYER_NAME_LENGTH + 1] = {0};
static void InitChildRecvBuffers(void);
static void InitParentSendData(void);

View File

@@ -31,8 +31,8 @@ struct ListMenuOverride
static EWRAM_DATA struct MysteryGiftLinkMenuStruct sMysteryGiftLinkMenu = {0};
struct ListMenuOverride gListMenuOverride;
struct ListMenuTemplate gMultiuseListMenuTemplate;
COMMON_DATA struct ListMenuOverride gListMenuOverride = {0};
COMMON_DATA struct ListMenuTemplate gMultiuseListMenuTemplate = {0};
static u8 ListMenuInitInternal(const struct ListMenuTemplate *listMenuTemplate, u16 cursorPos, u16 itemsAbove);
static bool8 ListMenuChangeSelection(struct ListMenu *list, bool8 updateCursorAndCallCallback, u8 count, bool8 movingDown);

View File

@@ -37,11 +37,11 @@ EWRAM_DATA struct PokemonStorageASLR gPokemonStorage = {0};
EWRAM_DATA struct LoadedSaveData gLoadedSaveData = {0};
// IWRAM common
bool32 gFlashMemoryPresent = 0;
struct SaveBlock1 *gSaveBlock1Ptr = NULL;
struct SaveBlock2 *gSaveBlock2Ptr = NULL;
COMMON_DATA bool32 gFlashMemoryPresent = 0;
COMMON_DATA struct SaveBlock1 *gSaveBlock1Ptr = NULL;
COMMON_DATA struct SaveBlock2 *gSaveBlock2Ptr = NULL;
IWRAM_INIT struct SaveBlock3 *gSaveBlock3Ptr = &gSaveblock3;
struct PokemonStorage *gPokemonStoragePtr = NULL;
COMMON_DATA struct PokemonStorage *gPokemonStoragePtr = NULL;
void CheckForFlashMemory(void)
{

View File

@@ -109,14 +109,14 @@ static EWRAM_DATA s16 sCreditsOverworld_CmdIndex = 0;
EWRAM_DATA struct LinkPlayerObjectEvent gLinkPlayerObjectEvents[4] = {};
u16 *gBGTilemapBuffers1;
u16 *gBGTilemapBuffers2;
u16 *gBGTilemapBuffers3;
void (*gFieldCallback)(void);
bool8 (*gFieldCallback2)(void);
u16 gHeldKeyCodeToSend;
u8 gLocalLinkPlayerId;
u8 gFieldLinkPlayerCount;
COMMON_DATA u16 *gBGTilemapBuffers1 = NULL;
COMMON_DATA u16 *gBGTilemapBuffers2 = NULL;
COMMON_DATA u16 *gBGTilemapBuffers3 = NULL;
COMMON_DATA void (*gFieldCallback)(void) = NULL;
COMMON_DATA bool8 (*gFieldCallback2)(void) = NULL;
COMMON_DATA u16 gHeldKeyCodeToSend = 0;
COMMON_DATA u8 gLocalLinkPlayerId = 0;
COMMON_DATA u8 gFieldLinkPlayerCount = 0;
static u8 sPlayerLinkStates[MAX_LINK_PLAYERS];
static KeyInterCB sPlayerKeyInterceptCallback;

View File

@@ -442,7 +442,7 @@ static EWRAM_DATA u16 sEvBefore = 0;
static EWRAM_DATA u16 sEvAfter = 0;
void (*gItemUseCB)(u8, TaskFunc);
COMMON_DATA void (*gItemUseCB)(u8, TaskFunc) = NULL;
#include "data/party_menu.h"

View File

@@ -22,7 +22,7 @@ void ChoosePartyMon(void)
BeginNormalPaletteFade(PALETTES_ALL, 0, 0, 0x10, RGB_BLACK);
}
void SelectMoveTutorMon(void)
void ChooseMonForMoveRelearner(void)
{
u8 taskId;

View File

@@ -67,10 +67,10 @@ struct FlagOrVarRecord
u16 value;
};
u8 gQuestLogPlaybackState;
u16 sMaxActionsInScene;
struct FieldInput gQuestLogFieldInput;
struct QuestLogAction * sCurSceneActions;
COMMON_DATA u8 gQuestLogPlaybackState = 0;
COMMON_DATA u16 sMaxActionsInScene = 0;
COMMON_DATA struct FieldInput gQuestLogFieldInput = {0};
COMMON_DATA struct QuestLogAction * sCurSceneActions = NULL;
static struct FlagOrVarRecord * sFlagOrVarRecords;
static u16 sNumFlagsOrVars;

View File

@@ -5,8 +5,8 @@
#endif
// IWRAM common
rng_value_t gRngValue;
rng_value_t gRng2Value;
COMMON_DATA rng_value_t gRngValue = {0};
COMMON_DATA rng_value_t gRng2Value = {0};
EWRAM_DATA static volatile bool8 sRngLoopUnlocked;

View File

@@ -639,79 +639,79 @@ static const union AnimCmd *const sAnims_SwitchMapCursor[] = {
static const struct DungeonMapInfo sDungeonInfo[] = {
{
.id = MAPSEC_VIRIDIAN_FOREST,
.name = sMapsecName_VIRIDIANFOREST,
.name = sMapsecName_VIRIDIAN_FOREST,
.desc = gText_RegionMap_AreaDesc_ViridianForest
}, {
.id = MAPSEC_MT_MOON,
.name = sMapsecName_MTMOON,
.name = sMapsecName_MT__MOON,
.desc = gText_RegionMap_AreaDesc_MtMoon
}, {
.id = MAPSEC_DIGLETTS_CAVE,
.name = sMapsecName_DIGLETTSCAVE,
.name = sMapsecName_DIGLETT_S_CAVE,
.desc = gText_RegionMap_AreaDesc_DiglettsCave
}, {
.id = MAPSEC_KANTO_VICTORY_ROAD,
.name = sMapsecName_VICTORYROAD,
.name = sMapsecName_VICTORY_ROAD,
.desc = gText_RegionMap_AreaDesc_VictoryRoad
}, {
.id = MAPSEC_POKEMON_MANSION,
.name = sMapsecName_POKMONMANSION,
.name = sMapsecName_POK__MON_MANSION,
.desc = gText_RegionMap_AreaDesc_PokemonMansion
}, {
.id = MAPSEC_KANTO_SAFARI_ZONE,
.name = sMapsecName_SAFARIZONE,
.name = sMapsecName_SAFARI_ZONE,
.desc = gText_RegionMap_AreaDesc_SafariZone
}, {
.id = MAPSEC_ROCK_TUNNEL,
.name = sMapsecName_ROCKTUNNEL,
.name = sMapsecName_ROCK_TUNNEL,
.desc = gText_RegionMap_AreaDesc_RockTunnel
}, {
.id = MAPSEC_SEAFOAM_ISLANDS,
.name = sMapsecName_SEAFOAMISLANDS,
.name = sMapsecName_SEAFOAM_ISLANDS,
.desc = gText_RegionMap_AreaDesc_SeafoamIslands
}, {
.id = MAPSEC_POKEMON_TOWER,
.name = sMapsecName_POKMONTOWER,
.name = sMapsecName_POK__MON_TOWER,
.desc = gText_RegionMap_AreaDesc_PokemonTower
}, {
.id = MAPSEC_CERULEAN_CAVE,
.name = sMapsecName_CERULEANCAVE,
.name = sMapsecName_CERULEAN_CAVE,
.desc = gText_RegionMap_AreaDesc_CeruleanCave
}, {
.id = MAPSEC_POWER_PLANT,
.name = sMapsecName_POWERPLANT,
.name = sMapsecName_POWER_PLANT,
.desc = gText_RegionMap_AreaDesc_PowerPlant
}, {
.id = MAPSEC_MT_EMBER,
.name = sMapsecName_MTEMBER,
.name = sMapsecName_MT__EMBER,
.desc = gText_RegionMap_AreaDesc_MtEmber
}, {
.id = MAPSEC_BERRY_FOREST,
.name = sMapsecName_BERRYFOREST,
.name = sMapsecName_BERRY_FOREST,
.desc = gText_RegionMap_AreaDesc_BerryForest
}, {
.id = MAPSEC_ICEFALL_CAVE,
.name = sMapsecName_ICEFALLCAVE,
.name = sMapsecName_ICEFALL_CAVE,
.desc = gText_RegionMap_AreaDesc_IcefallCave
}, {
.id = MAPSEC_LOST_CAVE,
.name = sMapsecName_LOSTCAVE,
.name = sMapsecName_LOST_CAVE,
.desc = gText_RegionMap_AreaDesc_LostCave
}, {
.id = MAPSEC_TANOBY_CHAMBERS,
.name = sMapsecName_TANOBYCHAMBERS,
.name = sMapsecName_TANOBY_CHAMBERS,
.desc = gText_RegionMap_AreaDesc_TanobyRuins
}, {
.id = MAPSEC_ALTERING_CAVE,
.name = sMapsecName_ALTERINGCAVE,
.name = sMapsecName_ALTERING_CAVE,
.desc = gText_RegionMap_AreaDesc_AlteringCave
}, {
.id = MAPSEC_PATTERN_BUSH,
.name = sMapsecName_PATTERNBUSH,
.name = sMapsecName_PATTERN_BUSH,
.desc = gText_RegionMap_AreaDesc_PatternBush
}, {
.id = MAPSEC_DOTTED_HOLE,
.name = sMapsecName_DOTTEDHOLE,
.name = sMapsecName_DOTTED_HOLE,
.desc = gText_RegionMap_AreaDesc_DottedHole
}
};
@@ -3793,7 +3793,7 @@ u8 *GetMapName(u8 *dst0, u16 mapsec, u16 fill)
if ((idx = mapsec - MAPSECS_KANTO) <= MAPSEC_SPECIAL_AREA - MAPSECS_KANTO)
{
if (IsCeladonDeptStoreMapsec(mapsec) == TRUE)
dst = StringCopy(dst0, sMapsecName_CELADONDEPT);
dst = StringCopy(dst0, sMapsecName_CELADON_DEPT_);
else
dst = StringCopy(dst0, sMapNames[idx]);
}

View File

@@ -84,18 +84,18 @@ STATIC_ASSERT(sizeof(struct SaveBlock1) <= SECTOR_DATA_SIZE * (SECTOR_ID_SAVEBLO
STATIC_ASSERT(sizeof(struct PokemonStorage) <= SECTOR_DATA_SIZE * (SECTOR_ID_PKMN_STORAGE_END - SECTOR_ID_PKMN_STORAGE_START + 1), PokemonStorageFreeSpace);
// Sector num to begin writing save data. Sectors are rotated each time the game is saved. (possibly to avoid wear on flash memory?)
u16 gLastWrittenSector;
u32 gLastSaveCounter;
u16 gLastKnownGoodSector;
u32 gDamagedSaveSectors;
u32 gSaveCounter;
struct SaveSector *gReadWriteSector; // the pointer is in fast IWRAM but points to the slower EWRAM.
u16 gIncrementalSectorId;
u16 gSaveUnusedVar;
u16 gSaveFileStatus;
void (*gGameContinueCallback)(void);
struct SaveSectorLocation gRamSaveSectorLocations[NUM_SECTORS_PER_SLOT];
u16 gSaveAttemptStatus;
COMMON_DATA u16 gLastWrittenSector = 0;
COMMON_DATA u32 gLastSaveCounter = 0;
COMMON_DATA u16 gLastKnownGoodSector = 0;
COMMON_DATA u32 gDamagedSaveSectors = 0;
COMMON_DATA u32 gSaveCounter = 0;
COMMON_DATA struct SaveSector *gReadWriteSector = NULL; // the pointer is in fast IWRAM but points to the slower EWRAM.
COMMON_DATA u16 gIncrementalSectorId = 0;
COMMON_DATA u16 gSaveUnusedVar = 0;
COMMON_DATA u16 gSaveFileStatus = 0;
COMMON_DATA void (*gGameContinueCallback)(void) = NULL;
COMMON_DATA struct SaveSectorLocation gRamSaveSectorLocations[NUM_SECTORS_PER_SLOT] = {0};
COMMON_DATA u16 gSaveAttemptStatus = 0;
EWRAM_DATA struct SaveSector gSaveDataBuffer = {0};
EWRAM_DATA u32 gSaveUnusedVar2 = 0;

View File

@@ -12,7 +12,7 @@
#include "save.h"
#include "strings.h"
bool32 sIsInSaveFailedScreen;
COMMON_DATA bool32 sIsInSaveFailedScreen = 0;
static EWRAM_DATA u16 sSaveType = SAVE_NORMAL;
static EWRAM_DATA u8 sSaveFailedScreenState = 0;

View File

@@ -68,8 +68,8 @@ static EWRAM_DATA u16 sFieldEffectScriptId = 0;
static bool8 sIsScriptedWildDouble;
struct ScriptContext * sQuestLogScriptContextPtr;
u8 gSelectedObjectEvent;
COMMON_DATA struct ScriptContext * sQuestLogScriptContextPtr = NULL;
COMMON_DATA u8 gSelectedObjectEvent = 0;
// This is defined in here so the optimizer can't see its value when compiling
// script.c.

View File

@@ -32,7 +32,7 @@ static u8 sMapMusicFadeInSpeed;
static u16 sFanfareCounter;
// iwram common
bool8 gDisableMusic;
COMMON_DATA bool8 gDisableMusic = 0;
extern u32 gBattleTypeFlags;
extern struct MusicPlayerInfo gMPlayInfo_BGM;

View File

@@ -277,8 +277,8 @@ static u16 sSpriteTileRanges[MAX_SPRITES * 2];
static struct AffineAnimState sAffineAnimStates[OAM_MATRIX_COUNT];
static u16 sSpritePaletteTags[16];
u32 gOamMatrixAllocBitmap;
u8 gReservedSpritePaletteCount;
COMMON_DATA u32 gOamMatrixAllocBitmap = 0;
COMMON_DATA u8 gReservedSpritePaletteCount = 0;
EWRAM_DATA struct Sprite gSprites[MAX_SPRITES + 1] = {0};
EWRAM_DATA static u8 sSpriteOrder[MAX_SPRITES] = {0};

View File

@@ -4,7 +4,7 @@
#define HEAD_SENTINEL 0xFE
#define TAIL_SENTINEL 0xFF
struct Task gTasks[NUM_TASKS];
COMMON_DATA struct Task gTasks[NUM_TASKS] = {0};
static void InsertTask(u8 newTaskId);
static u8 FindFirstActiveTask();

View File

@@ -69,9 +69,9 @@ static u16 sLastTextBgColor;
static u16 sLastTextFgColor;
static u16 sLastTextShadowColor;
const struct FontInfo *gFonts;
struct GlyphInfo gGlyphInfo;
TextFlags gTextFlags;
COMMON_DATA const struct FontInfo *gFonts = NULL;
COMMON_DATA struct GlyphInfo gGlyphInfo = {0};
COMMON_DATA TextFlags gTextFlags = {0};
static const u8 sFontHalfRowOffsets[] =
{
@@ -93,7 +93,7 @@ static const u8 sFontHalfRowOffsets[] =
0x00, 0x01, 0x02, 0x00, 0x03, 0x04, 0x05, 0x03, 0x06, 0x07, 0x08, 0x06, 0x00, 0x01, 0x02, 0x00
};
static const u8 sDownArrowTiles[] = INCBIN_U8("graphics/fonts/down_arrows.4bpp");
static const u8 sDownArrowTiles[] = INCBIN_U8("graphics/fonts/down_arrows.4bpp");
static const u8 sDoubleArrowTiles1[] = INCBIN_U8("graphics/fonts/down_arrow_3.4bpp");
static const u8 sDoubleArrowTiles2[] = INCBIN_U8("graphics/fonts/down_arrow_4.4bpp");

View File

@@ -6,8 +6,8 @@
#include "window.h"
u8 gTransparentTileNumber;
void *gWindowBgTilemapBuffers[NUM_BACKGROUNDS];
COMMON_DATA u8 gTransparentTileNumber;
COMMON_DATA void *gWindowBgTilemapBuffers[NUM_BACKGROUNDS];
EWRAM_DATA struct Window gWindows[WINDOWS_MAX] = {0};
EWRAM_DATA static struct Window* sWindowPtr = NULL;

0
tools/jsonproc/.gitignore vendored Normal file → Executable file
View File

14
tools/jsonproc/Makefile Normal file → Executable file
View File

@@ -1,6 +1,6 @@
CXX := g++
CXX ?= g++
CXXFLAGS := -Wall -std=c++11 -O2
CXXFLAGS := -Wall -std=c++17 -O2
INCLUDES := -I .
@@ -8,12 +8,18 @@ SRCS := jsonproc.cpp
HEADERS := jsonproc.h inja.hpp nlohmann/json.hpp
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
.PHONY: all clean
all: jsonproc
all: jsonproc$(EXE)
@:
jsonproc: $(SRCS) $(HEADERS)
jsonproc$(EXE): $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(INCLUDES) $(SRCS) -o $@ $(LDFLAGS)
clean:

5462
tools/jsonproc/inja.hpp Normal file → Executable file

File diff suppressed because it is too large Load Diff

18
tools/jsonproc/jsonproc.cpp Normal file → Executable file
View File

@@ -1,4 +1,6 @@
// jsonproc.cpp
// jsonproc converts JSON data to an output file based on an Inja template.
// https://github.com/pantor/inja
#include "jsonproc.h"
@@ -7,6 +9,9 @@
#include <string>
using std::string; using std::to_string;
#include <algorithm>
using std::replace_if;
#include <inja.hpp>
using namespace inja;
using json = nlohmann::json;
@@ -109,11 +114,16 @@ int main(int argc, char *argv[])
});
env.add_callback("cleanString", 1, [](Arguments& args) {
string badChars = ".'{} \n\t-_\u00e9";
string str = args.at(0)->get<string>();
str.erase(remove_if(str.begin(), str.end(), [&badChars](const char &c) {
return badChars.find(c) != std::string::npos;
}), str.end());
for (unsigned int i = 0; i < str.length(); i++) {
// This code is not Unicode aware, so UTF-8 is not easily parsable without introducing
// another library. Just filter out any non-alphanumeric characters for now.
// TODO: proper Unicode string normalization
if ((i == 0 && isdigit(str[i]))
|| !isalnum(str[i])) {
str[i] = '_';
}
}
return str;
});

0
tools/jsonproc/jsonproc.h Normal file → Executable file
View File

19586
tools/jsonproc/nlohmann/json.hpp Normal file → Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,4 @@
CXX := g++
CXX ?= g++
CXXFLAGS := -std=c++11 -O2 -Wall -Wno-switch -Werror
@@ -6,12 +6,18 @@ SRCS := agb.cpp error.cpp main.cpp midi.cpp tables.cpp
HEADERS := agb.h error.h main.h midi.h tables.h
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
.PHONY: all clean
all: mid2agb
all: mid2agb$(EXE)
@:
mid2agb: $(SRCS) $(HEADERS)
mid2agb$(EXE): $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS)
clean:

View File

@@ -702,14 +702,12 @@ int AsmFile::FindLastLineNumber(std::string& filename)
if (pos < 0)
RaiseError("line indicator for header file not found before `enum`");
pos++;
while (m_buffer[pos] == ' ' || m_buffer[pos] == '\t')
pos++;
if (!IsAsciiDigit(m_buffer[pos]))
RaiseError("malformatted line indicator found before `enum`, expected line number");
unsigned n = 0;
int digit = 0;
while ((digit = ConvertDigit(m_buffer[pos++], 10)) != -1)
@@ -744,7 +742,6 @@ int AsmFile::FindLastLineNumber(std::string& filename)
filename += c;
}
return n + linebreaks - 1;
}

View File

@@ -1,4 +1,4 @@
CXX := g++
CXX ?= g++
CXXFLAGS := -std=c++11 -O2 -Wall -Wno-switch -Werror
@@ -8,10 +8,16 @@ HEADERS := ramscrgen.h sym_file.h elf.h char_util.h
.PHONY: all clean
all: ramscrgen
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
all: ramscrgen$(EXE)
@:
ramscrgen: $(SRCS) $(HEADERS)
ramscrgen$(EXE): $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(SRCS) -o $@ $(LDFLAGS)
clean:

View File

@@ -1,7 +1,6 @@
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <map>
#include <vector>
#include <string>
#include "ramscrgen.h"
@@ -22,6 +21,7 @@ static int s_shstrtabIndex;
static std::uint32_t s_symtabOffset;
static std::uint32_t s_strtabOffset;
static std::uint32_t s_pseudoCommonSectionIndex;
static std::uint32_t s_symbolCount;
static std::uint32_t s_elfFileOffset;
@@ -101,18 +101,6 @@ static void VerifyElfIdent()
FATAL_ERROR("error: \"%s\" not little-endian ELF\n", s_elfPath.c_str());
}
static void VerifyAr()
{
char expectedMagic[8] = {'!', '<', 'a', 'r', 'c', 'h', '>', '\n'};
char magic[8];
if (std::fread(magic, 8, 1, s_file) != 1)
FATAL_ERROR("error: failed to read AR magic from \"%s\"\n", s_archiveFilePath.c_str());
if (std::memcmp(magic, expectedMagic, 8) != 0)
FATAL_ERROR("error: AR magic did not match in \"%s\"\n", s_archiveFilePath.c_str());
}
static void ReadElfHeader()
{
Seek(0x20);
@@ -123,40 +111,6 @@ static void ReadElfHeader()
s_shstrtabIndex = ReadInt16();
}
static void FindArObj()
{
char file_ident[17] = {0};
char filesize_s[11] = {0};
char expectedEndMagic[2] = { 0x60, 0x0a };
char end_magic[2];
std::size_t filesize;
Seek(8);
while (!std::feof(s_file)) {
if (std::fread(file_ident, 16, 1, s_file) != 1)
FATAL_ERROR("error: failed to read file ident in \"%s\"\n", s_archiveFilePath.c_str());
Skip(32);
if (std::fread(filesize_s, 10, 1, s_file) != 1)
FATAL_ERROR("error: failed to read filesize in \"%s\"\n", s_archiveFilePath.c_str());
if (std::fread(end_magic, 2, 1, s_file) != 1)
FATAL_ERROR("error: failed to read end sentinel in \"%s\"\n", s_archiveFilePath.c_str());
if (std::memcmp(end_magic, expectedEndMagic, 2) != 0)
FATAL_ERROR("error: corrupted archive header in \"%s\" at \"%s\"\n", s_archiveFilePath.c_str(), file_ident);
char * ptr = std::strchr(file_ident, '/');
if (ptr != nullptr)
*ptr = 0;
filesize = std::strtoul(filesize_s, nullptr, 10);
if (std::strncmp(s_archiveObjectPath.c_str(), file_ident, 16) == 0) {
s_elfFileOffset = std::ftell(s_file);
return;
}
Skip(filesize);
}
FATAL_ERROR("error: could not find object \"%s\" in archive \"%s\"\n", s_archiveObjectPath.c_str(), s_archiveFilePath.c_str());
}
static std::string GetSectionName(std::uint32_t shstrtabOffset, int index)
{
Seek(s_sectionHeaderOffset + s_sectionHeaderEntrySize * index);
@@ -169,6 +123,7 @@ static void FindTableOffsets()
{
s_symtabOffset = 0;
s_strtabOffset = 0;
s_pseudoCommonSectionIndex = 0;
Seek(s_sectionHeaderOffset + s_sectionHeaderEntrySize * s_shstrtabIndex + 0x10);
std::uint32_t shstrtabOffset = ReadInt32();
@@ -192,6 +147,11 @@ static void FindTableOffsets()
FATAL_ERROR("error: mutiple .strtab sections found in \"%s\"\n", s_elfPath.c_str());
Seek(s_sectionHeaderOffset + s_sectionHeaderEntrySize * i + 0x10);
s_strtabOffset = ReadInt32();
} else if (name == "common_data") {
if (s_pseudoCommonSectionIndex) {
FATAL_ERROR("error: mutiple common_data sections found in \"%s\"\n", s_elfPath.c_str());
}
s_pseudoCommonSectionIndex = i;
}
}
@@ -202,65 +162,50 @@ static void FindTableOffsets()
FATAL_ERROR("error: couldn't find .strtab section in \"%s\"\n", s_elfPath.c_str());
}
static std::map<std::string, std::uint32_t> GetCommonSymbols_Shared()
static std::vector<std::pair<std::string, std::uint32_t>> GetCommonSymbols_Shared()
{
VerifyElfIdent();
ReadElfHeader();
FindTableOffsets();
std::map<std::string, std::uint32_t> commonSymbols;
std::vector<std::pair<std::string, std::uint32_t>> commonSymbols;
std::vector<Symbol> commonSymbolVec;
Seek(s_symtabOffset);
for (std::uint32_t i = 0; i < s_symbolCount; i++)
{
Symbol sym;
sym.nameOffset = ReadInt32();
Skip(4);
sym.size = ReadInt32();
Skip(2);
std::uint16_t sectionIndex = ReadInt16();
if (sectionIndex == SHN_COMMON)
commonSymbolVec.push_back(sym);
}
for (const Symbol& sym : commonSymbolVec)
{
Seek(s_strtabOffset + sym.nameOffset);
std::string name = ReadString();
commonSymbols[name] = sym.size;
if (s_pseudoCommonSectionIndex) {
std::vector<Symbol> commonSymbolVec;
Seek(s_symtabOffset);
for (std::uint32_t i = 0; i < s_symbolCount; i++)
{
Symbol sym;
sym.nameOffset = ReadInt32();
Skip(4);
sym.size = ReadInt32();
Skip(2);
std::uint16_t sectionIndex = ReadInt16();
if (sectionIndex == s_pseudoCommonSectionIndex)
commonSymbolVec.push_back(sym);
}
for (const Symbol& sym : commonSymbolVec)
{
Seek(s_strtabOffset + sym.nameOffset);
std::string name = ReadString();
if (name == "$d" || name == "") {
continue;
}
commonSymbols.emplace_back(name, sym.size);
}
}
return commonSymbols;
}
std::map<std::string, std::uint32_t> GetCommonSymbolsFromLib(std::string sourcePath, std::string libpath)
{
std::size_t colonPos = libpath.find(':');
if (colonPos == std::string::npos)
FATAL_ERROR("error: missing colon separator in libfile \"%s\"\n", s_elfPath.c_str());
s_archiveObjectPath = libpath.substr(colonPos + 1);
s_archiveFilePath = sourcePath + "/" + libpath.substr(1, colonPos - 1);
s_elfPath = sourcePath + "/" + libpath.substr(1);
s_file = std::fopen(s_archiveFilePath.c_str(), "rb");
if (s_file == NULL)
FATAL_ERROR("error: failed to open \"%s\" for reading\n", s_archiveFilePath.c_str());
VerifyAr();
FindArObj();
return GetCommonSymbols_Shared();
}
std::map<std::string, std::uint32_t> GetCommonSymbols(std::string sourcePath, std::string path)
std::vector<std::pair<std::string, std::uint32_t>> GetCommonSymbols(std::string sourcePath, std::string path)
{
s_elfFileOffset = 0;
if (path[0] == '*')
return GetCommonSymbolsFromLib(sourcePath, path);
FATAL_ERROR("error: library common syms are unsupported (filename: \"%s\")\n", path.c_str());
s_elfPath = sourcePath + "/" + path;
s_file = std::fopen(s_elfPath.c_str(), "rb");

View File

@@ -22,9 +22,9 @@
#define ELF_H
#include <cstdint>
#include <map>
#include <vector>
#include <string>
std::map<std::string, std::uint32_t> GetCommonSymbols(std::string sourcePath, std::string path);
std::vector<std::pair<std::string, std::uint32_t>> GetCommonSymbols(std::string sourcePath, std::string path);
#endif // ELF_H

View File

@@ -28,54 +28,19 @@
void HandleCommonInclude(std::string filename, std::string sourcePath, std::string symOrderPath, std::string lang)
{
auto commonSymbols = GetCommonSymbols(sourcePath, filename);
std::size_t dotIndex;
if (filename[0] == '*') {
dotIndex = filename.find_last_of(':');
filename = filename.substr(dotIndex + 1);
}
dotIndex = filename.find_last_of('.');
if (dotIndex == std::string::npos)
FATAL_ERROR("error: \"%s\" doesn't have a file extension\n", filename.c_str());
std::string symOrderFilename = filename.substr(0, dotIndex + 1) + "txt";
SymFile symFile(symOrderPath + "/" + symOrderFilename);
while (!symFile.IsAtEnd())
for (const auto& commonSym : commonSymbols)
{
symFile.HandleLangConditional(lang);
unsigned long size = commonSym.second;
std::string label = symFile.GetLabel(false);
if (label.length() == 0)
{
unsigned long length;
if (symFile.ReadInteger(length))
{
if (length & 3)
symFile.RaiseWarning("gap length %d is not multiple of 4", length);
printf(". += 0x%lX;\n", length);
}
}
else
{
if (commonSymbols.count(label) == 0)
symFile.RaiseError("no common symbol named \"%s\"", label.c_str());
unsigned long size = commonSymbols[label];
int alignment = 4;
if (size > 4)
alignment = 8;
if (size > 8)
alignment = 16;
printf(". = ALIGN(%d);\n", alignment);
printf("%s = .;\n", label.c_str());
printf(". += 0x%lX;\n", size);
}
symFile.ExpectEmptyRestOfLine();
int alignment = 4;
if (size > 4)
alignment = 8;
if (size > 8)
alignment = 16;
printf(". = ALIGN(%d);\n", alignment);
printf("%s = .;\n", commonSym.first.c_str());
printf(". += 0x%lX;\n", size);
}
}