summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortheo3 <arisstephenson2@gmail.com>2021-01-31 11:23:42 -0800
committertheo3 <arisstephenson2@gmail.com>2021-01-31 11:23:42 -0800
commitced13c2c8d727e01bdb687a4c982ed9296c9e10e (patch)
tree90a244a8a4ee7aba1106deae3673c50c8972cbde /src
parentb9e07c12024895de9abde045cc1d1421a5bc2139 (diff)
finish main.c
Diffstat (limited to 'src')
-rw-r--r--src/code_0807CC3C.c2
-rw-r--r--src/enemy/helmasaur.c2
-rw-r--r--src/main.c (renamed from src/mainLoop.c)129
-rw-r--r--src/npc/beedle.c2
-rw-r--r--src/npc/forestMinish.c4
-rw-r--r--src/npc/goron.c2
-rw-r--r--src/npc/goronMerchant.c2
-rw-r--r--src/npc/guard.c4
-rw-r--r--src/npc/mutoh.c2
-rw-r--r--src/npc/townMinish.c2
-rw-r--r--src/object/lightableSwitch.c2
-rw-r--r--src/room.c2
-rw-r--r--src/textbox.c35
-rw-r--r--src/tmc.code-workspace4
14 files changed, 160 insertions, 34 deletions
diff --git a/src/code_0807CC3C.c b/src/code_0807CC3C.c
index 80e0bfe7..b16dca9e 100644
--- a/src/code_0807CC3C.c
+++ b/src/code_0807CC3C.c
@@ -42,7 +42,7 @@ u32 sub_0807CDE8(u32 arg0) {
temp = 1;
break;
case 2:
- temp = sub_0807CF10((u8*)gUnk_02000000->header);
+ temp = sub_0807CF10((u8*)&gUnk_02000000->signature);
break;
}
gMenu.field_0xa = temp;
diff --git a/src/enemy/helmasaur.c b/src/enemy/helmasaur.c
index 3980c94c..5dd4c27d 100644
--- a/src/enemy/helmasaur.c
+++ b/src/enemy/helmasaur.c
@@ -337,7 +337,7 @@ bool32 sub_0802C0E8(Entity* this) {
u32 ret = FALSE;
if (!sub_0806FC24(TILE(x, y), 9)) {
u32 tmp = sub_080AE4CC(ent, x, y, 0);
- ret = (-tmp | tmp) >> 0x1f;
+ ret = BOOLCAST(tmp);
}
return ret;
}
diff --git a/src/mainLoop.c b/src/main.c
index 33c1d27a..ed058b61 100644
--- a/src/mainLoop.c
+++ b/src/main.c
@@ -1,9 +1,13 @@
#include "global.h"
#include "functions.h"
+#include "structures.h"
#include "main.h"
+#include "screen.h"
#include "random.h"
#include "readKeyInput.h"
+extern u8 gUnk_03003DE4;
+
extern void sub_0804FF84(u32);
extern u16 gPaletteBuffer[];
extern void VBlankInterruptWait(void);
@@ -137,3 +141,128 @@ void DoSoftReset(void) {
DisableInterruptsAndDMA();
SoftReset(RESET_ALL & ~(RESET_EWRAM | RESET_SIO_REGS));
}
+
+const int sDefaultSettings[] = { SIGNATURE, '\1\1\1\0', 'KNIL', '\0\0\0\0' };
+
+// single misplaced ldr
+NONMATCH("asm/non_matching/sub_080560B8.inc", void sub_080560B8(void)) {
+ u32 temp;
+ u32 b;
+
+ if (!sub_08056134()) {
+ switch ((s32)sub_0807CF30((void*)0x2000000)) {
+ case 1:
+ if (sub_08056134())
+ break;
+ case 0:
+ case -1:
+ default:
+ _DmaCopy(&sDefaultSettings, (void*)0x2000000, 16);
+ sub_0807CF10((u8*)0x2000000);
+ break;
+ }
+ }
+
+ temp = gUnk_02000010.signature ^ SIGNATURE;
+ b = BOOLCAST(temp);
+
+ if ((gUnk_02000010.field_0x4 != 0) && (gUnk_02000010.field_0x4 != 0xc1)) {
+ b = 1;
+ }
+ if (b != 0) {
+ _DmaZero((u8*)&gUnk_02000010.signature, 0x20);
+ gUnk_02000010.signature = SIGNATURE;
+ }
+}
+END_NONMATCH
+
+u32 sub_08056134(void) {
+ if ((gUnk_02000000->signature != SIGNATURE) || (gUnk_02000000->saveFileId >= MAX_SAVE_FILES) ||
+ (gUnk_02000000->messageSpeed >= MAX_MSG_SPEED) || (gUnk_02000000->brightnessPref >= MAX_BRIGHTNESS) ||
+ (gUnk_02000000->gameLanguage != GAME_LANGUAGE) || (gUnk_02000000->_e != 0))
+ return FALSE;
+
+ return TRUE;
+}
+
+void sub_0805616C() {
+ PlaySFX(0x80040000);
+ gScreen._6d = gScreen._6c;
+ gScreen._6c = 0;
+
+ DmaStop(0);
+
+ DmaWait(0);
+ DmaWait(1);
+ DmaWait(2);
+ DmaWait(3);
+}
+
+void sub_08056208() {
+ PlaySFX(0x80060000);
+ gScreen._6c = gScreen._6d;
+ gScreen._6d = 0;
+}
+
+void sub_0805622C(u32 a1, u32 a2, u32 a3) {
+ gScreen._70 = a1;
+ gScreen._74 = a2;
+ gScreen._78 = a3;
+ gScreen._6c = 1;
+ gUnk_03003DE4 ^= 1;
+}
+
+void sub_08056250() {
+ gScreen._6c = 0;
+}
+
+void sub_08056260(void) {
+ u32 temp;
+ Main* temp2;
+
+ REG_DISPCNT = 0x80;
+ REG_KEYCNT = 0x8304;
+ REG_IME = 0;
+ temp = REG_IE;
+ REG_IE = 0x3000;
+ REG_IME = 1;
+ Stop();
+ REG_IME = 0;
+ REG_IE = temp;
+ REG_IME = 1;
+ temp2 = &gUnk_03001000;
+ asm("ldrb r1, [r0, #0x1]");
+ temp2->field_0x1 = 0;
+}
+
+// Convert in-game AABB to screen coordinates and check if it's within the viewport
+u32 sub_080562CC(u32 x0, u32 y0, u32 x1, u32 y1) {
+ u32 result;
+ u32 x = ((gRoomControls.roomScrollX - gRoomControls.roomOriginX) - x0 + DISPLAY_WIDTH);
+ u32 y = ((gRoomControls.roomScrollY - gRoomControls.roomOriginY) - y0 + DISPLAY_HEIGHT);
+ u32 a = x1 + DISPLAY_WIDTH;
+ u32 b = y1 + DISPLAY_HEIGHT;
+ if ((x < a) && (y < b))
+ result = TRUE;
+ else
+ result = FALSE;
+ return result;
+}
+
+// Iterate over array of AABBs and check if any fit on screen
+u16 sub_08056300(u16* arr) {
+ u16* i;
+ for (i = arr; *i != 0xff; i += 5) {
+ if (sub_080562CC(i[1], i[2], i[3], i[4]) != 0)
+ return *i;
+ }
+ return 0xff;
+}
+
+void NulledItem() {
+ DeleteThisEntity();
+}
+
+void sub_08056330() {
+ DeleteThisEntity();
+}
diff --git a/src/npc/beedle.c b/src/npc/beedle.c
index 3b30e19b..6e6a525a 100644
--- a/src/npc/beedle.c
+++ b/src/npc/beedle.c
@@ -159,5 +159,5 @@ void sub_08063504(Entity* this, u32* param_2) {
u32 uVar1;
uVar1 = sub_080544DC(gUnk_0810C88C[this->entityType.parameter]);
- param_2[5] = (-uVar1 | uVar1) >> 0x1F;
+ param_2[5] = BOOLCAST(uVar1);
}
diff --git a/src/npc/forestMinish.c b/src/npc/forestMinish.c
index abf4878d..be59fbaa 100644
--- a/src/npc/forestMinish.c
+++ b/src/npc/forestMinish.c
@@ -154,7 +154,7 @@ void sub_080601D4(Entity* this) {
uVar2 = 2;
} else {
temp = CheckKinstoneFused(0x17);
- uVar2 = (-temp | temp) >> 0x1f;
+ uVar2 = BOOLCAST(temp);
}
TextboxNoOverlap(gUnk_0810A354[uVar2], this);
}
@@ -169,7 +169,7 @@ void sub_0806021C(Entity* this) {
// jabber nut
uVar1 = GetInventoryValue(0x5B);
- uVar2 = (-uVar1 | uVar1) >> 0x1f;
+ uVar2 = BOOLCAST(uVar1);
// earth element
if (GetInventoryValue(0x40)) {
diff --git a/src/npc/goron.c b/src/npc/goron.c
index 33345e48..dcc0ac33 100644
--- a/src/npc/goron.c
+++ b/src/npc/goron.c
@@ -64,7 +64,7 @@ void sub_080693D0(Entity* this) {
sub_0807DD94(this, 0);
if (this->animIndex == 8) {
u32 var0 = this->field_0x82.HWORD & 0xF;
- bool32 createFx65 = ((-var0) | var0) >> 0x1F; // = !var0
+ bool32 createFx65 = BOOLCAST(var0); // = !var0
if (this->frames.all == 1) {
this->frames.all = 0;
diff --git a/src/npc/goronMerchant.c b/src/npc/goronMerchant.c
index 35de4c0a..7cfdb685 100644
--- a/src/npc/goronMerchant.c
+++ b/src/npc/goronMerchant.c
@@ -114,7 +114,7 @@ u32 sub_080696BC(Entity* this) {
}
temp = CheckGlobalFlag(0x3e);
- uVar1 = (-temp | temp) >> 0x1f;
+ uVar1 = BOOLCAST(temp);
if (CheckGlobalFlag(0x3f)) {
uVar1 = 2;
diff --git a/src/npc/guard.c b/src/npc/guard.c
index cfcb027d..e225c33b 100644
--- a/src/npc/guard.c
+++ b/src/npc/guard.c
@@ -68,7 +68,7 @@ void sub_08063D44(Entity* this) {
temp = this->entityType.subtype;
temp ^= 0x15;
- idx = ((-temp | temp) >> 0x1f) * 4;
+ idx = BOOLCAST(temp) * 4;
if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx]))
return;
@@ -132,7 +132,7 @@ void sub_08063E90(Entity* this) {
temp = this->entityType.subtype;
temp ^= 0x15;
- idx = ((-temp | temp) >> 0x1f) * 4;
+ idx = BOOLCAST(temp) * 4;
if (!LoadExtraSpriteData(this, &gUnk_0810F524[idx]))
return;
diff --git a/src/npc/mutoh.c b/src/npc/mutoh.c
index 1be4d5e8..01cf6481 100644
--- a/src/npc/mutoh.c
+++ b/src/npc/mutoh.c
@@ -66,7 +66,7 @@ void sub_080670B4(Entity* this) {
uVar2 = 0;
if (GetInventoryValue(0x11) == 0) {
uVar1 = CheckGlobalFlag(TABIDACHI);
- uVar2 = (-uVar1 | uVar1) >> 0x1f;
+ uVar2 = BOOLCAST(uVar1);
}
TextboxNoOverlap(gUnk_08110C0C[uVar2], this);
}
diff --git a/src/npc/townMinish.c b/src/npc/townMinish.c
index 0f454fc6..69b7eda7 100644
--- a/src/npc/townMinish.c
+++ b/src/npc/townMinish.c
@@ -299,7 +299,7 @@ void sub_0806B098(Entity* this) {
idx = 1;
if (CheckGlobalFlag(0x29)) {
f = CheckGlobalFlag(0x2a);
- idx = (-f | f) >> 0x1f;
+ idx = BOOLCAST(f);
}
}
TextboxNoOverlap(gUnk_08112C50[(this->entityType.parameter - 7) * 3 + idx], this);
diff --git a/src/object/lightableSwitch.c b/src/object/lightableSwitch.c
index ecc6449e..16609d50 100644
--- a/src/object/lightableSwitch.c
+++ b/src/object/lightableSwitch.c
@@ -60,7 +60,7 @@ void sub_0809EABC(Entity* this) {
u32 f;
f = CheckFlags(this->field_0x86.HWORD);
- anySet = (-f | f) >> 0x1F;
+ anySet = BOOLCAST(f);
if (this->frameIndex != anySet) {
this->frameIndex = anySet;
}
diff --git a/src/room.c b/src/room.c
index e9d2c358..e2c418c6 100644
--- a/src/room.c
+++ b/src/room.c
@@ -4489,7 +4489,7 @@ void sub_0804E3C4() {
u32 index;
u32 tmp;
tmp = CheckGlobalFlag(LV4_CLEAR);
- index = (-tmp | tmp) >> 0x1F;
+ index = BOOLCAST(tmp);
if (CheckGlobalFlag(LV5_CLEAR)) {
index = 2;
}
diff --git a/src/textbox.c b/src/textbox.c
index f426e392..6237ffe5 100644
--- a/src/textbox.c
+++ b/src/textbox.c
@@ -2,6 +2,7 @@
#include "room.h"
#include "entity.h"
#include "textbox.h"
+#include "structures.h"
void _DmaZero();
void ShowTextbox();
@@ -10,31 +11,31 @@ void TextboxAtPosition();
extern u32 gUnk_02022780;
extern u32 gUnk_02036A40;
extern u32 gUnk_02036A38;
-extern u32 gUnk_02000040;
-void sub_08056360(void)
+s32 sub_08056338(void) {
+ s32 result;
-{
- if ((gTextBox.doTextBox & 127) != 0) {
- gTextBox.doTextBox = 136;
- }
- return;
+ result = -1;
+ if (((gTextBox.doTextBox & 0x7f) == 0) && (gUnk_02000040.unk_00 == 3))
+ result = gUnk_02000040.unk_01;
+ return result;
}
-void TextboxNoOverlapFollow(u32 index)
+void sub_08056360(void) {
+ if ((gTextBox.doTextBox & 0x7f) != 0) {
+ gTextBox.doTextBox = 0x80 | 0x8;
+ }
+}
-{
+void TextboxNoOverlapFollow(u32 index) {
if (gRoomControls.cameraTarget != NULL) {
TextboxNoOverlap(index, gRoomControls.cameraTarget);
} else {
ShowTextbox(index);
}
- return;
}
-void TextboxNoOverlap(u32 index, Entity* ent)
-
-{
+void TextboxNoOverlap(u32 index, Entity* ent) {
s16 y;
s16 h;
@@ -43,22 +44,19 @@ void TextboxNoOverlap(u32 index, Entity* ent)
y = ent->y.HALF.HI;
h = ent->height.HALF.HI;
- if (88 < ((y + h) - gRoomControls.roomScrollY)) {
+ if (((y + h) - gRoomControls.roomScrollY) > 0x58) {
gTextBox.textWindowPosY = 1;
}
- return;
}
void sub_080563C8(u32 param_1, u32 param_2) {
TextboxAtPosition(param_1, 1, param_2);
- return;
}
void TextboxAtPosition(u32 index, u32 x, u32 y) {
ShowTextbox(index);
gTextBox.textWindowPosX = x;
gTextBox.textWindowPosY = y;
- return;
}
void ShowTextbox(u32 index, u32 param_2, u32* dest) {
@@ -70,15 +68,12 @@ void ShowTextbox(u32 index, u32 param_2, u32* dest) {
gTextBox.textWindowPosX = 1;
gTextBox.textWindowPosY = 12;
gTextBox.doTextBox = 1;
- return;
}
void sub_08056418(void) {
-
_DmaZero(&gTextBox, 32);
_DmaZero(&gUnk_02022780, 168);
_DmaZero(&gUnk_02036A40, 8);
_DmaZero(&gUnk_02036A38, 8);
_DmaZero(&gUnk_02000040, 4);
- return;
}
diff --git a/src/tmc.code-workspace b/src/tmc.code-workspace
index f890504e..6ed05aa3 100644
--- a/src/tmc.code-workspace
+++ b/src/tmc.code-workspace
@@ -1,7 +1,9 @@
{
"folders" : [ { "path" : ".." } ], "settings" : {
"files.associations" : {
- "algorithm" : "cpp", "ios" : "c"
+ "algorithm": "cpp",
+ "ios": "c",
+ "functions.h": "c"
}
}
}