Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROM space on debug menu #3453

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions data/scripts/debug.inc
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,26 @@ Debug_CheckSaveBlock::
end

Debug_SaveBlock1Size::
.string "SaveBlock1 size: {STR_VAR_1}/{STR_VAR_2}.$"
.string "SaveBlock1 size: {STR_VAR_1}b/{STR_VAR_2}b.\n"
.string "Free space: {STR_VAR_3}b.$"

Debug_SaveBlock2Size::
.string "SaveBlock2 size: {STR_VAR_1}/{STR_VAR_2}.$"
.string "SaveBlock2 size: {STR_VAR_1}b/{STR_VAR_2}b.\n"
.string "Free space: {STR_VAR_3}b.$"

Debug_PokemonStorageSize::
.string "{PKMN}Storage size: {STR_VAR_1}/{STR_VAR_2}.$"
.string "{PKMN}Storage size: {STR_VAR_1}b/{STR_VAR_2}b.\n"
.string "Free space: {STR_VAR_3}b.$"

Debug_CheckROMSpace::
callnative CheckROMSize
msgbox Debug_ROMSize, MSGBOX_DEFAULT
release
end

Debug_ROMSize::
.string "ROM size: {STR_VAR_1}MB/32MB.\n"
.string "Free space: {STR_VAR_2}MB.$"

Debug_HatchAnEgg::
lockall
Expand Down
2 changes: 2 additions & 0 deletions ld_script.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,8 @@ SECTIONS {
data/*.o(.rodata);
} = 0

__rom_end = .;

/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
Expand Down
2 changes: 2 additions & 0 deletions ld_script_modern.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ SECTIONS {
src/graphics.o(.rodata);
} =0

__rom_end = .;

/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
Expand Down
2 changes: 2 additions & 0 deletions ld_script_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ SECTIONS {
test/*.o(.rodata*);
} =0

__rom_end = .;

/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
Expand Down
64 changes: 64 additions & 0 deletions src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ enum { // Util
DEBUG_UTIL_MENU_ITEM_WARP,
DEBUG_UTIL_MENU_ITEM_POISON_MONS,
DEBUG_UTIL_MENU_ITEM_SAVEBLOCK,
DEBUG_UTIL_MENU_ITEM_ROM_SPACE,
DEBUG_UTIL_MENU_ITEM_WEATHER,
DEBUG_UTIL_MENU_ITEM_CHECKWALLCLOCK,
DEBUG_UTIL_MENU_ITEM_SETWALLCLOCK,
Expand Down Expand Up @@ -303,6 +304,7 @@ static void DebugAction_Util_Warp_SelectWarp(u8 taskId);
static void DebugAction_FlagsVars_RunningShoes(u8 taskId);
static void DebugAction_Util_PoisonMons(u8 taskId);
static void DebugAction_Util_CheckSaveBlock(u8 taskId);
static void DebugAction_Util_CheckROMSpace(u8 taskId);
static void DebugAction_Util_Weather(u8 taskId);
static void DebugAction_Util_Weather_SelectId(u8 taskId);
static void DebugAction_Util_CheckWallClock(u8 taskId);
Expand Down Expand Up @@ -390,6 +392,7 @@ extern const u8 Debug_HatchAnEgg[];
extern const u8 PlayersHouse_2F_EventScript_SetWallClock[];
extern const u8 PlayersHouse_2F_EventScript_CheckWallClock[];
extern const u8 Debug_CheckSaveBlock[];
extern const u8 Debug_CheckROMSpace[];
extern const u8 Debug_BoxFilledMessage[];

#include "data/map_group_count.h"
Expand Down Expand Up @@ -432,6 +435,7 @@ static const u8 sDebugText_Util_WarpToMap_SelectWarp[] = _("Warp:{CLEAR_TO 90
static const u8 sDebugText_Util_WarpToMap_SelMax[] = _("{STR_VAR_1} / {STR_VAR_2}");
static const u8 sDebugText_Util_PoisonMons[] = _("Poison all mons");
static const u8 sDebugText_Util_SaveBlockSpace[] = _("SaveBlock Space…{CLEAR_TO 110}{RIGHT_ARROW}");
static const u8 sDebugText_Util_ROMSpace[] = _("ROM Space…{CLEAR_TO 110}{RIGHT_ARROW}");
static const u8 sDebugText_Util_Weather[] = _("Set weather…{CLEAR_TO 110}{RIGHT_ARROW}");
static const u8 sDebugText_Util_Weather_ID[] = _("Weather Id: {STR_VAR_3}\n{STR_VAR_1}\n{STR_VAR_2}");
static const u8 sDebugText_Util_CheckWallClock[] = _("Check Wall Clock…{CLEAR_TO 110}{RIGHT_ARROW}");
Expand Down Expand Up @@ -595,6 +599,7 @@ static const struct ListMenuItem sDebugMenu_Items_Utilities[] =
[DEBUG_UTIL_MENU_ITEM_WARP] = {sDebugText_Util_WarpToMap, DEBUG_UTIL_MENU_ITEM_WARP},
[DEBUG_UTIL_MENU_ITEM_POISON_MONS] = {sDebugText_Util_PoisonMons, DEBUG_UTIL_MENU_ITEM_POISON_MONS},
[DEBUG_UTIL_MENU_ITEM_SAVEBLOCK] = {sDebugText_Util_SaveBlockSpace, DEBUG_UTIL_MENU_ITEM_SAVEBLOCK},
[DEBUG_UTIL_MENU_ITEM_ROM_SPACE] = {sDebugText_Util_ROMSpace, DEBUG_UTIL_MENU_ITEM_ROM_SPACE},
[DEBUG_UTIL_MENU_ITEM_WEATHER] = {sDebugText_Util_Weather, DEBUG_UTIL_MENU_ITEM_WEATHER},
[DEBUG_UTIL_MENU_ITEM_CHECKWALLCLOCK] = {sDebugText_Util_CheckWallClock, DEBUG_UTIL_MENU_ITEM_CHECKWALLCLOCK},
[DEBUG_UTIL_MENU_ITEM_SETWALLCLOCK] = {sDebugText_Util_SetWallClock, DEBUG_UTIL_MENU_ITEM_SETWALLCLOCK},
Expand Down Expand Up @@ -728,6 +733,7 @@ static void (*const sDebugMenu_Actions_Utilities[])(u8) =
[DEBUG_UTIL_MENU_ITEM_WARP] = DebugAction_Util_Warp_Warp,
[DEBUG_UTIL_MENU_ITEM_POISON_MONS] = DebugAction_Util_PoisonMons,
[DEBUG_UTIL_MENU_ITEM_SAVEBLOCK] = DebugAction_Util_CheckSaveBlock,
[DEBUG_UTIL_MENU_ITEM_ROM_SPACE] = DebugAction_Util_CheckROMSpace,
[DEBUG_UTIL_MENU_ITEM_WEATHER] = DebugAction_Util_Weather,
[DEBUG_UTIL_MENU_ITEM_CHECKWALLCLOCK] = DebugAction_Util_CheckWallClock,
[DEBUG_UTIL_MENU_ITEM_SETWALLCLOCK] = DebugAction_Util_SetWallClock,
Expand Down Expand Up @@ -1800,6 +1806,7 @@ void CheckSaveBlock1Size(struct ScriptContext *ctx)
u32 maxSb1Size = SECTOR_DATA_SIZE * (SECTOR_ID_SAVEBLOCK1_END - SECTOR_ID_SAVEBLOCK1_START + 1);
ConvertIntToDecimalStringN(gStringVar1, currSb1Size, STR_CONV_MODE_LEFT_ALIGN, 6);
ConvertIntToDecimalStringN(gStringVar2, maxSb1Size, STR_CONV_MODE_LEFT_ALIGN, 6);
ConvertIntToDecimalStringN(gStringVar3, maxSb1Size - currSb1Size, STR_CONV_MODE_LEFT_ALIGN, 6);
}

void CheckSaveBlock2Size(struct ScriptContext *ctx)
Expand All @@ -1808,6 +1815,7 @@ void CheckSaveBlock2Size(struct ScriptContext *ctx)
u32 maxSb2Size = SECTOR_DATA_SIZE;
ConvertIntToDecimalStringN(gStringVar1, currSb2Size, STR_CONV_MODE_LEFT_ALIGN, 6);
ConvertIntToDecimalStringN(gStringVar2, maxSb2Size, STR_CONV_MODE_LEFT_ALIGN, 6);
ConvertIntToDecimalStringN(gStringVar3, maxSb2Size - currSb2Size, STR_CONV_MODE_LEFT_ALIGN, 6);
}

void CheckPokemonStorageSize(struct ScriptContext *ctx)
Expand All @@ -1816,6 +1824,7 @@ void CheckPokemonStorageSize(struct ScriptContext *ctx)
u32 maxPkmnStorageSize = SECTOR_DATA_SIZE * (SECTOR_ID_PKMN_STORAGE_END - SECTOR_ID_PKMN_STORAGE_START + 1);
ConvertIntToDecimalStringN(gStringVar1, currPkmnStorageSize, STR_CONV_MODE_LEFT_ALIGN, 6);
ConvertIntToDecimalStringN(gStringVar2, maxPkmnStorageSize, STR_CONV_MODE_LEFT_ALIGN, 6);
ConvertIntToDecimalStringN(gStringVar3, maxPkmnStorageSize - currPkmnStorageSize, STR_CONV_MODE_LEFT_ALIGN, 6);
}

static void DebugAction_Util_CheckSaveBlock(u8 taskId)
Expand All @@ -1825,6 +1834,61 @@ static void DebugAction_Util_CheckSaveBlock(u8 taskId)
ScriptContext_SetupScript(Debug_CheckSaveBlock);
}

enum RoundMode
{
ROUND_CEILING,
ROUND_NEAREST,
ROUND_FLOOR,
};

static u8 *ConvertQ22_10ToDecimalString(u8 *string, u32 q22_10, u32 decimalDigits, enum RoundMode roundMode)
{
string = ConvertIntToDecimalStringN(string, q22_10 >> 10, STR_CONV_MODE_LEFT_ALIGN, 10);

if (decimalDigits == 0)
return string;

*string++ = CHAR_PERIOD;

q22_10 &= (1 << 10) - 1;
while (decimalDigits-- > 1)
{
q22_10 *= 10;
*string++ = CHAR_0 + (q22_10 >> 10);
q22_10 &= (1 << 10) - 1;
}

q22_10 *= 10;
switch (roundMode)
{
case ROUND_CEILING: q22_10 += (1 << 10) - 1; break;
case ROUND_NEAREST: q22_10 += 1 << (10 - 1); break;
case ROUND_FLOOR: break;
}
*string++ = CHAR_0 + (q22_10 >> 10);

*string++ = EOS;

return string;
}

void CheckROMSize(struct ScriptContext *ctx)
{
extern u8 __rom_end[];
u32 currROMSizeB = __rom_end - (const u8 *)ROM_START;
u32 currROMSizeKB = (currROMSizeB + 1023) / 1024;
u32 currROMFreeKB = ((const u8 *)ROM_END - __rom_end) / 1024;
ConvertQ22_10ToDecimalString(gStringVar1, currROMSizeKB, 2, ROUND_CEILING);
ConvertQ22_10ToDecimalString(gStringVar2, currROMFreeKB, 2, ROUND_FLOOR);
}

static void DebugAction_Util_CheckROMSpace(u8 taskId)
{
Debug_DestroyMenu_Full(taskId);
LockPlayerFieldControls();
ScriptContext_SetupScript(Debug_CheckROMSpace);
}

static const u8 sWeatherNames[22][24] = {
[WEATHER_NONE] = _("NONE"),
[WEATHER_SUNNY_CLOUDS] = _("SUNNY CLOUDS"),
Expand Down
Loading