1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-05-10 19:13:42 +00:00

Change linker script so gGameOverTimer can be in z_game_over.c (#1939)

* Change linker script so gGameOverTimer can be in z_game_over.c

* gGameOverTimer -> sGameOverTimer

* include_data_only_with_rodata -> include_data_only_within_rodata
This commit is contained in:
cadmic 2024-06-10 07:07:51 -07:00 committed by GitHub
parent e88084fe65
commit eb660765b1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 64 additions and 86 deletions

8
spec
View file

@ -597,8 +597,12 @@ beginseg
include "$(BUILD_DIR)/src/code/fmodf.o" include "$(BUILD_DIR)/src/code/fmodf.o"
include "$(BUILD_DIR)/src/code/__osMemset.o" include "$(BUILD_DIR)/src/code/__osMemset.o"
include "$(BUILD_DIR)/src/code/__osMemmove.o" include "$(BUILD_DIR)/src/code/__osMemmove.o"
include_data_with_rodata "$(BUILD_DIR)/src/code/z_message_PAL.o" // For some reason, the data sections of these files are placed here near the
include "$(BUILD_DIR)/src/code/z_game_over.o" // rodata sections of the other files
include_data_only_within_rodata "$(BUILD_DIR)/src/code/z_message_PAL.o"
include_data_only_within_rodata "$(BUILD_DIR)/src/code/z_game_over.o"
include_no_data "$(BUILD_DIR)/src/code/z_message_PAL.o"
include_no_data "$(BUILD_DIR)/src/code/z_game_over.o"
include "$(BUILD_DIR)/src/code/z_construct.o" include "$(BUILD_DIR)/src/code/z_construct.o"
include "$(BUILD_DIR)/data/audio_tables.rodata.o" include "$(BUILD_DIR)/data/audio_tables.rodata.o"
include "$(BUILD_DIR)/data/rsp.text.o" include "$(BUILD_DIR)/data/rsp.text.o"

View file

@ -13,8 +13,7 @@ void GameOver_FadeInLights(PlayState* play) {
} }
} }
// This variable cannot be moved into this file as all of z_message_PAL rodata is in the way s16 sGameOverTimer = 0;
extern s16 gGameOverTimer;
void GameOver_Update(PlayState* play) { void GameOver_Update(PlayState* play) {
GameOverContext* gameOverCtx = &play->gameOverCtx; GameOverContext* gameOverCtx = &play->gameOverCtx;
@ -74,7 +73,7 @@ void GameOver_Update(PlayState* play) {
gSaveContext.hudVisibilityModeTimer = 0; // false, HUD_VISIBILITY_NO_CHANGE gSaveContext.hudVisibilityModeTimer = 0; // false, HUD_VISIBILITY_NO_CHANGE
Environment_InitGameOverLights(play); Environment_InitGameOverLights(play);
gGameOverTimer = 20; sGameOverTimer = 20;
if (1) {} if (1) {}
rumbleStrength = R_GAME_OVER_RUMBLE_STRENGTH; rumbleStrength = R_GAME_OVER_RUMBLE_STRENGTH;
@ -92,9 +91,9 @@ void GameOver_Update(PlayState* play) {
break; break;
case GAMEOVER_DEATH_DELAY_MENU: case GAMEOVER_DEATH_DELAY_MENU:
gGameOverTimer--; sGameOverTimer--;
if (gGameOverTimer == 0) { if (sGameOverTimer == 0) {
play->pauseCtx.state = PAUSE_STATE_8; play->pauseCtx.state = PAUSE_STATE_8;
gameOverCtx->state++; gameOverCtx->state++;
Rumble_Reset(); Rumble_Reset();
@ -103,13 +102,13 @@ void GameOver_Update(PlayState* play) {
case GAMEOVER_REVIVE_START: case GAMEOVER_REVIVE_START:
gameOverCtx->state++; gameOverCtx->state++;
gGameOverTimer = 0; sGameOverTimer = 0;
Environment_InitGameOverLights(play); Environment_InitGameOverLights(play);
Letterbox_SetSizeTarget(32); Letterbox_SetSizeTarget(32);
return; return;
case GAMEOVER_REVIVE_RUMBLE: case GAMEOVER_REVIVE_RUMBLE:
gGameOverTimer = 50; sGameOverTimer = 50;
gameOverCtx->state++; gameOverCtx->state++;
if (1) {} if (1) {}
@ -123,28 +122,28 @@ void GameOver_Update(PlayState* play) {
break; break;
case GAMEOVER_REVIVE_WAIT_GROUND: case GAMEOVER_REVIVE_WAIT_GROUND:
gGameOverTimer--; sGameOverTimer--;
if (gGameOverTimer == 0) { if (sGameOverTimer == 0) {
gGameOverTimer = 64; sGameOverTimer = 64;
gameOverCtx->state++; gameOverCtx->state++;
} }
break; break;
case GAMEOVER_REVIVE_WAIT_FAIRY: case GAMEOVER_REVIVE_WAIT_FAIRY:
gGameOverTimer--; sGameOverTimer--;
if (gGameOverTimer == 0) { if (sGameOverTimer == 0) {
gGameOverTimer = 50; sGameOverTimer = 50;
gameOverCtx->state++; gameOverCtx->state++;
} }
break; break;
case GAMEOVER_REVIVE_FADE_OUT: case GAMEOVER_REVIVE_FADE_OUT:
Environment_FadeOutGameOverLights(play); Environment_FadeOutGameOverLights(play);
gGameOverTimer--; sGameOverTimer--;
if (gGameOverTimer == 0) { if (sGameOverTimer == 0) {
gameOverCtx->state = GAMEOVER_INACTIVE; gameOverCtx->state = GAMEOVER_INACTIVE;
} }
break; break;

View file

@ -3358,12 +3358,3 @@ void Message_SetTables(void) {
sFraMessageEntryTablePtr = sFraMessageEntryTable; sFraMessageEntryTablePtr = sFraMessageEntryTable;
sStaffMessageEntryTablePtr = sStaffMessageEntryTable; sStaffMessageEntryTablePtr = sStaffMessageEntryTable;
} }
#if OOT_DEBUG
// Appears to be file padding
UNK_TYPE D_80153D7C = 0x00000000;
#endif
// This should be part of z_game_over.c, but cannot be moved there as the entire
// late_rodata section of this file is in the way
s16 gGameOverTimer = 0;

View file

@ -42,10 +42,6 @@ static void write_ld_script(FILE *fout)
// initialized data (.text, .data, .rodata, .sdata) // initialized data (.text, .data, .rodata, .sdata)
// Increment the start of the section
//if (seg->fields & (1 << STMT_increment))
//fprintf(fout, " . += 0x%08X;\n", seg->increment);
fprintf(fout, " _%sSegmentRomStartTemp = _RomSize;\n" fprintf(fout, " _%sSegmentRomStartTemp = _RomSize;\n"
" _%sSegmentRomStart = _%sSegmentRomStartTemp;\n" " _%sSegmentRomStart = _%sSegmentRomStartTemp;\n"
" ..%s ", seg->name, seg->name, seg->name, seg->name); " ..%s ", seg->name, seg->name, seg->name, seg->name);
@ -68,10 +64,13 @@ static void write_ld_script(FILE *fout)
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
{ {
fprintf(fout, " %s (.text)\n", seg->includes[j].fpath); if (!seg->includes[j].dataOnlyWithinRodata)
if (seg->includes[j].linkerPadding != 0) {
fprintf(fout, " . += 0x%X;\n", seg->includes[j].linkerPadding); fprintf(fout, " %s (.text)\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n"); if (seg->includes[j].linkerPadding != 0)
fprintf(fout, " . += 0x%X;\n", seg->includes[j].linkerPadding);
fprintf(fout, " . = ALIGN(0x10);\n");
}
} }
fprintf(fout, " _%sSegmentTextEnd = .;\n", seg->name); fprintf(fout, " _%sSegmentTextEnd = .;\n", seg->name);
@ -82,20 +81,11 @@ static void write_ld_script(FILE *fout)
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
{ {
if (!seg->includes[j].dataWithRodata) if (!seg->includes[j].dataOnlyWithinRodata && !seg->includes[j].noData)
fprintf(fout, " %s (.data)\n" fprintf(fout, " %s (.data)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath); " . = ALIGN(0x10);\n", seg->includes[j].fpath);
} }
/*
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.rodata)\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.sdata)\n", seg->includes[j].fpath);
*/
//fprintf(fout, " . = ALIGN(0x10);\n");
fprintf(fout, " _%sSegmentDataEnd = .;\n", seg->name); fprintf(fout, " _%sSegmentDataEnd = .;\n", seg->name);
fprintf(fout, " _%sSegmentDataSize = ABSOLUTE( _%sSegmentDataEnd - _%sSegmentDataStart );\n", seg->name, seg->name, seg->name); fprintf(fout, " _%sSegmentDataSize = ABSOLUTE( _%sSegmentDataEnd - _%sSegmentDataStart );\n", seg->name, seg->name, seg->name);
@ -104,7 +94,7 @@ static void write_ld_script(FILE *fout)
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
{ {
if (seg->includes[j].dataWithRodata) if (seg->includes[j].dataOnlyWithinRodata)
fprintf(fout, " %s (.data)\n" fprintf(fout, " %s (.data)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath); " . = ALIGN(0x10);\n", seg->includes[j].fpath);
@ -116,11 +106,12 @@ static void write_ld_script(FILE *fout)
// the beginning of the entire rodata area in order to remain consistent. // the beginning of the entire rodata area in order to remain consistent.
// Inconsistencies will lead to various .rodata reloc crashes as a result of // Inconsistencies will lead to various .rodata reloc crashes as a result of
// either missing relocs or wrong relocs. // either missing relocs or wrong relocs.
fprintf(fout, " %s (.rodata)\n" if (!seg->includes[j].dataOnlyWithinRodata)
" %s (.rodata.str*)\n" fprintf(fout, " %s (.rodata)\n"
" %s (.rodata.cst*)\n" " %s (.rodata.str*)\n"
" . = ALIGN(0x10);\n", " %s (.rodata.cst*)\n"
seg->includes[j].fpath, seg->includes[j].fpath, seg->includes[j].fpath); " . = ALIGN(0x10);\n",
seg->includes[j].fpath, seg->includes[j].fpath, seg->includes[j].fpath);
} }
fprintf(fout, " _%sSegmentRoDataEnd = .;\n", seg->name); fprintf(fout, " _%sSegmentRoDataEnd = .;\n", seg->name);
@ -130,15 +121,17 @@ static void write_ld_script(FILE *fout)
fprintf(fout, " _%sSegmentSDataStart = .;\n", seg->name); fprintf(fout, " _%sSegmentSDataStart = .;\n", seg->name);
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.sdata)\n" if (!seg->includes[j].dataOnlyWithinRodata)
" . = ALIGN(0x10);\n", seg->includes[j].fpath); fprintf(fout, " %s (.sdata)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
fprintf(fout, " _%sSegmentSDataEnd = .;\n", seg->name); fprintf(fout, " _%sSegmentSDataEnd = .;\n", seg->name);
fprintf(fout, " _%sSegmentOvlStart = .;\n", seg->name); fprintf(fout, " _%sSegmentOvlStart = .;\n", seg->name);
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.ovl)\n", seg->includes[j].fpath); if (!seg->includes[j].dataOnlyWithinRodata)
fprintf(fout, " %s (.ovl)\n", seg->includes[j].fpath);
fprintf(fout, " _%sSegmentOvlEnd = .;\n", seg->name); fprintf(fout, " _%sSegmentOvlEnd = .;\n", seg->name);
@ -166,20 +159,24 @@ static void write_ld_script(FILE *fout)
seg->name, seg->name, seg->name, seg->name); seg->name, seg->name, seg->name, seg->name);
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.sbss)\n" if (!seg->includes[j].dataOnlyWithinRodata)
" . = ALIGN(0x10);\n", seg->includes[j].fpath); fprintf(fout, " %s (.sbss)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.scommon)\n" if (!seg->includes[j].dataOnlyWithinRodata)
" . = ALIGN(0x10);\n", seg->includes[j].fpath); fprintf(fout, " %s (.scommon)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (.bss)\n" if (!seg->includes[j].dataOnlyWithinRodata)
" . = ALIGN(0x10);\n", seg->includes[j].fpath); fprintf(fout, " %s (.bss)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
for (j = 0; j < seg->includesCount; j++) for (j = 0; j < seg->includesCount; j++)
fprintf(fout, " %s (COMMON)\n" if (!seg->includes[j].dataOnlyWithinRodata)
" . = ALIGN(0x10);\n", seg->includes[j].fpath); fprintf(fout, " %s (COMMON)\n"
" . = ALIGN(0x10);\n", seg->includes[j].fpath);
fprintf(fout, " . = ALIGN(0x10);\n" fprintf(fout, " . = ALIGN(0x10);\n"
" _%sSegmentBssEnd = .;\n" " _%sSegmentBssEnd = .;\n"
@ -187,25 +184,6 @@ static void write_ld_script(FILE *fout)
" }\n" " }\n"
" _%sSegmentBssSize = ABSOLUTE( _%sSegmentBssEnd - _%sSegmentBssStart );\n\n", " _%sSegmentBssSize = ABSOLUTE( _%sSegmentBssEnd - _%sSegmentBssStart );\n\n",
seg->name, seg->name, seg->name, seg->name, seg->name); seg->name, seg->name, seg->name, seg->name, seg->name);
// Increment the end of the segment
//if (seg->fields & (1 << STMT_increment))
//fprintf(fout, " . += 0x%08X;\n", seg->increment);
//fprintf(fout, " ..%s.ovl ADDR(..%s) + SIZEOF(..%s) :\n"
// /*" ..%s.bss :\n"*/
// " {\n",
// seg->name, seg->name, seg->name);
//fprintf(fout, " _%sSegmentOvlStart = .;\n", seg->name);
//for (j = 0; j < seg->includesCount; j++)
// fprintf(fout, " %s (.ovl)\n", seg->includes[j].fpath);
////fprintf(fout, " . = ALIGN(0x10);\n");
//fprintf(fout, " _%sSegmentOvlEnd = .;\n", seg->name);
//fprintf(fout, "\n }\n");
} }
fputs(" _RomEnd = _RomSize;\n\n", fout); fputs(" _RomEnd = _RomSize;\n\n", fout);

View file

@ -136,7 +136,8 @@ static const char *const stmtNames[] =
[STMT_entry] = "entry", [STMT_entry] = "entry",
[STMT_flags] = "flags", [STMT_flags] = "flags",
[STMT_include] = "include", [STMT_include] = "include",
[STMT_include_data_with_rodata] = "include_data_with_rodata", [STMT_include_data_only_within_rodata] = "include_data_only_within_rodata",
[STMT_include_no_data] = "include_no_data",
[STMT_name] = "name", [STMT_name] = "name",
[STMT_number] = "number", [STMT_number] = "number",
[STMT_romalign] = "romalign", [STMT_romalign] = "romalign",
@ -158,7 +159,8 @@ STMTId get_stmt_id_by_stmt_name(const char *stmtName, int lineNum) {
bool parse_segment_statement(struct Segment *currSeg, STMTId stmt, char* args, int lineNum) { bool parse_segment_statement(struct Segment *currSeg, STMTId stmt, char* args, int lineNum) {
// ensure no duplicates (except for 'include' or 'pad_text') // ensure no duplicates (except for 'include' or 'pad_text')
if (stmt != STMT_include && stmt != STMT_include_data_with_rodata && stmt != STMT_pad_text && if (stmt != STMT_include && stmt != STMT_include_data_only_within_rodata &&
stmt != STMT_include_no_data && stmt != STMT_pad_text &&
(currSeg->fields & (1 << stmt))) (currSeg->fields & (1 << stmt)))
util_fatal_error("line %i: duplicate '%s' statement", lineNum, stmtNames[stmt]); util_fatal_error("line %i: duplicate '%s' statement", lineNum, stmtNames[stmt]);
@ -211,7 +213,8 @@ bool parse_segment_statement(struct Segment *currSeg, STMTId stmt, char* args, i
util_fatal_error("line %i: alignment is not a power of two", lineNum); util_fatal_error("line %i: alignment is not a power of two", lineNum);
break; break;
case STMT_include: case STMT_include:
case STMT_include_data_with_rodata: case STMT_include_data_only_within_rodata:
case STMT_include_no_data:
currSeg->includesCount++; currSeg->includesCount++;
currSeg->includes = realloc(currSeg->includes, currSeg->includesCount * sizeof(*currSeg->includes)); currSeg->includes = realloc(currSeg->includes, currSeg->includesCount * sizeof(*currSeg->includes));
@ -219,7 +222,8 @@ bool parse_segment_statement(struct Segment *currSeg, STMTId stmt, char* args, i
util_fatal_error("line %i: invalid filename", lineNum); util_fatal_error("line %i: invalid filename", lineNum);
currSeg->includes[currSeg->includesCount - 1].linkerPadding = 0; currSeg->includes[currSeg->includesCount - 1].linkerPadding = 0;
currSeg->includes[currSeg->includesCount - 1].dataWithRodata = (stmt == STMT_include_data_with_rodata); currSeg->includes[currSeg->includesCount - 1].dataOnlyWithinRodata = (stmt == STMT_include_data_only_within_rodata);
currSeg->includes[currSeg->includesCount - 1].noData = (stmt == STMT_include_no_data);
break; break;
case STMT_increment: case STMT_increment:
if (!parse_number(args, &currSeg->increment)) if (!parse_number(args, &currSeg->increment))

View file

@ -14,7 +14,8 @@ typedef enum {
STMT_entry, STMT_entry,
STMT_flags, STMT_flags,
STMT_include, STMT_include,
STMT_include_data_with_rodata, STMT_include_data_only_within_rodata,
STMT_include_no_data,
STMT_name, STMT_name,
STMT_number, STMT_number,
STMT_romalign, STMT_romalign,
@ -34,7 +35,8 @@ enum {
struct Include { struct Include {
char* fpath; char* fpath;
int linkerPadding; int linkerPadding;
uint8_t dataWithRodata; bool dataOnlyWithinRodata;
bool noData;
}; };
typedef struct Segment { typedef struct Segment {