sa1: match entities manager

This commit is contained in:
Oliver Bell committed 2026-05-01 02:06:01 +01:00
1 parent d7bbcbdbd4
commit d96865a0b9
3 files changed
+115 -1927

No files matched your search

@@ -1,573 +0,0 @@
.include "constants/constants.inc"
.syntax unified
.text
push {r4, r5, r6, r7, lr}
mov r7, sl
mov r6, sb
mov r5, r8
push {r5, r6, r7}
sub sp, #0x30
ldr r0, _08008A30 @ =gStageFlags
ldrh r1, [r0]
movs r0, #2
ands r0, r1
lsls r0, r0, #0x10
lsrs r4, r0, #0x10
cmp r4, #0
beq _080088C6
b _08008CCA
_080088C6:
ldr r0, _08008A34 @ =gCurTask
ldr r0, [r0]
ldrh r1, [r0, #6]
movs r0, #0xc0
lsls r0, r0, #0x12
adds r1, r1, r0
str r1, [sp, #0x10]
ldr r0, [r1]
str r0, [sp, #0x14]
ldr r0, _08008A38 @ =gGameMode
ldrb r0, [r0]
cmp r0, #6
beq _080088EC
ldr r0, [r1, #8]
adds r0, #0xc
str r0, [sp, #0x1c]
ldr r0, [r1, #4]
adds r0, #0xc
str r0, [sp, #0x18]
_080088EC:
ldr r1, [sp, #0x14]
adds r1, #4
ldm r1!, {r0}
lsls r0, r0, #0x10
lsrs r0, r0, #0x10
str r0, [sp, #8]
ldm r1!, {r0}
str r1, [sp, #0x14]
lsls r0, r0, #0x10
lsrs r0, r0, #0x10
str r0, [sp, #0xc]
mov r1, sp
ldr r2, _08008A3C @ =gCamera
ldrh r3, [r2]
adds r0, r3, #0
subs r0, #0x80
strh r0, [r1]
movs r5, #0xb8
lsls r5, r5, #1
adds r0, r3, r5
strh r0, [r1, #4]
ldrh r2, [r2, #2]
adds r0, r2, #0
subs r0, #0x80
strh r0, [r1, #2]
movs r3, #0x90
lsls r3, r3, #1
adds r0, r2, r3
strh r0, [r1, #6]
mov r0, sp
movs r5, #0
ldrsh r0, [r0, r5]
cmp r0, #0
bge _08008934
mov r0, sp
strh r4, [r0]
_08008934:
mov r0, sp
ldrh r0, [r0, #2]
lsls r0, r0, #0x10
cmp r0, #0
bge _08008942
mov r0, sp
strh r4, [r0, #2]
_08008942:
mov r0, sp
movs r1, #4
ldrsh r0, [r0, r1]
cmp r0, #0
bge _08008950
mov r0, sp
strh r4, [r0, #4]
_08008950:
mov r0, sp
movs r2, #6
ldrsh r0, [r0, r2]
cmp r0, #0
bge _0800895E
mov r0, sp
strh r4, [r0, #6]
_0800895E:
mov r0, sp
movs r3, #0
ldrsh r0, [r0, r3]
ldr r5, [sp, #8]
lsls r3, r5, #8
cmp r0, r3
blo _08008972
mov r1, sp
subs r0, r3, #1
strh r0, [r1]
_08008972:
mov r0, sp
movs r1, #2
ldrsh r0, [r0, r1]
ldr r5, [sp, #0xc]
lsls r2, r5, #8
cmp r0, r2
blo _08008986
mov r1, sp
subs r0, r2, #1
strh r0, [r1, #2]
_08008986:
mov r0, sp
movs r1, #4
ldrsh r0, [r0, r1]
cmp r0, r3
blo _08008996
mov r1, sp
subs r0, r3, #1
strh r0, [r1, #4]
_08008996:
mov r0, sp
movs r3, #6
ldrsh r0, [r0, r3]
cmp r0, r2
blo _080089A6
mov r1, sp
subs r0, r2, #1
strh r0, [r1, #6]
_080089A6:
mov r0, sp
ldrh r0, [r0, #2]
lsls r0, r0, #0x10
asrs r0, r0, #0x18
lsls r0, r0, #0x10
lsrs r0, r0, #0x10
mov sb, r0
lsls r1, r0, #8
mov r0, sp
movs r5, #6
ldrsh r0, [r0, r5]
cmp r1, r0
blt _080089C2
b _08008CB2
_080089C2:
ldr r0, [sp, #0xc]
cmp sb, r0
blo _080089CA
b _08008CB2
_080089CA:
mov r0, sp
ldrh r0, [r0]
lsls r0, r0, #0x10
asrs r0, r0, #0x18
lsls r0, r0, #0x10
lsrs r0, r0, #0x10
mov r8, r0
lsls r1, r0, #8
mov r0, sp
movs r2, #4
ldrsh r0, [r0, r2]
mov r3, sb
adds r3, #1
str r3, [sp, #0x24]
cmp r1, r0
blt _080089EC
b _08008C96
_080089EC:
ldr r5, [sp, #8]
cmp r8, r5
blo _080089F4
b _08008C96
_080089F4:
movs r0, #1
rsbs r0, r0, #0
mov sl, r0
mov r7, sp
_080089FC:
ldr r0, _08008A38 @ =gGameMode
ldrb r0, [r0]
cmp r0, #6
bne _08008A06
b _08008BE4
_08008A06:
ldr r1, [sp, #8]
mov r0, sb
muls r0, r1, r0
mov r3, r8
lsls r2, r3, #2
lsls r1, r0, #2
ldr r5, [sp, #0x14]
adds r1, r1, r5
adds r1, r2, r1
ldr r6, [r1]
str r0, [sp, #0x2c]
str r2, [sp, #0x28]
adds r3, #1
str r3, [sp, #0x20]
cmp r6, #0
beq _08008AB2
adds r0, r6, #0
subs r0, #8
adds r5, r5, r0
movs r6, #0
b _08008AA8
.align 2, 0
_08008A30: .4byte gStageFlags
_08008A34: .4byte gCurTask
_08008A38: .4byte gGameMode
_08008A3C: .4byte gCamera
_08008A40:
lsls r0, r1, #0x18
asrs r0, r0, #0x18
movs r1, #2
rsbs r1, r1, #0
cmp r0, r1
blt _08008AA4
ldrb r2, [r5]
lsls r2, r2, #3
mov r3, r8
lsls r0, r3, #8
adds r2, r2, r0
ldrb r0, [r5, #1]
lsls r0, r0, #3
mov r3, sb
lsls r1, r3, #8
adds r0, r0, r1
lsls r0, r0, #0x10
lsrs r1, r0, #0x10
lsls r2, r2, #0x10
asrs r2, r2, #0x10
movs r3, #0
ldrsh r0, [r7, r3]
cmp r2, r0
blt _08008AA4
movs r3, #4
ldrsh r0, [r7, r3]
cmp r2, r0
bgt _08008AA4
ldrh r0, [r7, #2]
lsls r1, r1, #0x10
lsls r0, r0, #0x10
asrs r2, r1, #0x10
cmp r1, r0
blt _08008AA4
movs r1, #6
ldrsh r0, [r7, r1]
cmp r2, r0
bgt _08008AA4
ldr r1, _08008BDC @ =gSpriteInits_Interactables
ldrb r0, [r5, #2]
lsls r0, r0, #2
adds r0, r0, r1
lsls r3, r6, #0x18
lsrs r3, r3, #0x18
ldr r4, [r0]
adds r0, r5, #0
mov r1, r8
mov r2, sb
bl _call_via_r4
_08008AA4:
adds r5, #7
adds r6, #1
_08008AA8:
ldrb r1, [r5]
movs r0, #0
ldrsb r0, [r5, r0]
cmp r0, sl
bne _08008A40
_08008AB2:
ldr r2, [sp, #0x2c]
lsls r0, r2, #2
ldr r3, [sp, #0x18]
adds r0, r0, r3
ldr r5, [sp, #0x28]
adds r0, r5, r0
ldr r6, [r0]
cmp r6, #0
beq _08008B3E
adds r0, r6, #0
subs r0, #8
adds r4, r3, r0
movs r6, #0
ldrb r1, [r4]
movs r0, #0
ldrsb r0, [r4, r0]
cmp r0, sl
beq _08008B3E
movs r5, #2
rsbs r5, r5, #0
_08008ADA:
lsls r0, r1, #0x18
asrs r0, r0, #0x18
cmp r0, r5
blt _08008B30
ldrb r2, [r4]
lsls r2, r2, #3
mov r1, r8
lsls r0, r1, #8
adds r2, r2, r0
ldrb r0, [r4, #1]
lsls r0, r0, #3
mov r3, sb
lsls r1, r3, #8
adds r0, r0, r1
lsls r0, r0, #0x10
lsrs r1, r0, #0x10
lsls r2, r2, #0x10
asrs r2, r2, #0x10
movs r3, #0
ldrsh r0, [r7, r3]
cmp r2, r0
blt _08008B30
movs r3, #4
ldrsh r0, [r7, r3]
cmp r2, r0
bgt _08008B30
ldrh r0, [r7, #2]
lsls r1, r1, #0x10
lsls r0, r0, #0x10
asrs r2, r1, #0x10
cmp r1, r0
blt _08008B30
movs r1, #6
ldrsh r0, [r7, r1]
cmp r2, r0
bgt _08008B30
lsls r3, r6, #0x18
lsrs r3, r3, #0x18
adds r0, r4, #0
mov r1, r8
mov r2, sb
bl CreateEntity_ItemBox
_08008B30:
adds r4, #3
adds r6, #1
ldrb r1, [r4]
movs r0, #0
ldrsb r0, [r4, r0]
cmp r0, sl
bne _08008ADA
_08008B3E:
ldr r2, [sp, #0x2c]
lsls r0, r2, #2
ldr r3, [sp, #0x1c]
adds r0, r0, r3
ldr r5, [sp, #0x28]
adds r0, r5, r0
ldr r6, [r0]
cmp r6, #0
bne _08008B52
b _08008C7C
_08008B52:
adds r0, r6, #0
subs r0, #8
adds r5, r3, r0
movs r6, #0
ldrb r1, [r5]
movs r0, #0
ldrsb r0, [r5, r0]
cmp r0, sl
bne _08008B66
b _08008C7C
_08008B66:
lsls r0, r1, #0x18
asrs r0, r0, #0x18
movs r1, #2
rsbs r1, r1, #0
cmp r0, r1
blt _08008BCA
ldrb r2, [r5]
lsls r2, r2, #3
mov r3, r8
lsls r0, r3, #8
adds r2, r2, r0
ldrb r0, [r5, #1]
lsls r0, r0, #3
mov r3, sb
lsls r1, r3, #8
adds r0, r0, r1
lsls r0, r0, #0x10
lsrs r1, r0, #0x10
lsls r2, r2, #0x10
asrs r2, r2, #0x10
movs r3, #0
ldrsh r0, [r7, r3]
cmp r2, r0
blt _08008BCA
movs r3, #4
ldrsh r0, [r7, r3]
cmp r2, r0
bgt _08008BCA
ldrh r0, [r7, #2]
lsls r1, r1, #0x10
lsls r0, r0, #0x10
asrs r2, r1, #0x10
cmp r1, r0
blt _08008BCA
movs r1, #6
ldrsh r0, [r7, r1]
cmp r2, r0
bgt _08008BCA
ldr r1, _08008BE0 @ =gSpriteInits_Enemies
ldrb r0, [r5, #2]
lsls r0, r0, #2
adds r0, r0, r1
lsls r3, r6, #0x18
lsrs r3, r3, #0x18
ldr r4, [r0]
adds r0, r5, #0
mov r1, r8
mov r2, sb
bl _call_via_r4
_08008BCA:
adds r5, #7
adds r6, #1
ldrb r1, [r5]
movs r0, #0
ldrsb r0, [r5, r0]
cmp r0, sl
bne _08008B66
b _08008C7C
.align 2, 0
_08008BDC: .4byte gSpriteInits_Interactables
_08008BE0: .4byte gSpriteInits_Enemies
_08008BE4:
ldr r2, [sp, #8]
mov r0, sb
muls r0, r2, r0
mov r3, r8
lsls r1, r3, #2
lsls r0, r0, #2
ldr r5, [sp, #0x14]
adds r0, r0, r5
adds r1, r1, r0
ldr r6, [r1]
adds r3, #1
str r3, [sp, #0x20]
cmp r6, #0
beq _08008C7C
adds r0, r6, #0
subs r0, #8
adds r5, r5, r0
movs r6, #0
b _08008C72
_08008C0A:
lsls r0, r1, #0x18
asrs r0, r0, #0x18
movs r1, #2
rsbs r1, r1, #0
cmp r0, r1
blt _08008C6E
ldrb r2, [r5]
lsls r2, r2, #3
mov r3, r8
lsls r0, r3, #8
adds r2, r2, r0
ldrb r0, [r5, #1]
lsls r0, r0, #3
mov r3, sb
lsls r1, r3, #8
adds r0, r0, r1
lsls r0, r0, #0x10
lsrs r1, r0, #0x10
lsls r2, r2, #0x10
asrs r2, r2, #0x10
movs r3, #0
ldrsh r0, [r7, r3]
cmp r2, r0
blt _08008C6E
movs r3, #4
ldrsh r0, [r7, r3]
cmp r2, r0
bgt _08008C6E
ldrh r0, [r7, #2]
lsls r1, r1, #0x10
lsls r0, r0, #0x10
asrs r2, r1, #0x10
cmp r1, r0
blt _08008C6E
movs r1, #6
ldrsh r0, [r7, r1]
cmp r2, r0
bgt _08008C6E
ldr r1, _08008CDC @ =gSpriteInits_InteractablesMultiplayer
ldrb r0, [r5, #2]
lsls r0, r0, #2
adds r0, r0, r1
lsls r3, r6, #0x18
lsrs r3, r3, #0x18
ldr r4, [r0]
adds r0, r5, #0
mov r1, r8
mov r2, sb
bl _call_via_r4
_08008C6E:
adds r5, #7
adds r6, #1
_08008C72:
ldrb r1, [r5]
movs r0, #0
ldrsb r0, [r5, r0]
cmp r0, sl
bne _08008C0A
_08008C7C:
ldr r2, [sp, #0x20]
lsls r0, r2, #0x10
lsrs r0, r0, #0x10
mov r8, r0
lsls r1, r0, #8
movs r3, #4
ldrsh r0, [r7, r3]
cmp r1, r0
bge _08008C96
ldr r5, [sp, #8]
cmp r8, r5
bhs _08008C96
b _080089FC
_08008C96:
ldr r1, [sp, #0x24]
lsls r0, r1, #0x10
lsrs r0, r0, #0x10
mov sb, r0
lsls r1, r0, #8
mov r0, sp
movs r2, #6
ldrsh r0, [r0, r2]
cmp r1, r0
bge _08008CB2
ldr r3, [sp, #0xc]
cmp sb, r3
bhs _08008CB2
b _080089CA
_08008CB2:
ldr r1, _08008CE0 @ =gCamera
ldrh r0, [r1]
movs r2, #0
ldr r5, [sp, #0x10]
strh r0, [r5, #0xc]
ldrh r0, [r1, #2]
strh r0, [r5, #0xe]
strb r2, [r5, #0x10]
ldr r0, _08008CE4 @ =gCurTask
ldr r1, [r0]
ldr r0, _08008CE8 @ =sa2__Task_8008DCC
str r0, [r1, #8]
_08008CCA:
add sp, #0x30
pop {r3, r4, r5}
mov r8, r3
mov sb, r4
mov sl, r5
pop {r4, r5, r6, r7}
pop {r0}
bx r0
.align 2, 0
_08008CDC: .4byte gSpriteInits_InteractablesMultiplayer
_08008CE0: .4byte gCamera
_08008CE4: .4byte gCurTask
_08008CE8: .4byte sa2__Task_8008DCC
.syntax divided
File diff suppressed because it is too large. Load diff
+115 -149
View File
@@ -842,20 +842,12 @@ void CreateStageEntitiesManager(void)
gEntitiesManagerTask = t;
}
// NOTE: Not aligned with SA2, matches there.
// (94.91%) https://decomp.me/scratch/88ibj
NONMATCH("asm/non_matching/game/shared/stage/ent_manager__SpawnMapEntities.inc", void SpawnMapEntities())
void SpawnMapEntities()
{
// Required to be here to help the stack match
#ifndef NON_MATCHING
u32 temp, space;
#endif
if ((gStageFlags & 2) == 0) {
u32 i;
u16 regionX, regionY;
struct Range rangeData;
struct Range *range;
CamCoord rangeData[4];
u32 h_regionCount, v_regionCount;
EntitiesManager *em = TASK_DATA(gCurTask);
@@ -870,52 +862,48 @@ NONMATCH("asm/non_matching/game/shared/stage/ent_manager__SpawnMapEntities.inc",
}
interactables++;
#ifndef NON_MATCHING
h_regionCount = (u16)(temp = *interactables++);
#else
h_regionCount = (u16)*interactables++;
#endif
v_regionCount = (u16)*interactables++;
range = &rangeData;
range->xLow = gCamera.x - 128;
range->xHigh = gCamera.x + (DISPLAY_WIDTH + 128);
// range = &rangeData;
rangeData[0] = gCamera.x - 128;
rangeData[2] = gCamera.x + (DISPLAY_WIDTH + 128);
range->yLow = gCamera.y - 128;
range->yHigh = gCamera.y + (DISPLAY_HEIGHT + 128);
rangeData[1] = gCamera.y - 128;
rangeData[3] = gCamera.y + (DISPLAY_HEIGHT + 128);
if (range->xLow < 0) {
range->xLow = 0;
if (rangeData[0] < 0) {
rangeData[0] = 0;
}
if (range->yLow < 0) {
range->yLow = 0;
if (rangeData[1] < 0) {
rangeData[1] = 0;
}
if (range->xHigh < 0) {
range->xHigh = 0;
if (rangeData[2] < 0) {
rangeData[2] = 0;
}
if (range->yHigh < 0) {
range->yHigh = 0;
if (rangeData[3] < 0) {
rangeData[3] = 0;
}
if ((u32)range->xLow >= Q(h_regionCount)) {
range->xLow = Q(h_regionCount) - 1;
if ((u32)rangeData[0] >= Q(h_regionCount)) {
rangeData[0] = Q(h_regionCount) - 1;
}
if ((u32)range->yLow >= Q(v_regionCount)) {
range->yLow = Q(v_regionCount) - 1;
if ((u32)rangeData[1] >= Q(v_regionCount)) {
rangeData[1] = Q(v_regionCount) - 1;
}
if ((u32)range->xHigh >= Q(h_regionCount)) {
range->xHigh = Q(h_regionCount) - 1;
if ((u32)rangeData[2] >= Q(h_regionCount)) {
rangeData[2] = Q(h_regionCount) - 1;
}
if ((u32)range->yHigh >= Q(v_regionCount)) {
range->yHigh = Q(v_regionCount) - 1;
if ((u32)rangeData[3] >= Q(v_regionCount)) {
rangeData[3] = Q(v_regionCount) - 1;
}
regionY = I(range->yLow);
while (Q(regionY) < range->yHigh && regionY < v_regionCount) {
regionX = I(range->xLow);
while (Q(regionX) < range->xHigh && regionX < h_regionCount) {
regionY = I(rangeData[1]);
while (Q(regionY) < rangeData[3] && regionY < v_regionCount) {
regionX = I(rangeData[0]);
while (Q(regionX) < rangeData[2] && regionX < h_regionCount) {
if (gGameMode != GAME_MODE_MULTI_PLAYER_COLLECT_RINGS) {
i = READ_START_INDEX(interactables, h_regionCount, regionX, regionY);
if (i != 0) {
@@ -924,7 +912,7 @@ NONMATCH("asm/non_matching/game/shared/stage/ent_manager__SpawnMapEntities.inc",
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= range->xLow && x <= range->xHigh && y >= range->yLow && y <= range->yHigh) {
if (x >= rangeData[0] && x <= rangeData[2] && y >= rangeData[1] && y <= rangeData[3]) {
gSpriteInits_Interactables[me->index](me, regionX, regionY, i);
}
}
@@ -938,7 +926,7 @@ NONMATCH("asm/non_matching/game/shared/stage/ent_manager__SpawnMapEntities.inc",
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= range->xLow && x <= range->xHigh && y >= range->yLow && y <= range->yHigh) {
if (x >= rangeData[0] && x <= rangeData[2] && y >= rangeData[1] && y <= rangeData[3]) {
CreateEntity_ItemBox((void *)me, regionX, regionY, i);
}
}
@@ -953,7 +941,7 @@ NONMATCH("asm/non_matching/game/shared/stage/ent_manager__SpawnMapEntities.inc",
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= range->xLow && x <= range->xHigh && y >= range->yLow && y <= range->yHigh) {
if (x >= rangeData[0] && x <= rangeData[2] && y >= rangeData[1] && y <= rangeData[3]) {
gSpriteInits_Enemies[me->index](me, regionX, regionY, i);
}
}
@@ -967,7 +955,7 @@ NONMATCH("asm/non_matching/game/shared/stage/ent_manager__SpawnMapEntities.inc",
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= range->xLow && x <= range->xHigh && y >= range->yLow && y <= range->yHigh) {
if (x >= rangeData[0] && x <= rangeData[2] && y >= rangeData[1] && y <= rangeData[3]) {
gSpriteInits_InteractablesMultiplayer[me->index](me, regionX, regionY, i);
}
}
@@ -984,18 +972,9 @@ NONMATCH("asm/non_matching/game/shared/stage/ent_manager__SpawnMapEntities.inc",
gCurTask->main = SA2_LABEL(Task_8008DCC);
}
}
END_NONMATCH
#if (GAME == GAME_SA1)
// (89.13%) https://decomp.me/scratch/pvPFD
NONMATCH("asm/non_matching/game/shared/stage/ent_manager__Task_8008DCC.inc", void SA2_LABEL(Task_8008DCC)(void))
#else
void SA2_LABEL(Task_8008DCC)(void)
#endif
{
#ifndef NON_MATCHING
struct Range *newRange2Ptr;
#endif
if (!(gStageFlags & 2)) {
u32 i;
@@ -1003,10 +982,11 @@ void SA2_LABEL(Task_8008DCC)(void)
#if (GAME == GAME_SA1)
// This matches more in SA1, but not at all in SA2, and vice versa.
struct Ranges ranges;
CamCoord range1[4];
CamCoord range2[4];
#define RANGE1 ranges.a
#define RANGE2 ranges.b
#define RANGE1 range1
#define RANGE2 range2
#elif (GAME == GAME_SA2)
struct Range range1;
struct Range range2;
@@ -1047,42 +1027,42 @@ void SA2_LABEL(Task_8008DCC)(void)
v_regionCount = (u16)*interactables++;
if (gCamera.x > em->prevCamX) {
RANGE1.xLow = em->prevCamX + (DISPLAY_WIDTH + 128);
RANGE1.xHigh = gCamera.x + (DISPLAY_WIDTH + 128);
RANGE1[0] = em->prevCamX + (DISPLAY_WIDTH + 128);
RANGE1[2] = gCamera.x + (DISPLAY_WIDTH + 128);
#if TAS_TESTING && TAS_TESTING_WIDESCREEN_HACK && DISPLAY_WIDTH > 240
if (LEVEL_TO_ZONE(gCurrentLevel) == ZONE_3) {
// HACK: in zone 3 the TAS we are using depends on going so far off the screen
// that some IAs do not spawn and so it gets to skip them. We have to emulate
// that behaviour so that we can test the TAS in widescreen
RANGE1.xLow = em->prevCamX + (426 + 45);
RANGE1.xHigh = gCamera.x + (426 + 45);
RANGE1[0] = em->prevCamX + (426 + 45);
RANGE1[2] = gCamera.x + (426 + 45);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_4, ACT_2)) {
// In this stage there is a pen which initialises earlier
// than the TAS expects, so this limits that
RANGE1.xLow = em->prevCamX + (426 + 80);
RANGE1.xHigh = gCamera.x + (426 + 80);
RANGE1[0] = em->prevCamX + (426 + 80);
RANGE1[2] = gCamera.x + (426 + 80);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_5, ACT_1)) {
// In this stage there are some birds which initialise early
RANGE1.xLow = em->prevCamX + (240 + 128);
RANGE1.xHigh = gCamera.x + (240 + 128);
RANGE1[0] = em->prevCamX + (240 + 128);
RANGE1[2] = gCamera.x + (240 + 128);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_6, ACT_1)) {
// In this stage some robot bird thing jumps too early
RANGE1.xLow = em->prevCamX + (426 + 35);
RANGE1.xHigh = gCamera.x + (426 + 35);
RANGE1[0] = em->prevCamX + (426 + 35);
RANGE1[2] = gCamera.x + (426 + 35);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_7, ACT_1)) {
// Some spike thing generates too early
RANGE1.xLow = em->prevCamX + (426 + 35);
RANGE1.xHigh = gCamera.x + (426 + 35);
RANGE1[0] = em->prevCamX + (426 + 35);
RANGE1[2] = gCamera.x + (426 + 35);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_7, ACT_2)) {
// A grind rail generates too early
RANGE1.xLow = em->prevCamX + (426 + 40);
RANGE1.xHigh = gCamera.x + (426 + 40);
RANGE1[0] = em->prevCamX + (426 + 40);
RANGE1[2] = gCamera.x + (426 + 40);
}
#endif
} else {
RANGE1.xLow = gCamera.x - 128;
RANGE1.xHigh = em->prevCamX - 128;
RANGE1[0] = gCamera.x - 128;
RANGE1[2] = em->prevCamX - 128;
}
if (em->SA2_LABEL(unk14) != 0) {
@@ -1090,113 +1070,108 @@ void SA2_LABEL(Task_8008DCC)(void)
return;
}
RANGE1.yLow = gCamera.y - 128;
RANGE1.yHigh = gCamera.y + (DISPLAY_HEIGHT + 128);
RANGE1[1] = gCamera.y - 128;
RANGE1[3] = gCamera.y + (DISPLAY_HEIGHT + 128);
if (gCamera.y > em->prevCamY) {
RANGE2.yLow = em->prevCamY + (DISPLAY_HEIGHT + 128);
RANGE2.yHigh = gCamera.y + (DISPLAY_HEIGHT + 128);
RANGE2[1] = em->prevCamY + (DISPLAY_HEIGHT + 128);
RANGE2[3] = gCamera.y + (DISPLAY_HEIGHT + 128);
} else {
RANGE2.yLow = gCamera.y - 128;
RANGE2.yHigh = em->prevCamY - 128;
RANGE2[1] = gCamera.y - 128;
RANGE2[3] = em->prevCamY - 128;
}
RANGE2.xLow = gCamera.x - 128;
RANGE2.xHigh = gCamera.x + (DISPLAY_WIDTH + 128);
RANGE2[0] = gCamera.x - 128;
RANGE2[2] = gCamera.x + (DISPLAY_WIDTH + 128);
#if TAS_TESTING && TAS_TESTING_WIDESCREEN_HACK && DISPLAY_WIDTH > 240
if (LEVEL_TO_ZONE(gCurrentLevel) == ZONE_3) {
RANGE2.xHigh = gCamera.x + (426 + 45);
RANGE2[2] = gCamera.x + (426 + 45);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_4, ACT_2)) {
RANGE2.xHigh = gCamera.x + (426 + 80);
RANGE2[2] = gCamera.x + (426 + 80);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_5, ACT_1)) {
RANGE2.xHigh = gCamera.x + (240 + 128);
RANGE2[2] = gCamera.x + (240 + 128);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_6, ACT_1)) {
RANGE2.xHigh = gCamera.x + (426 + 35);
RANGE2[2] = gCamera.x + (426 + 35);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_7, ACT_1)) {
RANGE2.xHigh = gCamera.x + (426 + 35);
RANGE2[2] = gCamera.x + (426 + 35);
} else if (gCurrentLevel == LEVEL_INDEX(ZONE_7, ACT_2)) {
RANGE2.xHigh = gCamera.x + (426 + 40);
RANGE2[2] = gCamera.x + (426 + 40);
}
#endif
if (RANGE1.xLow < 0) {
RANGE1.xLow = 0;
if (RANGE1[0] < 0) {
RANGE1[0] = 0;
}
if (RANGE1.yLow < 0) {
RANGE1.yLow = 0;
if (RANGE1[1] < 0) {
RANGE1[1] = 0;
}
if (RANGE1.xHigh < 0) {
RANGE1.xHigh = 0;
if (RANGE1[2] < 0) {
RANGE1[2] = 0;
}
if (RANGE1.yHigh < 0) {
RANGE1.yHigh = 0;
if (RANGE1[3] < 0) {
RANGE1[3] = 0;
}
temp2 = RANGE1.xLow;
temp2 = RANGE1[0];
temp = Q(h_regionCount);
if (temp2 >= temp) {
RANGE1.xLow = temp - 1;
RANGE1[0] = temp - 1;
}
temp3 = RANGE1.yLow;
temp3 = RANGE1[1];
temp4 = Q(v_regionCount);
if (temp3 >= temp4) {
RANGE1.yLow = temp4 - 1;
RANGE1[1] = temp4 - 1;
}
if (RANGE1.xHigh >= temp) {
RANGE1.xHigh = temp - 1;
if (RANGE1[2] >= temp) {
RANGE1[2] = temp - 1;
}
if (RANGE1.yHigh >= temp4) {
RANGE1.yHigh = temp4 - 1;
if (RANGE1[3] >= temp4) {
RANGE1[3] = temp4 - 1;
}
if (RANGE2.xLow < 0) {
RANGE2.xLow = 0;
if (RANGE2[0] < 0) {
RANGE2[0] = 0;
}
if (RANGE2.yLow < 0) {
RANGE2.yLow = 0;
if (RANGE2[1] < 0) {
RANGE2[1] = 0;
}
if (RANGE2.xHigh < 0) {
RANGE2.xHigh = 0;
if (RANGE2[2] < 0) {
RANGE2[2] = 0;
}
if (RANGE2.yHigh < 0) {
RANGE2.yHigh = 0;
if (RANGE2[3] < 0) {
RANGE2[3] = 0;
}
if (RANGE2.xLow >= temp) {
RANGE2.xLow = temp - 1;
if (RANGE2[0] >= temp) {
RANGE2[0] = temp - 1;
}
if (RANGE2.yLow >= temp4) {
RANGE2.yLow = temp4 - 1;
if (RANGE2[1] >= temp4) {
RANGE2[1] = temp4 - 1;
}
if (RANGE2.xHigh >= temp) {
RANGE2.xHigh = temp - 1;
if (RANGE2[2] >= temp) {
RANGE2[2] = temp - 1;
}
if (RANGE2.yHigh >= temp4) {
RANGE2.yHigh = temp4 - 1;
if (RANGE2[3] >= temp4) {
RANGE2[3] = temp4 - 1;
}
// Hack to fix a stack mismatch, must be placed here
#ifndef NON_MATCHING
newRange2Ptr = &RANGE2;
#endif
if (gCamera.x != em->prevCamX && RANGE1[0] != RANGE1[2] && RANGE1[1] != RANGE1[3]) {
regionY = I(RANGE1[1]);
if (gCamera.x != em->prevCamX && RANGE1.xLow != RANGE1.xHigh && RANGE1.yLow != RANGE1.yHigh) {
regionY = I(RANGE1.yLow);
while (Q(regionY) < RANGE1.yHigh && regionY < v_regionCount) {
regionX = I(RANGE1.xLow);
while (Q(regionX) < RANGE1.xHigh && regionX < h_regionCount) {
while (Q(regionY) < RANGE1[3] && regionY < v_regionCount) {
regionX = I(RANGE1[0]);
while (Q(regionX) < RANGE1[2] && regionX < h_regionCount) {
if (gGameMode != GAME_MODE_MULTI_PLAYER_COLLECT_RINGS) {
i = READ_START_INDEX(interactables, h_regionCount, regionX, regionY);
if (i != 0) {
@@ -1205,7 +1180,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE1.xLow && x <= RANGE1.xHigh && y >= RANGE1.yLow && y <= RANGE1.yHigh) {
if (x >= RANGE1[0] && x <= RANGE1[2] && y >= RANGE1[1] && y <= RANGE1[3]) {
gSpriteInits_Interactables[me->index](me, regionX, regionY, i);
}
}
@@ -1219,7 +1194,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE1.xLow && x <= RANGE1.xHigh && y >= RANGE1.yLow && y <= RANGE1.yHigh) {
if (x >= RANGE1[0] && x <= RANGE1[2] && y >= RANGE1[1] && y <= RANGE1[3]) {
CreateEntity_ItemBox((MapEntity *)me, regionX, regionY, i);
}
}
@@ -1233,7 +1208,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE1.xLow && x <= RANGE1.xHigh && y >= RANGE1.yLow && y <= RANGE1.yHigh) {
if (x >= RANGE1[0] && x <= RANGE1[2] && y >= RANGE1[1] && y <= RANGE1[3]) {
gSpriteInits_Enemies[me->index](me, regionX, regionY, i);
}
}
@@ -1247,7 +1222,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE1.xLow && x <= RANGE1.xHigh && y >= RANGE1.yLow && y <= RANGE1.yHigh) {
if (x >= RANGE1[0] && x <= RANGE1[2] && y >= RANGE1[1] && y <= RANGE1[3]) {
gSpriteInits_InteractablesMultiplayer[me->index](me, regionX, regionY, i);
}
}
@@ -1260,17 +1235,11 @@ void SA2_LABEL(Task_8008DCC)(void)
}
}
#ifndef NON_MATCHING
if (((gCamera.y != em->prevCamY) && ((*newRange2Ptr).yLow != (*newRange2Ptr).yHigh)) && (RANGE2.xLow != (*newRange2Ptr).xHigh)) {
regionY = I((*newRange2Ptr).yLow);
while (Q(regionY) < (*newRange2Ptr).yHigh && regionY < v_regionCount) {
#else
if (((gCamera.y != em->prevCamY) && (RANGE2.yLow != RANGE2.yHigh)) && (RANGE2.xLow != RANGE2.xHigh)) {
regionY = I(RANGE2.yLow);
while (Q(regionY) < RANGE2.yHigh && regionY < v_regionCount) {
#endif
regionX = I(RANGE2.xLow);
while (Q(regionX) < RANGE2.xHigh && regionX < h_regionCount) {
if (((gCamera.y != em->prevCamY) && ((RANGE2)[1] != (RANGE2)[3])) && (RANGE2[0] != (RANGE2)[2])) {
regionY = I((RANGE2)[1]);
while (({ Q(regionY); }) < (RANGE2)[3] && regionY < v_regionCount) {
regionX = I(RANGE2[0]);
while (Q(regionX) < RANGE2[2] && regionX < h_regionCount) {
if (gGameMode != GAME_MODE_MULTI_PLAYER_COLLECT_RINGS) {
i = READ_START_INDEX(interactables, h_regionCount, regionX, regionY);
if (i != 0) {
@@ -1279,7 +1248,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE2.xLow && x <= RANGE2.xHigh && y >= RANGE2.yLow && y <= RANGE2.yHigh) {
if (x >= RANGE2[0] && x <= RANGE2[2] && y >= RANGE2[1] && y <= RANGE2[3]) {
gSpriteInits_Interactables[me->index](me, regionX, regionY, i);
}
}
@@ -1293,7 +1262,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE2.xLow && x <= RANGE2.xHigh && y >= RANGE2.yLow && y <= RANGE2.yHigh) {
if (x >= RANGE2[0] && x <= RANGE2[2] && y >= RANGE2[1] && y <= RANGE2[3]) {
CreateEntity_ItemBox((MapEntity *)me, regionX, regionY, i);
}
}
@@ -1307,7 +1276,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE2.xLow && x <= RANGE2.xHigh && y >= RANGE2.yLow && y <= RANGE2.yHigh) {
if (x >= RANGE2[0] && x <= RANGE2[2] && y >= RANGE2[1] && y <= RANGE2[3]) {
gSpriteInits_Enemies[me->index](me, regionX, regionY, i);
}
}
@@ -1321,7 +1290,7 @@ void SA2_LABEL(Task_8008DCC)(void)
if ((s8)me->x >= -2) {
CamCoord x = TO_WORLD_POS(me->x, regionX);
CamCoord y = TO_WORLD_POS(me->y, regionY);
if (x >= RANGE2.xLow && x <= RANGE2.xHigh && y >= RANGE2.yLow && y <= RANGE2.yHigh) {
if (x >= RANGE2[0] && x <= RANGE2[2] && y >= RANGE2[1] && y <= RANGE2[3]) {
gSpriteInits_InteractablesMultiplayer[me->index](me, regionX, regionY, i);
}
}
@@ -1337,9 +1306,6 @@ void SA2_LABEL(Task_8008DCC)(void)
em->prevCamY = gCamera.y;
}
}
#if (GAME == GAME_SA1)
END_NONMATCH
#endif
void CreateEnemyDefeatScoreAndManageLives(s16 x, s16 y)
{