summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorIbot02 <jtp.jtp@gmx.de>2022-01-09 20:46:03 +0100
committerIbot02 <jtp.jtp@gmx.de>2022-01-09 20:46:03 +0100
commit4fc5a7c3e4dd240db3bc190439d07fcecba7b0e1 (patch)
treefc7aa8be7f80de6c1a2c5a760e4862e86b863f07 /include
parent85fa74cc57166378e150086abb407ca0f3b756db (diff)
parent7b87141d9b708b5baa0458303bf7d68c4d11a99a (diff)
Merge branch 'master' into gyorg
Diffstat (limited to 'include')
-rw-r--r--include/area.h4
-rw-r--r--include/asm.h28
-rw-r--r--include/color.h21
-rw-r--r--include/common.h126
-rw-r--r--include/coord.h2
-rw-r--r--include/enemy.h219
-rw-r--r--include/entity.h517
-rw-r--r--include/fade.h89
-rw-r--r--include/fileselect.h (renamed from include/fileScreen.h)16
-rw-r--r--include/flags.h8
-rw-r--r--include/functions.h109
-rw-r--r--include/game.h321
-rw-r--r--include/global.h21
-rw-r--r--include/item.h3
-rw-r--r--include/kinstone.h30
-rw-r--r--include/main.h126
-rw-r--r--include/manager.h6
-rw-r--r--include/menu.h48
-rw-r--r--include/message.h (renamed from include/textbox.h)15
-rw-r--r--include/npc.h326
-rw-r--r--include/object.h397
-rw-r--r--include/overworld.h63
-rw-r--r--include/player.h90
-rw-r--r--include/projectile.h40
-rw-r--r--include/room.h223
-rw-r--r--include/save.h96
-rw-r--r--include/screen.h47
-rw-r--r--include/script.h36
-rw-r--r--include/sound.h (renamed from include/audio.h)6
-rw-r--r--include/structures.h76
-rw-r--r--include/subtask.h16
-rw-r--r--include/utils.h75
32 files changed, 1990 insertions, 1210 deletions
diff --git a/include/area.h b/include/area.h
index 3f1c0421..b0869bb6 100644
--- a/include/area.h
+++ b/include/area.h
@@ -43,8 +43,8 @@ typedef struct {
RoomResInfo roomResInfos[MAX_ROOMS];
RoomResInfo currentRoomInfo;
RoomResInfo* pCurrentRoomInfo;
- u32 musicIndex;
- u32 pMusicIndex;
+ u32 bgm;
+ u32 queued_bgm;
u8 filler5[0x20];
void* transitionManager;
void (*onEnter)();
diff --git a/include/asm.h b/include/asm.h
index cd151320..b889ab88 100644
--- a/include/asm.h
+++ b/include/asm.h
@@ -3,23 +3,35 @@
#include "global.h"
-struct Entity_;
-
extern u32 Random(void);
-extern void sub_08000152(u32);
+extern void sub_08000152(u32, u32, u32);
+extern u32 GetTileTypeByEntity(struct Entity_*);
+extern u32 GetTileTypeByPos(s32 x, s32 y, u32 layer);
+extern u32 GetTileType(u32 pos, u32 layer);
extern void SetTile(u32 index, u32 position, u32 layer);
+extern void UpdateScrollVram(void);
+extern u32 sub_080002D0(struct Entity_*);
+extern u32 sub_080002F0(u32, u32, u32);
+extern void LoadResourceAsync(const void*, u32, u32);
extern void sub_08001242(struct Entity_*);
extern void sub_08001290(struct Entity_*, u32);
extern void sub_08001324(struct Entity_*);
extern u32 sub_08002632(struct Entity_*);
-extern u32 sub_08003FC4(struct Entity_*, u32);
+extern u32 CheckPlayerInRegion(u32 centerX, u32 centerY, u32 radiusX, u32 radiusY);
+extern u32 GravityUpdate(struct Entity_*, u32);
+extern u32 CheckOnScreen(struct Entity_*);
+extern u32 EntityInRectRadius(struct Entity_*, struct Entity_*, u32, u32);
+extern void UpdateAnimationVariableFrames(struct Entity_*, u32);
extern u32 sub_080043E8(struct Entity_*);
extern void sub_08004484(struct Entity_*, struct Entity_*);
-extern u32 sub_080045D4(s16, s16, u32, u32);
-extern u32 sub_080045DA(s32, s32);
+extern void ResetCollisionLayer(struct Entity_*);
extern void sub_08004596(struct Entity_*, u32);
extern u32 sub_080045B4(struct Entity_*, u32, u32);
-extern u32 EntityInRectRadius(struct Entity_*, struct Entity_*, u32, u32);
-extern void UpdateAnimationVariableFrames(struct Entity_*, u32);
+extern u32 sub_080045D4(u32, u32, u32, u32);
+extern u32 sub_080045DA(s32, s32);
+extern u32 sub_080086B4(u32, u32, u8*);
+extern u32 ResolveCollisionLayer(struct Entity_*);
+extern void sub_0800417E(struct Entity_*, u32);
+extern u32 sub_0800442E(struct Entity_*);
#endif // ASM_H
diff --git a/include/color.h b/include/color.h
new file mode 100644
index 00000000..9ff53264
--- /dev/null
+++ b/include/color.h
@@ -0,0 +1,21 @@
+#ifndef COLOR_H
+#define COLOR_H
+
+#include "global.h"
+
+typedef struct {
+ u8 _0;
+ u8 _1;
+ u16 _2;
+} Palette;
+extern Palette gPaletteList[];
+
+void ResetPaletteTable(u32 a1);
+void sub_0801D000(u32 a1);
+void LoadObjPalette(struct Entity_*, u32);
+void UnloadOBJPalette(struct Entity_* entity);
+void sub_0801D244(u32);
+void sub_0801D28C(struct Entity_* entity, u32 palette);
+void ChangeObjPalette(struct Entity_* entity, u32 palette);
+
+#endif // COLOR_H
diff --git a/include/common.h b/include/common.h
new file mode 100644
index 00000000..62f3acba
--- /dev/null
+++ b/include/common.h
@@ -0,0 +1,126 @@
+#ifndef COMMON_H
+#define COMMON_H
+
+#include "global.h"
+
+struct Entity_;
+
+/**
+ * Holds input information from system registers.
+ */
+typedef struct {
+ u16 heldKeys; /**< Keys held since last frame. */
+ u16 newKeys; /** Keys newly pressed this frame. */
+ u16 unk4;
+ u8 unk6;
+ u8 unk7;
+} Input;
+extern Input gInput; /**< Input instance. */
+
+void LoadPalettes(const u8*, s32, s32);
+
+/**
+ * Loads a packed group of palettes.
+ *
+ * @param group Group number.
+ */
+void LoadPaletteGroup(u32 group);
+
+/**
+ * Loads a packed group of tiles.
+ *
+ * @param group Group number.
+ */
+void LoadGfxGroup(u32 group);
+
+/**
+ * Set color in the palette.
+ *
+ * @param colorIndex Color index.
+ * @param color Color.
+ */
+void SetColor(u32 colorIndex, u32 color);
+
+void SetFillColor(u32 color, u32 arg1);
+
+/**
+ * Fill memory with 16 bit value.
+ *
+ * @param value Fill value.
+ * @param dest Destination.
+ * @param size Byte count.
+ */
+void MemFill16(u32 value, void* dest, u32 size);
+
+/**
+ * Fill memory with 32 bit value.
+ *
+ * @param value Fill value.
+ * @param dest Destination.
+ * @param size Byte count.
+ */
+void MemFill32(u32 value, void* dest, u32 size);
+
+/**
+ * Clear memory.
+ *
+ * @param dest Destination
+ * @param size Byte count.
+ */
+void MemClear(void* dest, u32 size);
+
+/**
+ * Copy memory.
+ *
+ * @param src Source.
+ * @param dest Destination.
+ * @param size Byte count.
+ */
+void MemCopy(const void* src, void* dest, u32 size);
+
+/**
+ * Refresh #gInput from system registers.
+ */
+void ReadKeyInput(void);
+
+/**
+ * Initialize the heap.
+ */
+void zMallocInit(void);
+
+/**
+ * Allocate memory on heap.
+ *
+ * The heap size is 0x1000 bytes and should be used sparingly.
+ * It is customary for entities store the returned pointer in the Entity.myHeap field.
+ *
+ * @param size u32 Size to be allocated.
+ * @return Pointer to allocated memory.
+ */
+void* zMalloc(u32 size);
+
+/**
+ * Free memory from heap.
+ * The Entity system will automatically free the pointer stored in the Entity.myHeap field.
+ *
+ * @param ptr Pointer to be freed.
+ */
+void zFree(void* ptr);
+
+/**
+ * Reset All display system registers.
+ *
+ * @param refresh Request refresh of HUD layer (bg 0).
+ */
+void DispReset(bool32 refresh);
+
+u32 CheckPlayerProximity(u32, u32, u32, u32);
+u32 CheckKinstoneFused(u32);
+void sub_0801E1EC(u32, u32, u32);
+void sub_0801DD58(u32, u32);
+void sub_0801E1B8(u32, u32);
+void sub_0801E738(u32);
+void sub_0801DFB4(struct Entity_*, u32, u32, u32);
+u32 sub_0801E00C(void);
+
+#endif // COMMON_H
diff --git a/include/coord.h b/include/coord.h
index 4b6556e6..85a56ce2 100644
--- a/include/coord.h
+++ b/include/coord.h
@@ -17,7 +17,7 @@ void ResolveEntityBelow(Entity*, Entity*);
u32 sub_0806F5A4(u32 idx);
u32 sub_0806F3E4(Entity*);
-void sub_0806F69C(Entity*);
+void LinearMoveUpdate(Entity*);
extern const s16 gSineTable[64];
extern const s16 gCosineTable[256];
diff --git a/include/enemy.h b/include/enemy.h
index 479e5273..1b7d1a07 100644
--- a/include/enemy.h
+++ b/include/enemy.h
@@ -4,18 +4,27 @@
#include "global.h"
#include "asm.h"
-#include "audio.h"
+#include "sound.h"
#include "effects.h"
#include "flags.h"
-#include "utils.h"
+#include "common.h"
#include "entity.h"
+#include "projectile.h"
extern u32 GetNextFunction(Entity*);
-extern void EnemyFunctionHandler(Entity*, void (*const func[])(Entity*));
+extern void EnemyFunctionHandler(Entity*, EntityActionArray);
extern void sub_08001324(Entity*);
+extern Entity* CreateDeathFx(Entity*, u32, u32);
extern Entity* sub_0804A9FC(Entity*, u32);
+extern void SetChildOffset(Entity*, s32, s32, s32);
+extern Entity* CreateProjectileWithParent(Entity*, u8, u8);
+
+extern void sub_0804A7D4(Entity*);
+extern void sub_08002724(void*, u8*);
+extern void sub_080026C4(u8*, u8*, u8*, u32);
+extern void sub_080026F2(u8*, void*, u8*, u32);
typedef enum {
/*0x00*/ OCTOROK,
@@ -123,107 +132,107 @@ typedef enum {
/*0x66*/ ENEMY_66
} Enemy;
-extern void Octorok(Entity*);
-extern void Chuchu(Entity*);
-extern void Leever(Entity*);
-extern void Peahat(Entity*);
-extern void Rollobite(Entity*);
-extern void DarkNut(Entity*);
-extern void HangingSeed(Entity*);
-extern void Beetle(Entity*);
-extern void Keese(Entity*);
-extern void DoorMimic(Entity*);
-extern void RockChuchu(Entity*);
-extern void SpinyChuchu(Entity*);
-extern void CuccoChickAggr(Entity*);
-extern void Moldorm(Entity*);
-extern void EnemyE(Entity*);
-extern void Moldworm(Entity*);
-extern void Sluggula(Entity*);
-extern void Pesto(Entity*);
-extern void Puffstool(Entity*);
-extern void ChuchuBoss(Entity*);
-extern void LikeLike(Entity*);
-extern void SpearMoblin(Entity*);
-extern void BusinessScrub(Entity*);
-extern void RupeeLike(Entity*);
-extern void Madderpillar(Entity*);
-extern void WaterDrop(Entity*);
-extern void WallMaster(Entity*);
-extern void BombPeahat(Entity*);
-extern void Spark(Entity*);
-extern void Chaser(Entity*);
-extern void SpikedBeetle(Entity*);
-extern void SensorBladeTrap(Entity*);
-extern void Helmasaur(Entity*);
-extern void FallingBoulder(Entity*);
-extern void Bobomb(Entity*);
-extern void WallMaster2(Entity*);
-extern void Gleerok(Entity*);
-extern void VaatiEyesMacro(Entity*);
-extern void Tektite(Entity*);
-extern void WizzrobeWind(Entity*);
-extern void WizzrobeFire(Entity*);
-extern void WizzrobeIce(Entity*);
-extern void Armos(Entity*);
-extern void Eyegore(Entity*);
-extern void Rope(Entity*);
-extern void SmallPesto(Entity*);
-extern void AcroBandit(Entity*);
-extern void BladeTrap(Entity*);
-extern void Keaton(Entity*);
-extern void Crow(Entity*);
-extern void Mulldozer(Entity*);
-extern void Bombarossa(Entity*);
-extern void Wisp(Entity*);
-extern void SpinyBeetle(Entity*);
-extern void MazaalHead(Entity*);
-extern void MazaalMacro(Entity*);
-extern void MazaalHand(Entity*);
-extern void OctorokBoss(Entity*);
-extern void FlyingPot(Entity*);
-extern void Gibdo(Entity*);
-extern void OctorokGolden(Entity*);
-extern void TektiteGolden(Entity*);
-extern void RopeGolden(Entity*);
-extern void CloudPiranha(Entity*);
-extern void ScissorsBeetle(Entity*);
-extern void CuccoAggr(Entity*);
-extern void Stalfos(Entity*);
-extern void FlyingSkull(Entity*);
-extern void MazaalBracelet(Entity*);
-extern void Takkuri(Entity*);
-extern void BowMoblin(Entity*);
-extern void Lakitu(Entity*);
-extern void LakituCloud(Entity*);
-extern void Enemy49(Entity*);
-extern void VaatiRebornEnemy(Entity*);
-extern void VaatiProjectile(Entity*);
-extern void BallChainSoldier(Entity*);
-extern void Enemy4D(Entity*);
-extern void Ghini(Entity*);
-extern void VaatiTransfigured(Entity*);
-extern void Enemy50(Entity*);
-extern void VaatiWrath(Entity*);
-extern void VaatiArm(Entity*);
-extern void Dust(Entity*);
-extern void VaatiBall(Entity*);
-extern void Slime(Entity*);
-extern void MiniSlime(Entity*);
-extern void FireballGuy(Entity*);
-extern void MiniFireballGuy(Entity*);
-extern void VaatiTransfiguredEye(Entity*);
-extern void BusinessScrubPrologue(Entity*);
-extern void GyorgFemale();
-extern void GyorgMale();
-extern void Curtain(Entity*);
-extern void VaatiWrathEye(Entity*);
-extern void GyorgChild();
-extern void GyorgFemaleEye();
-extern void Enemy62(Entity*);
-extern void GyorgFemaleMouth();
-extern void Enemy64(Entity*);
-extern void TreeItem(Entity*);
-extern void Enemy66(Entity*);
+void Octorok(Entity*);
+void Chuchu(Entity*);
+void Leever(Entity*);
+void Peahat(Entity*);
+void Rollobite(Entity*);
+void DarkNut(Entity*);
+void HangingSeed(Entity*);
+void Beetle(Entity*);
+void Keese(Entity*);
+void DoorMimic(Entity*);
+void RockChuchu(Entity*);
+void SpinyChuchu(Entity*);
+void CuccoChickAggr(Entity*);
+void Moldorm(Entity*);
+void EnemyE(Entity*);
+void Moldworm(Entity*);
+void Sluggula(Entity*);
+void Pesto(Entity*);
+void Puffstool(Entity*);
+void ChuchuBoss(Entity*);
+void LikeLike(Entity*);
+void SpearMoblin(Entity*);
+void BusinessScrub(Entity*);
+void RupeeLike(Entity*);
+void Madderpillar(Entity*);
+void WaterDrop(Entity*);
+void WallMaster(Entity*);
+void BombPeahat(Entity*);
+void Spark(Entity*);
+void Chaser(Entity*);
+void SpikedBeetle(Entity*);
+void SensorBladeTrap(Entity*);
+void Helmasaur(Entity*);
+void FallingBoulder(Entity*);
+void Bobomb(Entity*);
+void WallMaster2(Entity*);
+void Gleerok(Entity*);
+void VaatiEyesMacro(Entity*);
+void Tektite(Entity*);
+void WizzrobeWind(Entity*);
+void WizzrobeFire(Entity*);
+void WizzrobeIce(Entity*);
+void Armos(Entity*);
+void Eyegore(Entity*);
+void Rope(Entity*);
+void SmallPesto(Entity*);
+void AcroBandit(Entity*);
+void BladeTrap(Entity*);
+void Keaton(Entity*);
+void Crow(Entity*);
+void Mulldozer(Entity*);
+void Bombarossa(Entity*);
+void Wisp(Entity*);
+void SpinyBeetle(Entity*);
+void MazaalHead(Entity*);
+void MazaalMacro(Entity*);
+void MazaalHand(Entity*);
+void OctorokBoss(Entity*);
+void FlyingPot(Entity*);
+void Gibdo(Entity*);
+void OctorokGolden(Entity*);
+void TektiteGolden(Entity*);
+void RopeGolden(Entity*);
+void CloudPiranha(Entity*);
+void ScissorsBeetle(Entity*);
+void CuccoAggr(Entity*);
+void Stalfos(Entity*);
+void FlyingSkull(Entity*);
+void MazaalBracelet(Entity*);
+void Takkuri(Entity*);
+void BowMoblin(Entity*);
+void Lakitu(Entity*);
+void LakituCloud(Entity*);
+void Enemy49(Entity*);
+void VaatiRebornEnemy(Entity*);
+void VaatiProjectile(Entity*);
+void BallChainSoldier(Entity*);
+void Enemy4D(Entity*);
+void Ghini(Entity*);
+void VaatiTransfigured(Entity*);
+void Enemy50(Entity*);
+void VaatiWrath(Entity*);
+void VaatiArm(Entity*);
+void Dust(Entity*);
+void VaatiBall(Entity*);
+void Slime(Entity*);
+void MiniSlime(Entity*);
+void FireballGuy(Entity*);
+void MiniFireballGuy(Entity*);
+void VaatiTransfiguredEye(Entity*);
+void BusinessScrubPrologue(Entity*);
+void GyorgFemale();
+void GyorgMale();
+void Curtain(Entity*);
+void VaatiWrathEye(Entity*);
+void GyorgChild();
+void GyorgFemaleEye();
+void Enemy62(Entity*);
+void GyorgFemaleMouth();
+void Enemy64(Entity*);
+void TreeItem(Entity*);
+void Enemy66(Entity*);
#endif
diff --git a/include/entity.h b/include/entity.h
index 69d6a882..c3477e9e 100644
--- a/include/entity.h
+++ b/include/entity.h
@@ -3,19 +3,73 @@
#define ENTITY_H
#include "global.h"
+#include "color.h"
#include "sprite.h"
#define MAX_ENTITIES 71
+/** Kinds of Entity's supported by the game. */
typedef enum {
- PLAYER = 1,
- ENEMY = 3,
- PROJECTILE = 4,
- OBJECT = 6,
- NPC = 7,
- PLAYER_ITEM = 8,
- MANAGER = 9,
-} EntityType;
+ PLAYER = 1, /**< There is only one id assigned to the Player kind.
+ * The player Entity shares much of its code with LTTP GBA, however the game only supports
+ * one player Entity active at a time, assigned to the global #gPlayerEntity.
+ * Works next to PlayerState to control player behavior.
+ */
+ ENEMY = 3, /**< Can give and take damage in relation to the player.
+ * Most enemies call the a set of external helper functions which calculate what behavior to execute.
+ */
+ PROJECTILE = 4, /**< May damage the player. They are typically spawned by enemies.
+ */
+ OBJECT = 6, /**< Encapsulates any sort of prop. Generally they cannot be interacted with directly,
+ * but they may react to a player action or script event.
+ */
+ NPC = 7, /**< May be interacted with by the player. Almost every NPC is assigned a script.
+ * NPCs have three entry points: one for the head, one for the body, and one for kinstone fusion.
+ */
+ PLAYER_ITEM = 8, /**< Displays sprites for items outside of the inventory (check).
+ */
+ MANAGER = 9, /**< Utility Entity's that serve as a proxy between gameplay and the engine.
+ * Examples: drawing clouds, ezlo hints, playing cutscenes.
+ * Updates independently of other entities, and does not add to maximum entity count.
+ */
+} EntityKind;
+
+/** Entity flags. */
+typedef enum {
+ ENT_DID_INIT = 0x1, /**< Graphics and other data loaded. */
+ ENT_SCRIPTED = 0x2, /**< Execute in a scripted environment. */
+ ENT_DELETED = 0x10, /**< Queue deletion next frame. */
+ ENT_PERSIST = 0x20, /**< Persist between rooms. */
+ ENT_COLLIDE = 0x80, /**< Collide with other Entity's. */
+} EntityFlags;
+
+/** Priority level to determine what events will block an Entity from updating. */
+typedef enum {
+ PRIO_MIN, /**< Default priority. */
+ PRIO_PLAYER, /**< Default priority for player. */
+ PRIO_MESSAGE, /**< Do not block during message. */
+ PRIO_NO_BLOCK, /**< Do not block during entity requested priority. @see RequestPriority */
+ PRIO_4, /**< Unused. */
+ PRIO_5, /**< Unused. */
+ PRIO_PLAYER_EVENT, /**< Do not block during special player event. */
+ PRIO_HIGHEST, /**< Do not block EVER. */
+} Priority;
+
+/** Animation state. */
+typedef enum {
+ IdleNorth = 0x0, /**< Idle facing north. */
+ IdleEast = 0x2, /**< Idle facing east. */
+ IdleSouth = 0x4, /**< Idle facing south. */
+ IdleWest = 0x6, /**< Idle facing west. */
+} AnimationState;
+
+/** Direction. */
+typedef enum {
+ DirectionNorth = 0x00, /**< North. */
+ DirectionEast = 0x08, /**< East. */
+ DirectionSouth = 0x10, /**< South. */
+ DirectionWest = 0x18, /**< West. */
+} Direction;
typedef struct {
void* entity1;
@@ -23,6 +77,9 @@ typedef struct {
u8 filler[14];
} UnkStruct;
+/**
+ * Hitbox structure.
+ */
typedef struct {
s8 offset_x;
s8 offset_y;
@@ -31,6 +88,9 @@ typedef struct {
u8 height;
} Hitbox;
+/**
+ * Hitbox structure supporting depth.
+ */
typedef struct {
s8 offset_x;
s8 offset_y;
@@ -41,38 +101,48 @@ typedef struct {
u8 unknown2[3];
} Hitbox3D;
+typedef struct {
+ u8 b0 : 3; // 1-4
+ u8 b1 : 3; // 8
+ u8 b2 : 1; // 0x40
+ u8 b3 : 1; // 0x80
+} PACKED SpritePriority;
+
+/**
+ * Container for instantiable behavior.
+ */
typedef struct Entity_ {
- /*0x00*/ struct Entity_* prev;
- /*0x04*/ struct Entity_* next;
- /*0x08*/ u8 kind;
- /*0x09*/ u8 id;
- /*0x0a*/ u8 type;
- /*0x0b*/ u8 type2;
- /*0x0c*/ u8 action;
- /*0x0d*/ u8 subAction;
- /*0x0e*/ u8 actionDelay;
- /*0x0f*/ u8 field_0xf;
- /*0x10*/ u8 flags;
- /*0x11*/ u8 updatePriority : 4; // Current priority -- See RequestPriority
- /* */ u8 updatePriorityPrev : 4; // Priority to restore after request is over
+ /*0x00*/ struct Entity_* prev; /**< previous Entity */
+ /*0x04*/ struct Entity_* next; /**< next Entity */
+ /*0x08*/ u8 kind; /**< @see EntityKind */
+ /*0x09*/ u8 id; /**< Entity id. */
+ /*0x0a*/ u8 type; /**< For use internally to allow different variations. */
+ /*0x0b*/ u8 type2; /**< For use internally. */
+ /*0x0c*/ u8 action; /**< Current action. Usually used to index a function table. */
+ /*0x0d*/ u8 subAction; /**< Optional sub-action. */
+ /*0x0e*/ u8 actionDelay; /**< General purpose timer. */
+ /*0x0f*/ u8 field_0xf; /**< General purpose timer. */
+ /*0x10*/ u8 flags; /**< @see EntityFlags */
+ /*0x11*/ u8 updatePriority : 4; /**< Current priority. @see Priority */
+ /* */ u8 updatePriorityPrev : 4; /**< Priority to restore after request is over. @see RequestPriority. */
/*0x12*/ s16 spriteIndex;
- /*0x14*/ u8 animationState;
- /*0x15*/ u8 direction;
+ /*0x14*/ u8 animationState; /**< Animation state. @see AnimationState */
+ /*0x15*/ u8 direction; /**< Facing direction. @see Direction */
/*0x16*/ u8 field_0x16;
/*0x17*/ u8 field_0x17;
/*0x18*/ struct {
- /* */ u32 draw : 2; // 1-2
- /* */ u32 ss2 : 1; // 4
- /* */ u32 ss3 : 1; // 8
- /* */ u32 shadow : 2; //0x10-0x20
- /* */ u32 flipX : 1; //0x40
- /* */ u32 flipY : 1; //0x80
+ /* */ u32 draw : 2; /**< Draw type. 0 = disabled, 1 = clip to screen, 3 = draw always */ /* 0x2 */
+ /* */ u32 ss2 : 1; /* 4 */
+ /* */ u32 ss3 : 1; /* 8 */
+ /* */ u32 shadow : 2; /* 0x10-0x20 */
+ /* */ u32 flipX : 1; /**< Flip sprite horizontally. */ /* 0x40 */
+ /* */ u32 flipY : 1; /**< Flip sprite vertically. */ /* 0x80 */
/* */ } PACKED spriteSettings;
/*0x19*/ struct {
- /* */ u32 b0 : 2; // 1-2
- /* */ u32 alphaBlend : 2; // 4-8
- /* */ u32 b2 : 2; //0x10
- /* */ u32 b3 : 2; //0x40
+ /* */ u32 b0 : 2; /* 1-2 */
+ /* */ u32 alphaBlend : 2; /* 4-8 */
+ /* */ u32 b2 : 2; /* 0x10 */
+ /* */ u32 b3 : 2; /* 0x40 */
/* */ } PACKED spriteRendering;
/*0x1a*/ union {
/* */ u8 raw;
@@ -82,45 +152,41 @@ typedef struct Entity_ {
/* */ } PACKED b;
/* */ } PACKED palette;
/*0x1b*/ struct {
- /* */ u32 b0 : 1;
- /* */ u32 b1 : 5; //0x10
- /* */ u32 flipY : 2; //0x40
+ /* */ u32 b0 : 1; /* 1 */
+ /* */ u32 b1 : 5; /* 0x2-0x10 */
+ /* */ u32 flipY : 2; /* 0x20-0x40 */
/* */ } PACKED spriteOrientation;
/*0x1c*/ u8 field_0x1c;
/*0x1d*/ u8 field_0x1d;
/*0x1e*/ u8 frameIndex;
/*0x1f*/ u8 lastFrameIndex;
- /*0x20*/ s32 zVelocity;
- /*0x24*/ s16 speed;
+ /*0x20*/ s32 zVelocity; /**< Z axis speed. */
+ /*0x24*/ s16 speed; /**< Magnitude of speed. */
/*0x26*/ u8 spriteAnimation[3];
- /*0x29*/ struct {
- /* */ u8 b0 : 3; // 1-4
- /* */ u8 b1 : 3; // 8
- /* */ u8 b2 : 2; //0x40
- /* */ } PACKED spritePriority;
+ /*0x29*/ SpritePriority spritePriority;
/*0x2a*/ u16 collisions;
- /*0x2c*/ union SplitWord x;
- /*0x30*/ union SplitWord y;
- /*0x34*/ union SplitWord z;
- /*0x38*/ u8 collisionLayer;
+ /*0x2c*/ union SplitWord x; /**< X position, fixed point. */
+ /*0x30*/ union SplitWord y; /**< Y position, fixed point. */
+ /*0x34*/ union SplitWord z; /**< Z position, fixed point. */
+ /*0x38*/ u8 collisionLayer; /**< Collision layer. */
/*0x39*/ s8 interactType;
/*0x3a*/ u8 field_0x3a;
/*0x3b*/ u8 flags2;
/*0x3c*/ u8 field_0x3c;
- /*0x3d*/ s8 iframes;
- /*0x3e*/ u8 knockbackDirection;
- /*0x3f*/ u8 hitType; // behavior as a collision sender
- /*0x40*/ u8 hurtType; // behavior as a collision reciever
+ /*0x3d*/ s8 iframes; /**< Invulnerability frames. */
+ /*0x3e*/ u8 knockbackDirection; /**< Direction of knockback. */
+ /*0x3f*/ u8 hitType; /**< Behavior as a collision sender. */
+ /*0x40*/ u8 hurtType; /**< behavior as a collision receiver. */
/*0x41*/ u8 bitfield;
- /*0x42*/ u8 knockbackDuration;
+ /*0x42*/ u8 knockbackDuration; /**< Duration of knockback. */
/*0x43*/ u8 field_0x43;
- /*0x44*/ u8 damage;
- /*0x45*/ u8 health;
+ /*0x44*/ u8 damage; /**< Damage this Entity inflicts. */
+ /*0x45*/ u8 health; /**< Health of this Entity. */
/*0x46*/ u16 field_0x46;
- /*0x48*/ Hitbox* hitbox;
+ /*0x48*/ Hitbox* hitbox; /**< Hitbox associated with this Entity. */
/*0x4c*/ struct Entity_* field_0x4c;
- /*0x50*/ struct Entity_* parent;
- /*0x54*/ struct Entity_* child;
+ /*0x50*/ struct Entity_* parent; /**< Parent Entity. Sometimes points to associated data. */
+ /*0x54*/ struct Entity_* child; /**< Child Entity. Sometimes points to associated data. */
/*0x58*/ u8 animIndex;
/*0x59*/ u8 frameDuration;
/*0x5a*/ u8 frame;
@@ -129,7 +195,7 @@ typedef struct Entity_ {
/*0x60*/ u16 spriteVramOffset;
/*0x62*/ u8 spriteOffsetX;
/*0x63*/ s8 spriteOffsetY;
- /*0x64*/ void* myHeap;
+ /*0x64*/ void* myHeap; /**< Heap data allocated with #zMalloc. */
#ifndef NENT_DEPRECATED
/*0x68*/ union SplitHWord field_0x68;
/*0x6a*/ union SplitHWord field_0x6a;
@@ -166,192 +232,301 @@ typedef struct {
/*0x86*/ union SplitHWord field_0x86;
} GenericEntity;
+/**
+ * Entity linked list structure.
+ */
typedef struct LinkedList {
Entity* last;
Entity* first;
} LinkedList;
-extern LinkedList gEntityLists[9];
-extern LinkedList gUnk_03003D90;
-
-extern LinkedList gUnk_03003DA0;
-
-enum {
- ENT_DID_INIT = 0x1,
- ENT_SCRIPTED = 0x2,
- ENT_ASLEEP = 0x10,
- ENT_20 = 0x20,
- ENT_COLLIDE = 0x80,
-};
-
-#define COLLISION_OFF(entity) ((entity)->flags &= ~ENT_COLLIDE)
-#define COLLISION_ON(entity) ((entity)->flags |= ENT_COLLIDE)
-
-#define TILE(x, y) \
- (((((x) - gRoomControls.roomOriginX) >> 4) & 0x3F) | \
- ((((y) - gRoomControls.roomOriginY) >> 4) & 0x3F) << 6)
-
-#define COORD_TO_TILE(entity) \
- TILE((entity)->x.HALF.HI, (entity)->y.HALF.HI)
-
-#define COORD_TO_TILE_OFFSET(entity, xOff, yOff) \
- TILE((entity)->x.HALF.HI - (xOff), (entity)->y.HALF.HI - (yOff))
-
-enum {
- IdleNorth = 0x0,
- IdleEast = 0x2,
- IdleSouth = 0x4,
- IdleWest = 0x6,
-};
+typedef void(EntityAction)(Entity*);
+typedef void (*EntityActionPtr)(Entity*);
+typedef void (*const* EntityActionArray)(Entity*);
-enum {
- DirectionNorth = 0x00,
- DirectionEast = 0x08,
- DirectionSouth = 0x10,
- DirectionWest = 0x18,
-};
+/**
+ * Draw an Entity.
+ *
+ * @param entity Entity to be drawn.
+ */
+void DrawEntity(Entity* entity);
-#define AnimationStateTurnAround(expr) ((expr) ^ 0x4)
-#define AnimationStateIdle(expr) ((expr) & 0x6)
-#define AnimationStateWalk(expr) ((expr) & 0xe)
+void InitializeAnimation(Entity*, u32);
+void InitAnimationForceUpdate(Entity*, u32);
+void UpdateAnimationSingleFrame(Entity*);
+void UpdateSpriteForCollisionLayer(Entity*);
+void GetNextFrame(Entity*);
+u32 LoadExtraSpriteData(Entity*, SpriteLoadData*);
+void SetExtraSpriteFrame(Entity*, u32, u32);
+void SetSpriteSubEntryOffsetData1(Entity*, u32, u32);
+void SetSpriteSubEntryOffsetData2(Entity*, u32, u32);
+u8* GetSpriteSubEntryOffsetDataPointer(u32, u32);
-#define DirectionRound(expr) ((expr) & 0x18)
-#define DirectionRoundUp(expr) DirectionRound((expr) + 4)
-#define DirectionIsHorizontal(expr) ((expr) & 0x08)
-#define DirectionIsVertical(expr) ((expr) & 0x10)
-#define DirectionTurnAround(expr) ((expr) ^ 0x10)
-#define DirectionToAnimationState(expr) (DirectionRoundUp(expr) >> 3)
-#define DirectionFromAnimationState(expr) ((expr) << 3)
-#define DirectionNormalize(expr) ((expr) & 0x1f)
+/**
+ * Return the direction pointing from one Entity to another.
+ *
+ * @param origin Entity to orient.
+ * @param target Entity to look at.
+ * @return Direction facing target.
+ */
+u32 GetFacingDirection(Entity* origin, Entity* target);
-#define Direction8Round(expr) ((expr) & 0x1c)
-#define Direction8RoundUp(expr) Direction8Round((expr) + 2)
-#define Direction8TurnAround(expr) (Direction8RoundUp(expr) ^ 0x10)
-#define Direction8ToAnimationState(expr) ((expr) >> 2)
-#define Direction8FromAnimationState(expr) ((expr) << 2)
+u32 ProcessMovement(Entity*);
+/// @{
+/**
+ * Allocate a new Entity.
+ *
+ * @return Allocated Entity or NULL if failed.
+ */
Entity* GetEmptyEntity(void);
-void DrawEntity(Entity*);
Entity* CreateEnemy(u32 id, u32 type);
Entity* CreateNPC(u32 id, u32 type, u32 type2);
Entity* CreateObject(u32 id, u32 type, u32 type2);
Entity* CreateObjectWithParent(Entity* parent, u32 id, u32 type, u32 type2);
Entity* CreateFx(Entity* parent, u32 type, u32 type2);
+/// @}
-void InitializeAnimation(Entity*, u32);
-void InitAnimationForceUpdate(Entity*, u32);
-void UpdateAnimationSingleFrame(Entity*);
-void UpdateSpriteForCollisionLayer(Entity*);
-void GetNextFrame(Entity*);
-u32 LoadExtraSpriteData(Entity*, SpriteLoadData*);
-void SetExtraSpriteFrame(Entity*, u32, u32);
-void SetSpriteSubEntryOffsetData1(Entity*, u32, u32);
-void SetSpriteSubEntryOffsetData2(Entity*, u32, u32);
+/**
+ * Iteratively execute every Entity. Call once per frame.
+ */
+void UpdateEntities(void);
+
+/**
+ * Iteratively execute every Manager. Call once per frame.
+ */
+void UpdateManagers(void);
-u32 GetFacingDirection(Entity*, Entity*);
+/**
+ * Delete a manager.
+ *
+ * @param manager Manager to delete.
+ */
+void DeleteManager(void* manager);
+/**
+ * Delete Manager or Entity.
+ *
+ * @param entity Entity or Manager to be deleted.
+ */
+void DeleteEntityAny(Entity* entity);
/**
- * @brief Delete the entity currently in execution.
+ * Erase all Entity's.
+ */
+void EraseAllEntities(void);
+
+/**
+ * Delete the Entity currently in execution.
+ *
+ * @see UpdateContext
*/
void DeleteThisEntity(void);
/**
- * @brief Delete an entity.
+ * Delete an Entity.
+ *
+ * @param entity Entity to delete.
*/
-void DeleteEntity(Entity*);
+void DeleteEntity(Entity* entity);
+/**
+ * Add an Entity to the end of a LinkedList.
+ *
+ * @param entity Entity to add.
+ * @param listIndex Target LinkedList.
+ */
void AppendEntityToList(Entity* entity, u32 listIndex);
+
+/**
+ * Add an Entity to the start of a LinkedList.
+ *
+ * @param entity Entity to add.
+ * @param listIndex Target LinkedList.
+ */
void PrependEntityToList(Entity* entity, u32 listIndex);
/**
- * @brief Find an entity for a given kind and ID.
- * @return Entity* First result or NULL if none found
+ * Find an Entity for a given kind and id, and LinkedList.
+ *
+ * @return Entity* First result or NULL if none found.
*/
Entity* FindEntityByID(u32 kind, u32 id, u32 listIndex);
/**
- * @brief Search all lists for an entity of same kind and id.
- * @return Entity* First result or NULL if none found
+ * Search all lists for an Entity of same kind and id.
+ *
+ * @return Entity* First result or NULL if none found.
*/
Entity* DeepFindEntityByID(u32 kind, u32 id);
/**
- * @brief Search all lists for entity of same kind and id.
- * @return bool32 Duplicate was entity found
+ * Search all lists for Entity of same kind and id.
+ *
+ * @return bool32 Duplicate was found.
*/
-bool32 EntityHasDuplicateID(Entity* ent);
+bool32 EntityHasDuplicateID(Entity* entity);
/**
- * @brief Find an entity of same kind and id in list.
- * @return Entity* First result or NULL if none found
+ * Find an Entity of same kind and id in LinkedList.
+ *
+ * @return Entity* First result or NULL if none found.
*/
-Entity* FindNextDuplicateID(Entity* ent, int listIndex);
+Entity* FindNextDuplicateID(Entity* entity, int listIndex);
/**
- * @brief Find Entity with full identifiers.
- * @return Entity* First result or NULL if none found
+ * Find an Entity with full identifiers.
+ *
+ * @return Entity* First result or NULL if none found.
*/
Entity* FindEntity(u32 kind, u32 id, u32 listIndex, u32 type, u32 type2);
-void DeleteManager(void*);
-void DeleteEntityAny(Entity* ent);
-
-void UpdateEntities(void);
-void UpdateManagers(void);
-
-void EraseAllEntities(void);
-
-enum {
- PRIO_MIN = 0,
- PRIO_PLAYER = 1,
- PRIO_MESSAGE = 2, /* do not block during message */
- PRIO_NO_BLOCK = 3, /* do not block during entity requested priority */
- PRIO_PLAYER_EVENT = 6, /* do not block during special player event */
- PRIO_HIGHEST = 7, /* do not block EVER */
-};
-
/**
- * @brief Set the default priority for entity.
+ * Set the default priority for entity.
+ *
+ * @param entity Entity to set the priority of.
+ * @param prio #Priority level.
*/
-void SetDefaultPriority(Entity* ent, u32 prio);
+void SetDefaultPriority(Entity* entity, u32 prio);
/**
- * @brief Check if entity should sleep this frame (according to priority).
+ * Check if entity will be deleted next frame.
*/
-bool32 CheckDontUpdate(Entity* this);
+bool32 EntityIsDeleted(Entity* entity);
/**
- * @brief Check if system or entity is blocking updates.
+ * Check if system or entity is blocking updates.
*/
bool32 AnyPrioritySet(void);
+/**
+ * Set the minimum Entity priority.
+ *
+ * @param prio Minimum #Priority.
+ * @return Success.
+ */
+s32 SetMinPriority(u32 prio);
-/// Entity Priority: Update blocking events requested by an entity.
+/**
+ * Request indefinite priority for an Entity.
+ *
+ * @param entity Entity requesting priority.
+ */
+void RequestPriority(Entity* entity);
-s32 SetMinPriority(u32 prio);
+/**
+ * Revoke priority from an Entity.
+ *
+ * @param entity Entity which requested priority.
+ */
+void RevokePriority(Entity* entity);
-void RequestPriority(Entity* this);
-void RevokePriority(Entity* e);
+/**
+ * Request update priority over other Entity's for a period of time.
+ *
+ * @param entity Entity requesting priority.
+ * @param time Number of frames.
+ */
+void RequestPriorityDuration(Entity* entity, u32 time);
-void RequestPriorityDuration(Entity* this, u32 time);
+/**
+ * Set the remaining frames of Entity priority.
+ *
+ * @param time Number of frames.
+ */
void SetPriorityTimer(u32 time);
-void RequestPriorityOverPlayer(Entity* this);
-void RevokePriorityOverPlayer(Entity* this);
-
-void ResetEntityPriority(void);
+/**
+ * Request priority over player update.
+ *
+ * @param entity Entity requesting priority.
+ */
+void RequestPriorityOverPlayer(Entity* entity);
+/**
+ * Revoke priority over player update.
+ *
+ * @param entity Entity which requested priority.
+ */
+void RevokePriorityOverPlayer(Entity* entity);
-/// System Priority: Update blocking events sent by the engine.
+/**
+ * Reset a priority event requested by an Entity.
+ */
+void ResetEntityPriority(void);
+/**
+ * Set entity and system priority to #PRIO_PLAYER_EVENT.
+ */
void SetPlayerEventPriority(void);
+
+/**
+ * Reset entity and system priority to defaults.
+ */
void ResetPlayerEventPriority(void);
+
+/**
+ * Set system priority to #PRIO_PLAYER_EVENT.
+ */
void SetRoomReloadPriority(void);
+
+/**
+ * Set system priority to #PRIO_HIGHEST.
+ */
void SetInitializationPriority(void);
+/**
+ * Reset the system update priority.
+ */
void ResetSystemPriority(void);
+/**
+ * LinkedList's which point to allocate Entities.
+ * These work together with Entity.prev and Entity.next fields
+ * to allow the iteration of all Entity's.
+ */
+extern LinkedList gEntityLists[9];
+
+/**
+ * Current number of entities.
+ * @see Entity
+ */
extern u8 gEntCount;
+/**
+ * Current number of managers.
+ * @see Manager
+ */
extern u8 gManagerCount;
-#endif
+#define COLLISION_OFF(entity) ((entity)->flags &= ~ENT_COLLIDE)
+#define COLLISION_ON(entity) ((entity)->flags |= ENT_COLLIDE)
+
+/** @name Tile Macros */ /// @{
+#define TILE(x, y) (((((x)-gRoomControls.origin_x) >> 4) & 0x3F) | ((((y)-gRoomControls.origin_y) >> 4) & 0x3F) << 6)
+#define COORD_TO_TILE(entity) TILE((entity)->x.HALF.HI, (entity)->y.HALF.HI)
+#define COORD_TO_TILE_OFFSET(entity, xOff, yOff) TILE((entity)->x.HALF.HI - (xOff), (entity)->y.HALF.HI - (yOff))
+/// @}
+
+/** @name Animation State Macros */ ///@{
+#define AnimationStateTurnAround(expr) ((expr) ^ 0x4)
+#define AnimationStateIdle(expr) ((expr)&0x6)
+#define AnimationStateWalk(expr) ((expr)&0xe)
+///@}
+
+/** @name Direction Macros */ ///@{
+#define DirectionRound(expr) ((expr)&0x18)
+#define DirectionRoundUp(expr) DirectionRound((expr) + 4)
+#define DirectionIsHorizontal(expr) ((expr) & 0x08)
+#define DirectionIsVertical(expr) ((expr) & 0x10)
+#define DirectionTurnAround(expr) ((expr) ^ 0x10)
+#define DirectionToAnimationState(expr) (DirectionRoundUp(expr) >> 3)
+#define DirectionFromAnimationState(expr) ((expr) << 3)
+#define DirectionNormalize(expr) ((expr) & 0x1f)
+#define Direction8Round(expr) ((expr) & 0x1c)
+#define Direction8RoundUp(expr) Direction8Round((expr) + 2)
+#define Direction8TurnAround(expr) (Direction8RoundUp(expr) ^ 0x10)
+#define Direction8ToAnimationState(expr) ((expr) >> 2)
+#define Direction8FromAnimationState(expr) ((expr) << 2)
+///@}
+
+#endif // ENTITY_H
+// clang-format on
diff --git a/include/fade.h b/include/fade.h
index 7e71a435..0de28da9 100644
--- a/include/fade.h
+++ b/include/fade.h
@@ -3,16 +3,93 @@
#include "global.h"
-void SetBrightness(u32 arg0);
-void DoFade(u32 type, u32 speed);
+/**
+ * @struct FadeControl
+ * @brief Controls screen fading effects.
+ * @see gFadeControl
+ */
+typedef struct {
+ bool8 active; /**< Currently fading. */
+ u8 unused1;
+ u8 color;
+ u8 unused2;
+ u32 mask; /**< Fade palette mask.
+ * LSB = foreground, MSB = background. */
+ u16 type;
+ u16 speed;
+ u16 progress;
+ u16 sustain; /**< Fade progress to sustain. */
+ s16 iris_size;
+ s16 iris_x;
+ s16 iris_y;
+ u16 win_inside_cnt;
+ u16 win_outside_cnt;
+} FadeControl;
+extern FadeControl gFadeControl; /**< FadeControl instance. */
-void sub_08050008(void);
-void sub_08050038(u32);
-void sub_080500F4(u32 arg0);
-void sub_08050110(u32 param_1, u32 param_2, u32 fadeType, u32 fadeSpeed);
+/** Set game brightness.
+ * @param brightness brightness level, 0-2
+ */
+void SetBrightness(u32 brightness);
+/**
+ * Start a fade effect.
+ *
+ * @param type Fade type. The following flags are supported:
+ * 0x1 | 0x2 | 0x4 | 0x8 | 0x10
+ * :-------|:------------|:--------|:-------|:-------------------------
+ * in/out | black/white | instant | mosaic | iris fade
+ * @param speed Effect speed, lower is slower. Negative values trigger an acid-like experience.
+ */
+void SetFade(u32 type, u32 speed);
+
+/**
+ * Perform the last fade effect in reverse.
+ *
+ * @param speed Fade speed.
+ */
+void SetFadeInverted(u32 speed);
+
+/**
+ * Peform an iris fade.
+ *
+ * @param x Screen x coordinate.
+ * @param y Screen y coordinate.
+ * @param type Fade type.
+ * @param speed Fade speed.
+ */
+void SetFadeIris(u32 x, u32 y, u32 type, u32 speed);
+
+/**
+ * Set the fade progress.
+ *
+ * When used on a fade in effect, this will set the progress of the fade.
+ * When used on a fade out effect, progress will be sustained at the value.
+ *
+ * @param progress Progress value. 0-256.
+ */
+void SetFadeProgress(u32 progress);
+
+/**
+ * Initialize the fade system.
+ *
+ * This will misbehave if called while a fade is active.
+ */
void InitFade(void);
+
+/**
+ * Entry point for the fade system.
+ */
void FadeMain(void);
+
+/**
+ * Fade VBlank entry point.
+ */
void FadeVBlank(void);
+/**
+ * Reset the fade palette mask.
+ */
+void ResetFadeMask(void);
+
#endif // FADE_H
diff --git a/include/fileScreen.h b/include/fileselect.h
index 04cfa4ba..bba9eed7 100644
--- a/include/fileScreen.h
+++ b/include/fileselect.h
@@ -1,16 +1,22 @@
#ifndef FILESELECT_H
#define FILESELECT_H
-#include "audio.h"
+#include "sound.h"
#include "global.h"
#include "save.h"
typedef struct {
- u8 filler0[0x5];
+ u8 unk_0x0;
+ u8 filler0[0x4];
u8 state;
u8 subState;
u16 timer;
- u8 fillerA[0x26];
+ u8 fillerA[0x5];
+ s16 unk_0x10;
+ u16 unk_0x12;
+ u8 fillerB[0xC];
+ u8 unk_0x20;
+ u8 fillerC[0xF];
} ChooseFileState;
static_assert(sizeof(ChooseFileState) == 0x30);
@@ -57,13 +63,14 @@ extern struct_02019EE0 gUnk_02019EE0;
extern void sub_08056FEC(u32, struct_020227E8*);
extern void sub_0805F46C(u32, void*);
extern void RecoverUI(u32 bottomPt, u32 topPt);
-extern void sub_08080668(void);
+extern void ClearTilemaps(void);
extern void sub_0805194C(u32);
extern struct_02036540* sub_0805F2C8(void);
extern void sub_0805F7DC(u32, struct_02036540*);
extern void sub_0805F300(struct_02036540*);
extern void sub_08050A64(u32);
extern void sub_08050AFC(u32);
+extern void sub_08050384();
extern const struct_080FC844 gUnk_080FC844;
extern const u16 gUnk_080FC85C[][3];
@@ -72,7 +79,6 @@ extern const u8 gGlobalGfxAndPalettes[];
extern void (*const gUnk_080FC93C[])();
extern u32 gUsedPalettes;
extern u8 gTextGfxBuffer[];
-extern u8 gUnk_02001B40;
extern u8 gUnk_02022030;
#endif \ No newline at end of file
diff --git a/include/flags.h b/include/flags.h
index 1d3080ae..10224374 100644
--- a/include/flags.h
+++ b/include/flags.h
@@ -25,10 +25,10 @@ void SetLocalFlag(u32);
void SetLocalFlagByBank(u32, u32);
void SetRoomFlag(u32);
-extern u32 ReadBit(u32*, u32);
-extern u32 CheckBits(u32*, u32, u32);
-extern void WriteBit(u32*, u32);
-extern void ClearBit(u32*, u32);
+extern u32 ReadBit(void*, u32);
+extern u32 CheckBits(void*, u32, u32);
+extern u32 WriteBit(void*, u32);
+extern u32 ClearBit(void*, u32);
extern u32 gGlobalFlags;
extern u32 gRoomFlags;
diff --git a/include/functions.h b/include/functions.h
index 3d646598..7709868b 100644
--- a/include/functions.h
+++ b/include/functions.h
@@ -12,53 +12,21 @@
#include "script.h"
// Identified - to be sorted into header files
-extern u32 CheckKinstoneFused(u32);
-extern void ForceEquipItem(u32, u32);
-extern void LoadRoomEntityList(EntityData* listPtr);
-extern void SetChildOffset(Entity*, s32, s32, s32);
-extern Entity* CreatePlayerItem(u32, u32, u32, u32);
-extern u32 GetTileTypeByPos(s32 x, s32 y, u32 layer);
-extern u32 GetTileType(u32 pos, u32 layer);
-extern void SetTile(u32, u32, u32);
extern void SetDirtTile(u32);
-extern Entity* CreateDeathFx(Entity*, u32, u32);
-extern u8* GetSpriteSubEntryOffsetDataPointer(u32, u32);
extern bool32 LoadFixedGFX(Entity*, u32);
-extern void CreateItemEntity(u32, u32, u32);
-extern u32 ProcessMovement(Entity*);
extern void MenuFadeIn(u32, u32);
-extern void LoadResourceAsync(const void*, u32, u32);
-extern void LoadPaletteGroup(u32);
extern void TryLoadPrologueHyruleTown(void);
-extern void LoadGfxGroup(u32);
-extern void ResetPlayer(void);
-extern u32 IsItemEquipped(u32);
-extern bool32 CheckPlayerInRegion(u32 centerX, u32 centerY, u32 radiusX, u32 radiusY);
-extern Entity* CreateProjectileWithParent(Entity*, u8, u8);
-extern u32 GetTileTypeByEntity(Entity*);
-extern u32 GetSaleItemConfirmMessageID(u32);
extern void FlushSprites(void);
-extern Entity* CreateProjectile(u32);
-extern void RegisterPlayerHitbox();
-extern s32 GetItemPrice();
-extern void DoExitTransition(const ScreenTransitionData*);
-extern void CreateDustAt(s32, s32, u32);
-extern void PutItemOnSlot(u32 itemID);
-extern Entity* CreateSpeechBubbleQuestionMark(Entity*, s32, s32);
-extern Entity* CreateSpeechBubbleExclamationMark(Entity*, s32, s32);
-extern Entity* CreateSpeechBubbleSleep(Entity*, s32, s32);
// Unidentified
-extern void sub_080791D0();
extern void sub_0805EC9C();
extern void sub_0805EC60(Entity*);
extern void sub_0806D0B0(Entity*);
extern void sub_0806D02C(Entity*);
-extern void ChangeObjPalette(Entity*, u32);
extern void sub_0806FD3C(Entity*);
extern void sub_0805ED14(u32*);
extern void sub_080A7C18(u32, u32, u32);
-extern void sub_0804AA30(Entity*, void (*const funcs[])());
+extern void sub_0804AA30(Entity*, void (*const[])());
extern void sub_0804A720(Entity*);
extern u32 sub_080AEFE0(Entity*);
extern u32 sub_08049FA0(Entity*);
@@ -72,8 +40,8 @@ extern void sub_08077F50(ItemBehavior* beh, u32 arg1);
extern void sub_0807AA80(Entity*);
extern s32 sub_0807887C(Entity*, u32, u32);
extern s32 sub_08078904();
-extern void sub_080AD9B0(void);
-extern void sub_080AD918(void);
+extern void DrawEntities(void);
+extern void CopyOAM(void);
extern void sub_0801E104(void);
extern void sub_080A57F4(void);
extern void sub_08030118(u32);
@@ -89,121 +57,58 @@ extern void sub_08059278(void);
extern void sub_0804C128(u32);
extern void sub_08058324(u32);
extern void sub_0801AFE4(void);
-extern u32 sub_08060354(void);
-extern void sub_08057E64(void);
-extern void sub_0809F814(u32);
-extern void sub_080300E8(void);
-extern void sub_08058D34(void);
extern void sub_0807AABC(Entity*);
extern void sub_0805B4D0(u32);
-extern void sub_0804D0B4(void);
-extern void sub_080534AC();
extern void sub_0807BA8C(u32, u32);
-extern void sub_0804D9B0();
-extern void sub_0807BB98(u32, u32, u32, u32);
-extern void sub_0801D000(u32);
-extern void sub_08018C58(u32);
extern void sub_080AF284(void);
extern void sub_080A71C4(u32, u32, u32, u32);
extern void sub_08054564();
-extern void sub_0801DD58(u32, u32);
-extern void sub_0804ED18();
-extern void sub_080AF2E4(void);
-extern void sub_0804F578(void);
-extern void sub_08059994(void);
-extern s32 sub_0801CFA8(u32);
-extern void sub_080ADA14(u32, u32); // trampoline to sub_080B27F4
-extern void sub_0801E1B8(u32, u32);
-extern void sub_0801E1EC(s32, s32, s32);
-extern void sub_080A3B74(void);
-extern void sub_080A4054(void);
+extern void DrawDirect(u32, u32); // trampoline to sub_080B27F4
extern void sub_0801C1D4(void);
-extern void sub_0801C208(void);
-extern void sub_080A4D34(void);
-extern u32 sub_080A4494(void);
-extern void sub_080A4528(void);
-extern void sub_080A4398(void);
-extern void sub_0801E738(u32);
-extern void sub_080A7114(u32);
+extern void DrawOAMCmd(void);
extern u32 sub_0807953C(void);
extern void sub_080AE068(Entity*);
extern u32 sub_0800445C(Entity*);
-extern void sub_0807A108(void);
extern u32 sub_0801766C(Entity*);
extern void sub_08004168(Entity*);
-extern void sub_08056208(void);
-extern void sub_08050384();
extern u32 sub_0806F520();
extern void sub_0806F4E8(Entity*);
-extern void sub_0804A7D4(Entity*);
-extern void sub_08033744(Entity*);
-extern void sub_0800417E(Entity*, u32);
extern void sub_080784C8();
extern u32 sub_0808288C(Entity*, u32, u32, u32);
extern void sub_0806FDA0(Entity*);
extern bool32 LoadSwapGFX(Entity*, u16, u32);
-extern u32 sub_08016A30(Entity*);
-extern void sub_08077728();
-extern void sub_0807AEE4();
-extern u32 sub_08078EFC();
extern void sub_0807921C();
-extern void UpdateFloorType();
-extern void sub_08079938();
extern void sub_0807ACCC(Entity*);
-extern void sub_080A2BE4(Entity*, u32);
-extern u32 sub_08097ADC(Entity*);
extern u32 sub_08079F8C(void);
extern void sub_080787CC(Entity*);
extern u32 sub_080044EC(Entity*, u32);
extern u32 sub_080002B8(Entity*);
extern u32 sub_08049F84(Entity*, u32);
-extern void sub_0802F45C(Entity*);
extern u32 sub_0800419C(Entity*, Entity*, u32, u32);
extern void sub_08004542(Entity*);
-extern void sub_08077B20();
-extern bool32 sub_080040A8(Entity*);
extern u32 sub_08017850(Entity*);
extern void sub_080809D4(void);
extern void sub_08080CB4(Entity*);
-extern u32 sub_0800442E(Entity*);
-extern void sub_08081404(Entity*, u32);
extern void sub_0807B7D8(u32, u32, u32);
extern void sub_0800451C(Entity*);
-extern u32 sub_080002F0(u32, u32, u32);
extern u32 sub_080040D8(Entity*, u8*, s32, s32);
-extern void sub_08053320();
-extern void SetColor(u32, u32);
extern u32 sub_0805F8F8(u32);
-extern void sub_08002724(void*, u8*);
-extern void sub_080026C4(u8*, u8*, u8*, u32);
-extern void sub_080026F2(u8*, void*, u8*, u32);
extern u32 sub_0805F7A0(u32);
extern u32* sub_0805F25C(u32);
u32 sub_0806FCB8(Entity*, u32, u32, u32);
extern void sub_0806F62C(Entity*, u32, u32);
extern void sub_080A1ED0(u32, u32, u32);
extern u32 sub_0806F5B0(u32);
-extern void sub_0801DFB4(Entity*, u32, u32, u32);
-extern void sub_0801E00C();
extern void sub_08078790(Entity*, u32);
extern void sub_080788E0(Entity*);
-extern void CreateEzloHint(u32, u32);
extern void sub_08078B48(void);
extern void sub_0807919C();
extern void sub_0807CAA0(u32, u32);
extern void sub_080085B0(Entity*);
extern u32 sub_08079D48();
-extern u32 sub_08008B22();
-extern void sub_080791BC9();
-extern void sub_080791BC();
-extern void MessageClose();
extern u32 sub_080542AC(u32);
extern u32 sub_08079FC4(u32);
-extern void sub_0800455E(Entity*);
-extern u32* sub_08008790(Entity*, u32);
-extern void sub_0804ACF8();
extern void sub_0805F8E4(u32 r0, WStruct* r1);
-
extern Entity* sub_08077C94(ItemBehavior*, u32);
extern Entity* sub_08077C0C(ItemBehavior*, u32);
extern void sub_08077D38(ItemBehavior*, u32);
@@ -213,13 +118,9 @@ extern u32 sub_0806F948(Entity*);
extern void sub_08077DF4(ItemBehavior*, u32);
extern void sub_08077BB8(ItemBehavior*);
extern bool32 sub_08077EFC(ItemBehavior*);
-
extern void sub_08078E84(Entity*, Entity*);
extern void sub_080042D0(Entity*, u32, u16);
-
extern u32 sub_080002A8(u32, u32, u32);
extern void sub_080806BC(u32, u32, u32, u32);
-extern void LoadObjPalette(Entity*, u32);
-
#endif
diff --git a/include/game.h b/include/game.h
new file mode 100644
index 00000000..2b4f950e
--- /dev/null
+++ b/include/game.h
@@ -0,0 +1,321 @@
+#ifndef GAME_H
+#define GAME_H
+
+#include "global.h"
+#include "area.h"
+
+/**
+ * Change the light level of the room.
+ *
+ * @param level The new light level.
+ */
+void ChangeLightLevel(s32 level);
+
+/**
+ * Set the dislayed popup state
+ *
+ * @param type The popup type.
+ * @param choice_idx The choice index.
+ */
+void SetPopupState(u32 type, u32 choice_idx);
+
+/**
+ * Check if an area is overworld (not dungeon or inside).
+ *
+ * @param area The area to check.
+ * @return True if the area is overworld.
+ */
+bool32 CheckAreaOverworld(u32 area);
+
+/**
+ * Check if the current area is overworld.
+ *
+ * @return True if the current area is overworld.
+ */
+bool32 AreaIsOverworld(void);
+
+/**
+ * Check if the current area is a dungeon.
+ *
+ * @return True if the current area is a dungeon.
+ */
+bool32 AreaIsDungeon(void);
+
+/**
+ * Check if the current area has enemies.
+ *
+ * @return True if the current area has enemies.
+ */
+bool32 AreaHasEnemies(void);
+
+/**
+ * Check if the current area has no enemies.
+ *
+ * @return True if the current area has no enemies.
+ */
+bool32 AreaHasNoEnemies(void);
+
+/**
+ * Check if the current area has a map
+ *
+ * @return True if the current area has a map.
+ */
+bool32 AreaHasMap(void);
+
+/**
+ * Check if current area has keys.
+ *
+ * @return True if the current area has keys.
+ */
+bool32 AreaHasKeys(void);
+
+#ifndef EU
+/**
+ * This function was introduced to allow warping from indoor areas (palace of winds).
+ *
+ * @return True if the current area allows warping.
+ */
+u32 AreaAllowsWarp(void);
+
+/**
+ * Related to a music bug?
+ */
+void sub_08052878(void);
+#endif
+
+void sub_080526F8(s32 a1);
+
+/**
+ * Check if the current dungeon has a map item.
+ *
+ * @return True if the current dungeon has a map item.
+ */
+bool32 HasDungeonMap(void);
+
+/**
+ * Check if the current dungeon has a compass item.
+ *
+ * @return True if the current dungeon has a compass item.
+ */
+bool32 HasDungeonCompass(void);
+
+/**
+ * Check if the current dungeon has a big key item.
+ *
+ * @return True if the current dungeon has a big key item.
+ */
+bool32 HasDungeonBigKey(void);
+
+/**
+ * Check if the current dungeon has a small key item.
+ *
+ * @return True if the current dungeon has a small key item.
+ */
+bool32 HasDungeonSmallKey(void);
+
+/**
+ * @brief Check if item is a sword.
+ *
+ * @param item The item to check.
+ * @return True if the item is a sword.
+ */
+bool32 ItemIsSword(u32 item);
+
+/**
+ * Check if item is a shield.
+ *
+ * @return True if the item is a shield.
+ */
+bool32 ItemIsShield(u32 item);
+
+/**
+ * @brief Get the index of the bottle containing the specified item.
+ *
+ * @param item The item to check.
+ * @return Bottle index, or 0 if the item is not in a bottle.
+ */
+u32 GetBottleContaining(u32 item);
+
+/**
+ * Put an item in A or B slot.
+ *
+ * @param item The item to put.
+ */
+void PutItemOnSlot(u32 item);
+
+/**
+ * Force equip an item.
+ *
+ * @param item The item to equip.
+ * @param slot The slot to equip the item in.
+ */
+void ForceEquipItem(u32 item, u32 slot);
+
+/**
+ * Get item price.
+ *
+ * @param item The item to get the price of.
+ * @return The price of the item.
+ */
+s32 GetItemPrice(u32 item);
+
+/**
+ * Get the item purchase enquiry message.
+ *
+ * @param item The item to get the message for.
+ * @return The message index.
+ */
+u32 GetSaleItemConfirmMessageID(u32 item);
+
+/**
+ * Automatically load overworld graphics groups.
+ */
+void LoadGfxGroups(void);
+/**
+ * Load an auxiliary room (no player present).
+ *
+ * @param area Area index.
+ * @param room Room index.
+ */
+void LoadAuxiliaryRoom(u32 area, u32 room);
+
+/**
+ * Initialize a loaded room.
+ */
+void InitRoom(void);
+
+/**
+ * Initialize a parachute room.
+ */
+void InitParachuteRoom(void);
+
+/**
+ * Register a manager for room changes.
+ *
+ * @param mgr Manager to register.
+ * @param onEnter Room enter callback.
+ * @param onExit Room exit callback.
+ */
+void RegisterTransitionManager(void* mgr, void (*onEnter)(void*), void (*onExit)(void*));
+
+/**
+ * Call the room exit callback.
+ */
+void RoomExitCallback(void);
+
+/**
+ * Restore the game task from a subtask.
+ *
+ * @param a1
+ */
+void RestoreGameTask(u32 a1);
+
+/**
+ * Check if an Ezlo message can be displayed.
+ *
+ * @return True if an Ezlo message can be displayed.
+ */
+bool32 CanDispEzloMessage(void);
+
+/**
+ * Display an Ezlo message.
+ */
+void DisplayEzloMessage(void);
+
+/**
+ * Set the player's world map position.
+ *
+ * @param area Area index.
+ * @param room Room index.
+ * @param x X position.
+ * @param y Y position.
+ */
+void SetWorldMapPos(u32 area, u32 room, u32 x, u32 y);
+
+/**
+ * Set the player's dungeon map position.
+ *
+ * @param area Area index.
+ * @param room Room index.
+ * @param x X position.
+ * @param y Y position.
+ */
+void SetDungeonMapPos(u32 area, u32 room, u32 x, u32 y);
+
+/**
+ * Get flag bank offset for area
+ *
+ * @param idx Area index.
+ * @return Flag bank offset.
+ */
+u32 GetFlagBankOffset(u32 idx);
+
+/**
+ * Retrieve information about the current room.
+ *
+ * @return RoomResInfo object.
+ */
+RoomResInfo* GetCurrentRoomInfo(void);
+
+void sub_08052EA0(void);
+void sub_08053250(void);
+void sub_080533CC(void);
+
+void sub_08053494(void);
+void sub_080534AC(void);
+void InitBiggoronTimer(void);
+
+/** Game tasks states */
+typedef enum {
+ GAMETASK_TRANSITION, /* transition from fileselect task */
+ GAMETASK_INIT,
+ GAMETASK_MAIN,
+ GAMETASK_EXIT, /* gameover task or reset */
+} EGameTaskState;
+
+/** game task main substates */
+typedef enum {
+ GAMEMAIN_INITROOM,
+ GAMEMAIN_CHANGEROOM,
+ GAMEMAIN_UPDATE,
+ GAMEMAIN_CHANGEAREA,
+ GAMEMAIN_MINISHPORTAL, /* moments after viewing portal cutscene */
+ GAMEMAIN_BARRELUPDATE, /* barrel in deepwood shrine */
+ GAMEMAIN_RESERVED,
+ GAMEMAIN_SUBTASK,
+} EGameMainState;
+
+/** Subtasks override the game task for short periods */
+typedef enum {
+ SUBTASK_EXIT,
+ SUBTASK_PAUSEMENU,
+ SUBTASK_EXIT2,
+ SUBTASK_MAPHINT,
+ SUBTASK_KINSTONEMENU,
+ SUBTASK_AUXCUTSCENE, /* cutscene without presence of player */
+ SUBTASK_PORTALCUTSCENE, /* player "falling" down portal cutscene */
+ SUBTASK_FIGURINEMENU,
+ SUBTASK_WORLDEVENT,
+ SUBTASK_FASTTRAVEL,
+ SUBTASK_LOCALMAPHINT,
+} ESubtask;
+
+typedef void(Subtask)(void);
+
+/** @name Subtask entrypoints */
+///@{
+/** Subtask entrypoint. */
+Subtask Subtask_Exit;
+Subtask Subtask_PauseMenu;
+Subtask Subtask_Exit;
+Subtask Subtask_MapHint;
+Subtask Subtask_KinstoneMenu;
+Subtask Subtask_AuxCutscene;
+Subtask Subtask_PortalCutscene;
+Subtask Subtask_FigurineMenu;
+Subtask Subtask_WorldEvent;
+Subtask Subtask_FastTravel;
+Subtask Subtask_LocalMapHint;
+///@}
+
+#endif // GAME_H
diff --git a/include/global.h b/include/global.h
index e7eddd31..d9d22943 100644
--- a/include/global.h
+++ b/include/global.h
@@ -1,6 +1,24 @@
#ifndef GUARD_GLOBAL_H
#define GUARD_GLOBAL_H
+/**
+ * @defgroup Tasks Tasks
+ * @defgroup Subtasks Subtasks
+ */
+
+/** @defgroup Entities Entities */
+///@{
+/**
+ * @defgroup Player Player
+ * @defgroup Enemies Enemies
+ * @defgroup Projectiles Projectiles
+ * @defgroup Objects Objects
+ * @defgroup NPCs NPCs
+ * @defgroup Items Items
+ * @defgroup Managers Managers
+ */
+///@}
+
#include "gba/gba.h"
#include <string.h>
@@ -101,4 +119,7 @@ union SplitHWord {
#define FORCE_WORD_ALIGNED __attribute__((packed, aligned(2)))
+/* forward decls */
+struct Entity_;
+
#endif // GUARD_GLOBAL_H
diff --git a/include/item.h b/include/item.h
index b47066da..c5409c29 100644
--- a/include/item.h
+++ b/include/item.h
@@ -5,6 +5,9 @@
#include "entity.h"
#include "player.h"
+void CreateItemEntity(u32, u32, u32);
+void sub_08081404(Entity*, u32);
+
extern void ItemDebug(ItemBehavior*, u32);
extern void ItemSword(ItemBehavior*, u32);
extern void ItemBomb(ItemBehavior*, u32);
diff --git a/include/kinstone.h b/include/kinstone.h
new file mode 100644
index 00000000..28b799dd
--- /dev/null
+++ b/include/kinstone.h
@@ -0,0 +1,30 @@
+#ifndef KINSTONE_H
+#define KINSTONE_H
+
+#include "global.h"
+
+extern void sub_08018C58(u32);
+
+typedef struct {
+ u8 unk[4];
+ u32 unk2;
+ u32 unk4;
+} Unk_struct;
+extern Unk_struct gUnk_03003DF0[];
+
+typedef struct {
+ u8 _0;
+ u8 action;
+ u8 _2;
+ u8 _3;
+ u8 _4;
+ u8 _5;
+ u16 _6;
+ u16 _8;
+ u16 _a;
+ Entity* ent;
+} FuseInfo;
+static_assert(sizeof(FuseInfo) == 0x10);
+extern FuseInfo gFuseInfo;
+
+#endif // KINSTONE_H
diff --git a/include/main.h b/include/main.h
index d5ffda2e..f7ab29c4 100644
--- a/include/main.h
+++ b/include/main.h
@@ -3,25 +3,16 @@
#include "global.h"
+/** File signature */
#define SIGNATURE 'MCZ3'
+/** Maximum message speed. */
#define MAX_MSG_SPEED 3
+/** Number of save slots */
#define NUM_SAVE_SLOTS 3
+/** Maximum brightness. */
#define MAX_BRIGHTNESS 3
-typedef struct { // 0x03001000
- u8 field_0x0;
- u8 field_0x1;
- u8 field_0x2;
- u8 field_0x3;
- u8 field_0x4;
- u16 field_0x6;
- u8 field_0x8;
- u8 field_0x9;
- u8 field_0xa;
- u8 field_0xb;
- u32 spritePriority;
-} MainStruct;
-
+/** Supported game languages. */
typedef enum {
LANGUAGE_JP,
LANGUAGE_EN,
@@ -38,37 +29,47 @@ typedef enum {
#define GAME_LANGUAGE LANGUAGE_JP
#endif
-enum {
- SCREEN_INTRO,
- SCREEN_CHOOSE_FILE,
- SCREEN_GAMEPLAY,
- SCREEN_GAME_OVER,
- SCREEN_CREDITS,
- SCREEN_DEBUG_TEXT,
-};
-
-enum {
+/** Program tasks. */
+typedef enum {
+ TASK_TITLE, /**< Title task. This is the first task to be entered. */
+ TASK_FILE_SELECT, /**< File selection task. */
+ TASK_GAME, /**< Gameplay task. Overworld, menus, cutscenes are all contained here. */
+ TASK_GAMEOVER, /**< Gameover task. */
+ TASK_STAFFROLL, /**< Staffroll task. Only accessible through the script played during the game ending. */
+ TASK_DEBUG, /**< Debug task. Inaccessible in normal gameplay. */
+} Task;
+
+/** System sleep status. */
+typedef enum {
DEFAULT,
SLEEP,
-};
+} SleepStatus;
+/**
+ * Main system structure.
+ */
typedef struct {
vu8 interruptFlag;
u8 sleepStatus;
- u8 screen;
- u8 funcIndex;
- u8 transition;
+ u8 task; /**< Current #Task. */
+ u8 state; /**< State of the current #Task. */
+ u8 substate; /**< Substate of the current #Task. */
u8 field_0x5;
- u8 muteAudio;
+ u8 muteAudio; /**< Mute audio. */
u8 field_0x7;
- u8 pauseFrames;
- u8 pauseCount;
- u8 pauseInterval;
- u16 ticks;
+ u8 pauseFrames; /**< Number of frames to pause. */
+ u8 pauseCount; /**< Number of pauses to make. */
+ u8 pauseInterval; /**< Number of frames to play between each pause. */
+ u8 pad;
+ union SplitHWord ticks; /**< Current time. */
} Main;
+/**
+ * HUD structure.
+ */
typedef struct {
- /*0x00*/ u16 nextToLoad;
+ /*0x00*/ u8 nextToLoad;
+ /*0x01*/ u8 _1;
/*0x02*/ u8 lastState;
/*0x03*/ u8 field_0x3;
/*0x04*/ u8 state;
@@ -81,31 +82,62 @@ typedef struct {
} UI;
static_assert(sizeof(UI) == 0x3b4);
-extern Main gMain;
-extern UI gUnk_02032EC0;
+extern Main gMain; /**< Main instance. */
+extern UI gUnk_02032EC0; /**< UI instance. */
/**
- * @brief Begin a subroutine.
+ * Program entry point.
*/
-void InitScreen(u32 screen);
+void AgbMain(void);
+/**
+ * Begin a new task.
+ *
+ * @param task #Task to begin.
+ */
+void SetTask(u32 task);
+
+/**
+ * Initialize the DMA system.
+ */
void InitDMA(void);
+/**
+ * Soft reset the system.
+ */
+void DoSoftReset(void);
+
+/**
+ * Put the system into sleep mode.
+ */
+void SetSleepMode(void);
+
+extern void sub_0805622C(void* a1, u32 a2, u32 a3);
extern void sub_08056208(void);
extern void ResetPalettes(void);
-
-extern void DoSoftReset(void);
-extern void SetSleepMode(void);
extern void VBlankIntrWait();
-extern void FadeMain(void);
-
-extern u8 gUnk_03003DE4;
-
-extern void SetBrightness(u32);
-extern u16 gPaletteBuffer[];
extern void VBlankInterruptWait(void);
extern void DisableInterruptsAndDMA(void);
extern void EnableVBlankIntr(void);
extern void sub_08056250(void);
+extern void sub_08056208(void);
+
+/** @name Task entrypoints */
+///@{
+/** Task entrypoint. */
+extern void TitleTask(void);
+extern void FileSelectTask(void);
+extern void GameTask(void);
+extern void GameOverTask(void);
+extern void StaffrollTask(void);
+extern void DebugTask(void);
+
+#ifdef DEMO_USA
+extern void DemoTask(void);
+#endif
+/// @}
+
+extern u8 gUnk_03003DE4;
+extern u16 gPaletteBuffer[];
#endif
diff --git a/include/manager.h b/include/manager.h
index 44852146..28a27922 100644
--- a/include/manager.h
+++ b/include/manager.h
@@ -130,10 +130,10 @@ typedef struct Manager11 {
typedef struct {
u16 unk_00;
- u8 source_roomID;
+ u8 source_room;
u8 unk_03;
- u8 target_areaID;
- u8 target_roomID;
+ u8 target_area;
+ u8 target_room;
u16 unk_06;
} DiggingCaveEntrance;
diff --git a/include/menu.h b/include/menu.h
index 052de3d2..e4c09e84 100644
--- a/include/menu.h
+++ b/include/menu.h
@@ -33,30 +33,30 @@ typedef struct {
extern void sub_080A70AC(const KeyButtonLayout*);
typedef struct {
- u8 field_0x0;
- u8 column_idx;
- u8 field_0x2;
- u8 field_0x3;
- u8 field_0x4;
- u8 menuType;
- u8 overlayType;
- u8 storyPanelIndex;
- u16 transitionTimer;
- u16 field_0xa;
- u8* field_0xc;
- u8 focusCoords[2];
- u8 field_0x12;
- u8 unk13;
- u8 unk14;
- u8 unk15;
- u8 unk16;
- // While struct offsets are usually loaded indirectly, this one is often loaded
- // directly in the code. This happens when you take the address off the field with '&`.
- // Perhaps they had a macro to cast this to different sized arrays.
- u8 selectMtx;
- u8 filler18[0x12];
- u8 unk2a;
- int field_0x2c;
+ /*0x00*/ u8 field_0x0;
+ /*0x01*/ u8 column_idx;
+ /*0x02*/ u8 field_0x2;
+ /*0x03*/ u8 field_0x3;
+ /*0x04*/ u8 field_0x4;
+ /*0x05*/ u8 menuType;
+ /*0x06*/ u8 overlayType;
+ /*0x07*/ u8 storyPanelIndex;
+ /*0x08*/ u16 transitionTimer;
+ /*0x0a*/ u16 field_0xa;
+ /*0x0c*/ u8* field_0xc;
+ /*0x10*/ u8 focusCoords[2];
+ /*0x12*/ u8 field_0x12;
+ /*0x13*/ u8 unk13;
+ /*0x14*/ u8 unk14;
+ /*0x15*/ u8 unk15;
+ /*0x16*/ u8 unk16;
+ /* */ // While struct offsets are usually loaded indirectly, this one is often loaded
+ /* */ // directly in the code. This happens when you take the address off the field with '&`.
+ /* */ // Perhaps they had a macro to cast this to different sized arrays.
+ /*0x17*/ u8 selectMtx;
+ /*0x18*/ u8 filler18[0x12];
+ /*0x2a*/ u8 unk2a;
+ /*0x2c*/ int field_0x2c;
} Menu;
static_assert(sizeof(Menu) == 0x30);
diff --git a/include/textbox.h b/include/message.h
index 894c5d9d..c0164810 100644
--- a/include/textbox.h
+++ b/include/message.h
@@ -1,5 +1,5 @@
-#ifndef TEXTBOX_H
-#define TEXTBOX_H
+#ifndef MESSAGE_H
+#define MESSAGE_H
#include "global.h"
#include "entity.h"
@@ -39,7 +39,7 @@ typedef struct {
Message message;
Token curToken;
WStruct _50;
- char playerName[10];
+ char player_name[10];
u8 _66[0x10];
u8 _76;
u8 _77[0x11];
@@ -126,6 +126,11 @@ void MessageFromTarget(u32 index);
*/
void MessageAtHeight(u32 index, u32 y);
-void DispMessageFrame(u16*, u32, u32, u32);
+/**
+ * @brief Close message.
+ */
+void MessageClose(void);
+
+void DispMessageFrame(u16*, s32, s32, u32);
-#endif
+#endif // MESSAGE_H
diff --git a/include/npc.h b/include/npc.h
index d67652de..1b84e617 100644
--- a/include/npc.h
+++ b/include/npc.h
@@ -3,14 +3,14 @@
#include "global.h"
#include "asm.h"
-#include "utils.h"
+#include "common.h"
-#include "audio.h"
+#include "sound.h"
#include "effects.h"
#include "room.h"
#include "flags.h"
#include "coord.h"
-#include "textbox.h"
+#include "message.h"
#include "script.h"
#include "save.h"
@@ -177,166 +177,166 @@ enum NPC {
/*0x7f*/ NPC_NONE_39,
};
-extern void Gentari(Entity*);
-extern void Gentari_Fusion(Entity*);
-extern void Festari(Entity*);
-extern void Festari_Fusion(Entity*);
-extern void ForestMinish(Entity*);
-extern void ForestMinish_Head(Entity*);
-extern void ForestMinish_Fusion(Entity*);
-extern void Postman(Entity*);
-extern void Postman_Fusion(Entity*);
-extern void NPC5(Entity*);
-extern void Townsperson(Entity*);
-extern void Townsperson_Head(Entity*);
-extern void Townsperson_Fusion(Entity*);
-extern void Kid(Entity*);
-extern void Kid_Head(Entity*);
-extern void Kid_Fusion(Entity*);
-extern void Guard(Entity*);
-extern void Guard_Head(Entity*);
-extern void NPC9(Entity*);
-extern void Stamp(Entity*);
-extern void Maid(Entity*);
-extern void Maid_Head(Entity*);
-extern void Marcy(Entity*);
-extern void Wheaton(Entity*);
-extern void Pita(Entity*);
-extern void MinishEzlo(Entity*);
-extern void MinishEzlo_Head(Entity*);
-extern void Mailbox(Entity*);
-extern void Beedle(Entity*);
-extern void Beedle_Head(Entity*);
-extern void Brocco(Entity*);
-extern void Brocco_Fusion(Entity*);
-extern void SittingPerson(Entity*);
-extern void SittingPerson_Head(Entity*);
-extern void SittingPerson_Fusion(Entity*);
-extern void Pina(Entity*);
-extern void Pina_Fusion(Entity*);
-extern void Din(Entity*);
-extern void Din_Fusion(Entity*);
-extern void Nayru(Entity*);
-extern void Nayru_Fusion(Entity*);
-extern void Farore(Entity*);
-extern void Farore_Fusion(Entity*);
-extern void Sturgeon(Entity*);
-extern void Sturgeon_Head(Entity*);
-extern void Sturgeon_Fusion(Entity*);
-extern void TingleSiblings(Entity*);
-extern void TingleSiblings_Fusion(Entity*);
-extern void Stockwell(Entity*);
-extern void Talon(Entity*);
-extern void Talon_Head(Entity*);
-extern void Talon_Fusion(Entity*);
-extern void Malon(Entity*);
-extern void Malon_Fusion(Entity*);
-extern void Epona(Entity*);
-extern void Epona_Fusion(Entity*);
-extern void MilkCart(Entity*);
-extern void GhostBrothers(Entity*);
-extern void GhostBrothers_Fusion(Entity*);
-extern void Smith(Entity*);
-extern void Smith_Head(Entity*);
-extern void Smith_Fusion(Entity*);
-extern void NPC23(Entity*);
-extern void KingDaltus(Entity*);
-extern void KingDaltus_Fusion(Entity*);
-extern void MinisterPotho(Entity*);
-extern void MinisterPotho_Fusion(Entity*);
-extern void NPC26(Entity*);
-extern void Vaati(Entity*);
-extern void Zelda(Entity*);
-extern void Mutoh(Entity*);
-extern void Mutoh_Head(Entity*);
-extern void Mutoh_Fusion(Entity*);
-extern void Carpenter(Entity*);
-extern void Carpenter_Head(Entity*);
-extern void Carpenter_Fusion(Entity*);
-extern void CastorWildsStatue(Entity*);
-extern void CastorWildsStatue_Fusion(Entity*);
-extern void Cat(Entity*);
-extern void Cat_Fusion(Entity*);
-extern void MountainMinish(Entity*);
-extern void MountainMinish_Head(Entity*);
-extern void MountainMinish_Fusion(Entity*);
-extern void ZeldaFollower(Entity*);
-extern void Melari(Entity*);
-extern void Melari_Head(Entity*);
-extern void Melari_Fusion(Entity*);
-extern void BladeBrothers(Entity*);
-extern void BladeBrothers_Fusion(Entity*);
-extern void Cow(Entity*);
-extern void Cow_Fusion(Entity*);
-extern void Goron(Entity*);
-extern void Goron_Fusion(Entity*);
-extern void GoronMerchant(Entity*);
-extern void Gorman(Entity*);
-extern void Gorman_Head(Entity*);
-extern void Dog(Entity*);
-extern void Dog_Head(Entity*);
-extern void Dog_Fusion(Entity*);
-extern void Syrup(Entity*);
-extern void Syrup_Head(Entity*);
-extern void Rem(Entity*);
-extern void TownMinish(Entity*);
-extern void TownMinish_Head(Entity*);
-extern void TownMinish_Fusion(Entity*);
-extern void Librari(Entity*);
-extern void Librari_Fusion(Entity*);
-extern void Percy(Entity*);
-extern void Percy_Head(Entity*);
-extern void Percy_Fusion(Entity*);
-extern void VaatiReborn(Entity*);
-extern void MoblinLady(Entity*);
-extern void Librarians(Entity*);
-extern void Farmers(Entity*);
-extern void Farmers_Head(Entity*);
-extern void Farmers_Fusion(Entity*);
-extern void Carlov(Entity*);
-extern void Dampe(Entity*);
-extern void Dampe_Fusion(Entity*);
-extern void DrLeft(Entity*);
-extern void KingGustaf(Entity*);
-extern void Gina(Entity*);
-extern void Gina_Fusion(Entity*);
-extern void Simon(Entity*);
-extern void Anju(Entity*);
-extern void Anju_Fusion(Entity*);
-extern void Mama(Entity*);
-extern void Mama_Head(Entity*);
-extern void Mama_Fusion(Entity*);
-extern void Emma(Entity*);
-extern void Teachers(Entity*);
-extern void Teachers_Head(Entity*);
-extern void Teachers_Fusion(Entity*);
-extern void WindTribespeople(Entity*);
-extern void WindTribespeople_Head(Entity*);
-extern void WindTribespeople_Fusion(Entity*);
-extern void Gregal(Entity*);
-extern void Gregal_Fusion(Entity*);
-extern void MayorHagen(Entity*);
-extern void MayorHagen_Fusion(Entity*);
-extern void BigGoron(Entity*);
-extern void Ezlo(Entity*);
-extern void NPC4E(Entity*);
-extern void NPC4E_Fusion(Entity*);
-extern void NPC4F(Entity*);
-extern void ClothesRack(Entity*);
-extern void PicolyteBottle(Entity*);
-extern void SmallTownMinish(Entity*);
-extern void HurdyGurdyMan(Entity*);
-extern void HurdyGurdyMan_Head(Entity*);
-extern void HurdyGurdyMan_Fusion(Entity*);
-extern void Cucco(Entity*);
-extern void Cucco_Fusion(Entity*);
-extern void CuccoChick(Entity*);
-extern void CuccoChick_Fusion(Entity*);
-extern void FusionMenuNPC(Entity*);
-extern void FusionMenuNPC_Head(Entity*);
-extern void Phonograph(Entity*);
-extern void NPC58(Entity*);
-extern void NPC58_Head(Entity*);
+void Gentari(Entity*);
+void Gentari_Fusion(Entity*);
+void Festari(Entity*);
+void Festari_Fusion(Entity*);
+void ForestMinish(Entity*);
+void ForestMinish_Head(Entity*);
+void ForestMinish_Fusion(Entity*);
+void Postman(Entity*);
+void Postman_Fusion(Entity*);
+void NPC5(Entity*);
+void Townsperson(Entity*);
+void Townsperson_Head(Entity*);
+void Townsperson_Fusion(Entity*);
+void Kid(Entity*);
+void Kid_Head(Entity*);
+void Kid_Fusion(Entity*);
+void Guard(Entity*);
+void Guard_Head(Entity*);
+void NPC9(Entity*);
+void Stamp(Entity*);
+void Maid(Entity*);
+void Maid_Head(Entity*);
+void Marcy(Entity*);
+void Wheaton(Entity*);
+void Pita(Entity*);
+void MinishEzlo(Entity*);
+void MinishEzlo_Head(Entity*);
+void Mailbox(Entity*);
+void Beedle(Entity*);
+void Beedle_Head(Entity*);
+void Brocco(Entity*);
+void Brocco_Fusion(Entity*);
+void SittingPerson(Entity*);
+void SittingPerson_Head(Entity*);
+void SittingPerson_Fusion(Entity*);
+void Pina(Entity*);
+void Pina_Fusion(Entity*);
+void Din(Entity*);
+void Din_Fusion(Entity*);
+void Nayru(Entity*);
+void Nayru_Fusion(Entity*);
+void Farore(Entity*);
+void Farore_Fusion(Entity*);
+void Sturgeon(Entity*);
+void Sturgeon_Head(Entity*);
+void Sturgeon_Fusion(Entity*);
+void TingleSiblings(Entity*);
+void TingleSiblings_Fusion(Entity*);
+void Stockwell(Entity*);
+void Talon(Entity*);
+void Talon_Head(Entity*);
+void Talon_Fusion(Entity*);
+void Malon(Entity*);
+void Malon_Fusion(Entity*);
+void Epona(Entity*);
+void Epona_Fusion(Entity*);
+void MilkCart(Entity*);
+void GhostBrothers(Entity*);
+void GhostBrothers_Fusion(Entity*);
+void Smith(Entity*);
+void Smith_Head(Entity*);
+void Smith_Fusion(Entity*);
+void NPC23(Entity*);
+void KingDaltus(Entity*);
+void KingDaltus_Fusion(Entity*);
+void MinisterPotho(Entity*);
+void MinisterPotho_Fusion(Entity*);
+void NPC26(Entity*);
+void Vaati(Entity*);
+void Zelda(Entity*);
+void Mutoh(Entity*);
+void Mutoh_Head(Entity*);
+void Mutoh_Fusion(Entity*);
+void Carpenter(Entity*);
+void Carpenter_Head(Entity*);
+void Carpenter_Fusion(Entity*);
+void CastorWildsStatue(Entity*);
+void CastorWildsStatue_Fusion(Entity*);
+void Cat(Entity*);
+void Cat_Fusion(Entity*);
+void MountainMinish(Entity*);
+void MountainMinish_Head(Entity*);
+void MountainMinish_Fusion(Entity*);
+void ZeldaFollower(Entity*);
+void Melari(Entity*);
+void Melari_Head(Entity*);
+void Melari_Fusion(Entity*);
+void BladeBrothers(Entity*);
+void BladeBrothers_Fusion(Entity*);
+void Cow(Entity*);
+void Cow_Fusion(Entity*);
+void Goron(Entity*);
+void Goron_Fusion(Entity*);
+void GoronMerchant(Entity*);
+void Gorman(Entity*);
+void Gorman_Head(Entity*);
+void Dog(Entity*);
+void Dog_Head(Entity*);
+void Dog_Fusion(Entity*);
+void Syrup(Entity*);
+void Syrup_Head(Entity*);
+void Rem(Entity*);
+void TownMinish(Entity*);
+void TownMinish_Head(Entity*);
+void TownMinish_Fusion(Entity*);
+void Librari(Entity*);
+void Librari_Fusion(Entity*);
+void Percy(Entity*);
+void Percy_Head(Entity*);
+void Percy_Fusion(Entity*);
+void VaatiReborn(Entity*);
+void MoblinLady(Entity*);
+void Librarians(Entity*);
+void Farmers(Entity*);
+void Farmers_Head(Entity*);
+void Farmers_Fusion(Entity*);
+void Carlov(Entity*);
+void Dampe(Entity*);
+void Dampe_Fusion(Entity*);
+void DrLeft(Entity*);
+void KingGustaf(Entity*);
+void Gina(Entity*);
+void Gina_Fusion(Entity*);
+void Simon(Entity*);
+void Anju(Entity*);
+void Anju_Fusion(Entity*);
+void Mama(Entity*);
+void Mama_Head(Entity*);
+void Mama_Fusion(Entity*);
+void Emma(Entity*);
+void Teachers(Entity*);
+void Teachers_Head(Entity*);
+void Teachers_Fusion(Entity*);
+void WindTribespeople(Entity*);
+void WindTribespeople_Head(Entity*);
+void WindTribespeople_Fusion(Entity*);
+void Gregal(Entity*);
+void Gregal_Fusion(Entity*);
+void MayorHagen(Entity*);
+void MayorHagen_Fusion(Entity*);
+void BigGoron(Entity*);
+void Ezlo(Entity*);
+void NPC4E(Entity*);
+void NPC4E_Fusion(Entity*);
+void NPC4F(Entity*);
+void ClothesRack(Entity*);
+void PicolyteBottle(Entity*);
+void SmallTownMinish(Entity*);
+void HurdyGurdyMan(Entity*);
+void HurdyGurdyMan_Head(Entity*);
+void HurdyGurdyMan_Fusion(Entity*);
+void Cucco(Entity*);
+void Cucco_Fusion(Entity*);
+void CuccoChick(Entity*);
+void CuccoChick_Fusion(Entity*);
+void FusionMenuNPC(Entity*);
+void FusionMenuNPC_Head(Entity*);
+void Phonograph(Entity*);
+void NPC58(Entity*);
+void NPC58_Head(Entity*);
extern void (*const gNPCFunctions[128][3])(Entity*);
diff --git a/include/object.h b/include/object.h
index d7256397..ded574e3 100644
--- a/include/object.h
+++ b/include/object.h
@@ -3,9 +3,9 @@
#include "global.h"
#include "asm.h"
-#include "utils.h"
+#include "common.h"
-#include "audio.h"
+#include "sound.h"
#include "flags.h"
#include "effects.h"
#include "room.h"
@@ -20,9 +20,14 @@ extern void sub_080787B4(Entity*);
extern void sub_0808C650(Entity*, u32);
extern u32 sub_0808C67C(void);
extern void sub_0808C688(void);
+extern void sub_080A2BE4(Entity*, u32);
void CreateDust(Entity* parent);
+void CreateDustAt(s32, s32, u32);
void CreateDustSmall(Entity* parent);
+Entity* CreateSpeechBubbleQuestionMark(Entity*, s32, s32);
+Entity* CreateSpeechBubbleExclamationMark(Entity*, s32, s32);
+Entity* CreateSpeechBubbleSleep(Entity*, s32, s32);
typedef enum {
GROUND_ITEM,
@@ -221,200 +226,200 @@ typedef enum {
OBJECT_C1,
} Object;
-extern void ItemOnGround(Entity*);
-extern void DeathFx(Entity*);
-extern void ItemForSale(Entity*);
-extern void Button(Entity*);
-extern void MinishEmoticon(Entity*);
-extern void Pot(Entity*);
-extern void EzloCap(Entity*);
-extern void BlockPushed(Entity*);
-extern void LockedDoor(Entity*);
-extern void Object9(Entity*);
-extern void ObjectA(Entity*);
-extern void ObjectB(Entity*);
-extern void ChestSpawner(Entity*);
-extern void ObjectD(Entity*);
-extern void ObjectE(Entity*);
-extern void SpecialFx(Entity*);
-extern void Object10(Entity*);
-extern void Object11(Entity*);
-extern void Object12(Entity*);
-extern void Railtrack(Entity*);
-extern void LilypadLarge(Entity*);
-extern void Object15(Entity*);
-extern void FloatingPlatform(Entity*);
-extern void Object17(Entity*);
-extern void EvilSpirit(Entity*);
-extern void HouseDoorExterior(Entity*);
-extern void Object1A(Entity*);
-extern void GreatFairy(Entity*);
-extern void Object1C(Entity*);
-extern void Object1D(Entity*);
-extern void Object1E(Entity*);
-extern void Object1F(Entity*);
-extern void Object20(Entity*);
-extern void Object21(Entity*);
-extern void FigurineDevice(Entity*);
-extern void EyeSwitch(Entity*);
-extern void PressurePlate(Entity*);
-extern void BigBarrel(Entity*);
-extern void BarrelInside(Entity*);
-extern void PushableStatue(Entity*);
-extern void Object28(Entity*);
-extern void AmbientClouds(Entity*);
-extern void Object2A(Entity*);
-extern void Object2B(Entity*);
-extern void Beanstalk(Entity*);
-extern void Smoke(Entity*);
-extern void PushableRock(Entity*);
-extern void HittableLever(Entity*);
-extern void Object30(Entity*);
-extern void FrozenFlower(Entity*);
-extern void PullableMushroom(Entity*);
-extern void Bollard(Entity*);
-extern void WarpPoint(Entity*);
-extern void Object35(Entity*);
-extern void Object36(Entity*);
-extern void Object37(Entity*);
-extern void JarPortal(Entity*);
-extern void BossDoor(Entity*);
-extern void Object3A(Entity*);
-extern void MacroMushromStalks(Entity*);
-extern void MacroPlayer(Entity*);
-extern void Object3D(Entity*);
-extern void Object3E(Entity*);
-extern void GiantLeaf(Entity*);
-extern void Fairy(Entity*);
-extern void LadderUp(Entity*);
-extern void Object42(Entity*);
-extern void Object43(Entity*);
-extern void Object44(Entity*);
-extern void Object45(Entity*);
-extern void GiantBookLadder(Entity*);
-extern void HeartContainer(Entity*);
-extern void FileScreenObjects(Entity*);
-extern void Object49(Entity*);
-extern void BackgroundCloud(Entity*);
-extern void Object4B(Entity*);
-extern void PushableFurniture(Entity*);
-extern void Furniture(Entity*);
-extern void MinishSizedEntrance(Entity*);
-extern void Archway(Entity*);
-extern void GiantRock(Entity*);
-extern void GiantRock2(Entity*);
-extern void Object52(Entity*);
-extern void Object53(Entity*);
-extern void PullableLever(Entity*);
-extern void Minecart(Entity*);
-extern void ThoughtBubble(Entity*);
-extern void HiddenLadderDown(Entity*);
-extern void GentariCurtain(Entity*);
-extern void LavaPlatform(Entity*);
-extern void Paper(Entity*);
-extern void Object5B(Entity*);
-extern void Mask(Entity*);
-extern void HouseDoorInterior(Entity*);
-extern void Whirlwind(Entity*);
-extern void ObjectBlockingStairs(Entity*);
-extern void SwordsmanNewsletter(Entity*);
-extern void Object61(Entity*);
-extern void GiantTwig(Entity*);
-extern void Object63(Entity*);
-extern void Object64(Entity*);
-extern void LadderHoleInBookshelf(Entity*);
-extern void Object66(Entity*);
-extern void Object67(Entity*);
-extern void Object68(Entity*);
-extern void Object69(Entity*);
-extern void Object6A(Entity*);
-extern void CrenalBeanSprout(Entity*);
-extern void MinecartDoor(Entity*);
-extern void ObjectOnPillar(Entity*);
-extern void MineralWaterSource(Entity*);
-extern void MinishSizedArchway(Entity*);
-extern void Object70(Entity*);
-extern void PushableGrave(Entity*);
-extern void StoneTablet(Entity*);
-extern void LilypadSmall(Entity*);
-extern void Object74(Entity*);
-extern void Object75(Entity*);
-extern void Object76(Entity*);
-extern void Bell(Entity*);
-extern void MacroDecoration(Entity*);
-extern void Object79(Entity*);
-extern void Steam(Entity*);
-extern void PushableLever(Entity*);
-extern void MacroShoes(Entity*);
-extern void ObjectOnSpinyBeetle(Entity*);
-extern void Object7E(Entity*);
-extern void PicoBloom(Entity*);
-extern void Board(Entity*);
-extern void Object81(Entity*);
-extern void BigVortex(Entity*);
-extern void BigPushableLever(Entity*);
-extern void SmallIceBlock(Entity*);
-extern void BigIceBlock(Entity*);
-extern void Object86(Entity*);
-extern void OctorokBossObject(Entity*);
-extern void MacroBook(Entity*);
-extern void MazaalBossObject(Entity*);
-extern void CabinFurniture(Entity*);
-extern void DoubleBookshelf(Entity*);
-extern void Book(Entity*);
-extern void Fireplace(Entity*);
-extern void Object8E(Entity*);
-extern void FrozenWaterElement(Entity*);
-extern void Object90(Entity*);
-extern void Object91(Entity*);
-extern void BakerOven(Entity*);
-extern void Lamp(Entity*);
-extern void WindTribeFlag(Entity*);
-extern void Bird(Entity*);
-extern void Object96(Entity*);
-extern void Object97(Entity*);
-extern void Object98(Entity*);
-extern void Object99(Entity*);
-extern void MacroAcorn(Entity*);
-extern void Object9B(Entity*);
-extern void TreeHidingPortal(Entity*);
-extern void LightableSwitch(Entity*);
-extern void TreeThorns(Entity*);
-extern void Fan(Entity*);
-extern void AngryStatue(Entity*);
-extern void PalaceArchway(Entity*);
-extern void ObjectA2(Entity*);
-extern void Cloud(Entity*);
-extern void MinishLight(Entity*);
-extern void FireballChain(Entity*);
-extern void ObjectA6(Entity*);
-extern void ObjectA7(Entity*);
-extern void ObjectA8(Entity*);
-extern void ObjectA9(Entity*);
-extern void WaterfallOpening(Entity*);
-extern void ObjectAB(Entity*);
-extern void FourElements(Entity*);
-extern void ObjectAD(Entity*);
-extern void FloatingBlock(Entity*);
-extern void ObjectAF(Entity*);
-extern void MetalDoor(Entity*);
-extern void JailBars(Entity*);
-extern void ObjectB2(Entity*);
-extern void ObjectB3(Entity*);
-extern void ObjectB4(Entity*);
-extern void ObjectB5(Entity*);
-extern void ObjectB6(Entity*);
-extern void Well(Entity*);
-extern void WindTribeTeleporter(Entity*);
-extern void ObjectB9(Entity*);
-extern void GyorgBossObject(Entity*);
-extern void Windcrest(Entity*);
-extern void LitArea(Entity*);
-extern void ObjectBD(Entity*);
-extern void Pinwheel(Entity*);
-extern void ObjectBF(Entity*);
-extern void EnemyItem(Entity*);
-extern void ObjectC1(Entity*);
+void ItemOnGround(Entity*);
+void DeathFx(Entity*);
+void ItemForSale(Entity*);
+void Button(Entity*);
+void MinishEmoticon(Entity*);
+void Pot(Entity*);
+void EzloCap(Entity*);
+void BlockPushed(Entity*);
+void LockedDoor(Entity*);
+void Object9(Entity*);
+void ObjectA(Entity*);
+void ObjectB(Entity*);
+void ChestSpawner(Entity*);
+void ObjectD(Entity*);
+void ObjectE(Entity*);
+void SpecialFx(Entity*);
+void Object10(Entity*);
+void Object11(Entity*);
+void Object12(Entity*);
+void Railtrack(Entity*);
+void LilypadLarge(Entity*);
+void Object15(Entity*);
+void FloatingPlatform(Entity*);
+void Object17(Entity*);
+void EvilSpirit(Entity*);
+void HouseDoorExterior(Entity*);
+void Object1A(Entity*);
+void GreatFairy(Entity*);
+void Object1C(Entity*);
+void Object1D(Entity*);
+void Object1E(Entity*);
+void Object1F(Entity*);
+void Object20(Entity*);
+void Object21(Entity*);
+void FigurineDevice(Entity*);
+void EyeSwitch(Entity*);
+void PressurePlate(Entity*);
+void BigBarrel(Entity*);
+void BarrelInside(Entity*);
+void PushableStatue(Entity*);
+void Object28(Entity*);
+void AmbientClouds(Entity*);
+void Object2A(Entity*);
+void Object2B(Entity*);
+void Beanstalk(Entity*);
+void Smoke(Entity*);
+void PushableRock(Entity*);
+void HittableLever(Entity*);
+void Object30(Entity*);
+void FrozenFlower(Entity*);
+void PullableMushroom(Entity*);
+void Bollard(Entity*);
+void WarpPoint(Entity*);
+void Object35(Entity*);
+void Object36(Entity*);
+void Object37(Entity*);
+void JarPortal(Entity*);
+void BossDoor(Entity*);
+void Object3A(Entity*);
+void MacroMushromStalks(Entity*);
+void MacroPlayer(Entity*);
+void Object3D(Entity*);
+void Object3E(Entity*);
+void GiantLeaf(Entity*);
+void Fairy(Entity*);
+void LadderUp(Entity*);
+void Object42(Entity*);
+void Object43(Entity*);
+void Object44(Entity*);
+void Object45(Entity*);
+void GiantBookLadder(Entity*);
+void HeartContainer(Entity*);
+void FileScreenObjects(Entity*);
+void Object49(Entity*);
+void BackgroundCloud(Entity*);
+void Object4B(Entity*);
+void PushableFurniture(Entity*);
+void Furniture(Entity*);
+void MinishSizedEntrance(Entity*);
+void Archway(Entity*);
+void GiantRock(Entity*);
+void GiantRock2(Entity*);
+void Object52(Entity*);
+void Object53(Entity*);
+void PullableLever(Entity*);
+void Minecart(Entity*);
+void ThoughtBubble(Entity*);
+void HiddenLadderDown(Entity*);
+void GentariCurtain(Entity*);
+void LavaPlatform(Entity*);
+void Paper(Entity*);
+void Object5B(Entity*);
+void Mask(Entity*);
+void HouseDoorInterior(Entity*);
+void Whirlwind(Entity*);
+void ObjectBlockingStairs(Entity*);
+void SwordsmanNewsletter(Entity*);
+void Object61(Entity*);
+void GiantTwig(Entity*);
+void Object63(Entity*);
+void Object64(Entity*);
+void LadderHoleInBookshelf(Entity*);
+void Object66(Entity*);
+void Object67(Entity*);
+void Object68(Entity*);
+void Object69(Entity*);
+void Object6A(Entity*);
+void CrenalBeanSprout(Entity*);
+void MinecartDoor(Entity*);
+void ObjectOnPillar(Entity*);
+void MineralWaterSource(Entity*);
+void MinishSizedArchway(Entity*);
+void Object70(Entity*);
+void PushableGrave(Entity*);
+void StoneTablet(Entity*);
+void LilypadSmall(Entity*);
+void Object74(Entity*);
+void Object75(Entity*);
+void Object76(Entity*);
+void Bell(Entity*);
+void MacroDecoration(Entity*);
+void Object79(Entity*);
+void Steam(Entity*);
+void PushableLever(Entity*);
+void MacroShoes(Entity*);
+void ObjectOnSpinyBeetle(Entity*);
+void Object7E(Entity*);
+void PicoBloom(Entity*);
+void Board(Entity*);
+void Object81(Entity*);
+void BigVortex(Entity*);
+void BigPushableLever(Entity*);
+void SmallIceBlock(Entity*);
+void BigIceBlock(Entity*);
+void Object86(Entity*);
+void OctorokBossObject(Entity*);
+void MacroBook(Entity*);
+void MazaalBossObject(Entity*);
+void CabinFurniture(Entity*);
+void DoubleBookshelf(Entity*);
+void Book(Entity*);
+void Fireplace(Entity*);
+void Object8E(Entity*);
+void FrozenWaterElement(Entity*);
+void Object90(Entity*);
+void Object91(Entity*);
+void BakerOven(Entity*);
+void Lamp(Entity*);
+void WindTribeFlag(Entity*);
+void Bird(Entity*);
+void Object96(Entity*);
+void Object97(Entity*);
+void Object98(Entity*);
+void Object99(Entity*);
+void MacroAcorn(Entity*);
+void Object9B(Entity*);
+void TreeHidingPortal(Entity*);
+void LightableSwitch(Entity*);
+void TreeThorns(Entity*);
+void Fan(Entity*);
+void AngryStatue(Entity*);
+void PalaceArchway(Entity*);
+void ObjectA2(Entity*);
+void Cloud(Entity*);
+void MinishLight(Entity*);
+void FireballChain(Entity*);
+void ObjectA6(Entity*);
+void ObjectA7(Entity*);
+void ObjectA8(Entity*);
+void ObjectA9(Entity*);
+void WaterfallOpening(Entity*);
+void ObjectAB(Entity*);
+void FourElements(Entity*);
+void ObjectAD(Entity*);
+void FloatingBlock(Entity*);
+void ObjectAF(Entity*);
+void MetalDoor(Entity*);
+void JailBars(Entity*);
+void ObjectB2(Entity*);
+void ObjectB3(Entity*);
+void ObjectB4(Entity*);
+void ObjectB5(Entity*);
+void ObjectB6(Entity*);
+void Well(Entity*);
+void WindTribeTeleporter(Entity*);
+void ObjectB9(Entity*);
+void GyorgBossObject(Entity*);
+void Windcrest(Entity*);
+void LitArea(Entity*);
+void ObjectBD(Entity*);
+void Pinwheel(Entity*);
+void ObjectBF(Entity*);
+void EnemyItem(Entity*);
+void ObjectC1(Entity*);
extern void (*const gObjectFunctions[194])(Entity*);
diff --git a/include/overworld.h b/include/overworld.h
deleted file mode 100644
index 2ffa87d9..00000000
--- a/include/overworld.h
+++ /dev/null
@@ -1,63 +0,0 @@
-#ifndef OVERWORLD_H
-#define OVERWORLD_H
-
-#include "global.h"
-#include "area.h"
-
-void ChangeLightLevel(s32);
-void SetPopupState(u32 type, u32 choice_idx);
-
-bool32 CheckIsOverworld(void);
-bool32 sub_08052638(u32 r0);
-#ifndef EU
-u32 sub_08052654(void);
-#endif
-u32 CheckIsDungeon(void);
-u32 CheckIsInteriorWithEnemies(void);
-u32 CheckIsInteriorNoEnemies(void);
-u32 CheckHasMap(void);
-
-s32 ModHealth(s32 deltaHealth);
-void ModRupees(s32 rupeeDelta);
-
-void sub_080526F8(s32 a1);
-u32 sub_08052724(void);
-u32 HasDungeonMap(void);
-u32 HasDungeonCompass(void);
-u32 HasDungeonBigKey(void);
-u32 HasDungeonSmallKey(void);
-
-void sub_080527FC(u32 a1, u32 a2);
-#ifndef EU
-void sub_08052878(void);
-#endif
-
-void RoomExitCallback(void);
-void InitParachuteRoom(void);
-u32 sub_08052B24(void);
-void DisplayEzloMessage(void);
-
-void sub_08052CA4(u32 area, u32 room, u32 x, u32 y);
-void sub_08052CD0(u32 area, u32 room, u32 x, u32 y);
-
-void sub_08052CFC(void);
-
-/**
- * @brief Get bank offset for area
- */
-u32 GetFlagBankOffset(u32 idx);
-
-RoomResInfo* GetCurrentRoomInfo(void);
-void sub_08052EA0(void);
-void sub_08052FD8(u32 room, u32 area);
-void UpdateGlobalProgress(void);
-void sub_08053250(void);
-void sub_08053320(void);
-void sub_080533CC(void);
-void sub_08053494(void);
-void sub_080534AC(void);
-void sub_08053500(void);
-
-u32 GetBottleContaining(u32);
-
-#endif // OVERWORLD_H
diff --git a/include/player.h b/include/player.h
index 943d7f5e..583d882b 100644
--- a/include/player.h
+++ b/include/player.h
@@ -34,7 +34,7 @@ enum PlayerActions {
PLAYER_INHOLE,
PLAYER_08072C9C,
PLAYER_08074C44,
- PLAYER_08072F34,
+ PLAYER_CLIMB,
PLAYER_USEENTRANCE,
PLAYER_PARACHUTE,
};
@@ -95,16 +95,30 @@ typedef enum {
} PlayerControlMode;
enum PlayerFlags {
- PL_BUSY = (1 << 0),
- PL_DROWNING = (1 << 2),
- PL_NO_CAP = (1 << 3),
- PL_USE_PORTAL = (1 << 5),
- PL_MINISH = (1 << 7),
- PL_BURNING = (1 << 10),
- PL_ROLLING = (1 << 18),
- PL_IN_HOLE = (1 << 20),
- PL_USE_LANTERN = (1 << 23),
- PL_USE_OCARINA = (1 << 28),
+ PL_BUSY = 0x1,
+ PL_DROWNING = 0x4,
+ PL_NO_CAP = 0x8,
+ PL_CAPTURED = 0x10,
+ PL_USE_PORTAL = 0x20,
+ PL_HIDDEN = 0x40,
+ PL_MINISH = 0x80,
+ PL_DISABLE_ITEMS = 0x100,
+ PL_FALLING = 0x200,
+ PL_BURNING = 0x400,
+ PL_FROZEN = 0x800,
+ PL_IN_MINECART = 0x1000,
+ PL_DRUGGED = 0x4000,
+ PL_ROLLING = 0x40000,
+ PL_MOLDWORM_CAPTURED = 0x80000,
+ PL_IN_HOLE = 0x100000,
+ PL_MOLDWORM_RELEASED = 0x200000,
+ PL_CLONING = 0x400000,
+ PL_USE_LANTERN = 0x800000,
+ PL_PARACHUTE = 0x1000000,
+ PL_ENTER_MINECART = 0x4000000,
+ PL_SWORD_THRUST = 0x8000000,
+ PL_USE_OCARINA = 0x10000000,
+ PL_CLIMBING = 0x20000000,
};
enum SurfaceType {
@@ -125,7 +139,7 @@ enum SurfaceType {
SURFACE_E,
SURFACE_F,
SURFACE_10,
- SURFACE_11,
+ SURFACE_SWAMP,
SURFACE_DOOR,
SURFACE_DOOR_13,
SURFACE_14,
@@ -137,9 +151,9 @@ enum SurfaceType {
SURFACE_BUTTON,
SURFACE_1B,
SURFACE_1C,
- SURFACE_1D,
+ SURFACE_1D, // nulled
SURFACE_LADDER,
- SURFACE_1F,
+ SURFACE_1F, // nulled
SURFACE_20,
SURFACE_21,
SURFACE_22,
@@ -157,7 +171,7 @@ enum SurfaceType {
typedef struct {
/*0x00*/ u8 field_0x0[2];
- /*0x02*/ u8 jumpStatus;
+ /*0x02*/ u8 jump_status;
/*0x03*/ u8 field_0x3[2];
/*0x05*/ u8 heldObject;
/*0x06*/ u8 pushedObject;
@@ -165,7 +179,7 @@ typedef struct {
/*0x08*/ u16 animation;
/*0x0a*/ u8 field_0xa;
/*0x0b*/ u8 keepFacing;
- /*0x0c*/ u8 playerAction;
+ /*0x0c*/ u8 queued_action;
/*0x0d*/ u8 field_0xd;
/*0x0e*/ u8 field_0xe;
/*0x0f*/ u8 hurtBlinkSpeed;
@@ -177,18 +191,20 @@ typedef struct {
/*0x15*/ u8 field_0x15;
/*0x16*/ u16 startPosX;
/*0x18*/ u16 startPosY;
- /*0x1a*/ u8 field_0x1a[2];
+ /*0x1a*/ u8 mobility;
+ /*0x1b*/ u8 sword_state;
/*0x1c*/ u8 field_0x1c;
/*0x1d*/ u8 field_0x1d;
/*0x1e*/ u8 dash_state;
/*0x1f*/ u8 field_0x1f[3];
/*0x22*/ u16 field_0x22[2];
- /*0x26*/ u8 swimState;
+ /*0x26*/ u8 swim_state;
/*0x27*/ u8 field_0x27[5];
/*0x2c*/ Entity* item;
/*0x30*/ u32 flags;
/*0x34*/ u8 field_0x34[2];
- /*0x36*/ s16 field_0x36;
+ /*0x36*/ u8 field_0x36;
+ /*0x37*/ u8 field_0x37;
/*0x38*/ u8 field_0x38;
/*0x39*/ u8 field_0x39;
/*0x3a*/ u8 field_0x3a;
@@ -198,13 +214,14 @@ typedef struct {
/* */ u8 swordBlueParticle : 1;
/* */ u8 filler14 : 6;
/*0x3f*/ u8 field_0x3f;
- /*0x40*/ u8 hurtType[64];
- /*0x80*/ u16 field_0x80;
+ /*0x40*/ u8 path_memory[64];
+ /*0x80*/ u16 speed_modifier;
/*0x82*/ u8 field_0x82[9];
/*0x8b*/ u8 controlMode;
/*0x8c*/ u16 vel_x;
/*0x8e*/ u16 vel_y;
- /*0x90*/ union SplitWord field_0x90;
+ /*0x90*/ u16 field_0x90;
+ /*0x92*/ u16 field_0x92;
/*0x94*/ u32 field_0x94;
/*0x98*/ u16 field_0x98;
/*0x9a*/ u16 field_0x9a;
@@ -261,14 +278,33 @@ extern u8 gQuiverSizes[];
extern u16 gWalletSizes[];
extern PlayerState gPlayerState;
-extern Stats gStats;
extern Entity gPlayerEntity;
-extern u32 GetInventoryValue(u32);
-extern s32 ModHealth(s32);
-extern void ModRupees(s32);
+u32 CheckPlayerInactive(void);
+void SetPlayerControl(PlayerControlMode mode);
+void ResetPlayer(void);
+void ResetPlayerVelocity(void);
+void ResetPlayerAnimationAndAction(void);
+void SetPlayerActionNormal(void);
+void RespawnAsMinish(void);
-extern void SetPlayerControl(PlayerControlMode);
+Entity* CreatePlayerItem(u32, u32, u32, u32);
+
+void ResolvePlayerAnimation(void);
+void RegisterPlayerHitbox(void);
+void UpdateFloorType(void);
+void CreateEzloHint(u32, u32);
+
+u32 IsItemEquipped(u32);
+u32 GetInventoryValue(u32);
+s32 ModHealth(s32 delta);
+void ModRupees(s32 delta);
+void DeleteClones(void);
+
+void sub_08077728();
+extern void sub_08077B20();
+extern u32 sub_08008B22();
+extern u32* sub_08008790(Entity*, u32);
#define COPY_FLAG_FROM_TO(base, src, dest) (base) = ((base) & ~(dest)) | (((dest) * ((base) & (src))) / src)
diff --git a/include/projectile.h b/include/projectile.h
index 0ad6e7e9..74b3580a 100644
--- a/include/projectile.h
+++ b/include/projectile.h
@@ -1,6 +1,46 @@
#ifndef PROJECTILE_H
#define PROJECTILE_H
+extern Entity* CreateProjectile(u32);
+
+void DarkNutSwordSlash(Entity*);
+void RockProjectile(Entity*);
+void BoneProjectile(Entity*);
+void MoblinSpear(Entity*);
+void DekuSeedProjectile(Entity*);
+void Projectile5(Entity*);
+void DirtBallProjectile(Entity*);
+void WindProjectile(Entity*);
+void FireProjectile(Entity*);
+void IceProjectile(Entity*);
+void GleerokProjectile(Entity*);
+void KeatonDagger(Entity*);
+void GuardLineOfSight(Entity*);
+void ArrowProjectile(Entity*);
+void MazaalEnergyBeam(Entity*);
+void OctorokBossProjectile(Entity*);
+void StalfosProjectile(Entity*);
+void LakituCloudProjectile(Entity*);
+void LakituLightning(Entity*);
+void MandiblesProjectile(Entity*);
+void RemovableDust(Entity*);
+void SpiderWeb(Entity*);
+void TorchTrapProjectile(Entity*);
+void GuruguruBarProjectile(Entity*);
+void V1DarkMagicProjectile(Entity*);
+void BallAndChain(Entity*);
+void V1FireProjectile(Entity*);
+void CannonballProjectile(Entity*);
+void V1EyeLaser(Entity*);
+void Winder(Entity*);
+void SpikedRollers(Entity*);
+void V2Projectile(Entity*);
+void V3HandProjectile(Entity*);
+void V3ElectricProjectile(Entity*);
+void GyorgTail(Entity*);
+void GyorgMaleEnergyProjectile(Entity*);
+void V3TennisBallProjectile(Entity*);
+
typedef enum {
/*00*/ DARK_NUT_SWORD_SLASH,
/*01*/ ROCK_PROJECTILE,
diff --git a/include/room.h b/include/room.h
index 8a837b91..0cd7f3c2 100644
--- a/include/room.h
+++ b/include/room.h
@@ -4,13 +4,6 @@
#include "global.h"
#include "entity.h"
-/*
-typedef struct {
- u8 areaID;
- u8 roomID;
-} RoomID;
-*/
-
enum RoomTransition {
TRANSITION_DEFAULT,
TRANSITION_CUT,
@@ -24,58 +17,66 @@ enum RoomTransition {
TRANSITION_CUT_FAST,
};
+enum RoomReloadType {
+ RELOAD_ALL = 1,
+ RELOAD_ENTITIES = 2,
+};
+
typedef struct {
- /*0x00*/ u16 unk2;
+ /*0x00*/ u16 reload_flags;
/*0x02*/ u8 unk3;
/*0x03*/ u8 unk4;
- /*0x04*/ u8 areaID;
- /*0x05*/ u8 roomID;
- /*0x06*/ u16 roomOriginX;
- /*0x08*/ u16 roomOriginY;
- /*0x0A*/ s16 roomScrollX;
- /*0x0C*/ s16 roomScrollY;
+ /*0x04*/ u8 area;
+ /*0x05*/ u8 room;
+ /*0x06*/ u16 origin_x;
+ /*0x08*/ u16 origin_y;
+ /*0x0A*/ s16 scroll_x;
+ /*0x0C*/ s16 scroll_y;
/*0x0E*/ u8 unk5;
- /*0x0F*/ u8 unk6;
- /*0x10*/ u8 unk_10;
+ /*0x0F*/ u8 scroll_flags; // 0x2 = ??, 0x4 = camera scrolling
+ /*0x10*/ u8 scroll_direction;
/*0x11*/ s8 oam_offset_x;
/*0x12*/ s8 oam_offset_y;
/*0x13*/ u8 unk13;
- /*0x14*/ u8 screenShakeMagnitude;
+ /*0x14*/ u8 shake_magnitude;
/*0x15*/ u8 unk7;
- /*0x16*/ u16 screenShakeTime;
+ /*0x16*/ u16 shake_duration;
/*0x18*/ u16 filler2[3];
/*0x1E*/ u16 width;
/*0x20*/ u16 height;
- /*0x22*/ u8 filler3[6];
+ /*0x22*/ u8 filler3[2];
+ /*0x24*/ s8 aff_x;
+ /*0x25*/ s8 aff_y;
+ /*0x26*/ u8 filler26[2];
/*0x28*/ union SplitWord bg3OffsetX;
/*0x2C*/ union SplitWord bg3OffsetY;
- /*0x30*/ Entity* cameraTarget;
+ /*0x30*/ Entity* camera_target;
} RoomControls;
extern RoomControls gRoomControls;
typedef struct {
- u8 field_0x0;
- u8 filler_0x1;
- u8 field_0x2;
- u8 field_0x3;
- u8 field_0x4;
- u8 filler1[1];
- u8 shopItemType;
- u8 shopItemType2;
- u8 field_0x8;
- u8 field_0x9;
- u8 unk2;
- u8 filler2;
- s16 lightLevel;
- u8 filler3[2];
- u8 unk_10[4];
- u32 roomFlags;
- u32 unk3;
- u8 filler4[48];
- u8 filler5[28];
- u32 animFlags;
- void* field_0x6c[8];
- void* field_0x8c[16];
+ /* 0x00 */ u8 field_0x0;
+ /* 0x01 */ u8 filler_0x1;
+ /* 0x02 */ u8 field_0x2;
+ /* 0x03 */ u8 field_0x3;
+ /* 0x04 */ u8 field_0x4;
+ /* 0x05 */ u8 filler1[1];
+ /* 0x06 */ u8 shopItemType;
+ /* 0x07 */ u8 shopItemType2;
+ /* 0x08 */ u8 field_0x8;
+ /* 0x09 */ u8 field_0x9;
+ /* 0x0a */ u8 unk2;
+ /* 0x0b */ u8 filler2;
+ /* 0x0c */ s16 lightLevel;
+ /* 0x0e */ u8 filler3[2];
+ /* 0x10 */ u8 unk_10[4];
+ /* 0x14 */ u32 flags;
+ /* 0x18 */ u32 unk3;
+ /* 0x1c */ u8 filler4[48];
+ /* 0x4c */ u8 filler5[28];
+ /* 0x68 */ u32 animFlags;
+ /* 0x6c */ void* field_0x6c[8];
+ /* 0x8c */ void* field_0x8c[16];
} RoomVars;
static_assert(sizeof(RoomVars) == 0xCC);
extern RoomVars gRoomVars;
@@ -92,57 +93,86 @@ typedef struct {
u32 spritePtr;
} EntityData;
-// Status of the player's positioning within the scene.
typedef struct {
- u8 area_next;
- u8 room_next;
- u8 start_anim;
- u8 spawn_type;
- Coords start_pos;
- u8 layer;
- u8 field_0x15;
- u8 field_0x16;
- u8 field_0x17;
- s16 field_0x18;
- s16 field_0x1a;
- s16 field_0x1c;
- s16 field_0x1e;
- s16 field_0x20;
- s16 field_0x22;
- u8 field_0x24[0x8];
-} PlayerWorldStatus;
-static_assert(sizeof(PlayerWorldStatus) == 0x20);
+ u16 field_0x0;
+ u16 field_0x2;
+ u8 field_0x4;
+ u8 field_0x5;
+ u8 field_0x6;
+ u8 field_0x7;
+} struct_030010EC;
typedef struct {
- s32 frameCount; // regular frame count? does anything reset it?
- u8 field_0x4[0x2];
- u16 field_0x6;
- bool8 transitioningOut;
- u8 transitionType; // transition when changing areas
- u16 stairs_idx; // seems to be a tile type
- PlayerWorldStatus player_status;
- u8 field_0x2c[0x9];
- u8 hint_height;
- u16 hint_idx;
- u8 field_0x38;
- u8 field_0x39;
- u8 field_0x3a;
- u8 field_0x3b;
- u8 field_0x3c;
- u8 field_0x3d;
- u16 field_0x3e;
- u16 hurtType;
- u16 field_0x42;
- u16 field_0x44;
- u16 field_0x46;
- u16 field_0x48;
- u16 field_0x4a;
- u8 minecart_data[0x20];
- u8 field_0x6c[0x40];
+ u16 data[32];
u16 field_0xac;
u16 field_0xae;
-} ScreenTransition;
-extern ScreenTransition gScreenTransition;
+} struct_0300110C;
+
+// Status of the player's positioning within the scene.
+typedef struct {
+ /* 0x00 */ u8 area_next;
+ /* 0x01 */ u8 room_next;
+ /* 0x02 */ u8 start_anim;
+ /* 0x03 */ u8 spawn_type;
+ /* 0x04 */ s16 start_pos_x;
+ /* 0x06 */ s16 start_pos_y;
+ /* 0x08 */ u8 layer;
+ /* 0x09 */ u8 field_0x15;
+ /* 0x0a */ u8 dungeon_area;
+ /* 0x0b */ u8 dungeon_room;
+ /* 0x0c */ s16 dungeon_x;
+ /* 0x0e */ s16 dungeon_y;
+ /* 0x10 */ u16 dungeon_map_x;
+ /* 0x12 */ u16 dungeon_map_y;
+ /* 0x14 */ s16 overworld_map_x;
+ /* 0x16 */ s16 overworld_map_y;
+ /* 0x18 */ u8 field_0x24[0x8];
+} PlayerRoomStatus;
+static_assert(sizeof(PlayerRoomStatus) == 0x20);
+
+typedef struct {
+ /* 0x00 */ s32 frameCount; // regular frame count? does anything reset it?
+ /* 0x04 */ u8 field_0x4[0x2];
+ /* 0x06 */ u16 field_0x6;
+ /* 0x08 */ bool8 transitioningOut;
+ /* 0x09 */ u8 type; // transition when changing areas
+ /* 0x0a */ u16 stairs_idx; // seems to be a tile type
+ /* 0x0c */ PlayerRoomStatus player_status;
+ /* 0x2c */ u8 field_0x2c[0x9];
+ /* 0x35 */ u8 hint_height;
+ /* 0x36 */ u16 hint_idx;
+ /* 0x38 */ u8 field_0x38;
+ /* 0x39 */ u8 field_0x39;
+ /* 0x3a */ u8 field_0x3a;
+ /* 0x3b */ u8 field_0x3b;
+ /* 0x3c */ u8 field_0x3c;
+ /* 0x3d */ u8 field_0x3d;
+ /* 0x3e */ u16 field_0x3e;
+ /* 0x40 */ u16 hurtType;
+ /* 0x42 */ u16 field_0x42;
+ /* 0x44 */ u16 field_0x44;
+ /* 0x46 */ u16 field_0x46;
+ /* 0x48 */ u16 field_0x48;
+ /* 0x4a */ u16 field_0x4a;
+ /* 0x4c */ struct_030010EC minecart_data[4];
+ /* 0x6c */ struct_0300110C armos_data;
+} RoomTransition;
+static_assert(sizeof(RoomTransition) == 0xB0);
+extern RoomTransition gRoomTransition;
+
+typedef struct {
+ u16 type;
+ u8 field_0x2[4];
+ s16 playerXPos;
+ s16 playerYPos;
+ u8 field_0xa;
+ u8 area;
+ u8 room;
+ u8 playerLayer;
+ u8 field_0xe;
+ u8 playerState;
+ u16 transitionSFX;
+} ScreenTransitionData;
typedef struct {
u8 type;
@@ -169,15 +199,22 @@ typedef enum {
DESTRUCTIBLE_TILE,
GRASS_DROP_CHANGER,
LOCATION_CHANGER,
- TILE_ENTITY_D
+ TILE_ENTITY_D,
} TileEntityType;
-extern void SetTileType(u32, u32, u32);
-extern void sub_08080964(u32 time, u32 magnitude); // shake screen
+void SetTileType(u32, u32, u32);
+void InitScreenShake(u32 time, u32 magnitude);
-extern void* GetCurrentRoomProperty(u32);
-extern void LoadRoomTileEntities();
+void CallRoomProp5And7(void);
+void LoadRoom(void);
+void SetCurrentRoomPropertyList(u32 area, u32 room);
+void* GetCurrentRoomProperty(u32);
+void LoadRoomTileEntities();
+void LoadRoomEntityList(EntityData* listPtr);
void sub_0804B3C4(void*);
+void sub_0804B0B0(u32 arg0, u32 arg1);
+
+void DoExitTransition(const ScreenTransitionData* data);
#endif
diff --git a/include/save.h b/include/save.h
index 1126973d..62d3a87e 100644
--- a/include/save.h
+++ b/include/save.h
@@ -20,47 +20,109 @@ typedef enum {
SAVE_DONE,
} SaveState;
-extern SaveResult HandleSave(u32 arg0);
+/**
+ * Attempt to save the game.
+ *
+ * @param idx The save slot.
+ * @return #SaveResult result.
+ */
+extern SaveResult HandleSave(u32 idx);
+/**
+ * Contains all information about a save file.
+ * The contents of this structure are read from and written to EEPROM.
+ */
typedef struct {
- /*0x000*/ u8 unk_00;
- /*0x000*/ u8 unk_01;
- /*0x002*/ u8 messageSpeed;
- /*0x003*/ u8 brightnessPref;
+ /*0x000*/ u8 invalid; /**< File is invalid. */
+ /*0x000*/ u8 initialized; /**< File is initialized. */
+ /*0x002*/ u8 msg_speed; /**< Message speed. */
+ /*0x003*/ u8 brightness; /**< Brightness. */
/*0x004*/ u8 filler4[0x2];
/*0x006*/ u8 unk6;
/*0x007*/ u8 unk7;
- /*0x008*/ u8 global_progress;
+ /*0x008*/ u8 global_progress; /**< @see UpdateGlobalProgress */
/*0x009*/ u8 field_0x9[0x34];
- /*0x040*/ u32 windcrests;
+ /*0x040*/ u32 windcrests; /**< Windcrest flags. */
/*0x044*/ u8 filler44[0xC];
/*0x050*/ u32 unk50;
/*0x054*/ u8 filler54[0xC];
- /*0x060*/ u32 areaVisitFlags[8];
- /*0x080*/ u8 playerName[FILENAME_LENGTH];
+ /*0x060*/ u32 areaVisitFlags[8]; /**< Area visit flags. */
+ /*0x080*/ char name[FILENAME_LENGTH]; /**< Save file name. */
/*0x086*/ u8 filler86[0x2];
- /*0x088*/ PlayerWorldStatus saved_status;
- /*0x0A8*/ Stats stats;
- /*0x0D0*/ u8 fillerD0[0x71];
- /*0x141*/ u8 unk141[0x1c1 - 0x141];
- /*0x1C1*/ u8 unk1C1[0x45c - 0x1c1];
+ /*0x088*/ PlayerRoomStatus saved_status; /**< Player room status. */
+ /*0x0A8*/ Stats stats; /**< Player stats. */
+ /*0x0D0*/ u8 fillerD0[0x48];
+ /*0x118*/ u8 unk118[0x13];
+ /*0x12B*/ u8 unk12B[0x16];
+ /*0x141*/ u8 unk141[128];
+ /*0x1C1*/ u8 unk1C1[128];
+ /*0x241*/ u8 unk241[13];
+ /*0x24E*/ u8 unk24E[14];
+ /*0x25C*/ u8 flags[0x200]; /**< Flags. */
/*0x45C*/ u8 unk45C[0x10];
/*0x46C*/ u8 unk46C[0x20];
- /*0x48C*/ u32 unk48C[8];
+ /*0x48C*/ u32 timers[7];
+ /*0x4A8*/ u32 demo_timer; /**< Demo timer. */
/*0x4AC*/ u8 filler4ac[0x8];
} SaveFile;
+/**
+ * The current save file.
+ */
extern SaveFile gSave;
+/**
+ * Initialize the save system.
+ *
+ * @return Success
+ */
u32 InitSaveData(void);
-u32 Write_02000000(struct_02000000*);
+/**
+ * Read save header.
+ *
+ * @return Success.
+ */
+u32 Read_02000000(SaveHeader*);
+
+/**
+ * Write save header.
+ *
+ * @return Success.
+ */
+u32 Write_02000000(SaveHeader*);
+
+/**
+ * Read save file.
+ *
+ * @return Success.
+ */
s32 ReadSaveFile(u32, SaveFile*);
-u32 Read_02000000(struct_02000000*);
+
+/**
+ * Mark a save file as deleted.
+ *
+ * @param index The save file index.
+ */
void SetFileStatusDeleted(u32 index);
extern const char gUnk_0811E470[];
+/**
+ * Update the global progress (0 - 10).
+ * There are 10 different indicators of game completion:
+ 9 : Flag SEIIKI_STAINED_GLASS
+ 8 : Flag LV5_CLEAR
+ 7 : Flag OUBO_KAKERA
+ 6 : Flag LV4_CLEAR
+ 5 : Flag LV3_CLEAR
+ 4 : Flag SOUGEN_08_TORITSUKI
+ 2 : Flag LV1_CLEAR
+ 1 : Default
+ }
+ */
+void UpdateGlobalProgress(void);
+
#ifdef DEMO_USA
extern const u8* const demoPointers[];
extern const u8 demoUnknown1[];
diff --git a/include/screen.h b/include/screen.h
index 18962f80..a5b05623 100644
--- a/include/screen.h
+++ b/include/screen.h
@@ -5,10 +5,10 @@
#include "fade.h"
typedef struct {
- u16 displayControl;
- u8 filler2[0x2];
- u16 unk4;
- u16 displayControlMask;
+ /*0x00*/ u16 displayControl;
+ /*0x02*/ u8 filler2[0x2];
+ /*0x04*/ u16 unk4;
+ /*0x06*/ u16 displayControlMask;
} LcdControls;
typedef struct {
@@ -28,22 +28,19 @@ typedef struct {
} BgAffSettings;
typedef struct {
- u16 bg2dx;
- u16 bg2dmx;
- u16 bg2dy;
- u16 bg2dmy;
- u16 bg2xPointLeastSig;
- u16 bg2xPointMostSig;
- u16 bg2yPointLeastSig;
- u16 bg2yPointMostSig;
- u16 bg3dx;
- u16 bg3dmx;
- u16 bg3dy;
- u16 bg3dmy;
- u16 bg3xPointLeastSig;
- u16 bg3xPointMostSig;
- u16 bg3yPointLeastSig;
- u16 bg3yPointMostSig;
+ u16 dx;
+ u16 dmx;
+ u16 dy;
+ u16 dmy;
+ u16 xPointLeastSig;
+ u16 xPointMostSig;
+ u16 yPointLeastSig;
+ u16 yPointMostSig;
+} BgTransformationSettings;
+
+typedef struct {
+ BgTransformationSettings bg2;
+ BgTransformationSettings bg3;
u16 window0HorizontalDimensions;
u16 window1HorizontalDimensions;
u16 window0VerticalDimensions;
@@ -65,20 +62,22 @@ typedef struct {
/*0x38*/ BgControls controls;
/*0x6c*/ u8 _6c;
/*0x6d*/ u8 _6d;
- /*0x70*/ u32 _70;
+ /*0x70*/ void* _70;
/*0x74*/ u32 _74;
/*0x78*/ u32 _78;
} Screen;
-struct OAMCommand {
+typedef struct {
u16 x;
u16 y;
u16 _4;
u16 _6;
u16 _8;
-} extern gOamCmd;
+} OAMCommand;
-extern BgControls gBgControls;
extern Screen gScreen;
+extern OAMCommand gOamCmd;
+
+extern void sub_080ADA04(OAMCommand*, void*);
#endif
diff --git a/include/script.h b/include/script.h
index b59d8916..33ce1767 100644
--- a/include/script.h
+++ b/include/script.h
@@ -4,28 +4,28 @@
#include "entity.h"
typedef struct ScriptExecutionContext {
- u16* scriptInstructionPointer;
- u32 intVariable;
- u32 postScriptActions;
- u8 unk_0C[0x4]; // unused
- u16 wait;
- u16 unk_12;
- u32 condition;
- u8 unk_18;
- u8 unk_19;
- u8 unk_1A;
- u8 unk_1B; // unused
- union SplitWord x;
- union SplitWord y;
+ /*0x00*/ u16* scriptInstructionPointer;
+ /*0x03*/ u32 intVariable;
+ /*0x08*/ u32 postScriptActions;
+ /*0x0C*/ u8 unk_0C[0x4]; // unused
+ /*0x10*/ u16 wait;
+ /*0x12*/ u16 unk_12;
+ /*0x14*/ u32 condition;
+ /*0x18*/ u8 unk_18;
+ /*0x19*/ u8 unk_19;
+ /*0x1A*/ u8 unk_1A;
+ /*0x1B*/ u8 unk_1B; // unused
+ /*0x1C*/ union SplitWord x;
+ /*0x20*/ union SplitWord y;
} ScriptExecutionContext;
typedef struct {
// Sync flags are used to synchronize scripts running on different entities
- u32 syncFlags;
- u16 commandIndex;
- u8 commandSize;
- u8 flags;
- u8 unk_08;
+ /*0x0*/ u32 syncFlags;
+ /*0x4*/ u16 commandIndex;
+ /*0x6*/ u8 commandSize;
+ /*0x7*/ u8 flags;
+ /*0x8*/ u8 unk_08;
} ActiveScriptInfo;
extern ActiveScriptInfo gActiveScriptInfo;
diff --git a/include/audio.h b/include/sound.h
index e5e4c0e4..8549510f 100644
--- a/include/audio.h
+++ b/include/sound.h
@@ -1,5 +1,5 @@
-#ifndef AUDIO_H
-#define AUDIO_H
+#ifndef SOUND_H
+#define SOUND_H
#include "global.h"
@@ -597,4 +597,4 @@ typedef enum {
SONG_BGM_0 = 0x80110000,
} Sound;
-#endif // AUDIO_H
+#endif // SOUND_H
diff --git a/include/structures.h b/include/structures.h
index c8843e00..52f2df1f 100644
--- a/include/structures.h
+++ b/include/structures.h
@@ -8,15 +8,15 @@
typedef struct {
int signature;
u8 saveFileId;
- u8 messageSpeed;
- u8 brightnessPref;
- u8 gameLanguage;
+ u8 msg_speed;
+ u8 brightness;
+ u8 language;
u8 name[6];
- u8 _e;
+ u8 invalid;
u8 _f;
-} struct_02000000;
-#define gSaveHeader ((struct_02000000*)(0x2000000))
-// extern struct_02000000 gSaveHeader;
+} SaveHeader;
+#define gSaveHeader ((SaveHeader*)(0x2000000))
+// extern SaveHeader gSaveHeader;
typedef struct {
u8 unk_00;
@@ -39,39 +39,6 @@ static_assert(sizeof(struct_02000010) == 0x20);
extern struct_02000010 gUnk_02000010;
typedef struct {
- u16 transitionType;
- u8 field_0x2[4];
- s16 playerXPos;
- s16 playerYPos;
- u8 field_0xa;
- u8 areaID;
- u8 roomID;
- u8 playerLayer;
- u8 field_0xe;
- u8 playerState;
- u16 transitionSFX;
-} ScreenTransitionData;
-
-typedef struct {
- u8 active;
- u8 field_0x1;
- u8 field_0x2;
- u8 field_0x3;
- u32 mask;
- u16 fadeType; // fade in or out, are there others?
- u16 fadeSpeed; // subtracted from duration
- u16 fadeDuration;
- u16 field_0xe;
- s16 field_0x10;
- s16 field_0x12;
- s16 field_0x14;
- u16 field_0x16;
- u16 field_0x18;
-} FadeControl;
-
-extern FadeControl gFadeControl;
-
-typedef struct {
u8 unk0;
u8 unk1;
u16 unk2;
@@ -110,7 +77,7 @@ typedef struct {
u16 a;
u16 b;
} indices;
- void (*func)(Entity*);
+ void (*func)(Entity* e);
} data;
} Dialog;
@@ -119,10 +86,7 @@ extern u16 gBG1Buffer[0x400];
extern u16 gBG2Buffer[0x400];
extern u16 gBG3Buffer[0x800];
-struct {
- u8 filler[0x70];
-} extern gUnk_03000B80;
-// TODO extern ItemBehavior gUnk_03000B80[4];
+extern ItemBehavior gUnk_03000B80[4];
static_assert(sizeof(gUnk_03000B80) == 0x70);
typedef struct {
@@ -135,7 +99,6 @@ typedef struct {
} PriorityHandler;
extern PriorityHandler gPriorityHandler;
-extern u8 gUnk_02022740[];
extern u8 gUnk_02034490[];
typedef struct {
@@ -148,4 +111,25 @@ typedef struct {
void* unk8;
} WStruct;
+typedef struct {
+ u16 unk0;
+ u16 unk2;
+ u16 unk4;
+ u8 unk6;
+ u8 unk7;
+} OAMObj;
+
+typedef struct {
+ u8 field_0x0;
+ u8 field_0x1;
+ u8 spritesOffset;
+ u8 updated;
+ u16 _4;
+ u16 _6;
+ u8 _0[0x18];
+ struct OamData oam[0x80];
+ OAMObj unk[0xA0]; /* todo: affine */
+} OAMControls;
+extern OAMControls gOAMControls;
+
#endif
diff --git a/include/subtask.h b/include/subtask.h
new file mode 100644
index 00000000..185210d8
--- /dev/null
+++ b/include/subtask.h
@@ -0,0 +1,16 @@
+#ifndef SUBTASK_H
+#define SUBTASK_H
+
+#include "global.h"
+
+// todo: separate headers for each subtask?
+
+extern void sub_080A4528(void);
+extern void sub_080A4398(void);
+extern void sub_080A7114(u32);
+extern void sub_080A3B74(void);
+extern void sub_080A4054(void);
+extern void sub_080A4D34(void);
+extern u32 sub_080A4494(void);
+
+#endif // SUBTASK_H
diff --git a/include/utils.h b/include/utils.h
deleted file mode 100644
index 8cb3e8d1..00000000
--- a/include/utils.h
+++ /dev/null
@@ -1,75 +0,0 @@
-#ifndef UTILS_H
-#define UTILS_H
-
-#include "global.h"
-
-typedef struct {
- u16 heldKeys;
- u16 newKeys;
- u16 unk4;
- u8 unk6;
- u8 unk7;
-} Input;
-
-extern Input gInput;
-
-/**
- * Fill memory with 16 bit value.
- */
-void MemFill16(u32 value, void* dest, u32 size);
-
-/**
- * Fill memory with 32 bit value.
- */
-void MemFill32(u32 value, void* dest, u32 size);
-
-/**
- * Clear memory.
- */
-void MemClear(void* dest, u32 size);
-
-/**
- * Copy memory.
- */
-void MemCopy(const void* src, void* dest, u32 size);
-
-/**
- * Refresh gInput from hardware registers.
- */
-void ReadKeyInput(void);
-
-void LoadPalettes(const u8*, s32, s32);
-void LoadPaletteGroup(u32 group);
-void SetColor(u32 colorIndex, u32 color);
-void SetFillColor(u32 color, u32 arg1);
-
-/**
- * Allocate memory on heap.
- *
- * The heap size is 0x1000 bytes and should be used sparingly.
- * It is customary for entities store the returned handle in their 'myHeap' field.
- *
- * @param size u32 Size to be allocated
- * @return void* Pointer to allocated memory
- */
-void* zMalloc(u32 size);
-
-/**
- * Free memory from heap.
- *
- * The entity system will automatically free the address stored in the 'myHeap' field.
- *
- * @param ptr void* Handle to be freed
- */
-void zFree(void* ptr);
-
-/**
- * Reset All display hardware registers.
- *
- * @param updateHUD bool32 Request refresh of HUD layer (bg 0)
- */
-void DispReset(bool32 updateHUD);
-
-u32 CheckPlayerProximity(u32, u32, u32, u32);
-
-#endif