1
0
mirror of https://github.com/zeldaret/oot.git synced 2024-09-21 04:24:43 +00:00

GameInfo -> RegEditor (#1354)

* -> `RegsContext* gRegsContext`

* Name regs-related functions

* Revert naming `GameState_UpdateRegs`

* -> `gRegEditor`

* `Regs_InitContext` -> `Regs_Init`

* remove mistakenly added file
This commit is contained in:
Dragorn421 2022-10-15 07:40:00 +02:00 committed by GitHub
parent d624733bf9
commit d1d946a197
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 60 additions and 65 deletions

View File

@ -160,15 +160,15 @@ on the address from the `D_address` containing the cutscene data.
## regconvert
This converts the direct memory references, of the form `gGameInfo->data[index]` or `gGameInfo + 0x<offset>`, into the corresponding REG macros defined in [regs.h](../include/regs.h). Run
This converts the direct memory references, of the form `gRegEditor->data[index]` or `gRegEditor + 0x<offset>`, into the corresponding REG macros defined in [regs.h](../include/regs.h). Run
```sh
./tools/regconvert.py <index>
```
if you have it in the form `gGameInfo->data[index]`, or
if you have it in the form `gRegEditor->data[index]`, or
```sh
./tools/regconvert.py --offset <offset>
```
if you have it in the form `gGameInfo + 0x<offset>`. You can also run it on a whole file using `--file <path/to/file>`.
if you have it in the form `gRegEditor + 0x<offset>`. You can also run it on a whole file using `--file <path/to/file>`.
## assist

View File

@ -774,12 +774,10 @@ s32 CollisionCheck_CylSideVsLineSeg(f32 radius, f32 height, f32 offset, Vec3f* a
u8 CollisionCheck_GetSwordDamage(s32 dmgFlags);
void SaveContext_Init(void);
s32 func_800635D0(s32);
void func_800636C0(void);
void Regs_Init(void);
void func_8006375C(s32 arg0, s32 arg1, const char* text);
void func_8006376C(u8 x, u8 y, u8 colorIndex, const char* text);
// ? func_80063828(?);
void func_8006390C(Input* input);
// ? func_80063C04(?);
void Regs_UpdateEditor(Input* input);
void func_80063D7C(GraphicsContext* gfxCtx);
void DebugDisplay_Init(void);
DebugDispObject* DebugDisplay_AddObject(f32 posX, f32 posY, f32 posZ, s16 rotX, s16 rotY, s16 rotZ, f32 scaleX,
@ -1522,11 +1520,9 @@ void AudioMgr_Unlock(AudioMgr* audioMgr);
void AudioMgr_Init(AudioMgr* audioMgr, void* stack, OSPri pri, OSId id, Scheduler* sched, IrqMgr* irqMgr);
void GameState_FaultPrint(void);
void GameState_SetFBFilter(Gfx** gfx);
// ? func_800C4344(?);
void GameState_DrawInputDisplay(u16 input, Gfx** gfx);
void GameState_Draw(GameState* gameState, GraphicsContext* gfxCtx);
void GameState_SetFrameBuffer(GraphicsContext* gfxCtx);
// ? func_800C49F4(?);
void GameState_ReqPadData(GameState* gameState);
void GameState_Update(GameState* gameState);
void GameState_InitArena(GameState* gameState, size_t size);
@ -2191,7 +2187,7 @@ void GameOver_Update(PlayState* play);
void Interface_Destroy(PlayState* play);
void Interface_Init(PlayState* play);
void Message_Init(PlayState* play);
void func_80112098(PlayState* play);
void Regs_InitData(PlayState* play);
void Setup_Init(GameState* thisx);
void Setup_Destroy(GameState* thisx);

View File

@ -6,7 +6,7 @@
#define REGS_PER_PAGE 16
#define REGS_PER_GROUP (REG_PAGES * REGS_PER_PAGE)
#define BASE_REG(n, r) gGameInfo->data[(n) * REGS_PER_GROUP + (r)]
#define BASE_REG(n, r) gRegEditor->data[(n) * REGS_PER_GROUP + (r)]
#define REG(r) BASE_REG(0, (r))
#define SREG(r) BASE_REG(1, (r))

View File

@ -173,7 +173,7 @@ extern u8 gSequenceTable[];
extern u8 gSampleBankTable[];
extern SaveContext gSaveContext;
extern GameInfo* gGameInfo;
extern RegEditor* gRegEditor;
extern u16 D_8015FCC0;
extern u16 D_8015FCC2;
extern u16 D_8015FCC4;

View File

@ -94,7 +94,7 @@ typedef struct {
/* 0x0C */ s32 dPadInputPrev;
/* 0x10 */ s32 inputRepeatTimer;
/* 0x14 */ s16 data[REG_GROUPS * REGS_PER_GROUP]; // Accessed through *REG macros, see regs.h
} GameInfo; // size = 0x15D4
} RegEditor; // size = 0x15D4
typedef struct {
/* 0x00000 */ u16 headMagic; // GFXPOOL_HEAD_MAGIC

View File

@ -84,7 +84,7 @@ void func_800C4344(GameState* gameState) {
}
if (gIsCtrlr2Valid) {
func_8006390C(&gameState->input[1]);
Regs_UpdateEditor(&gameState->input[1]);
}
gDmaMgrVerbose = HREG(60);

View File

@ -65,7 +65,7 @@ void Main(void* arg) {
}
osSyncPrintf("debug_InitArena(%08x, %08x)\n", debugHeapStart, debugHeapSize);
DebugArena_Init(debugHeapStart, debugHeapSize);
func_800636C0();
Regs_Init();
R_ENABLE_ARENA_DBG = 0;

View File

@ -191,7 +191,7 @@ void Message_Init(PlayState* play) {
YREG(31) = 0;
}
void func_80111070(void) {
void Regs_InitDataImpl(void) {
YREG(8) = 10;
YREG(14) = 0;
R_SCENE_CAM_TYPE = SCENE_CAM_TYPE_DEFAULT;
@ -602,6 +602,6 @@ void func_80111070(void) {
R_GAME_OVER_RUMBLE_DECREASE_RATE = -63;
}
void func_80112098(PlayState* play) {
func_80111070();
void Regs_InitData(PlayState* play) {
Regs_InitDataImpl();
}

View File

@ -12,7 +12,7 @@ typedef struct {
u16 press;
} InputCombo; // size = 0x4
GameInfo* gGameInfo;
RegEditor* gRegEditor;
PrintTextBufferEntry sDebugPrintTextBuffer[22];
s16 sDebugPrintTextBufferNumUsed = 0;
@ -92,18 +92,17 @@ char sRegGroupChars[REG_GROUPS] = {
'b', // bREG
};
// Initialize GameInfo
void func_800636C0(void) {
void Regs_Init(void) {
s32 i;
gGameInfo = SystemArena_MallocDebug(sizeof(GameInfo), "../z_debug.c", 260);
gGameInfo->regPage = 0;
gGameInfo->regGroup = 0;
gGameInfo->regCur = 0;
gGameInfo->dPadInputPrev = 0;
gGameInfo->inputRepeatTimer = 0;
for (i = 0; i < ARRAY_COUNT(gGameInfo->data); i++) {
gGameInfo->data[i] = 0;
gRegEditor = SystemArena_MallocDebug(sizeof(RegEditor), "../z_debug.c", 260);
gRegEditor->regPage = 0;
gRegEditor->regGroup = 0;
gRegEditor->regCur = 0;
gRegEditor->dPadInputPrev = 0;
gRegEditor->inputRepeatTimer = 0;
for (i = 0; i < ARRAY_COUNT(gRegEditor->data); i++) {
gRegEditor->data[i] = 0;
}
}
@ -154,9 +153,9 @@ void func_80063828(GfxPrint* printer) {
}
// Process inputs to control the reg editor
void func_8006390C(Input* input) {
void Regs_UpdateEditor(Input* input) {
s32 dPadInputCur;
s32 pageDataStart = ((gGameInfo->regGroup * REG_PAGES) + gGameInfo->regPage - 1) * REGS_PER_PAGE;
s32 pageDataStart = ((gRegEditor->regGroup * REG_PAGES) + gRegEditor->regPage - 1) * REGS_PER_PAGE;
s32 increment;
s32 i;
@ -173,16 +172,16 @@ void func_8006390C(Input* input) {
// If a combo corresponding to a reg group was found
if (i < REG_GROUPS) {
if (i == gGameInfo->regGroup) {
if (i == gRegEditor->regGroup) {
// Same reg group as current, advance page index
gGameInfo->regPage = (gGameInfo->regPage + 1) % (REG_PAGES + 1);
gRegEditor->regPage = (gRegEditor->regPage + 1) % (REG_PAGES + 1);
} else {
gGameInfo->regGroup = i; // Switch current reg group
gGameInfo->regPage = 0; // Disable reg editor
gRegEditor->regGroup = i; // Switch current reg group
gRegEditor->regPage = 0; // Disable reg editor
}
}
} else {
switch (gGameInfo->regPage) {
switch (gRegEditor->regPage) {
case 1:
case 2:
case 3:
@ -190,16 +189,16 @@ void func_8006390C(Input* input) {
case 5:
case 6:
if (dPadInputCur == gGameInfo->dPadInputPrev) {
gGameInfo->inputRepeatTimer--;
if (gGameInfo->inputRepeatTimer < 0) {
gGameInfo->inputRepeatTimer = 1;
if (dPadInputCur == gRegEditor->dPadInputPrev) {
gRegEditor->inputRepeatTimer--;
if (gRegEditor->inputRepeatTimer < 0) {
gRegEditor->inputRepeatTimer = 1;
} else {
dPadInputCur ^= gGameInfo->dPadInputPrev;
dPadInputCur ^= gRegEditor->dPadInputPrev;
}
} else {
gGameInfo->inputRepeatTimer = 16;
gGameInfo->dPadInputPrev = dPadInputCur;
gRegEditor->inputRepeatTimer = 16;
gRegEditor->dPadInputPrev = dPadInputCur;
}
increment =
@ -213,17 +212,17 @@ void func_8006390C(Input* input) {
: -1)
: 0;
gGameInfo->data[gGameInfo->regCur + pageDataStart] += increment;
gRegEditor->data[gRegEditor->regCur + pageDataStart] += increment;
if (CHECK_BTN_ANY(dPadInputCur, BTN_DUP)) {
gGameInfo->regCur--;
if (gGameInfo->regCur < 0) {
gGameInfo->regCur = REGS_PER_PAGE - 1;
gRegEditor->regCur--;
if (gRegEditor->regCur < 0) {
gRegEditor->regCur = REGS_PER_PAGE - 1;
}
} else if (CHECK_BTN_ANY(dPadInputCur, BTN_DDOWN)) {
gGameInfo->regCur++;
if (gGameInfo->regCur >= REGS_PER_PAGE) {
gGameInfo->regCur = 0;
gRegEditor->regCur++;
if (gRegEditor->regCur >= REGS_PER_PAGE) {
gRegEditor->regCur = 0;
}
}
@ -241,28 +240,28 @@ void func_8006390C(Input* input) {
}
// Draw the reg editor
void func_80063C04(GfxPrint* printer) {
void Regs_DrawEditor(GfxPrint* printer) {
s32 i;
s32 pageStart = (gGameInfo->regPage - 1) * REGS_PER_PAGE;
s32 pageDataStart = ((gGameInfo->regGroup * REG_PAGES) + gGameInfo->regPage - 1) * REGS_PER_PAGE;
s32 pageStart = (gRegEditor->regPage - 1) * REGS_PER_PAGE;
s32 pageDataStart = ((gRegEditor->regGroup * REG_PAGES) + gRegEditor->regPage - 1) * REGS_PER_PAGE;
s32 pad;
char regGroupName[3];
regGroupName[0] = 'R';
regGroupName[1] = sRegGroupChars[gGameInfo->regGroup];
regGroupName[1] = sRegGroupChars[gRegEditor->regGroup];
regGroupName[2] = '\0';
GfxPrint_SetColor(printer, 0, 128, 128, 128);
for (i = 0; i < REGS_PER_PAGE; i++) {
if (i == gGameInfo->regCur) {
if (i == gRegEditor->regCur) {
GfxPrint_SetColor(printer, 0, 255, 255, 255);
}
GfxPrint_SetPos(printer, 3, i + 5);
GfxPrint_Printf(printer, "%s%02d%6d", regGroupName, pageStart + i, gGameInfo->data[i + pageDataStart]);
GfxPrint_Printf(printer, "%s%02d%6d", regGroupName, pageStart + i, gRegEditor->data[i + pageDataStart]);
if (i == gGameInfo->regCur) {
if (i == gRegEditor->regCur) {
GfxPrint_SetColor(printer, 0, 128, 128, 128);
}
}
@ -286,8 +285,8 @@ void func_80063D7C(GraphicsContext* gfxCtx) {
func_80063828(&printer);
}
if (gGameInfo->regPage != 0) {
func_80063C04(&printer);
if (gRegEditor->regPage != 0) {
Regs_DrawEditor(&printer);
}
sDebugPrintTextBufferNumUsed = 0;

View File

@ -256,7 +256,7 @@ void Play_Init(GameState* thisx) {
this->activeCamId = CAM_ID_MAIN;
func_8005AC48(&this->mainCamera, 0xFF);
Sram_Init(this, &this->sramCtx);
func_80112098(this);
Regs_InitData(this);
Message_Init(this);
GameOver_Init(this);
SfxSource_InitAll(this);

View File

@ -29,7 +29,7 @@ def read_file(filename):
file_contents = src_file.read()
src_file.close()
pattern = re.compile("gGameInfo->data\[((0[xX])?[0-9a-fA-F]+)\]")
pattern = re.compile("gRegEditor->data\[((0[xX])?[0-9a-fA-F]+)\]")
match = pattern.search(file_contents)
while match:
@ -57,19 +57,19 @@ def check_valid_offset(offset):
return 0x14 <= offset <= 0x15D2
def main():
parser = argparse.ArgumentParser(description="Converts a gGameInfo->data index to a REG macro.")
parser = argparse.ArgumentParser(description="Converts a gRegEditor->data index to a REG macro.")
# TODO: Add a description and a better title
# index_group = parser.add_argument_group(title="index", description="")
index_group = parser.add_argument_group()
index_group.add_argument("index", help="index of gGameInfo->data in decimal (or hexadecimal if starts with 0x)")
index_group.add_argument("--offset", help="treat index argument as an offset to gGameInfo instead", action="store_true")
index_group.add_argument("index", help="index of gRegEditor->data in decimal (or hexadecimal if starts with 0x)")
index_group.add_argument("--offset", help="treat index argument as an offset to gRegEditor instead", action="store_true")
index_group.add_argument("--hex", help="treat index argument as hexadecimal, even without the 0x", action="store_true")
# TODO: Add a description and a better title
# file_group = parser.add_argument_group(title="file", description="")
file_group = parser.add_argument_group()
file_group.add_argument("--file", help="use the parameter as a filepath, then replace every occurrence of `gGameInfo->data[number]` in that file a REG macro", action="store_true")
file_group.add_argument("--file", help="use the parameter as a filepath, then replace every occurrence of `gRegEditor->data[number]` in that file a REG macro", action="store_true")
file_group.add_argument("--stdout", help="print the processed file to stdout instead of overwriting the original", action="store_true")
args = parser.parse_args()