Review changes.

Fixed taya_debug_window for good.
This commit is contained in:
Kaz 2020-08-18 04:38:42 -04:00
parent 7f94272bfa
commit 3d96e954c8
6 changed files with 52 additions and 308 deletions

View File

@ -1 +1 @@
261bec8dbd7159790cd5126bd47df5b5cef61ac1 pokesapphire_de_debug.gba
261bec8dbd7159790cd5126bd47df5b5cef61ac1 pokesapphire_de_debug.gba

View File

@ -684,36 +684,24 @@ void sub_80D3D68(u8 taskId)
case 0:
for (i = 0; i < task->data[4]; i++)
{
/*
It would be odd for the scanline buffers to follow ASM literal
and be initialized in reverse. Experimentation based upon how
compilers in general load variables and pointers showed that
they were initialized this way.
foo = bar = baz -> foo = (bar = baz)
*/
gScanlineEffectRegBuffers[0][i] =
gScanlineEffectRegBuffers[1][i] = task->data[2];
/* variable initialization isn't literal to ASM */
gScanlineEffectRegBuffers[0][i] = gScanlineEffectRegBuffers[1][i] = task->data[2];
}
for (i = task->data[4]; i < task->data[5]; i++)
{
gScanlineEffectRegBuffers[0][i] =
gScanlineEffectRegBuffers[1][i] = task->data[1];
gScanlineEffectRegBuffers[0][i] = gScanlineEffectRegBuffers[1][i] = task->data[1];
}
for (i = task->data[5]; i < 160; i++)
{
gScanlineEffectRegBuffers[0][i] =
gScanlineEffectRegBuffers[1][i] = task->data[2];
gScanlineEffectRegBuffers[0][i] = gScanlineEffectRegBuffers[1][i] = task->data[2];
}
if (task->data[4] == 0)
{
gScanlineEffectRegBuffers[0][i] =
gScanlineEffectRegBuffers[1][i] = task->data[1];
gScanlineEffectRegBuffers[0][i] = gScanlineEffectRegBuffers[1][i] = task->data[1];
}
else
{
gScanlineEffectRegBuffers[0][i] =
gScanlineEffectRegBuffers[1][i] = task->data[2];
gScanlineEffectRegBuffers[0][i] = gScanlineEffectRegBuffers[1][i] = task->data[2];
}
params.dmaDest = (vu16 *)REG_ADDR_BLDALPHA;
params.dmaControl = SCANLINE_EFFECT_DMACNT_16BIT;
@ -1313,63 +1301,16 @@ void sub_80D4D64(struct Sprite *sprite, s32 xDiff, s32 yDiff)
s16 randomSomethingY;
something = sprite->data[0] / 2;
// Without the weird hack? you are about to see below, regalloc acts funny here...
// regalloc acts strange here...
combinedX = sprite->pos1.x + sprite->pos2.x;
combinedY = sprite->pos1.y + sprite->pos2.y;
/*
Then goes back to normal at this exact point. Something must have existed here
that lined up regalloc properly. Whatever it was, it's not the traditional if
(0) or do {} while (0). Nor is it localvar++--. It's something completely obscene.
Upon random experiments, there was an observation about how parameters affected
regalloc in ways more bizarre than local variables. xDiff++; xDiff--; had actually
changed the regalloc immensely:
mov r2, #0x2e
ldrsh r1, [r0, r2]
lsr r2, r1, #0x1f
add r1, r1, r2
lsl r1, r1, #0xf
lsr r1, r1, #0x10
str r1, [sp]
ldrh r3, [r0, #0x24]
mov r8, r3
ldrh r1, [r0, #0x20]
add r8, r8, r1
mov r2, r8
lsl r2, r2, #0x10
lsr r2, r2, #0x10
mov r8, r2
ldrh r6, [r0, #0x26]
ldrh r0, [r0, #0x22]
add r6, r6, r0
lsl r6, r6, #0x10
lsr r6, r6, #0x10
compared to doing the same to a local variable, where there was no change at
all. It's more similar to the actual ASM, but not quite, telling us that
something did indeed poke xDiff, but not through mathematical statements.
The only ideal possibility to turn to in this situation now would be an if
statement.
*/
if (xDiff)
// ...then goes back to normal right here.
// Nothing but this appears to reproduce the behavior.
if (xDiff) // yDiff works too, but not sprite.
{
/*
if (xDiff) by itself won't match, so something needs to
be in here.
Virtually nothing what you are about to see is in the
assembly, you just have to to come up a strange variety
of compile time scenarios, question reality, and see if
something happens.
*/
// This absolutely needs to be a negation of some kind.
u8 unk = -unk; // ...this is what I came up with. It matches.
// i = -i; // This matches too. It might just work on any uninitialized.
u8 unk = -unk; // this can be any sort of negation
}
// by the way, yDiff works for the if case too, but oddly not sprite.
randomSomethingY = yDiff + (Random() % 10) - 5;
randomSomethingX = -xDiff + (Random() % 10) - 5;

View File

@ -5342,7 +5342,7 @@ static void atk23_getexp(void)
u16 calculatedExp;
s32 viaSentIn;
for (viaSentIn = 0, i = 0; i < 6; i++)
for (viaSentIn = 0, i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) == SPECIES_NONE || GetMonData(&gPlayerParty[i], MON_DATA_HP) == 0)
continue;
@ -5581,7 +5581,7 @@ static void atk24(void)
if (gBattleControllerExecFlags == 0)
{
for (i = 0; i < 6; i++)
for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) && !GetMonData(&gPlayerParty[i], MON_DATA_IS_EGG))
HP_count += GetMonData(&gPlayerParty[i], MON_DATA_HP);
@ -5590,7 +5590,7 @@ static void atk24(void)
if (HP_count == 0)
gBattleOutcome |= B_OUTCOME_LOST;
for (HP_count = 0, i = 0; i < 6; i++)
for (HP_count = 0, i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&gEnemyParty[i], MON_DATA_SPECIES) && !GetMonData(&gEnemyParty[i], MON_DATA_IS_EGG))
HP_count += GetMonData(&gEnemyParty[i], MON_DATA_HP);
@ -6993,7 +6993,7 @@ static void atk4F_jumpifcantswitch(void)
to_cmp = r7;
party = gPlayerParty;
}
for (val = 0; val < 6; val++)
for (val = 0; val < PARTY_SIZE; val++)
{
if (GetMonData(&party[val], MON_DATA_HP) != 0
&& GetMonData(&party[val], MON_DATA_SPECIES) != SPECIES_NONE
@ -8863,7 +8863,7 @@ static void atk61_drawpartystatussummary(void)
else
party = gEnemyParty;
for (i = 0; i < 6; i++)
for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&party[i], MON_DATA_SPECIES2) == 0 || GetMonData(&party[i], MON_DATA_SPECIES2) == SPECIES_EGG)
{
@ -10349,7 +10349,7 @@ static void atk8F_forcerandomswitch(void)
else
{
valid = 0;
for (i = 0; i < 6; i++)
for (i = 0; i < PARTY_SIZE; i++)
{
if (GetMonData(&party[i], MON_DATA_SPECIES) != SPECIES_NONE
&& !GetMonData(&party[i], MON_DATA_IS_EGG)
@ -12086,7 +12086,7 @@ static void atkAE_healpartystatus(void)
}
}
for (i = 0; i < 6; i++)
for (i = 0; i < PARTY_SIZE; i++)
{
u16 species = GetMonData(&party[i], MON_DATA_SPECIES2);
u8 abilityBit = GetMonData(&party[i], MON_DATA_ALT_ABILITY);
@ -12575,7 +12575,7 @@ static void atkC4_trydobeatup(void)
{
u8 beforeLoop = gBattleCommunication[0];
for (;gBattleCommunication[0] < 6; ++gBattleCommunication[0])
for (;gBattleCommunication[0] < PARTY_SIZE; ++gBattleCommunication[0])
{
if (GetMonData(&party[gBattleCommunication[0]], MON_DATA_HP)
&& GetMonData(&party[gBattleCommunication[0]], MON_DATA_SPECIES2)
@ -12583,7 +12583,7 @@ static void atkC4_trydobeatup(void)
&& !GetMonData(&party[gBattleCommunication[0]], MON_DATA_STATUS))
break;
}
if (gBattleCommunication[0] < 6)
if (gBattleCommunication[0] < PARTY_SIZE)
{
gBattleTextBuff1[0] = 0xFD;
gBattleTextBuff1[1] = 4;
@ -13176,7 +13176,7 @@ static void atkE4_getsecretpowereffect(void)
static void atkE5_pickup(void)
{
int i;
for (i = 0; i < 6; i++)
for (i = 0; i < PARTY_SIZE; i++)
{
u16 species = GetMonData(&gPlayerParty[i], MON_DATA_SPECIES2);
u16 held_item = GetMonData(&gPlayerParty[i], MON_DATA_HELD_ITEM);

View File

@ -439,8 +439,6 @@ void debug_sub_8090C44(void)
Menu_PrintText(eTayaLuckyNumber.charbuf, 1, 3);
}
#ifdef NONMATCHING
// haven't tested but should work
bool8 debug_sub_8090C88(void)
{
bool8 r8 = TRUE;
@ -509,186 +507,6 @@ bool8 debug_sub_8090C88(void)
debug_sub_8090C44();
return FALSE;
}
#else
NAKED bool8 debug_sub_8090C88(void)
{
asm("\tpush\t{r4, r5, r6, r7, lr}\n"
"\tmov\tr7, r8\n"
"\tpush\t{r7}\n"
"\tadd\tsp, sp, #0xfffffffc\n"
"\tmov\tr0, #0x1\n"
"\tmov\tr8, r0\n"
"\tldr\tr2, ._59 @ gMain\n"
"\tldrh\tr1, [r2, #0x2e]\n"
"\tmov\tr0, #0x20\n"
"\tand\tr0, r0, r1\n"
"\tadd\tr3, r2, #0\n"
"\tcmp\tr0, #0\n"
"\tbeq\t._57\t@cond_branch\n"
"\tldr\tr1, ._59 + 4 @ gSharedMem\n"
"\tldrb\tr0, [r1]\n"
"\tcmp\tr0, #0\n"
"\tbeq\t._57\t@cond_branch\n"
"\tsub\tr0, r0, #0x1\n"
"\tstrb\tr0, [r1]\n"
"\tb\t._62\n"
"._60:\n"
"\t.align\t2, 0\n"
"._59:\n"
"\t.word\tgMain\n"
"\t.word\tgSharedMem\n"
"._67:\n"
"\tadd\tr0, r0, #0x1\n"
"\tstrb\tr0, [r1]\n"
"\tb\t._62\n"
"._77:\n"
"\tstrh\tr1, [r7, #0x8]\n"
"\tb\t._62\n"
"._79:\n"
"\tldr\tr0, ._64 @ gSharedMem\n"
"\tldrh\tr0, [r0, #0x8]\n"
"\tbl\tSetLotteryNumber16_Unused\n"
"._78:\n"
"\tbl\tCloseMenu\n"
"\tmov\tr0, #0x1\n"
"\tb\t._63\n"
"._65:\n"
"\t.align\t2, 0\n"
"._64:\n"
"\t.word\tgSharedMem\n"
"._57:\n"
"\tldrh\tr1, [r3, #0x2e]\n"
"\tmov\tr0, #0x10\n"
"\tand\tr0, r0, r1\n"
"\tcmp\tr0, #0\n"
"\tbeq\t._66\t@cond_branch\n"
"\tldr\tr1, ._81 @ gSharedMem\n"
"\tldrb\tr0, [r1]\n"
"\tcmp\tr0, #0x3\n"
"\tbls\t._67\t@cond_branch\n"
"._66:\n"
"\tldrh\tr1, [r3, #0x30]\n"
"\tmov\tr0, #0x40\n"
"\tand\tr0, r0, r1\n"
"\tcmp\tr0, #0\n"
"\tbeq\t._68\t@cond_branch\n"
"\tldr\tr0, ._81 @ gSharedMem\n"
"\tldrh\tr1, [r0, #0x8]\n"
"\tstr\tr1, [r0, #0xc]\n"
"\tldr\tr1, ._81 + 4 @ 0x2710\n"
"\tstrh\tr1, [r0, #0x10]\n"
"\tmov\tr4, #0x0\n"
"\tldrb\tr1, [r0]\n"
"\tadd\tr7, r0, #0\n"
"\tcmp\tr4, r1\n"
"\tbcs\t._69\t@cond_branch\n"
"\tadd\tr5, r7, #0\n"
"\tadd\tr6, r1, #0\n"
"._70:\n"
"\tldrh\tr0, [r5, #0x10]\n"
"\tmov\tr1, #0xa\n"
"\tstr\tr3, [sp]\n"
"\tbl\t__udivsi3\n"
"\tstrh\tr0, [r5, #0x10]\n"
"\tadd\tr0, r4, #1\n"
"\tlsl\tr0, r0, #0x18\n"
"\tlsr\tr4, r0, #0x18\n"
"\tldr\tr3, [sp]\n"
"\tcmp\tr4, r6\n"
"\tbcc\t._70\t@cond_branch\n"
"._69:\n"
"\tldrh\tr1, [r7, #0x10]\n"
"\tldr\tr0, [r7, #0xc]\n"
"\tadd\tr0, r0, r1\n"
"\tstr\tr0, [r7, #0xc]\n"
"\tldr\tr1, ._81 + 8 @ 0xffff\n"
"\tcmp\tr0, r1\n"
"\tble\t._71\t@cond_branch\n"
"\tstr\tr1, [r7, #0xc]\n"
"._71:\n"
"\tldrh\tr0, [r7, #0x8]\n"
"\tldr\tr1, [r7, #0xc]\n"
"\tcmp\tr0, r1\n"
"\tbne\t._77\t@cond_branch\n"
"._68:\n"
"\tldrh\tr1, [r3, #0x30]\n"
"\tmov\tr0, #0x80\n"
"\tand\tr0, r0, r1\n"
"\tcmp\tr0, #0\n"
"\tbeq\t._73\t@cond_branch\n"
"\tldr\tr0, ._81 @ gSharedMem\n"
"\tldrh\tr1, [r0, #0x8]\n"
"\tstr\tr1, [r0, #0xc]\n"
"\tldr\tr1, ._81 + 4 @ 0x2710\n"
"\tstrh\tr1, [r0, #0x10]\n"
"\tmov\tr4, #0x0\n"
"\tldrb\tr1, [r0]\n"
"\tadd\tr7, r0, #0\n"
"\tcmp\tr4, r1\n"
"\tbcs\t._74\t@cond_branch\n"
"\tadd\tr5, r7, #0\n"
"\tadd\tr6, r1, #0\n"
"._75:\n"
"\tldrh\tr0, [r5, #0x10]\n"
"\tmov\tr1, #0xa\n"
"\tstr\tr3, [sp]\n"
"\tbl\t__udivsi3\n"
"\tstrh\tr0, [r5, #0x10]\n"
"\tadd\tr0, r4, #1\n"
"\tlsl\tr0, r0, #0x18\n"
"\tlsr\tr4, r0, #0x18\n"
"\tldr\tr3, [sp]\n"
"\tcmp\tr4, r6\n"
"\tbcc\t._75\t@cond_branch\n"
"._74:\n"
"\tadd\tr2, r7, #0\n"
"\tldrh\tr1, [r2, #0x10]\n"
"\tldr\tr0, [r2, #0xc]\n"
"\tsub\tr0, r0, r1\n"
"\tstr\tr0, [r2, #0xc]\n"
"\tcmp\tr0, #0\n"
"\tbge\t._76\t@cond_branch\n"
"\tmov\tr0, #0x0\n"
"\tstr\tr0, [r2, #0xc]\n"
"._76:\n"
"\tldrh\tr0, [r2, #0x8]\n"
"\tldr\tr1, [r2, #0xc]\n"
"\tcmp\tr0, r1\n"
"\tbne\t._77\t@cond_branch\n"
"._73:\n"
"\tldrh\tr2, [r3, #0x2e]\n"
"\tmov\tr0, #0x2\n"
"\tand\tr0, r0, r2\n"
"\tcmp\tr0, #0\n"
"\tbne\t._78\t@cond_branch\n"
"\tmov\tr0, #0x1\n"
"\tand\tr0, r0, r2\n"
"\tcmp\tr0, #0\n"
"\tbne\t._79\t@cond_branch\n"
"\tmov\tr0, #0x0\n"
"\tmov\tr8, r0\n"
"._62:\n"
"\tmov\tr0, r8\n"
"\tcmp\tr0, #0\n"
"\tbeq\t._80\t@cond_branch\n"
"\tbl\tdebug_sub_8090C44\n"
"._80:\n"
"\tmov\tr0, #0x0\n"
"._63:\n"
"\tadd\tsp, sp, #0x4\n"
"\tpop\t{r3}\n"
"\tmov\tr8, r3\n"
"\tpop\t{r4, r5, r6, r7}\n"
"\tpop\t{r1}\n"
"\tbx\tr1\n"
"._82:\n"
"\t.align\t2, 0\n"
"._81:\n"
"\t.word\tgSharedMem\n"
"\t.word\t0x2710\n"
"\t.word\t0xffff");
}
#endif // NONMATCHING
bool8 TayaDebugMenu_PKMNLottery(void)
{

View File

@ -1972,7 +1972,7 @@ u8 sub_809C664(void)
gotoBox = FALSE;
retVal = 0;
if (gMain.newAndRepeatedKeys & DPAD_UP)
if (JOY_REPT(DPAD_UP))
{
if (--cursorPosition < 0)
cursorPosition = 6;
@ -1981,7 +1981,7 @@ u8 sub_809C664(void)
break;
}
if (gMain.newAndRepeatedKeys & DPAD_DOWN)
if (JOY_REPT(DPAD_DOWN))
{
if (++cursorPosition > 6)
cursorPosition = 0;
@ -1990,7 +1990,7 @@ u8 sub_809C664(void)
break;
}
if (gMain.newAndRepeatedKeys & DPAD_LEFT && sBoxCursorPosition != 0)
if (JOY_REPT(DPAD_LEFT) && sBoxCursorPosition != 0)
{
retVal = 1;
gPokemonStorageSystemPtr->unk_11e2 = sBoxCursorPosition;
@ -1998,7 +1998,7 @@ u8 sub_809C664(void)
break;
}
if (gMain.newAndRepeatedKeys & DPAD_RIGHT)
if (JOY_REPT(DPAD_RIGHT))
{
if (sBoxCursorPosition == 0)
{
@ -2014,7 +2014,7 @@ u8 sub_809C664(void)
break;
}
if (gMain.newKeys & A_BUTTON)
if (JOY_NEW(A_BUTTON))
{
if (sBoxCursorPosition == 6)
{
@ -2044,7 +2044,7 @@ u8 sub_809C664(void)
}
}
if (gMain.newKeys & B_BUTTON)
if (JOY_NEW(B_BUTTON))
{
if (gPokemonStorageSystemPtr->unk_0005 == 1)
return 16;
@ -2060,7 +2060,7 @@ u8 sub_809C664(void)
break;
}
if (gMain.newKeys & SELECT_BUTTON)
if (JOY_NEW(SELECT_BUTTON))
{
sub_809CD88();
return 0;
@ -2087,7 +2087,7 @@ u8 sub_809C85C(void)
gPokemonStorageSystemPtr->unk_11de = 0;
gPokemonStorageSystemPtr->unk_11e3 = 0;
if (gMain.newAndRepeatedKeys & DPAD_UP)
if (JOY_REPT(DPAD_UP))
{
retVal = 1;
cursorArea = 3;
@ -2095,7 +2095,7 @@ u8 sub_809C85C(void)
gPokemonStorageSystemPtr->unk_11e3 = 1;
break;
}
else if (gMain.newAndRepeatedKeys & DPAD_DOWN)
else if (JOY_REPT(DPAD_DOWN))
{
retVal = 1;
cursorArea = 0;
@ -2116,17 +2116,17 @@ u8 sub_809C85C(void)
return 9;
}
if (gMain.newKeys & A_BUTTON)
if (JOY_NEW(A_BUTTON))
{
sub_809A860(FALSE);
sub_809CA8C();
return 7;
}
if (gMain.newKeys & B_BUTTON)
if (JOY_NEW(B_BUTTON))
return 16;
if (gMain.newKeys & SELECT_BUTTON)
if (JOY_NEW(SELECT_BUTTON))
{
sub_809CD88();
return 0;
@ -2159,7 +2159,7 @@ u8 sub_809C944(void)
gPokemonStorageSystemPtr->unk_11de = 0;
gPokemonStorageSystemPtr->unk_11e3 = 0;
if (gMain.newAndRepeatedKeys & DPAD_UP)
if (JOY_REPT(DPAD_UP))
{
retVal = 1;
cursorArea = 0;
@ -2172,7 +2172,7 @@ u8 sub_809C944(void)
break;
}
if (gMain.newAndRepeatedKeys & (DPAD_DOWN | START_BUTTON))
if (JOY_REPT(DPAD_DOWN | START_BUTTON))
{
retVal = 1;
cursorArea = 2;
@ -2181,7 +2181,7 @@ u8 sub_809C944(void)
break;
}
if (gMain.newAndRepeatedKeys & DPAD_LEFT)
if (JOY_REPT(DPAD_LEFT))
{
retVal = 1;
if (--cursorPosition < 0)
@ -2192,7 +2192,7 @@ u8 sub_809C944(void)
break;
}
if (gMain.newAndRepeatedKeys & DPAD_RIGHT)
if (JOY_REPT(DPAD_RIGHT))
{
retVal = 1;
if (++cursorPosition > 1)
@ -2203,12 +2203,12 @@ u8 sub_809C944(void)
break;
}
if (gMain.newKeys & A_BUTTON)
if (JOY_NEW(A_BUTTON))
return (cursorPosition == 0) ? 5 : 4;
if (gMain.newKeys & B_BUTTON)
if (JOY_NEW(B_BUTTON))
return 16;
if (gMain.newKeys & SELECT_BUTTON)
if (JOY_NEW(SELECT_BUTTON))
{
sub_809CD88();
return 0;
@ -2458,20 +2458,20 @@ s16 sub_809CF30(void)
do
{
if (!(gMain.newKeys & A_BUTTON))
if (!(JOY_NEW(A_BUTTON)))
{
if (gMain.newKeys & B_BUTTON)
if (JOY_NEW(B_BUTTON))
{
PlaySE(SE_SELECT);
textId++;
}
if (gMain.newKeys & DPAD_UP)
if (JOY_NEW(DPAD_UP))
{
PlaySE(SE_SELECT);
Menu_MoveCursor(-1);
}
else if (gMain.newKeys & DPAD_DOWN)
else if (JOY_NEW(DPAD_DOWN))
{
PlaySE(SE_SELECT);
Menu_MoveCursor(1);

View File

@ -687,29 +687,14 @@ void Pokeblock_BufferEnhancedStatText(u8 *dest, u8 statId, s16 enhanced)
{
if (enhanced)
{
/*
This is is a joke. One of the most absurd matches-- which may be
more real than fake! For absurd commentary on why this works, see
battle/anim/water.c, which does the same thing.
*/
if (enhanced > 0) enhanced = 0;
if (enhanced < 0)
{
/*
While "u8 var = -var" works, enhanced is an uninitialized, so
it can also be "enhanced = -enhanced". But not only can it be
"enhanced = -enhanced", it can also be
"enhanced = [any value]"
// This is a joke.
if (enhanced > 0)
enhanced = 0;
if (enhanced < 0)
// matches, but can also be a variety of values too
{ u8 unk = -unk; } // see water.c for a similar behavior
Rather. This was tested with the numbers 1, 5, -2, etc. As for
what may have been in the original source, it makes more sense
if enhanced had been set here. Multiple enhancement types for
Pokeblocks? Stupid error handling?
*/
u8 unk = -unk; // matches
// enhanced = any value here; // matches
}
StringCopy(dest, sContestStatNames[statId]);
StringAppend(dest, gOtherText_WasEnhanced);
}