Merge pull request #410 from DizzyEggg/will_i_match_sth_again

match 2 field functions
This commit is contained in:
Diegoisawesome 2018-11-29 17:46:30 -06:00 committed by GitHub
commit 275ce5deff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 277 deletions

View file

@ -1547,150 +1547,35 @@ void WaitFieldEffectSpriteAnim(struct Sprite *sprite)
UpdateEventObjectSpriteVisibility(sprite, FALSE);
}
#ifdef NONMATCHING
static void sub_81561FC(struct Sprite *sprite /*r6*/, u8 z, u8 offset)
static void sub_81561FC(struct Sprite *sprite, u8 z, u8 offset)
{
u8 i;
s16 xlo;
s16 xhi;
s16 lx;
s16 lyhi;
s16 ly;
s16 ylo;
s16 yhi;
struct EventObject *eventObject; // r4
const struct EventObjectGraphicsInfo *graphicsInfo; // destroyed
struct Sprite *linkedSprite; // r5
s16 var, xhi, lyhi, yhi, ylo;
const struct EventObjectGraphicsInfo *graphicsInfo; // Unused Variable
struct Sprite *linkedSprite;
SetObjectSubpriorityByZCoord(z, sprite, offset);
for (i = 0; i < 16; i ++)
for (i = 0; i < EVENT_OBJECTS_COUNT; i ++)
{
eventObject = &gEventObjects[i];
struct EventObject *eventObject = &gEventObjects[i];
if (eventObject->active)
{
graphicsInfo = GetEventObjectGraphicsInfo(eventObject->graphicsId);
linkedSprite = &gSprites[eventObject->spriteId];
xhi = sprite->pos1.x + sprite->centerToCornerVecX;
xlo = sprite->pos1.x - sprite->centerToCornerVecX;
lx = linkedSprite->pos1.x;
if (xhi < lx && xlo > lx)
var = sprite->pos1.x - sprite->centerToCornerVecX;
if (xhi < linkedSprite->pos1.x && var > linkedSprite->pos1.x)
{
lyhi = linkedSprite->pos1.y + linkedSprite->centerToCornerVecY;
ly = linkedSprite->pos1.y;
var = linkedSprite->pos1.y;
ylo = sprite->pos1.y - sprite->centerToCornerVecY;
yhi = ylo + linkedSprite->centerToCornerVecY;
if ((lyhi < yhi || lyhi < ylo) && ly > yhi)
if ((lyhi < yhi || lyhi < ylo) && var > yhi && sprite->subpriority <= linkedSprite->subpriority)
{
if (sprite->subpriority <= linkedSprite->subpriority)
{
sprite->subpriority = linkedSprite->subpriority + 2;
break;
}
sprite->subpriority = linkedSprite->subpriority + 2;
break;
}
}
}
}
}
#else
NAKED void sub_81561FC(struct Sprite *sprite /*r6*/, u8 z, u8 offset)
{
asm_unified("push {r4-r7,lr}\n\
adds r6, r0, 0\n\
adds r0, r1, 0\n\
lsls r0, 24\n\
lsrs r0, 24\n\
lsls r2, 24\n\
lsrs r2, 24\n\
adds r1, r6, 0\n\
bl SetObjectSubpriorityByZCoord\n\
movs r7, 0\n\
_08156212:\n\
lsls r0, r7, 3\n\
adds r0, r7\n\
lsls r0, 2\n\
ldr r1, =gEventObjects\n\
adds r4, r0, r1\n\
ldrb r0, [r4]\n\
lsls r0, 31\n\
cmp r0, 0\n\
beq _081562B4\n\
ldrb r0, [r4, 0x5]\n\
bl GetEventObjectGraphicsInfo\n\
ldrb r1, [r4, 0x4]\n\
lsls r0, r1, 4\n\
adds r0, r1\n\
lsls r0, 2\n\
ldr r1, =gSprites\n\
adds r5, r0, r1\n\
adds r0, r6, 0\n\
adds r0, 0x28\n\
movs r2, 0\n\
ldrsb r2, [r0, r2]\n\
ldrh r0, [r6, 0x20]\n\
adds r1, r0, r2\n\
subs r0, r2\n\
lsls r0, 16\n\
lsrs r4, r0, 16\n\
lsls r1, 16\n\
asrs r1, 16\n\
movs r0, 0x20\n\
ldrsh r2, [r5, r0]\n\
cmp r1, r2\n\
bge _081562B4\n\
lsls r0, r4, 16\n\
asrs r0, 16\n\
cmp r0, r2\n\
ble _081562B4\n\
adds r0, r5, 0\n\
adds r0, 0x29\n\
movs r3, 0\n\
ldrsb r3, [r0, r3]\n\
ldrh r2, [r5, 0x22]\n\
adds r2, r3\n\
ldrh r4, [r5, 0x22]\n\
adds r0, r6, 0\n\
adds r0, 0x29\n\
movs r1, 0\n\
ldrsb r1, [r0, r1]\n\
ldrh r0, [r6, 0x22]\n\
subs r0, r1\n\
lsls r0, 16\n\
asrs r0, 16\n\
adds r3, r0, r3\n\
lsls r2, 16\n\
asrs r2, 16\n\
lsls r3, 16\n\
asrs r3, 16\n\
cmp r2, r3\n\
blt _0815628C\n\
cmp r2, r0\n\
bge _081562B4\n\
_0815628C:\n\
lsls r0, r4, 16\n\
asrs r0, 16\n\
cmp r0, r3\n\
ble _081562B4\n\
adds r2, r6, 0\n\
adds r2, 0x43\n\
adds r0, r5, 0\n\
adds r0, 0x43\n\
ldrb r1, [r0]\n\
ldrb r0, [r2]\n\
cmp r0, r1\n\
bhi _081562B4\n\
adds r0, r1, 0x2\n\
strb r0, [r2]\n\
b _081562BE\n\
.pool\n\
_081562B4:\n\
adds r0, r7, 0x1\n\
lsls r0, 24\n\
lsrs r7, r0, 24\n\
cmp r7, 0xF\n\
bls _08156212\n\
_081562BE:\n\
pop {r4-r7}\n\
pop {r0}\n\
bx r0");
}
#endif

View file

@ -1709,8 +1709,18 @@ const u8 *const gElevatorFloorsTable[] = {
gText_Rooftop
};
const u16 gUnknown_085B2BF4[] = { 0x0329, 0x032a, 0x032b, 0x0331, 0x0332, 0x0333, 0x0339, 0x033a, 0x033b };
const u16 gUnknown_085B2C06[] = { 0x0329, 0x032b, 0x032a, 0x0331, 0x0333, 0x0332, 0x0339, 0x033b, 0x033a };
const u16 gUnknown_085B2BF4[][3] =
{
{0x0329, 0x032a, 0x032b},
{0x0331, 0x0332, 0x0333},
{0x0339, 0x033a, 0x033b},
};
const u16 gUnknown_085B2C06[][3] =
{
{0x0329, 0x032b, 0x032a},
{0x0331, 0x0333, 0x0332},
{0x0339, 0x033b, 0x033a},
};
void SetDepartmentStoreFloorVar(void)
{
@ -1866,9 +1876,6 @@ static void sub_8139C2C(u16 a1, u8 a2)
}
}
// Annoyingly close but compiler wants to add all the parts of the index into the arrays
// first and then shift by one, whereas we need each individual part to shift and then be added.
#ifdef NONMATCHING
static void sub_8139C80(u8 taskId)
{
u8 x, y;
@ -1883,7 +1890,7 @@ static void sub_8139C80(u8 taskId)
{
for (x = 0; x < 3; x++)
{
MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2BF4[y * 3 + data[0] % 3] | 0xC00);
MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2BF4[y][data[0] % 3] | 0xC00);
}
}
}
@ -1893,7 +1900,7 @@ static void sub_8139C80(u8 taskId)
{
for (x = 0; x < 3; x++)
{
MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2C06[y * 3 + data[0] % 3] | 0xC00);
MapGridSetMetatileIdAt(x + 8, y + 7, gUnknown_085B2C06[y][data[0] % 3] | 0xC00);
}
}
}
@ -1906,148 +1913,6 @@ static void sub_8139C80(u8 taskId)
}
data[1]++;
}
#else
NAKED
static void sub_8139C80(u8 taskId)
{
asm_unified("push {r4-r7,lr}\n\
mov r7, r10\n\
mov r6, r9\n\
mov r5, r8\n\
push {r5-r7}\n\
sub sp, 0x4\n\
lsls r0, 24\n\
lsrs r0, 24\n\
str r0, [sp]\n\
lsls r0, 2\n\
ldr r1, [sp]\n\
adds r0, r1\n\
lsls r0, 3\n\
ldr r1, =gTasks + 0x8\n\
adds r6, r0, r1\n\
movs r2, 0x2\n\
ldrsh r0, [r6, r2]\n\
cmp r0, 0x6\n\
bne _08139D7C\n\
ldrh r0, [r6]\n\
adds r0, 0x1\n\
strh r0, [r6]\n\
movs r1, 0x4\n\
ldrsh r0, [r6, r1]\n\
cmp r0, 0\n\
bne _08139D10\n\
movs r1, 0\n\
ldr r2, =gUnknown_085B2BF4\n\
mov r10, r2\n\
_08139CBA:\n\
movs r5, 0\n\
adds r7, r1, 0x7\n\
lsls r0, r1, 1\n\
adds r2, r1, 0x1\n\
mov r8, r2\n\
adds r0, r1\n\
lsls r0, 1\n\
mov r9, r0\n\
_08139CCA:\n\
adds r4, r5, 0\n\
adds r4, 0x8\n\
movs r1, 0\n\
ldrsh r0, [r6, r1]\n\
movs r1, 0x3\n\
bl __modsi3\n\
lsls r0, 16\n\
asrs r0, 15\n\
add r0, r9\n\
add r0, r10\n\
ldrh r0, [r0]\n\
movs r1, 0xC0\n\
lsls r1, 4\n\
adds r2, r1, 0\n\
orrs r2, r0\n\
adds r0, r4, 0\n\
adds r1, r7, 0\n\
bl MapGridSetMetatileIdAt\n\
adds r0, r5, 0x1\n\
lsls r0, 24\n\
lsrs r5, r0, 24\n\
cmp r5, 0x2\n\
bls _08139CCA\n\
mov r2, r8\n\
lsls r0, r2, 24\n\
lsrs r1, r0, 24\n\
cmp r1, 0x2\n\
bls _08139CBA\n\
b _08139D62\n\
.pool\n\
_08139D10:\n\
movs r1, 0\n\
ldr r0, =gUnknown_085B2C06\n\
mov r10, r0\n\
_08139D16:\n\
movs r5, 0\n\
adds r7, r1, 0x7\n\
lsls r0, r1, 1\n\
adds r2, r1, 0x1\n\
mov r8, r2\n\
adds r0, r1\n\
lsls r0, 1\n\
mov r9, r0\n\
_08139D26:\n\
adds r4, r5, 0\n\
adds r4, 0x8\n\
movs r1, 0\n\
ldrsh r0, [r6, r1]\n\
movs r1, 0x3\n\
bl __modsi3\n\
lsls r0, 16\n\
asrs r0, 15\n\
add r0, r9\n\
add r0, r10\n\
ldrh r0, [r0]\n\
movs r1, 0xC0\n\
lsls r1, 4\n\
adds r2, r1, 0\n\
orrs r2, r0\n\
adds r0, r4, 0\n\
adds r1, r7, 0\n\
bl MapGridSetMetatileIdAt\n\
adds r0, r5, 0x1\n\
lsls r0, 24\n\
lsrs r5, r0, 24\n\
cmp r5, 0x2\n\
bls _08139D26\n\
mov r2, r8\n\
lsls r0, r2, 24\n\
lsrs r1, r0, 24\n\
cmp r1, 0x2\n\
bls _08139D16\n\
_08139D62:\n\
bl DrawWholeMapView\n\
movs r0, 0\n\
strh r0, [r6, 0x2]\n\
movs r0, 0\n\
ldrsh r1, [r6, r0]\n\
movs r2, 0x6\n\
ldrsh r0, [r6, r2]\n\
cmp r1, r0\n\
bne _08139D7C\n\
ldr r0, [sp]\n\
bl DestroyTask\n\
_08139D7C:\n\
ldrh r0, [r6, 0x2]\n\
adds r0, 0x1\n\
strh r0, [r6, 0x2]\n\
add sp, 0x4\n\
pop {r3-r5}\n\
mov r8, r3\n\
mov r9, r4\n\
mov r10, r5\n\
pop {r4-r7}\n\
pop {r0}\n\
bx r0\n\
.pool");
}
#endif // NAKED
void sub_8139D98(void)
{
@ -2069,7 +1934,7 @@ void sub_8139D98(void)
}
gSpecialVar_0x8006 = 0;
gSpecialVar_0x8007 = ivStorage[STAT_HP];
gSpecialVar_0x8007 = ivStorage[STAT_HP];
for (i = 1; i < NUM_STATS; i++)
{