diff options
Diffstat (limited to 'src')
61 files changed, 496 insertions, 567 deletions
diff --git a/src/arm_proxy.c b/src/arm_proxy.c index 7de78b39..4e153936 100644 --- a/src/arm_proxy.c +++ b/src/arm_proxy.c @@ -8,7 +8,7 @@ #include "functions.h" #include "object.h" #include "manager.h" -#include "dma.h" +#include "utils.h" #include "npc.h" extern u8 gUnk_03003DE0; diff --git a/src/code_0801D714.c b/src/code_0801D714.c deleted file mode 100755 index f3e59253..00000000 --- a/src/code_0801D714.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "global.h" - -extern void LoadPalettes(const u8*, int, int); - -extern u32 gUsedPalettes; -extern u16 gPaletteBuffer[]; - -typedef struct { - u16 paletteId; - u8 destPaletteNum; - u8 numPalettes; -} PaletteGroup; - -extern const PaletteGroup* gPaletteGroups[]; -extern const u8 gGlobalGfxAndPalettes[]; - -void LoadPaletteGroup(u32 group) { - const PaletteGroup* paletteGroup = gPaletteGroups[group]; - while (1) { - u32 destPaletteNum = paletteGroup->destPaletteNum; - u32 numPalettes = paletteGroup->numPalettes & 0xF; - if (numPalettes == 0) { - numPalettes = 16; - } - LoadPalettes(&gGlobalGfxAndPalettes[paletteGroup->paletteId * 32], destPaletteNum, numPalettes); - if ((paletteGroup->numPalettes & 0x80) == 0) { - break; - } - paletteGroup++; - } -} - -void LoadPalettes(const u8* src, int destPaletteNum, int numPalettes) { - u16* dest; - u32 size = numPalettes * 32; - u32 usedPalettesMask = 1 << destPaletteNum; - while (--numPalettes > 0) { - usedPalettesMask |= (usedPalettesMask << 1); - } - gUsedPalettes |= usedPalettesMask; - dest = &gPaletteBuffer[destPaletteNum * 16]; - DmaCopy32(3, src, dest, size); -} diff --git a/src/code_0801D79C.c b/src/code_0801D79C.c deleted file mode 100644 index 8f085aae..00000000 --- a/src/code_0801D79C.c +++ /dev/null @@ -1,96 +0,0 @@ -#include "global.h" -#include "screen.h" -#include "structures.h" - -extern u16 gPaletteBuffer[]; -extern u32 gUsedPalettes; - -typedef struct { - union { - int raw; - struct { - u8 filler0[0x3]; - u8 unk3; - } bytes; - } unk0; - u32 dest; - u32 unk8; -} GfxItem; - -extern const GfxItem* gUnk_08100AA8[]; -extern const u8 gGlobalGfxAndPalettes[]; - -void sub_0801D79C(u32 colorIndex, u32 color) { - gPaletteBuffer[colorIndex] = color; - gUsedPalettes |= 1 << (colorIndex / 16); -} - -void sub_0801D7BC(u32 color, u32 arg1) { - if (arg1) { - gScreen.lcd.unk6 = 0xE0FF; - } else { - gScreen.lcd.unk6 = 0xFFFF; - } - sub_0801D79C(0, color); -} - -void LoadGfxGroup(u32 group) { - u32 terminator; - u32 dmaCtrl; - int gfxOffset; - const u8* src; - u32 dest; - int size; - const GfxItem* gfxItem = gUnk_08100AA8[group]; - while (1) { - u32 loadGfx = FALSE; - u32 ctrl = gfxItem->unk0.bytes.unk3; - ctrl &= 0xF; - switch (ctrl) { - case 0x7: - loadGfx = TRUE; - break; - case 0xD: - return; - case 0xE: - if (((struct_02000000*)0x2000000)->gameLanguage > 1) { - loadGfx = TRUE; - } - break; - case 0xF: - if (((struct_02000000*)0x2000000)->gameLanguage != 0) { - loadGfx = TRUE; - } - break; - default: - if (ctrl == ((struct_02000000*)0x2000000)->gameLanguage) { - loadGfx = TRUE; - } - break; - } - - if (loadGfx) { - gfxOffset = gfxItem->unk0.raw & 0xFFFFFF; - src = &gGlobalGfxAndPalettes[gfxOffset]; - dest = gfxItem->dest; - size = gfxItem->unk8; - dmaCtrl = 0x80000000; - if (size < 0) { - if (dest >= VRAM) { - LZ77UnCompVram(src, (void*)dest); - } else { - LZ77UnCompWram(src, (void*)dest); - } - } else { - DmaSet(3, src, dest, dmaCtrl | ((u32)size >> 1)); - } - } - - terminator = gfxItem->unk0.bytes.unk3; - terminator &= 0x80; - gfxItem++; - if (!terminator) { - break; - } - } -} diff --git a/src/code_080300AC.c b/src/code_080300AC.c index 16514810..993de6ee 100644 --- a/src/code_080300AC.c +++ b/src/code_080300AC.c @@ -1,5 +1,5 @@ #include "global.h" -#include "dma.h" +#include "utils.h" #include "functions.h" typedef struct { diff --git a/src/code_0804AA84.c b/src/code_0804AA84.c index 27c7c6c4..cdc00c3f 100644 --- a/src/code_0804AA84.c +++ b/src/code_0804AA84.c @@ -2,7 +2,7 @@ #include "entity.h" #include "area.h" #include "main.h" -#include "dma.h" +#include "utils.h" #include "functions.h" #include "screen.h" diff --git a/src/code_0805F9A0.c b/src/code_0805F9A0.c index d1c9af64..66ac2ba9 100644 --- a/src/code_0805F9A0.c +++ b/src/code_0805F9A0.c @@ -1,5 +1,5 @@ #include "global.h" -#include "dma.h" +#include "utils.h" #include "structures.h" #include "functions.h" diff --git a/src/code_08077B98.c b/src/code_08077B98.c index c3fbf5dd..856dc44b 100644 --- a/src/code_08077B98.c +++ b/src/code_08077B98.c @@ -82,7 +82,7 @@ void* sub_08077C54(UnkItemStruct* unk) { Entity* sub_08077C94(ItemBehavior* arg0, u32 arg1) { Entity* iVar1; - iVar1 = FindEntityInListBySubtype(8, gUnk_0811BE48[arg1].unk[3], 2); + iVar1 = FindEntityByID(8, gUnk_0811BE48[arg1].unk[3], 2); if (iVar1 == NULL) { return NULL; } diff --git a/src/code_08077DF4.c b/src/code_08077DF4.c index 23ba53f5..c25aa18e 100644 --- a/src/code_08077DF4.c +++ b/src/code_08077DF4.c @@ -1,7 +1,7 @@ #include "global.h" #include "entity.h" #include "player.h" -#include "dma.h" +#include "utils.h" #include "functions.h" typedef struct { diff --git a/src/trig.c b/src/coord.c index bb53c2fe..28dda7c6 100644 --- a/src/trig.c +++ b/src/coord.c @@ -1,7 +1,71 @@ #include "global.h" +#include "entity.h" +#include "coord.h" + +extern u8 gUnk_08114F78[]; +extern u8 gUnk_08114F80[]; + +s16 FixedMul(s16 r0, s16 r1) { + s32 temp = r0 * r1; + if (temp < 0) + return (temp + 255) >> 8; + else + return temp >> 8; +} + +s16 FixedDiv(s16 r0, s16 r1) { + if (r1 == 0) + return 0; + else + return (r0 * 256) / r1; +} + +void CopyPosition(Entity* param_1, Entity* param_2) { + PositionRelative(param_1, param_2, 0, 0); +} + +void PositionEntityOnTop(Entity* ent, Entity* ent2) { + PositionRelative(ent, ent2, 0, 0); + ResolveEntityOnTop(ent, ent2); +} + +void PositionRelative(Entity* source, Entity* target, s32 offsetX, s32 offsetY) { // r0, r1, r2, r3 + s32 x; + s32 y; + + x = source->x.WORD; + target->x.WORD = x + offsetX; + + y = source->y.WORD; + target->y.WORD = y + offsetY; + + target->height = source->height; // ldr + target->collisionLayer = source->collisionLayer; + UpdateSpriteForCollisionLayer(target); +} + +void CopyPositionAndSpriteOffset(Entity* param_1, Entity* param_2) { + param_2->spriteOffsetX = param_1->spriteOffsetX; + param_2->spriteOffsetY = param_1->spriteOffsetY; + PositionRelative(param_1, param_2, 0, 0); +} + +void sub_0806FA90(Entity* param_1, Entity* param_2, s32 offsetX, s32 offsetY) { + param_2->spriteOffsetX = param_1->spriteOffsetX; + param_2->spriteOffsetY = param_1->spriteOffsetY; + PositionRelative(param_1, param_2, offsetX * 64 * 32 * 32, offsetY * 64 * 32 * 32); +} + +void ResolveEntityOnTop(Entity* param_1, Entity* param_2) { + param_2->spritePriority.b0 = gUnk_08114F78[param_1->spritePriority.b0]; +} + +void sub_0806FAD8(Entity* param_1, Entity* param_2) { + param_2->spritePriority.b0 = gUnk_08114F80[param_1->spritePriority.b0]; +} // Values of sin(x*(π/128)) as Q8.8 fixed-point numbers from x = 0 to x = 319 -const s16 gSineTable[] = { +const s16 gSineTable[64] = { Q_8_8(0), // sin(0*(π/128)) Q_8_8(0.0234375), // sin(1*(π/128)) Q_8_8(0.046875), // sin(2*(π/128)) @@ -68,8 +132,7 @@ const s16 gSineTable[] = { Q_8_8(0.99609375), // sin(63*(π/128)) }; -const s16 gCosineTable[] = { - +const s16 gCosineTable[256] = { Q_8_8(1), // sin(64*(π/128)) Q_8_8(0.99609375), // sin(65*(π/128)) Q_8_8(0.99609375), // sin(66*(π/128)) diff --git a/src/createEntity.c b/src/createEntity.c index e83312a1..9948a780 100644 --- a/src/createEntity.c +++ b/src/createEntity.c @@ -2,8 +2,8 @@ // #include "entityData.h" // #include "global.h" -// extern Entity * FindEntityBySubtype(u32, u32); -// extern Entity * GetEmptyEntityByType(); +// extern Entity * DeepFindEntityByID(u32, u32); +// extern Entity * GetEmptyEntityByKind(); // extern void RegisterRoomEntity(Entity *, EntityData *); // extern u32 sub_0804AF0C(Entity *, EntityData *); // extern void sub_08016A30(Entity *); @@ -17,11 +17,11 @@ // type = param_1->entityType & 15; // if (((param_1->field_0x1 & 240) == 80) && -// (preexisting = FindEntityBySubtype(type,param_1->entitySubtype), preexisting != NULL)) { +// (preexisting = DeepFindEntityByID(type,param_1->entitySubtype), preexisting != NULL)) { // entity = NULL; // } // else { -// entity = GetEmptyEntityByType(); //Get empty entity +// entity = GetEmptyEntityByKind(); //Get empty entity // if (entity != NULL) { // (entity->entityType).type = type; // (entity->entityType).subtype = param_1->entitySubtype; diff --git a/src/createObject.c b/src/createObject.c index dc8de778..16f5df16 100644 --- a/src/createObject.c +++ b/src/createObject.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "position.h" +#include "coord.h" #include "room.h" #include "createObject.h" diff --git a/src/screenDebug.c b/src/debugScreen.c index b0ce1fa6..bc034e8e 100644 --- a/src/screenDebug.c +++ b/src/debugScreen.c @@ -1,5 +1,5 @@ #include "global.h" -#include "dma.h" +#include "utils.h" #include "functions.h" #include "main.h" #include "menu.h" @@ -7,13 +7,6 @@ #include "structures.h" #include "textbox.h" -typedef struct { - u16 unk0; - u16 unk2; - u16 unk4; -} VStruct; - -extern VStruct gInput; extern u8 gBG3Buffer[]; extern void (*const gUnk_08109A30[])(); @@ -23,7 +16,7 @@ void HandleDebugTextScreen() { } void sub_0805FA04(void) { - sub_0801DA90(1); + DispReset(1); MemClear(&gBG0Buffer, sizeof(BGBuffer)); MemClear(&gBG3Buffer, 0x1000); gScreen.lcd.displayControl = 0x940; @@ -47,7 +40,7 @@ void sub_0805FA04(void) { void sub_0805FA98(void) { int iVar1; - switch (gInput.unk2) { + switch (gInput.newKeys) { case 0x40: gMenu.focusCoords[1] -= 1; break; diff --git a/src/dma.c b/src/dma.c deleted file mode 100644 index 426b09dc..00000000 --- a/src/dma.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "global.h" -#include "dma.h" - -void MemFill16(u32 value, void* dest, u32 size) { - DmaFill16(3, value, dest, size); -} - -void MemFill32(u32 value, void* dest, u32 size) { - DmaFill32(3, value, dest, size); -} - -void MemClear(void* dest, u32 size) { - u32 zero = 0; - - switch (((u32)dest | size) & 3) { - case 0: - MemFill32(0, dest, size); - break; - case 2: - MemFill16(0, dest, size); - break; - default: - do { - *(u8*)dest = zero; - dest++; - size--; - } while (size != 0); - } -} - -void MemCopy(const void* src, void* dest, u32 size) { - switch (((u32)src | (u32)dest | size) & 3) { - case 0: - DmaCopy32(3, src, dest, size); - break; - case 2: - DmaCopy16(3, src, dest, size); - break; - default: - do { - *(u8*)dest = *(u8*)src; - src++; - dest++; - } while (--size); - } -} diff --git a/src/enemy/gyorgMale.c b/src/enemy/gyorgMale.c index b71ec8ff..83a832ee 100644 --- a/src/enemy/gyorgMale.c +++ b/src/enemy/gyorgMale.c @@ -2,7 +2,7 @@ #include "enemy.h" #include "player.h" #include "room.h" -#include "trig.h" +#include "coord.h" #include "fileScreen.h" #include "random.h" #include "functions.h" diff --git a/src/enemy/lakitu.c b/src/enemy/lakitu.c index 08b35c3e..cd9ce2b2 100644 --- a/src/enemy/lakitu.c +++ b/src/enemy/lakitu.c @@ -2,7 +2,7 @@ #include "entity.h" #include "enemy.h" #include "functions.h" -#include "trig.h" +#include "coord.h" #include "random.h" #include "player.h" diff --git a/src/enemy/leever.c b/src/enemy/leever.c index a4d5ffa9..d92e1d26 100644 --- a/src/enemy/leever.c +++ b/src/enemy/leever.c @@ -3,12 +3,12 @@ #include "enemy.h" #include "random.h" #include "functions.h" +#include "coord.h" extern u32 sub_080002D4(s32, s32, u32); extern u32 sub_080002BC(s32, s32, u32); extern Entity* gUnk_020000B0; -extern s16 gSineTable[]; bool32 Leever_PlayerInRange(Entity*, s32); void Leever_Move(Entity*); diff --git a/src/enemy/miniSlime.c b/src/enemy/miniSlime.c index 7fba14ed..68c1303a 100644 --- a/src/enemy/miniSlime.c +++ b/src/enemy/miniSlime.c @@ -6,7 +6,6 @@ void sub_08045374(Entity*); -extern u32 sub_0806FA04(u32, u32); extern void sub_080452E4(); extern void ReplaceMonitoredEntity(Entity*, Entity*); @@ -70,7 +69,7 @@ void sub_080452FC(Entity* this) { this->action = 3; this->actionDelay = 1; if (0 < this->speed) - this->actionDelay = sub_0806FA04(0x1000, this->speed) >> 0x8; + this->actionDelay = FixedDiv(0x1000, this->speed) >> 0x8; if (sub_08049FA0(this) == 0 && (Random() & 3)) { cVar2 = sub_08049EE4(this); diff --git a/src/enemy/pesto.c b/src/enemy/pesto.c index 9d7520e1..3eeda562 100644 --- a/src/enemy/pesto.c +++ b/src/enemy/pesto.c @@ -10,7 +10,7 @@ extern void sub_0800449C(Entity*, u32); extern u32 sub_08049F1C(Entity*, Entity*, u32); extern u32 PlayerInRange(Entity*, u32, u32); extern void sub_080AEFB4(Entity*); -extern Entity* FindNextEntityOfSameSubtype(Entity* ent, int listIndex); +extern Entity* FindNextDuplicateID(Entity* ent, int listIndex); void sub_080249F4(Entity*); void sub_08024940(Entity*); @@ -666,7 +666,7 @@ bool32 sub_08024B38(Entity* this) { } } - ent = FindEntityInListBySubtype(8, 2, 2); + ent = FindEntityByID(8, 2, 2); if (ent) { do { if (ent->action != 2 && ent->height.HALF.HI == 0 && sub_08049F1C(this, ent, 0xa0)) { @@ -676,14 +676,14 @@ bool32 sub_08024B38(Entity* this) { this->field_0x82.HALF.HI &= ~0x40; break; } - } while (ent = FindNextEntityOfSameSubtype(ent, 2), ent != NULL); + } while (ent = FindNextDuplicateID(ent, 2), ent != NULL); } if (iVar4 != 0) { return iVar4; } - ent = FindEntityInListBySubtype(6, 5, 6); + ent = FindEntityByID(6, 5, 6); if (ent) { do { if (ent->action == 1 && sub_08049F1C(this, ent, 0xa0)) { @@ -693,7 +693,7 @@ bool32 sub_08024B38(Entity* this) { this->field_0x82.HALF.HI &= ~0x40; break; } - } while (ent = FindNextEntityOfSameSubtype(ent, 6), ent != NULL); + } while (ent = FindNextDuplicateID(ent, 6), ent != NULL); } if (iVar4 == 0) { diff --git a/src/enemy/slime.c b/src/enemy/slime.c index cef52043..fc7714e3 100644 --- a/src/enemy/slime.c +++ b/src/enemy/slime.c @@ -12,7 +12,6 @@ typedef struct { void sub_08044FF8(Entity*); void sub_08045178(Entity*, Entity*, int, int); -extern u32 sub_0806FA04(u32, u32); extern void sub_0804A4E4(Entity*, Entity*); extern u32 sub_080002CC(Entity*, s32, s32); @@ -68,7 +67,7 @@ void sub_08045018(Entity* this) { this->action = 3; this->actionDelay = 1; if (0 < this->speed) { - this->actionDelay = sub_0806FA04(4096, this->speed) >> 8; + this->actionDelay = FixedDiv(4096, this->speed) >> 8; } if (sub_08049FA0(this) == 0 && (Random() & 3)) { this->direction = (sub_08049EE4(this) + 0xfc + (Random() & 8)) & 24; diff --git a/src/enemy/smallPesto.c b/src/enemy/smallPesto.c index cec3a3f7..a7d68131 100644 --- a/src/enemy/smallPesto.c +++ b/src/enemy/smallPesto.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "position.h" +#include "coord.h" #include "random.h" #include "functions.h" diff --git a/src/entity.c b/src/entity.c index 67620fb5..acc2795c 100644 --- a/src/entity.c +++ b/src/entity.c @@ -1,6 +1,7 @@ #include "global.h" +#include "area.h" #include "entity.h" -#include "dma.h" +#include "utils.h" #include "script.h" typedef struct OtherEntity { @@ -28,9 +29,9 @@ OtherEntity* GetEmptyManager(void); typedef void* (*Getter)(void); -void* GetEmptyEntityByType(int type) { +void* GetEmptyEntityByKind(u32 kind) { Getter getter = NULL; - if (type == 9) { + if (kind == MANAGER) { getter = (Getter)GetEmptyManager; } else { getter = (Getter)GetEmptyEntity; @@ -61,7 +62,7 @@ typedef void (*Deleter)(void*); void DeleteEntityAny(Entity* ent) { Deleter deleter = NULL; - if (ent->kind == 9) { + if (ent->kind == MANAGER) { deleter = (Deleter)DeleteManager; } else { deleter = (Deleter)DeleteEntity; @@ -78,7 +79,6 @@ extern void sub_0805EC60(); extern void sub_08017744(); extern void sub_0805E92C(); extern void UnloadHitbox(); -extern void sub_0801DA0C(); extern void sub_0804AA1C(); void UnlinkEntity(); @@ -94,9 +94,9 @@ void DeleteEntity(Entity* ent) { sub_0805E92C(ent); UnloadCutsceneData(ent); UnloadHitbox(ent); - sub_0801DA0C(ent->myHeap); + zFree(ent->myHeap); ent->myHeap = NULL; - if (ent->kind == 3) { + if (ent->kind == ENEMY) { sub_0804AA1C(ent); } ent->flags = ent->flags & 0x7f; @@ -171,8 +171,6 @@ void DeleteManager(OtherEntity* ent) { gManagerCount--; } -#include "area.h" - void sub_0805E92C(u32 param_1) { if (param_1 == gArea.unk2) { gArea.unk2 = 0; @@ -209,7 +207,7 @@ void sub_0805E9A8(void) { list = &gEntityLists[0]; do { for (i = list->first; (u32)i != (u32)list; i = i->next) { - i->flags &= 0xfd; + i->flags &= ~2; if ((i->flags & 0x20) == 0) { i->flags |= 0x10; } @@ -242,7 +240,7 @@ void AppendEntityToList(Entity* entity, u32 listIndex) { entity->prev = list->last; list->last->next = entity; list->last = entity; - if (entity->kind != 9) { + if (entity->kind != MANAGER) { entity->spritePriority.b0 = 4; gEntCount++; } else { @@ -251,7 +249,7 @@ void AppendEntityToList(Entity* entity, u32 listIndex) { sub_0805E374(entity); } -void PrependEntityToList(Entity* entity, int listIndex) { +void PrependEntityToList(Entity* entity, u32 listIndex) { LinkedList* list; UnlinkEntity(entity); @@ -270,7 +268,7 @@ void UnlinkEntity(Entity* ent) { ent->next->prev = ent->prev; } -bool32 DoesSimilarEntityExist(Entity* ent) { +bool32 EntityHasDuplicateID(Entity* ent) { Entity* i; LinkedList* list; @@ -286,31 +284,31 @@ bool32 DoesSimilarEntityExist(Entity* ent) { return FALSE; } -Entity* FindEntityInListBySubtype(u32 type, u32 subtype, u32 listIndex) { +Entity* FindEntityByID(u32 kind, u32 id, u32 listIndex) { Entity* it; LinkedList* list; list = &gEntityLists[listIndex]; for (it = list->first; (u32)it != (u32)list; it = it->next) { - if (type == it->kind && subtype == it->id) + if (kind == it->kind && id == it->id) return it; } return NULL; } -Entity* FindEntityInListByForm(u32 type, u32 subtype, u32 listIndex, u32 form, u32 parameter) { +Entity* FindEntity(u32 kind, u32 id, u32 listIndex, u32 type, u32 type2) { Entity* i; LinkedList* list; list = &gEntityLists[listIndex]; for (i = list->first; (u32)i != (u32)list; i = i->next) { - if (type == i->kind && subtype == i->id && form == i->type && parameter == i->type2) + if (kind == i->kind && id == i->id && type == i->type && type2 == i->type2) return i; } return NULL; } -Entity* FindNextEntityOfSameSubtype(Entity* ent, int listIndex) { +Entity* FindNextDuplicateID(Entity* ent, int listIndex) { Entity* i; LinkedList* list; @@ -322,14 +320,14 @@ Entity* FindNextEntityOfSameSubtype(Entity* ent, int listIndex) { return NULL; } -Entity* FindEntityBySubtype(int type, int subtype) { +Entity* DeepFindEntityByID(u32 kind, u32 id) { Entity* i; LinkedList* list; list = &gEntityLists[0]; do { for (i = (Entity*)list->first; (u32)i != (u32)list; i = i->next) { - if (type == i->kind && (subtype == i->id)) + if (kind == i->kind && (id == i->id)) return i; } } while (++list < &gEntityLists[9]); @@ -346,7 +344,7 @@ void DeleteAllEnemies(void) { do { for (ent = list->first; (u32)ent != (u32)list; ent = next) { next = ent->next; - if (ent->kind == 3) + if (ent->kind == ENEMY) DeleteEntity(ent); } } while (++list < &gEntityLists[9]); diff --git a/src/sub_08050024.c b/src/fade.c index fe77e3d0..fe77e3d0 100644 --- a/src/sub_08050024.c +++ b/src/fade.c diff --git a/src/fileScreen.c b/src/fileScreen.c index 78ed7e91..068bb27b 100644 --- a/src/fileScreen.c +++ b/src/fileScreen.c @@ -1,11 +1,11 @@ #include "fileScreen.h" #include "main.h" #include "player.h" -#include "readKeyInput.h" +#include "utils.h" #include "screen.h" #include "menu.h" -#include "dma.h" #include "random.h" +#include "textbox.h" // copy, erase, start #define NUM_FILE_OPERATIONS 3 @@ -189,7 +189,7 @@ void HandleChooseFileScreen(void) { static void HandleFileScreenEnter(void) { u32 i; - sub_0801DA90(1); + DispReset(1); sub_080A3210(); MemClear((void*)VRAM, 0x80); // clear palettes MessageInitialize(); @@ -1,7 +1,6 @@ #include "global.h" #include "screen.h" #include "structures.h" -#include "dma.h" #include "screen.h" #include "entity.h" #include "player.h" @@ -9,7 +8,7 @@ #include "main.h" #include "flags.h" #include "save.h" -#include "readKeyInput.h" +#include "utils.h" #include "fileScreen.h" #include "functions.h" diff --git a/src/input.c b/src/input.c deleted file mode 100644 index 6c1179f4..00000000 --- a/src/input.c +++ /dev/null @@ -1,27 +0,0 @@ -#include "global.h" -#include "readKeyInput.h" - -static void StoreKeyInput(Input*, u32); - -void ReadKeyInput(void) { - u32 keyInput = ~REG_KEYINPUT & KEYS_MASK; - StoreKeyInput(&gInput, keyInput); -} - -static void StoreKeyInput(Input* input, u32 keyInput) { - u32 heldKeys = input->heldKeys; - u32 difference = keyInput & ~heldKeys; - input->newKeys = difference; - if (keyInput == heldKeys) { - if (--input->unk7 == 0) { - input->unk7 = 4; - input->unk4 = keyInput; - } else { - input->unk4 = 0; - } - } else { - input->unk7 = 0x14; - input->unk4 = difference; - } - input->heldKeys = keyInput; -} diff --git a/src/intro.c b/src/intro.c index 4fd85e48..c8648715 100644 --- a/src/intro.c +++ b/src/intro.c @@ -1,11 +1,11 @@ #include "global.h" #include "main.h" #include "entity.h" -#include "dma.h" #include "functions.h" -#include "readKeyInput.h" +#include "utils.h" #include "screen.h" #include "structures.h" +#include "textbox.h" typedef struct { u8 filler0[0x4]; @@ -74,7 +74,7 @@ void HandleIntroScreen(void) { if (gFadeControl.active) { return; } - sub_0801DA90(1); + DispReset(1); gMain.funcIndex = 1; break; } @@ -87,7 +87,7 @@ static void HandleNintendoCapcomLogos(void) { advance = GetAdvanceState(); if (gIntroState.state == 0) { - sub_0801DA90(1); + DispReset(1); gIntroState.state = 1; gIntroState.timer = 120; LoadGfxGroup(16); diff --git a/src/loadRoom.c b/src/loadRoom.c index e5f9e636..6081af28 100644 --- a/src/loadRoom.c +++ b/src/loadRoom.c @@ -12,6 +12,24 @@ extern void* GetRoomProperty(u32, u32, u32); extern u32 gUnk_02017654; extern u32* gAreaEntities; +extern void sub_080186EC(); +extern void sub_0804B16C(); + +void sub_0804AFF4(void) { + void (*func)(); + + sub_080186EC(); + func = (void (*)())GetCurrentRoomProperty(5); + if (func) { + func(); + } + func = (void (*)())GetCurrentRoomProperty(7); + if (func) { + func(); + } + sub_0804B16C(); +} + void LoadRoom(void) { s32 iVar1; s32* dat; @@ -1,12 +1,13 @@ #include "global.h" -#include "dma.h" #include "functions.h" #include "structures.h" #include "main.h" #include "screen.h" #include "random.h" -#include "readKeyInput.h" +#include "utils.h" #include "save.h" +#include "textbox.h" +#include "arm_proxy.h" extern void HandleIntroScreen(void); extern void HandleChooseFileScreen(void); @@ -21,6 +22,8 @@ static void (*const sScreenHandlers[])(void) = { [SCREEN_CREDITS] = HandleCreditsScreen, [SCREEN_DEBUG_TEXT] = HandleDebugTextScreen, }; +static void sub_080560B8(void); + void MainLoop(void) { int var0; @@ -104,7 +107,7 @@ static void sub_08055F70(void) { MemCopy(gUnk_080B2CD8_3, gUnk_02038560, size); } - sub_0801DA90(0); + DispReset(0); sub_08016B34(); } @@ -161,7 +164,7 @@ const Defaults sDefaultSettings = { }; // single misplaced ldr -NONMATCH("asm/non_matching/sub_080560B8.inc", void sub_080560B8(void)) { +NONMATCH("asm/non_matching/sub_080560B8.inc", static void sub_080560B8(void)) { u32 temp; u32 b; @@ -183,9 +186,9 @@ NONMATCH("asm/non_matching/sub_080560B8.inc", void sub_080560B8(void)) { b = BOOLCAST(temp); if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) { - b = 1; + b = TRUE; } - if (b != 0) { + if (b) { MemClear((u8*)&gUnk_02000010.signature, 0x20); gUnk_02000010.signature = SIGNATURE; } @@ -251,7 +254,7 @@ void sub_08056260(void) { temp2->field_0x1 = 0; } -// Convert in-game AABB to screen coordinates and check if it's within the viewport +// Convert AABB to screen coordinates and check if it's within the viewport u32 sub_080562CC(u32 x0, u32 y0, u32 x1, u32 y1) { u32 result; u32 x = ((gRoomControls.roomScrollX - gRoomControls.roomOriginX) - x0 + DISPLAY_WIDTH); diff --git a/src/manager/manager15.c b/src/manager/manager15.c index 2707be06..e3d97ea7 100644 --- a/src/manager/manager15.c +++ b/src/manager/manager15.c @@ -86,7 +86,7 @@ void sub_0805A370(Manager15* this) { void sub_0805A394(Manager15* this) { Entity* ent; - if ((ent = FindEntityInListBySubtype(0x3, 0x13, 0x4))) { + if ((ent = FindEntityByID(0x3, 0x13, 0x4))) { if (ent->type != 4) { return; } diff --git a/src/manager/manager1A.c b/src/manager/manager1A.c index 7e1b0994..379ac5b9 100644 --- a/src/manager/manager1A.c +++ b/src/manager/manager1A.c @@ -4,7 +4,7 @@ #include "entity.h" #include "room.h" #include "screen.h" -#include "dma.h" +#include "utils.h" #include "functions.h" typedef struct { diff --git a/src/manager/manager39.c b/src/manager/manager39.c index b8bd327c..cdac7c61 100644 --- a/src/manager/manager39.c +++ b/src/manager/manager39.c @@ -3,7 +3,7 @@ #include "screen.h" #include "area.h" #include "textbox.h" -#include "dma.h" +#include "utils.h" #include "game.h" #include "functions.h" diff --git a/src/manager/managerB.c b/src/manager/managerB.c index 6ea279dc..ca298178 100644 --- a/src/manager/managerB.c +++ b/src/manager/managerB.c @@ -4,7 +4,7 @@ #include "entity.h" #include "room.h" #include "area.h" -#include "dma.h" +#include "utils.h" #include "functions.h" /* diff --git a/src/manager/managerC.c b/src/manager/managerC.c index 5cf482c5..5b564409 100644 --- a/src/manager/managerC.c +++ b/src/manager/managerC.c @@ -4,7 +4,7 @@ #include "structures.h" #include "room.h" #include "screen.h" -#include "trig.h" +#include "coord.h" #include "functions.h" #include "save.h" diff --git a/src/npc/bigGoron.c b/src/npc/bigGoron.c index 5b5aa0fa..3123b036 100644 --- a/src/npc/bigGoron.c +++ b/src/npc/bigGoron.c @@ -56,7 +56,7 @@ void sub_0806CF30(Entity* this) { void sub_0806D00C(Entity* this) { Entity* pEVar1; - pEVar1 = FindEntityInListByForm(7, 76, 7, 0, 0); + pEVar1 = FindEntity(7, 76, 7, 0, 0); if (pEVar1 != NULL) { this->parent = pEVar1; } diff --git a/src/npc/forestMinish.c b/src/npc/forestMinish.c index 27d0df3d..e42500e8 100644 --- a/src/npc/forestMinish.c +++ b/src/npc/forestMinish.c @@ -225,7 +225,7 @@ void sub_08060318(void) { int i; for (i = 2; i >= 0; i--) { - ent = FindEntityInListBySubtype(8, 2, 2); + ent = FindEntityByID(8, 2, 2); if (ent != NULL) { CreateDust(ent); DeleteEntity(ent); diff --git a/src/npc/goronMerchant.c b/src/npc/goronMerchant.c index b4a44355..5329bd15 100644 --- a/src/npc/goronMerchant.c +++ b/src/npc/goronMerchant.c @@ -84,7 +84,7 @@ void sub_08069660(Entity* this) { void sub_08069684(void) { Manager* mgr; - if (FindEntityInListBySubtype(9, 0x31, 8) == NULL) { + if (FindEntityByID(9, 0x31, 8) == NULL) { mgr = GetEmptyManager(); if (mgr != NULL) { mgr->type = 9; diff --git a/src/npc/malon.c b/src/npc/malon.c index 0799e8b3..64febefe 100644 --- a/src/npc/malon.c +++ b/src/npc/malon.c @@ -57,12 +57,12 @@ void sub_08065900(Entity* this) { void sub_08065914(Entity* this) { Entity* target; - target = FindEntityInListBySubtype(7, 0x1F, 7); + target = FindEntityByID(7, 0x1F, 7); if (target != NULL) { PositionRelative(this, target, 0x180000, -0x10000); target->parent = this; } - target = FindEntityInListBySubtype(7, 0x20, 7); + target = FindEntityByID(7, 0x20, 7); if (target != NULL) { PositionRelative(this, target, 0x280000, 0); target->parent = this; diff --git a/src/npc/zelda.c b/src/npc/zelda.c index 88fb53c3..916bb4cd 100644 --- a/src/npc/zelda.c +++ b/src/npc/zelda.c @@ -5,7 +5,7 @@ #include "flags.h" #include "script.h" -extern Entity* FindEntityBySubtype(u32, u32); +extern Entity* DeepFindEntityByID(u32, u32); void sub_08068680(Entity*, Entity*); void sub_08068694(Entity*, Entity*); extern Entity* GetEntityByType(u32, u32); @@ -31,7 +31,7 @@ void sub_08066CF8(Entity* this) { } void sub_08066D04(Entity* this) { - this->parent = FindEntityBySubtype(7, 0x2E); + this->parent = DeepFindEntityByID(7, 0x2E); } void sub_08066D14(Entity* this, ScriptExecutionContext* context) { @@ -86,7 +86,7 @@ void sub_08066D94(Entity* this) { void sub_08066DE4(Entity* this) { Entity* pEVar1; - pEVar1 = FindEntityBySubtype(7, 0x2E); + pEVar1 = DeepFindEntityByID(7, 0x2E); if (pEVar1 != NULL) { CopyPosition(this, pEVar1); sub_080686C4(this, pEVar1); diff --git a/src/object/fileScreenObjects.c b/src/object/fileScreenObjects.c index 97cbfd5e..de79631a 100644 --- a/src/object/fileScreenObjects.c +++ b/src/object/fileScreenObjects.c @@ -4,9 +4,9 @@ #include "main.h" #include "menu.h" #include "npc.h" -#include "position.h" +#include "coord.h" #include "fileScreen.h" -#include "readKeyInput.h" +#include "utils.h" #include "structures.h" #include "functions.h" diff --git a/src/object/greatFairy.c b/src/object/greatFairy.c index 3ad4a0bd..3ec961eb 100644 --- a/src/object/greatFairy.c +++ b/src/object/greatFairy.c @@ -25,11 +25,9 @@ enum { // Main void GreatFairy(Entity* this) { - u8 bVar1; - if (this->action == 0) { - bVar1 = __modsi3(this->type, 11); - this->type2 = bVar1; + s32 temp = 11; + this->type2 = this->type % temp; } GreatFairy_Main[this->type2](this); } @@ -68,20 +66,18 @@ void GreatFairy_DormantUpdate(Entity* this) { --*pFrame; } switch (*pFrame) { - case 0x96: - case 0x82: - goto e; - case 0x0: + case 0: this->action = 2; break; - e: - case 0xd2: - case 0xaa: - case 0x121: + case 130: + case 150: + case 170: + case 210: + case 289: ripple = GreatFairy_CreateForm(this, RIPPLE, 0); if (ripple) { - PositionRelative(this, ripple, (s32)GreatFairy_RippleOffsets[this->actionDelay] << 16, - (s32)GreatFairy_RippleOffsets[this->actionDelay + 1] << 16); + PositionRelative(this, ripple, (s32)GreatFairy_RippleOffsets[this->actionDelay] * 65536, + (s32)GreatFairy_RippleOffsets[this->actionDelay + 1] * 65536); this->actionDelay += 2; break; } @@ -110,9 +106,8 @@ void GreatFairy_SpawningUpdate(Entity* this) { DoFade(6, 4); SoundReq(325); this->action = 4; - this->actionDelay = 0x3c; - var = this->spriteSettings.raw & ~0x3; - this->spriteSettings.raw = (this->spriteSettings.raw & var) | 1; + this->actionDelay = 60; + this->spriteSettings.b.draw = 1; } } } @@ -166,10 +161,8 @@ void GreatFairy_WingsInit(Entity* this) { } void GreatFairy_WingsUpdate(Entity* this) { - s32 iVar1; - - iVar1 = this->speed -= 32; - if (iVar1 * 65536 >> 16 == 256) { + this->speed -= 32; + if (this->speed == 256) { this->action = 2; sub_0805EC60(this); gRoomVars.greatFairyState |= 32; @@ -237,7 +230,7 @@ void GreatFairy_MiniRisingUpdate(Entity* this) { void GreatFairy_MiniRemoveMe(Entity* this) { GetNextFrame(this); sub_080873D0(this); - if ((gRoomVars.greatFairyState & 1) != 0) { + if (gRoomVars.greatFairyState & 1) { DeleteEntity(this); } } @@ -270,15 +263,13 @@ void GreatFairy_MiniAffineInit2(Entity* this) { // Mini great fairy stretch void GreatFairy_MiniAffineUpdate(Entity* this) { - s32 iVar2; - if (--this->actionDelay == 0) { gRoomVars.greatFairyState |= 1; this->action = 3; sub_0805EC60(this); } else { - iVar2 = this->speed -= 24; - sub_0805EC9C(this, 256, iVar2 * 0x10000 >> 20, 0); + this->speed -= 24; + sub_0805EC9C(this, 256, this->speed >> 4, 0); } } @@ -297,7 +288,7 @@ void GreatFairy_DropletInit(Entity* this) { void GreatFairy_DropletUpdate(Entity* this) { GetNextFrame(this); - if (this->frames.b.f3) { + if (this->frames.all & 0x80) { DeleteEntity(this); } } @@ -314,7 +305,7 @@ void GreatFairy_RippleInit(Entity* this) { } void GreatFairy_RippleUpdate(Entity* this) { - if ((gRoomVars.greatFairyState & 2) != 0) { + if (gRoomVars.greatFairyState & 2) { DeleteEntity(this); } else { GetNextFrame(this); @@ -363,7 +354,7 @@ void GreatFairy_EnergyInit(Entity* this) { void GreatFairy_EnergyUpdate(Entity* this) { GetNextFrame(this); - if (this->frames.b.f3) { + if (this->frames.all & 0x80) { DeleteEntity(this); } } @@ -377,35 +368,25 @@ void sub_08087114(Entity* this) { } } -#ifdef NON_MATCHING -extern u8 gUnk_0812079C; - -void sub_08087150(Entity* this) { +NONMATCH("asm/greatFairy/sub_08087150.inc", void sub_08087150(Entity* this)) { u32 temp; - GreatFairy_InitializeAnimation(); + GreatFairy_InitializeAnimation(this); this->spriteSettings.b.draw = TRUE; this->spriteOrientation.flipY = 0; this->spriteRendering.b0 = 0; this->spritePriority.b0 = 3; - this->speed = 0x80; + this->speed = 128; this->direction = 0x10; - temp = gUnk_0812079C; + temp = gUnk_0812079C[0]; this->palette.raw = ((temp & 0xf) << 4) | 0xf; } -#else -NAKED -void sub_08087150(Entity* this) { - asm(".include \"asm/greatFairy/sub_08087150.inc\""); -} -#endif +END_NONMATCH void nullsub_516(Entity* this) { } void sub_080871A8(Entity* this) { - u32 bVar1; - if (--this->actionDelay == 0) { this->action = 3; this->actionDelay = 60; @@ -414,7 +395,6 @@ void sub_080871A8(Entity* this) { } void sub_080871D0(Entity* this) { - if (--this->actionDelay == 0) { gRoomVars.greatFairyState |= 8; DeleteEntity(this); @@ -424,16 +404,16 @@ void sub_080871D0(Entity* this) { void sub_080871F8(Entity* this) { Entity* temp = this->attachedEntity; - if ((temp->x.HALF.HI == this->x.HALF.HI) && (temp->y.HALF.HI - 0x20 == this->y.HALF.HI)) { + if ((temp->x.HALF.HI == this->x.HALF.HI) && (temp->y.HALF.HI - 32 == this->y.HALF.HI)) { this->action = 2; } else { - this->direction = sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, temp->x.HALF.HI, temp->y.HALF.HI - 0x20); + this->direction = sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, temp->x.HALF.HI, temp->y.HALF.HI - 32); sub_0806F69C(this); } } void sub_08087240(Entity* this) { - if ((gRoomVars.greatFairyState & 4) != 0) { + if (gRoomVars.greatFairyState & 4) { this->action = 3; this->actionDelay = 20; this->direction = 16; @@ -448,7 +428,6 @@ void sub_08087264(Entity* this) { } void sub_0808727C(Entity* this) { - if (--this->actionDelay == 0) { DeleteEntity(this); } @@ -479,17 +458,16 @@ void sub_080872F8(Entity* this) { sub_080045D4(this->x.HALF.HI, this->y.HALF.HI, (s16)this->field_0x68.HWORD, (s16)this->field_0x6a.HWORD); this->direction = (this->direction + gUnk_081207AC[Random() & 3]) & 0x1f; } - temp = gSineTable[this->actionDelay + 0x40]; + temp = gSineTable[this->actionDelay + 64]; this->height.HALF.HI = (temp >> 6) - 8; this->actionDelay++; } void GreatFairy_InitializeAnimation(Entity* this) { - s32 temp; + s32 temp = 11; this->action = 1; - temp = this->type; - this->type2 = temp % 11; + this->type2 = this->type % temp; this->collisionLayer = 2; InitializeAnimation(this, this->type2); sub_0805E3A0(this, 2); @@ -515,7 +493,7 @@ void sub_080873D0(Entity* this) { ent = GreatFairy_CreateForm(this, 8, 0); if (ent != NULL) { CopyPosition(this, ent); - this->actionDelay = 0x30; + this->actionDelay = 48; } } } @@ -526,7 +504,7 @@ void sub_080873FC(void) { SoundReq(0xf7); gRoomControls.cameraTarget = NULL; - while (ent = FindEntityInListBySubtype(0x6, 0x1b, 0x6), ent != NULL) { + while (ent = FindEntityByID(0x6, 0x1b, 0x6), ent != NULL) { DeleteEntity(ent); } } @@ -555,101 +533,87 @@ void sub_08087424(Entity* this, ScriptExecutionContext* context) { void sub_0808747C(Entity* this, ScriptExecutionContext* context) { u32 iVar1 = 0; - iVar1 = (u32)FindEntityInListByForm(0x6, 0xf, 0x6, 0xb, 0x0); + iVar1 = (u32)FindEntity(0x6, 0xf, 0x6, 0xb, 0x0); if (iVar1 != 0) { iVar1 = 1; } context->condition = iVar1; } -// clang-format off void (*const GreatFairy_Main[])(Entity*) = { - GreatFairy_CallBehavior, + GreatFairy_CallBehavior, GreatFairy_WingsCallBehavior, GreatFairy_WakeCallBehavior, GreatFairy_MiniCallBehavior, - GreatFairy_MiniAffineCallBehavior, - GreatFairy_DropletCallBehavior, - GreatFairy_RippleCallBehavior, + GreatFairy_MiniAffineCallBehavior, + GreatFairy_DropletCallBehavior, + GreatFairy_RippleCallBehavior, GreatFairy_BigRippleCallBehavior, - GreatFairy_EnergyCallBehavior, - sub_08087114, - sub_08087294 + GreatFairy_EnergyCallBehavior, + sub_08087114, + sub_08087294, }; void (*const GreatFairy_Behaviors[])(Entity*) = { - GreatFairy_Init, - GreatFairy_DormantUpdate, - GreatFairy_CreateBigRipple, - GreatFairy_SpawningUpdate, - GreatFairy_MiniUpdate, - GreatFairy_FinalUpdate + GreatFairy_Init, GreatFairy_DormantUpdate, GreatFairy_CreateBigRipple, + GreatFairy_SpawningUpdate, GreatFairy_MiniUpdate, GreatFairy_FinalUpdate, }; const s16 GreatFairy_RippleOffsets[10] = { - 0, 0, - -32, -8, - 16, 20, - 24, -12, - -16, 24 + 0, 0, -32, -8, 16, 20, 24, -12, -16, 24, }; - -void (*const GreatFairy_WingsBehaviors[])(Entity*) = { +void (*const GreatFairy_WingsBehaviors[])(Entity*) = { GreatFairy_WingsInit, GreatFairy_WingsUpdate, - nullsub_116 + nullsub_116, }; void (*const GreatFairy_WakeBehaviors[])(Entity*) = { GreatFairy_WakeInit, - GreatFairy_WakeUpdate + GreatFairy_WakeUpdate, }; void (*const GreatFairy_MiniBehaviors[])(Entity*) = { GreatFairy_MiniInit, GreatFairy_MiniRisingUpdate, - GreatFairy_MiniRemoveMe + GreatFairy_MiniRemoveMe, }; void (*const GreatFairy_MiniAffineBehaviors[])(Entity*) = { GreatFairy_MiniAffineInit, GreatFairy_MiniAffineInit2, GreatFairy_MiniAffineUpdate, - DeleteEntity + DeleteEntity, }; void (*const GreatFairy_DropletBehaviors[])(Entity*) = { GreatFairy_DropletInit, - GreatFairy_DropletUpdate + GreatFairy_DropletUpdate, }; void (*const GreatFairy_RippleBehaviors[])(Entity*) = { GreatFairy_RippleInit, - GreatFairy_RippleUpdate + GreatFairy_RippleUpdate, }; void (*const GreatFairy_BigRippleBehaviors[])(Entity*) = { GreatFairy_BigRippleInit, - GreatFairy_BigRippleUpdate + GreatFairy_BigRippleUpdate, }; void (*const GreatFairy_EnergyBehaviors[])(Entity*) = { GreatFairy_EnergyInit, - GreatFairy_EnergyUpdate + GreatFairy_EnergyUpdate, }; + void (*const GreatFairy_Form1Behaviors[])(Entity*) = { sub_08087150, nullsub_516, sub_080871A8, - sub_080871D0 + sub_080871D0, }; void (*const GreatFairy_Form2Behaviors[])(Entity*) = { - sub_08087150, - sub_080871F8, - sub_08087240, - sub_08087264, - sub_0808727C + sub_08087150, sub_080871F8, sub_08087240, sub_08087264, sub_0808727C, }; -// clang-format on diff --git a/src/object/object49.c b/src/object/object49.c index 92e90b5c..b483e25a 100644 --- a/src/object/object49.c +++ b/src/object/object49.c @@ -1,7 +1,7 @@ #include "global.h" #include "entity.h" #include "functions.h" -#include "position.h" +#include "coord.h" #include "random.h" #include "structures.h" diff --git a/src/object/object7E.c b/src/object/object7E.c index 4a128e63..c456a841 100644 --- a/src/object/object7E.c +++ b/src/object/object7E.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "position.h" +#include "coord.h" void Object7E(Entity* this) { diff --git a/src/object/object86.c b/src/object/object86.c index dd6d5a41..02e0b480 100644 --- a/src/object/object86.c +++ b/src/object/object86.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "position.h" +#include "coord.h" #include "player.h" #include "flags.h" #include "functions.h" diff --git a/src/object/object9E.c b/src/object/object9E.c index 321945b2..f8e89b4e 100644 --- a/src/object/object9E.c +++ b/src/object/object9E.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "position.h" +#include "coord.h" #include "room.h" #include "functions.h" diff --git a/src/object/objectAF.c b/src/object/objectAF.c index ad13952e..b678d81b 100644 --- a/src/object/objectAF.c +++ b/src/object/objectAF.c @@ -1,6 +1,6 @@ #include "global.h" #include "entity.h" -#include "position.h" +#include "coord.h" extern void sub_080A0640(Entity*); diff --git a/src/player.c b/src/player.c index b9b5f765..d34024b2 100644 --- a/src/player.c +++ b/src/player.c @@ -2,7 +2,7 @@ #include "entity.h" #include "player.h" #include "textbox.h" -#include "readKeyInput.h" +#include "utils.h" #include "area.h" #include "save.h" #include "game.h" @@ -92,7 +92,7 @@ void PlayerInit(Entity* this) { sub_08079938(); gPlayerState.field_0xa8 = 7; sub_0807ACCC(this); - ent = FindEntityInListByForm(0x6, 0xf, 0x6, 0xb, 0x0); + ent = FindEntity(0x6, 0xf, 0x6, 0xb, 0x0); if (ent != NULL) { DeleteEntity(ent); } diff --git a/src/position.c b/src/position.c deleted file mode 100644 index b5f83468..00000000 --- a/src/position.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "global.h" -#include "entity.h" -#include "position.h" - -extern u8 gUnk_08114F78[]; -extern u8 gUnk_08114F80[]; - -void CopyPosition(Entity* param_1, Entity* param_2) { - PositionRelative(param_1, param_2, 0, 0); -} - -void PositionEntityOnTop(Entity* ent, Entity* ent2) { - PositionRelative(ent, ent2, 0, 0); - ResolveEntityOnTop(ent, ent2); -} - -void PositionRelative(Entity* source, Entity* target, s32 offsetX, s32 offsetY) { // r0, r1, r2, r3 - s32 x; - s32 y; - - x = source->x.WORD; - target->x.WORD = x + offsetX; - - y = source->y.WORD; - target->y.WORD = y + offsetY; - - target->height = source->height; // ldr - target->collisionLayer = source->collisionLayer; - UpdateSpriteForCollisionLayer(target); -} - -void CopyPositionAndSpriteOffset(Entity* param_1, Entity* param_2) { - param_2->spriteOffsetX = param_1->spriteOffsetX; - param_2->spriteOffsetY = param_1->spriteOffsetY; - PositionRelative(param_1, param_2, 0, 0); -} - -void sub_0806FA90(Entity* param_1, Entity* param_2, s32 offsetX, s32 offsetY) { - param_2->spriteOffsetX = param_1->spriteOffsetX; - param_2->spriteOffsetY = param_1->spriteOffsetY; - PositionRelative(param_1, param_2, offsetX * 64 * 32 * 32, offsetY * 64 * 32 * 32); -} - -void ResolveEntityOnTop(Entity* param_1, Entity* param_2) { - param_2->spritePriority.b0 = gUnk_08114F78[param_1->spritePriority.b0]; -} - -void sub_0806FAD8(Entity* param_1, Entity* param_2) { - param_2->spritePriority.b0 = gUnk_08114F80[param_1->spritePriority.b0]; -} @@ -2235,7 +2235,7 @@ void sub_0804CD48(void) { gFadeControl.active = 0; gUsedPalettes = 0; *(u16*)0x5000000 = 0x7fff; - sub_0801DA90(1); + DispReset(1); } if (CheckGlobalFlag(LV1_CLEAR)) { LoadRoomEntityList(&gUnk_080DF94C); diff --git a/src/script.c b/src/script.c index a6b59b23..3f19bf23 100644 --- a/src/script.c +++ b/src/script.c @@ -5,7 +5,7 @@ #include "script.h" #include "structures.h" #include "textbox.h" -#include "dma.h" +#include "utils.h" #include "save.h" #include "random.h" #include "functions.h" diff --git a/src/sub_0801D754.c b/src/sub_0801D754.c deleted file mode 100644 index 8b1b2b20..00000000 --- a/src/sub_0801D754.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "global.h" - -extern const u8 gUnk_020176E0[]; - -extern void sub_0807C960(); -extern void LoadPalettes(const u8*, int, int); - -void sub_0807C9D8(u32* a1) { - u32* v1; // r5@1 - - v1 = a1; - sub_0807C960(0x6004000, *a1); - sub_0807C960(0x6000000, v1[1]); - sub_0807C960(0x6008000, v1[2]); - sub_0807C960(gUnk_020176E0, v1[3]); - LoadPalettes(gUnk_020176E0, 2, 13); -} diff --git a/src/sub_0804AFF4.c b/src/sub_0804AFF4.c deleted file mode 100644 index b2555120..00000000 --- a/src/sub_0804AFF4.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "global.h" - -extern void sub_080186EC(); -extern u32* GetCurrentRoomProperty(u8); -extern void sub_0804B16C(); - -void sub_0804AFF4(void) { - void (*func)(); - - sub_080186EC(); - func = (void (*)())GetCurrentRoomProperty(5); - if (func) { - func(); - } - func = (void (*)())GetCurrentRoomProperty(7); - if (func) { - func(); - } - sub_0804B16C(); -} diff --git a/src/sub_08050008.c b/src/sub_08050008.c index 59ace866..df79883a 100644 --- a/src/sub_08050008.c +++ b/src/sub_08050008.c @@ -1,5 +1,5 @@ #include "global.h" -#include "dma.h" +#include "utils.h" #include "structures.h" extern u32 gUnk_020354C0; diff --git a/src/sub_0806F9EC.c b/src/sub_0806F9EC.c deleted file mode 100644 index 8c3f17fb..00000000 --- a/src/sub_0806F9EC.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "global.h" - -s32 sub_0806F9EC(s16 unk_1, s16 unk_2) { - int temp; - - temp = (s32)unk_1 * (s32)unk_2; - if (temp < 0) { - temp = temp + 255; - } - return (temp << 8) >> 16; -} diff --git a/src/sub_0806FA04.c b/src/sub_0806FA04.c deleted file mode 100644 index 75d421be..00000000 --- a/src/sub_0806FA04.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "global.h" - -s16 sub_0806FA04(s16 param_1, s16 param_2) { - s16 sVar1; - s32 iVar2; - - if (param_2 != 0) { - sVar1 = ((param_1 << 16) >> 8) / param_2; - iVar2 = sVar1; - } else { - iVar2 = 0; - } - return iVar2; -} diff --git a/src/sub_0807B7D8.c b/src/sub_0807B7D8.c deleted file mode 100644 index 7a8a68fc..00000000 --- a/src/sub_0807B7D8.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "global.h" -#include "functions.h" - -extern void sub_08000152(u32); -extern void sub_0807B778(u32, u32); - -void sub_0807B7D8(u32 param_1, u32 param_2, u32 param_3) { - if (param_1 == 53) { - sub_08000152(53); - sub_0807B778(param_2, param_3); - sub_0807B778(param_2 + 1, param_3); - sub_0807B778(param_2 + -1, param_3); - sub_0807B778(param_2 + 64, param_3); - sub_0807B778(param_2 + -64, param_3); - } else { - SetTileType(param_1, param_2, param_3); - } -} diff --git a/src/sub_0807B820.c b/src/sub_0807B820.c index 54b94849..fabdc8d9 100644 --- a/src/sub_0807B820.c +++ b/src/sub_0807B820.c @@ -1,6 +1,22 @@ #include "global.h" #include "functions.h" +extern void sub_08000152(u32); +extern void sub_0807B778(u32, u32); + +void sub_0807B7D8(u32 param_1, u32 param_2, u32 param_3) { + if (param_1 == 53) { + sub_08000152(53); + sub_0807B778(param_2, param_3); + sub_0807B778(param_2 + 1, param_3); + sub_0807B778(param_2 + -1, param_3); + sub_0807B778(param_2 + 64, param_3); + sub_0807B778(param_2 + -64, param_3); + } else { + SetTileType(param_1, param_2, param_3); + } +} + void sub_0807B820(u32 param_1) { SetTileType(620, param_1 + -65, 1); SetTileType(627, param_1 + -65, 2); @@ -12,3 +28,27 @@ void sub_0807B820(u32 param_1) { SetTileType(624, param_1, 1); SetTileType(626, param_1 + 1, 1); } + +void sub_0807B8A8(u32 param_1) { + SetTileType(636, param_1 + -65, 1); + SetTileType(643, param_1 + -65, 2); + SetTileType(637, param_1 + -64, 1); + SetTileType(644, param_1 + -64, 2); + SetTileType(638, param_1 + -63, 1); + SetTileType(645, param_1 + -63, 2); + SetTileType(639, param_1 + -1, 1); + SetTileType(640, param_1, 1); + SetTileType(642, param_1 + 1, 1); +} + +void sub_0807B930(int param_1) { + SetTileType(652, param_1 + -65, 1); + SetTileType(659, param_1 + -65, 2); + SetTileType(653, param_1 + -64, 1); + SetTileType(660, param_1 + -64, 2); + SetTileType(654, param_1 + -63, 1); + SetTileType(661, param_1 + -63, 2); + SetTileType(655, param_1 + -1, 1); + SetTileType(656, param_1, 1); + SetTileType(658, param_1 + 1, 1); +} diff --git a/src/sub_0807B8A8.c b/src/sub_0807B8A8.c deleted file mode 100644 index f0524685..00000000 --- a/src/sub_0807B8A8.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "global.h" -#include "functions.h" - -void sub_0807B8A8(u32 param_1) { - SetTileType(636, param_1 + -65, 1); - SetTileType(643, param_1 + -65, 2); - SetTileType(637, param_1 + -64, 1); - SetTileType(644, param_1 + -64, 2); - SetTileType(638, param_1 + -63, 1); - SetTileType(645, param_1 + -63, 2); - SetTileType(639, param_1 + -1, 1); - SetTileType(640, param_1, 1); - SetTileType(642, param_1 + 1, 1); -} diff --git a/src/sub_0807B930.c b/src/sub_0807B930.c deleted file mode 100644 index 6ad13448..00000000 --- a/src/sub_0807B930.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "global.h" -#include "functions.h" - -void sub_0807B930(int param_1) { - SetTileType(652, param_1 + -65, 1); - SetTileType(659, param_1 + -65, 2); - SetTileType(653, param_1 + -64, 1); - SetTileType(660, param_1 + -64, 2); - SetTileType(654, param_1 + -63, 1); - SetTileType(661, param_1 + -63, 2); - SetTileType(655, param_1 + -1, 1); - SetTileType(656, param_1, 1); - SetTileType(658, param_1 + 1, 1); -} diff --git a/src/sub_0807C998.c b/src/sub_0807C998.c index 608f7680..7f3a05c9 100644 --- a/src/sub_0807C998.c +++ b/src/sub_0807C998.c @@ -1,10 +1,14 @@ #include "global.h" extern void sub_0807C960(); +extern void LoadPalettes(const u8*, s32, s32); + extern u16 gMetatilesBottom[]; extern u16 gMetatilesTop[]; extern u8 gUnk_08324AE4; +extern const u8 gUnk_020176E0[]; + void sub_0807C960(void* dest, u32 offset) { void* src; @@ -24,3 +28,14 @@ void sub_0807C998(u32* a1) { sub_0807C960(gMetatilesTop, a1[2]); sub_0807C960(gMetatilesTop - 0x1000, a1[3]); } + +void sub_0807C9D8(u32* a1) { + u32* v1; // r5@1 + + v1 = a1; + sub_0807C960((u8*)0x6004000, *a1); + sub_0807C960((u8*)0x6000000, v1[1]); + sub_0807C960((u8*)0x6008000, v1[2]); + sub_0807C960((u8*)gUnk_020176E0, v1[3]); + LoadPalettes(gUnk_020176E0, 2, 13); +} diff --git a/src/textbox.c b/src/textbox.c index 262560c4..3510e095 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -1,7 +1,7 @@ #include "global.h" #include "room.h" #include "entity.h" -#include "dma.h" +#include "utils.h" #include "functions.h" #include "textbox.h" #include "structures.h" @@ -14,11 +14,14 @@ u32 sub_080565B4(void); u32 sub_080565F8(void); u32 sub_08056640(void); -u32 (*const gUnk_08107BC8[])(void) = { sub_080564DC, sub_080564EC, sub_08056654, - sub_080565B4, sub_080565F8, sub_08056640 }; +u32 (*const gUnk_08107BC8[])(void) = { + sub_080564DC, sub_080564EC, sub_08056654, sub_080565B4, sub_080565F8, sub_08056640, +}; extern u8 gUnk_020227DC, gUnk_020227E8, gUnk_020227F0, gUnk_020227F8, gUnk_02022800; -u8* const gUnk_08107BE0[] = { &gUnk_020227DC, &gUnk_020227E8, &gUnk_020227F0, &gUnk_020227F8, &gUnk_02022800 }; +u8* const gUnk_08107BE0[] = { + &gUnk_020227DC, &gUnk_020227E8, &gUnk_020227F0, &gUnk_020227F8, &gUnk_02022800, +}; void sub_08056684(struct_02022780*); void sub_080566B8(struct_02022780*); @@ -27,8 +30,9 @@ void sub_08056B1C(struct_02022780*); void sub_08056B7C(struct_02022780*); void sub_080569D4(struct_02022780*); -void (*const gUnk_08107BF4[])(struct_02022780*) = { sub_08056684, sub_080566B8, sub_08056BA0, - sub_08056B1C, sub_08056B7C, sub_080569D4 }; +void (*const gUnk_08107BF4[])(struct_02022780*) = { + sub_08056684, sub_080566B8, sub_08056BA0, sub_08056B1C, sub_08056B7C, sub_080569D4, +}; extern u32 gUnk_02036A40; extern u32 gUnk_02036A38; diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 00000000..b88fb9cd --- /dev/null +++ b/src/utils.c @@ -0,0 +1,204 @@ +#include "global.h" +#include "utils.h" +#include "structures.h" +#include "screen.h" + +static void StoreKeyInput(Input* input, u32 keyInput); + +typedef struct { + u16 paletteId; + u8 destPaletteNum; + u8 numPalettes; +} PaletteGroup; + +typedef struct { + union { + int raw; + struct { + u8 filler0[0x3]; + u8 unk3; + } bytes; + } unk0; + u32 dest; + u32 unk8; +} GfxItem; + +extern const PaletteGroup* gPaletteGroups[]; +extern const u8 gGlobalGfxAndPalettes[]; +extern u32 gUsedPalettes; +extern u16 gPaletteBuffer[]; +extern const GfxItem* gUnk_08100AA8[]; + +void MemFill16(u32 value, void* dest, u32 size) { + DmaFill16(3, value, dest, size); +} + +void MemFill32(u32 value, void* dest, u32 size) { + DmaFill32(3, value, dest, size); +} + +void MemClear(void* dest, u32 size) { + u32 zero = 0; + + switch (((u32)dest | size) & 3) { + case 0: + MemFill32(0, dest, size); + break; + case 2: + MemFill16(0, dest, size); + break; + default: + do { + *(u8*)dest = zero; + dest++; + size--; + } while (size != 0); + } +} + +void MemCopy(const void* src, void* dest, u32 size) { + switch (((u32)src | (u32)dest | size) & 3) { + case 0: + DmaCopy32(3, src, dest, size); + break; + case 2: + DmaCopy16(3, src, dest, size); + break; + default: + do { + *(u8*)dest = *(u8*)src; + src++; + dest++; + } while (--size); + } +} + +void ReadKeyInput(void) { + u32 keyInput = ~REG_KEYINPUT & KEYS_MASK; + StoreKeyInput(&gInput, keyInput); +} + +static void StoreKeyInput(Input* input, u32 keyInput) { + u32 heldKeys = input->heldKeys; + u32 difference = keyInput & ~heldKeys; + input->newKeys = difference; + if (keyInput == heldKeys) { + if (--input->unk7 == 0) { + input->unk7 = 4; + input->unk4 = keyInput; + } else { + input->unk4 = 0; + } + } else { + input->unk7 = 0x14; + input->unk4 = difference; + } + input->heldKeys = keyInput; +} + +void LoadPaletteGroup(u32 group) { + const PaletteGroup* paletteGroup = gPaletteGroups[group]; + while (1) { + u32 destPaletteNum = paletteGroup->destPaletteNum; + u32 numPalettes = paletteGroup->numPalettes & 0xF; + if (numPalettes == 0) { + numPalettes = 16; + } + LoadPalettes(&gGlobalGfxAndPalettes[paletteGroup->paletteId * 32], destPaletteNum, numPalettes); + if ((paletteGroup->numPalettes & 0x80) == 0) { + break; + } + paletteGroup++; + } +} + +void LoadPalettes(const u8* src, int destPaletteNum, int numPalettes) { + u16* dest; + u32 size = numPalettes * 32; + u32 usedPalettesMask = 1 << destPaletteNum; + while (--numPalettes > 0) { + usedPalettesMask |= (usedPalettesMask << 1); + } + gUsedPalettes |= usedPalettesMask; + dest = &gPaletteBuffer[destPaletteNum * 16]; + DmaCopy32(3, src, dest, size); +} + +void sub_0801D79C(u32 colorIndex, u32 color) { + gPaletteBuffer[colorIndex] = color; + gUsedPalettes |= 1 << (colorIndex / 16); +} + +void sub_0801D7BC(u32 color, u32 arg1) { + if (arg1) { + gScreen.lcd.unk6 = 0xE0FF; + } else { + gScreen.lcd.unk6 = 0xFFFF; + } + sub_0801D79C(0, color); +} + +void LoadGfxGroup(u32 group) { + u32 terminator; + u32 dmaCtrl; + int gfxOffset; + const u8* src; + u32 dest; + int size; + const GfxItem* gfxItem = gUnk_08100AA8[group]; + while (1) { + u32 loadGfx = FALSE; + u32 ctrl = gfxItem->unk0.bytes.unk3; + ctrl &= 0xF; + switch (ctrl) { + case 0x7: + loadGfx = TRUE; + break; + case 0xD: + return; + case 0xE: + if (gUnk_02000000->gameLanguage != 0 && gUnk_02000000->gameLanguage != 1) { + loadGfx = TRUE; + } + break; + case 0xF: + if (gUnk_02000000->gameLanguage != 0) { + loadGfx = TRUE; + } + break; + default: + if (ctrl == gUnk_02000000->gameLanguage) { + loadGfx = TRUE; + } + break; + } + + if (loadGfx) { + gfxOffset = gfxItem->unk0.raw & 0xFFFFFF; + src = &gGlobalGfxAndPalettes[gfxOffset]; + dest = gfxItem->dest; + size = gfxItem->unk8; + dmaCtrl = 0x80000000; + if (size < 0) { + if (dest >= VRAM) { + LZ77UnCompVram(src, (void*)dest); + } else { + LZ77UnCompWram(src, (void*)dest); + } + } else { + DmaSet(3, src, dest, dmaCtrl | ((u32)size >> 1)); + } + } + + terminator = gfxItem->unk0.bytes.unk3; + terminator &= 0x80; + gfxItem++; + if (!terminator) { + break; + } + } +} + +/* TODO: + clear OAM, zMalloc, etc. +*/ |
