Skip to content

Commit d20fc55

Browse files
committed
Error Handler - draw the register names using sprintf
Also used variables to calculate the NewPosY increment amount after drawing the register values.
1 parent dc312b1 commit d20fc55

File tree

3 files changed

+20
-53
lines changed

3 files changed

+20
-53
lines changed

ttyd-tools/rel/include/assembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int32_t forceNPCItemDrop(void *ptr);
4141
void *fallThroughMostObjects(void *ptr);
4242

4343
// draw.cpp
44-
bool disableDPadOptionsDisplay(uint16_t unkVar);
44+
bool disableDPadOptionsDisplay(uint16_t unkVar);;
4545
void StartErrorHandlerInterrupts();
4646

4747
}

ttyd-tools/rel/include/global.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ struct ErrorHandlerStrings
800800
{
801801
#define MAX_LEVELS 32
802802
char ContextAddress[32];
803-
char RegisterValues[32][11];
803+
char GeneralRegisterValues[32][11];
804804
char AdditionalRegisterValues[6][11];
805805
char AddressList[MAX_LEVELS * 3][11];
806806
char InstructionAndAddress[128];

ttyd-tools/rel/source/draw.cpp

Lines changed: 18 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4746,48 +4746,13 @@ void Mod::errorHandler(uint16_t error, gc::OSContext::OSContext *context, uint32
47464746
"---- Context 0x%08" PRIX32 " ----",
47474747
reinterpret_cast<uint32_t>(context));
47484748

4749-
// Register names
4750-
static const char *RegisterNames[] =
4751-
{
4752-
"r0",
4753-
"r1",
4754-
"r2",
4755-
"r3",
4756-
"r4",
4757-
"r5",
4758-
"r6",
4759-
"r7",
4760-
"r8",
4761-
"r9",
4762-
"r10",
4763-
"r11",
4764-
"r12",
4765-
"r13",
4766-
"r14",
4767-
"r15",
4768-
"r16",
4769-
"r17",
4770-
"r18",
4771-
"r19",
4772-
"r20",
4773-
"r21",
4774-
"r22",
4775-
"r23",
4776-
"r24",
4777-
"r25",
4778-
"r26",
4779-
"r27",
4780-
"r28",
4781-
"r29",
4782-
"r30",
4783-
"r31",
4784-
};
4749+
// Get the general purpose register values
4750+
uint32_t GeneralRegistersSize = sizeof(ErrorHandler->GeneralRegisterValues) /
4751+
sizeof(ErrorHandler->GeneralRegisterValues[0]);
47854752

4786-
// Get the register values
4787-
uint32_t RegisterNamesSize = sizeof(RegisterNames) / sizeof(RegisterNames[0]);
4788-
for (uint32_t i = 0; i < RegisterNamesSize; i++)
4753+
for (uint32_t i = 0; i < GeneralRegistersSize; i++)
47894754
{
4790-
sprintf(ErrorHandler->RegisterValues[i],
4755+
sprintf(ErrorHandler->GeneralRegisterValues[i],
47914756
"0x%08" PRIX32,
47924757
context->gpr[i]);
47934758
}
@@ -5182,8 +5147,8 @@ void Mod::errorHandler(uint16_t error, gc::OSContext::OSContext *context, uint32
51825147
int32_t NewPosY = PosY;
51835148

51845149
// Draw the help text
5185-
const char *HelpText = "Press/hold the D-Pad to move the text\nPress A to zoom in\nPress B to zoom out";
5186-
drawString(NewPosX, NewPosY, HelpText, FontScale);
5150+
const char *Text = "Press/hold the D-Pad to move the text\nPress A to zoom in\nPress B to zoom out";
5151+
drawString(NewPosX, NewPosY, Text, FontScale);
51875152
NewPosY += PosYIncrementAmount * 4;
51885153

51895154
// Draw the register OSError if it is valid
@@ -5197,19 +5162,21 @@ void Mod::errorHandler(uint16_t error, gc::OSContext::OSContext *context, uint32
51975162
drawString(NewPosX, NewPosY, ErrorHandler->ContextAddress, FontScale);
51985163
NewPosY += PosYIncrementAmount;
51995164

5200-
// Draw the registers and values in 3 columns
5201-
uint32_t TotalRowsZeroIndexed = (RegisterNamesSize - 1) / 3;
5165+
// Draw the general purpose registers and values in 3 columns
5166+
uint32_t TotalRowsZeroIndexed = (GeneralRegistersSize - 1) / 3;
52025167
uint32_t Counter = 0;
52035168
int32_t tempPosX = NewPosX;
52045169
int32_t tempPosY = NewPosY;
52055170

5206-
for (uint32_t i = 0; i < RegisterNamesSize; i++)
5171+
char NameBuffer[4];
5172+
for (uint32_t i = 0; i < GeneralRegistersSize; i++)
52075173
{
5208-
// Draw the register names
5209-
drawString(tempPosX, tempPosY, RegisterNames[i], FontScale);
5174+
// Draw the general purpose register names
5175+
sprintf(NameBuffer, "r%" PRIu32, i);
5176+
drawString(tempPosX, tempPosY, NameBuffer, FontScale);
52105177

5211-
// Draw the register values
5212-
drawString(tempPosX + 40, tempPosY, ErrorHandler->RegisterValues[i], FontScale);
5178+
// Draw the general purpose register values
5179+
drawString(tempPosX + 40, tempPosY, ErrorHandler->GeneralRegisterValues[i], FontScale);
52135180

52145181
if (Counter >= TotalRowsZeroIndexed)
52155182
{
@@ -5224,7 +5191,7 @@ void Mod::errorHandler(uint16_t error, gc::OSContext::OSContext *context, uint32
52245191
Counter++;
52255192
}
52265193
}
5227-
NewPosY += (PosYIncrementAmount * 11) + PosYIncrementAmount;
5194+
NewPosY += (PosYIncrementAmount * TotalRowsZeroIndexed) + (PosYIncrementAmount * 2);
52285195

52295196
// Draw the additional registers and values in 2 columns
52305197
uint32_t SecondRowAdjustment = 0;
@@ -5263,7 +5230,7 @@ void Mod::errorHandler(uint16_t error, gc::OSContext::OSContext *context, uint32
52635230
Counter++;
52645231
}
52655232
}
5266-
NewPosY += (PosYIncrementAmount * 3) + PosYIncrementAmount;
5233+
NewPosY += (PosYIncrementAmount * TotalRowsZeroIndexed) + (PosYIncrementAmount * 2);
52675234

52685235
// Draw the names for the addresses, back chains, and LR saves in 3 columns
52695236
tempPosX = NewPosX;

0 commit comments

Comments
 (0)