fix sub_80E8CB0

This commit is contained in:
PikalaxALT 2017-10-24 20:56:40 -04:00
parent 45479c14b6
commit eeecca9671

View File

@ -130,8 +130,6 @@ void sub_80E8C98(void)
gSpecialVar_0x8007 = sub_80E8BF8();
}
#ifdef NONMATCHING
// This function was refactored in some mysterious way
void sub_80E8CB0(s16 *xPtr, s16 *yPtr, u16 tile)
{
struct MapData *mapData;
@ -143,7 +141,7 @@ void sub_80E8CB0(s16 *xPtr, s16 *yPtr, u16 tile)
{
for (x = 0; x < mapData->width; x ++)
{
if ((mapData->map[y * mapData->width + x] % 0x400) == tile)
if ((mapData->map[y * mapData->width + x] & 0x3ff) == tile)
{
*xPtr = x;
*yPtr = y;
@ -152,90 +150,6 @@ void sub_80E8CB0(s16 *xPtr, s16 *yPtr, u16 tile)
}
}
}
#else
__attribute__((naked)) void sub_80E8CB0(s16 *xPtr, s16 *yPtr, u16 tile)
{
asm_unified("\tpush {r4-r7,lr}\n"
"\tmov r7, r10\n"
"\tmov r6, r9\n"
"\tmov r5, r8\n"
"\tpush {r5-r7}\n"
"\tsub sp, 0x8\n"
"\tstr r0, [sp]\n"
"\tstr r1, [sp, 0x4]\n"
"\tlsls r2, 16\n"
"\tlsrs r2, 16\n"
"\tmov r10, r2\n"
"\tldr r0, =gMapHeader\n"
"\tldr r0, [r0]\n"
"\tmov r8, r0\n"
"\tmovs r0, 0\n"
"\tmov r12, r0\n"
"\tmov r1, r8\n"
"\tldr r0, [r1, 0x4]\n"
"\tcmp r12, r0\n"
"\tbge _080E8D3C\n"
"\tldr r4, [r1]\n"
"_080E8CDA:\n"
"\tmovs r2, 0\n"
"\tmov r0, r12\n"
"\tlsls r7, r0, 16\n"
"\tcmp r2, r4\n"
"\tbge _080E8D28\n"
"\tasrs r0, r7, 16\n"
"\tadds r6, r0, 0\n"
"\tmuls r6, r4\n"
"\tmov r1, r8\n"
"\tldr r5, [r1, 0xC]\n"
"\tldr r0, =0x000003ff\n"
"\tmov r9, r0\n"
"_080E8CF2:\n"
"\tlsls r0, r2, 16\n"
"\tasrs r3, r0, 16\n"
"\tadds r0, r6, r3\n"
"\tlsls r0, 1\n"
"\tadds r0, r5\n"
"\tldrh r1, [r0]\n"
"\tmov r0, r9\n"
"\tands r0, r1\n"
"\tcmp r0, r10\n"
"\tbne _080E8D1C\n"
"\tldr r1, [sp]\n"
"\tstrh r2, [r1]\n"
"\tmov r0, r12\n"
"\tldr r2, [sp, 0x4]\n"
"\tstrh r0, [r2]\n"
"\tb _080E8D3C\n"
"\t.pool\n"
"_080E8D1C:\n"
"\tadds r0, r3, 0x1\n"
"\tlsls r0, 16\n"
"\tlsrs r2, r0, 16\n"
"\tasrs r0, 16\n"
"\tcmp r0, r4\n"
"\tblt _080E8CF2\n"
"_080E8D28:\n"
"\tmovs r2, 0x80\n"
"\tlsls r2, 9\n"
"\tadds r1, r7, r2\n"
"\tlsrs r0, r1, 16\n"
"\tmov r12, r0\n"
"\tasrs r1, 16\n"
"\tmov r2, r8\n"
"\tldr r0, [r2, 0x4]\n"
"\tcmp r1, r0\n"
"\tblt _080E8CDA\n"
"_080E8D3C:\n"
"\tadd sp, 0x8\n"
"\tpop {r3-r5}\n"
"\tmov r8, r3\n"
"\tmov r9, r4\n"
"\tmov r10, r5\n"
"\tpop {r4-r7}\n"
"\tpop {r0}\n"
"\tbx r0");
}
#endif
void sub_80E8D4C(void)
{