summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arm9/asm/OS_protectionUnit.s18
-rw-r--r--arm9/lib/include/FS_file.h15
-rw-r--r--arm9/lib/include/FS_rom.h10
-rw-r--r--arm9/lib/include/OS_arena.h4
-rw-r--r--arm9/lib/include/OS_emulator.h4
-rw-r--r--arm9/lib/include/OS_entropy.h4
-rw-r--r--arm9/lib/include/OS_init.h3
-rw-r--r--arm9/lib/include/OS_interrupt.h2
-rw-r--r--arm9/lib/include/OS_protectionUnit.h11
-rw-r--r--arm9/lib/include/OS_reset.h6
-rw-r--r--arm9/lib/include/OS_system.h14
-rw-r--r--arm9/lib/include/OS_tcm.h2
-rw-r--r--arm9/lib/include/OS_terminate_proc.h4
-rw-r--r--arm9/lib/include/fx.h2
-rw-r--r--arm9/lib/src/FS_rom.c18
-rw-r--r--arm9/lib/src/FX_mtx33.c42
-rw-r--r--arm9/lib/src/FX_mtx43.c48
-rw-r--r--arm9/lib/src/FX_vec.c54
-rw-r--r--arm9/lib/src/GX_g3imm.c2
-rw-r--r--arm9/lib/src/GX_g3x.c38
-rw-r--r--arm9/lib/src/OS_arena.c26
-rw-r--r--arm9/lib/src/OS_emulator.c6
-rw-r--r--arm9/lib/src/OS_init.c18
-rw-r--r--arm9/lib/src/OS_interrupt.c2
-rw-r--r--arm9/lib/src/OS_protectionUnit.c21
-rw-r--r--arm9/lib/src/OS_reset.c6
-rw-r--r--arm9/lib/src/OS_system.c14
-rw-r--r--arm9/lib/src/OS_tcm.c2
-rw-r--r--arm9/lib/src/OS_terminate_proc.c4
-rw-r--r--arm9/src/main.c39
-rw-r--r--arm9/src/poke_overlay.c20
-rw-r--r--arm9/src/script.c7
-rw-r--r--arm9/src/string_util.c16
-rw-r--r--include/main.h18
-rw-r--r--include/poke_overlay.h15
-rw-r--r--include/pokemon.h3
-rw-r--r--include/script.h14
-rw-r--r--include/string_util.h25
-rw-r--r--include/structs.h2
39 files changed, 317 insertions, 242 deletions
diff --git a/arm9/asm/OS_protectionUnit.s b/arm9/asm/OS_protectionUnit.s
deleted file mode 100644
index c26f86ba..00000000
--- a/arm9/asm/OS_protectionUnit.s
+++ /dev/null
@@ -1,18 +0,0 @@
- .include "asm/macros.inc"
- .include "global.inc"
-
- .text
-
- arm_func_start OS_EnableProtectionUnit
-OS_EnableProtectionUnit: ; 0x020CC9B8
- mrc p15, 0x0, r0, c1, c0, 0x0
- orr r0, r0, #0x1
- mcr p15, 0x0, r0, c1, c0, 0x0
- bx lr
-
- arm_func_start OS_DisableProtectionUnit
-OS_DisableProtectionUnit: ; 0x020CC9C8
- mrc p15, 0x0, r0, c1, c0, 0x0
- bic r0, r0, #0x1
- mcr p15, 0x0, r0, c1, c0, 0x0
- bx lr
diff --git a/arm9/lib/include/FS_file.h b/arm9/lib/include/FS_file.h
index 3a7d8730..6a4bea80 100644
--- a/arm9/lib/include/FS_file.h
+++ b/arm9/lib/include/FS_file.h
@@ -174,16 +174,21 @@ typedef struct FSFile
}
FSFile;
-u32 FS_SetDefaultDMA(u32 dma_no); // returns the previous selection
+void FS_Init(u32 default_dma_no);
+BOOL FS_IsAvailable(void);
void FS_InitFile(FSFile * p_file);
-BOOL FS_WaitAsync(FSFile * p_file);
+static BOOL FSi_FindPath(FSFile * p_dir, const char * path, FSFileID * p_file_id, FSDirPos * p_dir_pos);
+int FSi_ReadFileCore(FSFile * p_file, void * dst, s32 len, BOOL async);
+BOOL FS_ConvertPathToFileID(FSFileID * p_file_id, const char * path);
BOOL FS_OpenFileDirect(FSFile * p_file, FSArchive * p_arc, u32 image_top, u32 image_bottom, u32 file_index);
-int FS_ReadFile(FSFile * p_file, void * dst, s32 len);
-int FS_ReadFileAsync(FSFile * p_file, void * dst, s32 len);
-BOOL FS_OpenFile(FSFile * p_file, const char * path);
BOOL FS_OpenFileFast(FSFile * p_file, FSFileID file_id);
+BOOL FS_OpenFile(FSFile * p_file, const char * path);
BOOL FS_CloseFile(FSFile * p_file);
+BOOL FS_WaitAsync(FSFile * p_file);
+int FS_ReadFileAsync(FSFile * p_file, void * dst, s32 len);
+int FS_ReadFile(FSFile * p_file, void * dst, s32 len);
BOOL FS_SeekFile(FSFile * p_file, int offset, FSSeekFileMode origin);
+BOOL FS_ChangeDir(const char * path);
static inline u32 const FS_GetFileImageTop(volatile const FSFile * p_file) {
return p_file->prop.file.top;
diff --git a/arm9/lib/include/FS_rom.h b/arm9/lib/include/FS_rom.h
index ac8ad8fb..a98c8a9c 100644
--- a/arm9/lib/include/FS_rom.h
+++ b/arm9/lib/include/FS_rom.h
@@ -2,13 +2,23 @@
#define NITRO_FS_ROM_H_
#include "FS_archive.h"
+#include "FS_file.h"
#include "CARD_rom.h"
+#include "types.h"
extern FSArchive fsi_arc_rom;
extern s32 fsi_card_lock_id;
extern CARDRomRegion fsi_ovt7;
extern CARDRomRegion fsi_ovt9;
+void FSi_OnRomReadDone(void * p_arc);
+FSResult FSi_ReadRomCallback(FSArchive * p_arc, void * dst, u32 src, u32 len);
+FSResult FSi_WriteDummyCallback(FSArchive * p_arc, const void *src, u32 dst, u32 len);
+FSResult FSi_RomArchiveProc(FSFile * p_arc, FSCommandType cmd);
+FSResult FSi_ReadDummyCallback(FSArchive *p_arc, void *dst, u32 src, u32 len);
+FSResult FSi_EmptyArchiveProc(FSFile *p_file, FSCommandType cmd);
void FSi_InitRom(u32 default_dma_no);
+u32 FS_SetDefaultDMA(u32 dma_no);
+u32 FS_TryLoadTable(void * p_mem, u32 size);
#endif //NITRO_FS_ROM_H_
diff --git a/arm9/lib/include/OS_arena.h b/arm9/lib/include/OS_arena.h
index f1893a3d..8cfef81d 100644
--- a/arm9/lib/include/OS_arena.h
+++ b/arm9/lib/include/OS_arena.h
@@ -27,8 +27,8 @@ typedef struct {
u8 padding[2];
} OSArenaInfo;
-void OS_InitArena();
-void OS_InitArenaEx();
+void OS_InitArena(void);
+void OS_InitArenaEx(void);
void* OS_GetArenaHi(OSArenaId id);
void* OS_GetArenaLo(OSArenaId id);
void* OS_GetInitArenaHi(OSArenaId id);
diff --git a/arm9/lib/include/OS_emulator.h b/arm9/lib/include/OS_emulator.h
index 54105258..30acec16 100644
--- a/arm9/lib/include/OS_emulator.h
+++ b/arm9/lib/include/OS_emulator.h
@@ -7,7 +7,7 @@
#include "consts.h"
-BOOL OS_IsRunOnEmulator();
-u32 OS_GetConsoleType();
+BOOL OS_IsRunOnEmulator(void);
+u32 OS_GetConsoleType(void);
#endif //POKEDIAMOND_OS_EMULATOR_H
diff --git a/arm9/lib/include/OS_entropy.h b/arm9/lib/include/OS_entropy.h
index b4695a72..78ac71b7 100644
--- a/arm9/lib/include/OS_entropy.h
+++ b/arm9/lib/include/OS_entropy.h
@@ -17,9 +17,9 @@ typedef struct NVRAMConfig{
extern vu64 OSi_TickCounter;
-extern u16 OS_GetTickLo();
+extern u16 OS_GetTickLo(void);
-static inline s32 GX_GetVCount()
+static inline s32 GX_GetVCount(void)
{
return reg_GX_VCOUNT;
}
diff --git a/arm9/lib/include/OS_init.h b/arm9/lib/include/OS_init.h
index 69d21213..40685513 100644
--- a/arm9/lib/include/OS_init.h
+++ b/arm9/lib/include/OS_init.h
@@ -15,6 +15,7 @@
#include "OS_mutex.h"
#include "OS_thread.h"
#include "OS_protectionRegion.h"
+#include "OS_protectionUnit.h"
#include "OS_entropy.h"
#include "OS_emulator.h"
#include "OS_arena.h"
@@ -25,6 +26,6 @@
#include "OS_reset.h"
#include "OS_spinLock.h"
-void OS_Init();
+void OS_Init(void);
#endif //POKEDIAMOND_OS_INIT_H
diff --git a/arm9/lib/include/OS_interrupt.h b/arm9/lib/include/OS_interrupt.h
index 21ae8079..cbdc225f 100644
--- a/arm9/lib/include/OS_interrupt.h
+++ b/arm9/lib/include/OS_interrupt.h
@@ -21,7 +21,7 @@ typedef u32 OSIrqMask;
extern OSIrqFunction OS_IRQTable[];
extern OSIrqCallbackInfo OSi_IrqCallbackInfo[8];
-void OS_InitIrqTable();
+void OS_InitIrqTable(void);
void OS_SetIrqFunction(OSIrqMask intrBit, OSIrqFunction function);
OSIrqFunction OS_GetIrqFunction(OSIrqMask intrBit);
void OSi_EnterDmaCallback(u32 dmaNo, void (*callback) (void *), void *arg);
diff --git a/arm9/lib/include/OS_protectionUnit.h b/arm9/lib/include/OS_protectionUnit.h
new file mode 100644
index 00000000..e7dc32d8
--- /dev/null
+++ b/arm9/lib/include/OS_protectionUnit.h
@@ -0,0 +1,11 @@
+//
+// Created by red031000 on 2020-05-24.
+//
+
+#ifndef POKEDIAMOND_OS_PROTECTIONUNIT_H
+#define POKEDIAMOND_OS_PROTECTIONUNIT_H
+
+void OS_EnableProtectionUnit(void);
+void OS_DisableProtectionUnit(void);
+
+#endif //POKEDIAMOND_OS_PROTECTIONUNIT_H
diff --git a/arm9/lib/include/OS_reset.h b/arm9/lib/include/OS_reset.h
index c3b60c98..c50106da 100644
--- a/arm9/lib/include/OS_reset.h
+++ b/arm9/lib/include/OS_reset.h
@@ -12,9 +12,9 @@
#define OS_PXI_COMMAND_SHIFT 8
#define OS_PXI_COMMAND_RESET 0x10
-void OS_InitReset();
-void OSi_CommonCallback(PXIFifoTag tag, u32 data, BOOL err);
-void OSi_SendToPxi(u16 data);
+void OS_InitReset(void);
+static void OSi_CommonCallback(PXIFifoTag tag, u32 data, BOOL err);
+static void OSi_SendToPxi(u16 data);
void OS_ResetSystem(u32 parameter);
#endif //POKEDIAMOND_OS_RESET_H
diff --git a/arm9/lib/include/OS_system.h b/arm9/lib/include/OS_system.h
index 6ce585dc..f71c6f98 100644
--- a/arm9/lib/include/OS_system.h
+++ b/arm9/lib/include/OS_system.h
@@ -26,15 +26,15 @@ typedef enum {
} OSIntrMode;
ENUMS_ALWAYS_INT_RESET
-OSIntrMode OS_EnableInterrupts();
-OSIntrMode OS_DisableInterrupts();
+OSIntrMode OS_EnableInterrupts(void);
+OSIntrMode OS_DisableInterrupts(void);
OSIntrMode OS_RestoreInterrupts(OSIntrMode state);
-OSIntrMode OS_DisableInterrupts_IrqAndFiq();
+OSIntrMode OS_DisableInterrupts_IrqAndFiq(void);
OSIntrMode OS_RestoreInterrupts_IrqAndFiq(OSIntrMode state);
-OSIntrMode OS_GetCpsrIrq();
-OSProcMode OS_GetProcMode();
-void OS_SpinWait();
-void OS_WaitVBlankIntr();
+OSIntrMode OS_GetCpsrIrq(void);
+OSProcMode OS_GetProcMode(void);
+void OS_SpinWait(void);
+void OS_WaitVBlankIntr(void);
void OS_WaitIrq(BOOL, u32);
#endif //POKEDIAMOND_OS_SYSTEM_H
diff --git a/arm9/lib/include/OS_tcm.h b/arm9/lib/include/OS_tcm.h
index 7112ca0e..66f8ec59 100644
--- a/arm9/lib/include/OS_tcm.h
+++ b/arm9/lib/include/OS_tcm.h
@@ -7,6 +7,6 @@
#include "consts.h"
-u32 OS_GetDTCMAddress();
+u32 OS_GetDTCMAddress(void);
#endif //POKEDIAMOND_OS_TCM_H
diff --git a/arm9/lib/include/OS_terminate_proc.h b/arm9/lib/include/OS_terminate_proc.h
index 26741e5d..d1abe3ad 100644
--- a/arm9/lib/include/OS_terminate_proc.h
+++ b/arm9/lib/include/OS_terminate_proc.h
@@ -5,7 +5,7 @@
#ifndef POKEDIAMOND_OS_TERMINATE_PROC_H
#define POKEDIAMOND_OS_TERMINATE_PROC_H
-void OS_Terminate();
-void OS_Halt();
+void OS_Terminate(void);
+void OS_Halt(void);
#endif //POKEDIAMOND_OS_TERMINATE_PROC_H
diff --git a/arm9/lib/include/fx.h b/arm9/lib/include/fx.h
index 3df89293..c09b24ae 100644
--- a/arm9/lib/include/fx.h
+++ b/arm9/lib/include/fx.h
@@ -142,7 +142,7 @@ void MTX_RotY44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi);
void MTX_RotZ44_(struct Mtx44 *mtx, fx32 sinphi, fx32 cosphi);
//Mtx43
-void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 z);
+void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, fx32 x, fx32 y, fx32 z);
fx32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv);
void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c);
void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32 *dst);
diff --git a/arm9/lib/src/FS_rom.c b/arm9/lib/src/FS_rom.c
index 4160e3b1..09098dfe 100644
--- a/arm9/lib/src/FS_rom.c
+++ b/arm9/lib/src/FS_rom.c
@@ -26,18 +26,20 @@ ARM_FUNC FSResult FSi_ReadRomCallback(FSArchive * p_arc, void * dst, u32 src, u3
ARM_FUNC FSResult FSi_WriteDummyCallback(FSArchive * p_arc, const void *src, u32 dst, u32 len)
{
+#pragma unused(p_arc, src, dst, len)
return FS_RESULT_FAILURE;
}
ARM_FUNC FSResult FSi_RomArchiveProc(FSFile * p_arc, FSCommandType cmd)
{
+#pragma unused(p_arc)
switch (cmd)
{
case FS_COMMAND_ACTIVATE:
- CARD_LockRom(fsi_card_lock_id);
+ CARD_LockRom((u16)fsi_card_lock_id);
return FS_RESULT_SUCCESS;
case FS_COMMAND_IDLE:
- CARD_UnlockRom(fsi_card_lock_id);
+ CARD_UnlockRom((u16)fsi_card_lock_id);
return FS_RESULT_SUCCESS;
case FS_COMMAND_WRITEFILE:
return FS_RESULT_UNSUPPORTED;
@@ -48,11 +50,13 @@ ARM_FUNC FSResult FSi_RomArchiveProc(FSFile * p_arc, FSCommandType cmd)
ARM_FUNC FSResult FSi_ReadDummyCallback(FSArchive *p_arc, void *dst, u32 src, u32 len)
{
+#pragma unused (p_arc, dst, src, len)
return FS_RESULT_FAILURE;
}
ARM_FUNC FSResult FSi_EmptyArchiveProc(FSFile *p_file, FSCommandType cmd)
{
+#pragma unused(p_file, cmd)
return FS_RESULT_UNSUPPORTED;
}
@@ -68,7 +72,7 @@ ARM_FUNC void FSi_InitRom(u32 default_dma_no)
CARD_Init();
FS_InitArchive(&fsi_arc_rom);
- FS_RegisterArchiveName(&fsi_arc_rom, "rom", 3);
+ (void)FS_RegisterArchiveName(&fsi_arc_rom, "rom", 3);
if (MB_IsMultiBootChild())
{
@@ -77,7 +81,7 @@ ARM_FUNC void FSi_InitRom(u32 default_dma_no)
fsi_ovt7.offset = (u32)~0;
fsi_ovt7.length = 0;
FS_SetArchiveProc(&fsi_arc_rom, FSi_EmptyArchiveProc, (u32)FS_ARCHIVE_PROC_ALL);
- FS_LoadArchive(&fsi_arc_rom, 0x00000000, 0, 0, 0, 0, FSi_ReadDummyCallback, FSi_WriteDummyCallback);
+ (void)FS_LoadArchive(&fsi_arc_rom, 0x00000000, 0, 0, 0, 0, FSi_ReadDummyCallback, FSi_WriteDummyCallback);
}
else
{
@@ -95,7 +99,7 @@ ARM_FUNC void FSi_InitRom(u32 default_dma_no)
}
else
{
- FS_LoadArchive(&fsi_arc_rom, 0x00000000,
+ (void)FS_LoadArchive(&fsi_arc_rom, 0x00000000,
fat->offset, fat->length,
fnt->offset, fnt->length,
FSi_ReadRomCallback, FSi_WriteDummyCallback);
@@ -110,8 +114,8 @@ ARM_FUNC u32 FS_SetDefaultDMA(u32 dma_no)
BOOL bak_stat = FS_SuspendArchive(&fsi_arc_rom);
fsi_default_dma_no = dma_no;
if (bak_stat)
- FS_ResumeArchive(&fsi_arc_rom);
- OS_RestoreInterrupts(bak_psr);
+ (void)FS_ResumeArchive(&fsi_arc_rom);
+ (void)OS_RestoreInterrupts(bak_psr);
return bak_dma_no;
}
diff --git a/arm9/lib/src/FX_mtx33.c b/arm9/lib/src/FX_mtx33.c
index 90beddba..86169ea0 100644
--- a/arm9/lib/src/FX_mtx33.c
+++ b/arm9/lib/src/FX_mtx33.c
@@ -3,15 +3,15 @@
#include "fx.h"
ARM_FUNC void MTX_ScaleApply33(struct Mtx33 *mtx, struct Mtx33 *dst, fx32 x, fx32 y, fx32 z){
- dst->_[0] = ((fx64)x * mtx->_[0]) >> FX32_INT_SHIFT;
- dst->_[1] = ((fx64)x * mtx->_[1]) >> FX32_INT_SHIFT;
- dst->_[2] = ((fx64)x * mtx->_[2]) >> FX32_INT_SHIFT;
- dst->_[3] = ((fx64)y * mtx->_[3]) >> FX32_INT_SHIFT;
- dst->_[4] = ((fx64)y * mtx->_[4]) >> FX32_INT_SHIFT;
- dst->_[5] = ((fx64)y * mtx->_[5]) >> FX32_INT_SHIFT;
- dst->_[6] = ((fx64)z * mtx->_[6]) >> FX32_INT_SHIFT;
- dst->_[7] = ((fx64)z * mtx->_[7]) >> FX32_INT_SHIFT;
- dst->_[8] = ((fx64)z * mtx->_[8]) >> FX32_INT_SHIFT;
+ dst->_[0] = (fx32)(((fx64)x * mtx->_[0]) >> FX32_INT_SHIFT);
+ dst->_[1] = (fx32)(((fx64)x * mtx->_[1]) >> FX32_INT_SHIFT);
+ dst->_[2] = (fx32)(((fx64)x * mtx->_[2]) >> FX32_INT_SHIFT);
+ dst->_[3] = (fx32)(((fx64)y * mtx->_[3]) >> FX32_INT_SHIFT);
+ dst->_[4] = (fx32)(((fx64)y * mtx->_[4]) >> FX32_INT_SHIFT);
+ dst->_[5] = (fx32)(((fx64)y * mtx->_[5]) >> FX32_INT_SHIFT);
+ dst->_[6] = (fx32)(((fx64)z * mtx->_[6]) >> FX32_INT_SHIFT);
+ dst->_[7] = (fx32)(((fx64)z * mtx->_[7]) >> FX32_INT_SHIFT);
+ dst->_[8] = (fx32)(((fx64)z * mtx->_[8]) >> FX32_INT_SHIFT);
}
ARM_FUNC void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){
@@ -28,30 +28,30 @@ ARM_FUNC void MTX_Concat33(struct Mtx33 *a, struct Mtx33 *b, struct Mtx33 *c){
a0 = a->_[0];
a1 = a->_[1];
a2 = a->_[2];
- dst->_[0] = (((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6] ) >> FX32_INT_SHIFT);
- dst->_[1] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
+ dst->_[0] = (fx32)(((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6] ) >> FX32_INT_SHIFT);
+ dst->_[1] = (fx32)(((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
b0 = b->_[2];
b1 = b->_[5];
b2 = b->_[8];
- dst->_[2] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[2] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
a0 = a->_[3];
a1 = a->_[4];
a2 = a->_[5];
- dst->_[5] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
- dst->_[4] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
+ dst->_[5] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[4] = (fx32)(((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
b0 = b->_[0];
b1 = b->_[3];
b2 = b->_[6];
- dst->_[3] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[3] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
a0 = a->_[6];
a1 = a->_[7];
a2 = a->_[8];
- dst->_[6] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
- dst->_[7] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
+ dst->_[6] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[7] = (fx32)(((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
b0 = b->_[2];
b1 = b->_[5];
b2 = b->_[8];
- dst->_[8] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[8] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
if (dst == &temp)
*c = temp;
@@ -62,9 +62,9 @@ ARM_FUNC void MTX_MultVec33(struct Vecx32 *vec, struct Mtx33 *mtx, struct Vecx32
x = vec->x;
y = vec->y;
z = vec->z;
- dst->x = ((fx64)x * mtx->_[0] + (fx64)y * mtx->_[3] + (fx64)z * mtx->_[6]) >> FX32_INT_SHIFT;
- dst->y = ((fx64)x * mtx->_[1] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[7]) >> FX32_INT_SHIFT;
- dst->z = ((fx64)x * mtx->_[2] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[8]) >> FX32_INT_SHIFT;
+ dst->x = (fx32)(((fx64)x * mtx->_[0] + (fx64)y * mtx->_[3] + (fx64)z * mtx->_[6]) >> FX32_INT_SHIFT);
+ dst->y = (fx32)(((fx64)x * mtx->_[1] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[7]) >> FX32_INT_SHIFT);
+ dst->z = (fx32)(((fx64)x * mtx->_[2] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[8]) >> FX32_INT_SHIFT);
}
ARM_FUNC asm void MTX_Identity33_(struct Mtx33 *mtx){
diff --git a/arm9/lib/src/FX_mtx43.c b/arm9/lib/src/FX_mtx43.c
index 96ab4062..693dddff 100644
--- a/arm9/lib/src/FX_mtx43.c
+++ b/arm9/lib/src/FX_mtx43.c
@@ -2,6 +2,8 @@
#include "main.h"
#include "fx.h"
+void MI_Copy48B(void *src, void *dst);
+
ARM_FUNC void MTX_ScaleApply43(struct Mtx43 *mtx, struct Mtx43 *dst, fx32 x, fx32 y, fx32 z){
//this works because matrices are indexed columns first
@@ -21,21 +23,21 @@ ARM_FUNC fx32 MTX_Inverse43(struct Mtx43 *mtx, struct Mtx43 *inv){
else
dst = inv;
//subdeterminants
- det0 = ((fx64)mtx->_[4] * mtx->_[8] - (fx64)mtx->_[5] * mtx->_[7] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT;
- det1 = ((fx64)mtx->_[3] * mtx->_[8] - (fx64)mtx->_[5] * mtx->_[6] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT;
- det2 = ((fx64)mtx->_[3] * mtx->_[7] - (fx64)mtx->_[4] * mtx->_[6] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT;
+ det0 = (fx32)(((fx64)mtx->_[4] * mtx->_[8] - (fx64)mtx->_[5] * mtx->_[7] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT);
+ det1 = (fx32)(((fx64)mtx->_[3] * mtx->_[8] - (fx64)mtx->_[5] * mtx->_[6] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT);
+ det2 = (fx32)(((fx64)mtx->_[3] * mtx->_[7] - (fx64)mtx->_[4] * mtx->_[6] + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT);
//matrix determinant
- det = ((fx64)mtx->_[0] * det0 - (fx64)mtx->_[1] * det1 + (fx64)mtx->_[2] * det2 + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT;
+ det = (fx32)(((fx64)mtx->_[0] * det0 - (fx64)mtx->_[1] * det1 + (fx64)mtx->_[2] * det2 + (fx64)(1 << (FX32_INT_SHIFT - 1))) >> FX32_INT_SHIFT);
if (det == 0)
return -1; //not invertible
FX_InvAsync(det);
- var0 = ((fx64)mtx->_[1] * mtx->_[8] - (fx64)mtx->_[7] * mtx->_[2]) >> FX32_INT_SHIFT;
- var1 = ((fx64)mtx->_[1] * mtx->_[5] - (fx64)mtx->_[4] * mtx->_[2]) >> FX32_INT_SHIFT;
- var2 = ((fx64)mtx->_[0] * mtx->_[8] - (fx64)mtx->_[6] * mtx->_[2]) >> FX32_INT_SHIFT;
- var3 = ((fx64)mtx->_[0] * mtx->_[5] - (fx64)mtx->_[3] * mtx->_[2]) >> FX32_INT_SHIFT;
+ var0 = (fx32)(((fx64)mtx->_[1] * mtx->_[8] - (fx64)mtx->_[7] * mtx->_[2]) >> FX32_INT_SHIFT);
+ var1 = (fx32)(((fx64)mtx->_[1] * mtx->_[5] - (fx64)mtx->_[4] * mtx->_[2]) >> FX32_INT_SHIFT);
+ var2 = (fx32)(((fx64)mtx->_[0] * mtx->_[8] - (fx64)mtx->_[6] * mtx->_[2]) >> FX32_INT_SHIFT);
+ var3 = (fx32)(((fx64)mtx->_[0] * mtx->_[5] - (fx64)mtx->_[3] * mtx->_[2]) >> FX32_INT_SHIFT);
fx32 ret = FX_GetDivResult();
dst->_[0] = (fx32)(((fx64)ret * det0) >> FX32_INT_SHIFT);
@@ -73,36 +75,36 @@ ARM_FUNC void MTX_Concat43(struct Mtx43 *a, struct Mtx43 *b, struct Mtx43 *c){
a0 = a->_[0];
a1 = a->_[1];
a2 = a->_[2];
- dst->_[0] = (((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6] ) >> FX32_INT_SHIFT);
- dst->_[1] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
+ dst->_[0] = (fx32)(((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6] ) >> FX32_INT_SHIFT);
+ dst->_[1] = (fx32)(((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
b0 = b->_[2];
b1 = b->_[5];
b2 = b->_[8];
- dst->_[2] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[2] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
a0 = a->_[3];
a1 = a->_[4];
a2 = a->_[5];
- dst->_[5] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
- dst->_[4] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
+ dst->_[5] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[4] = (fx32)(((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
b0 = b->_[0];
b1 = b->_[3];
b2 = b->_[6];
- dst->_[3] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[3] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
a0 = a->_[6];
a1 = a->_[7];
a2 = a->_[8];
- dst->_[6] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
- dst->_[7] = (((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
+ dst->_[6] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[7] = (fx32)(((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7] ) >> FX32_INT_SHIFT);
b0 = b->_[2];
b1 = b->_[5];
b2 = b->_[8];
- dst->_[8] = (((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
+ dst->_[8] = (fx32)(((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT);
a0 = a->_[9];
a1 = a->_[10];
a2 = a->_[11];
- dst->_[11] = ((((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT) + b->_[11]);
- dst->_[10] = ((((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7]) >> FX32_INT_SHIFT) + b->_[10]);
- dst->_[9] = ((((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6]) >> FX32_INT_SHIFT) + b->_[9]);
+ dst->_[11] = (fx32)((((fx64)a0 * b0 + (fx64)a1 * b1 + (fx64)a2 * b2) >> FX32_INT_SHIFT) + b->_[11]);
+ dst->_[10] = (fx32)((((fx64)a0 * b->_[1] + (fx64)a1 * b->_[4] + (fx64)a2 * b->_[7]) >> FX32_INT_SHIFT) + b->_[10]);
+ dst->_[9] = (fx32)((((fx64)a0 * b->_[0] + (fx64)a1 * b->_[3] + (fx64)a2 * b->_[6]) >> FX32_INT_SHIFT) + b->_[9]);
if (dst == &temp)
*c = temp;
}
@@ -112,11 +114,11 @@ ARM_FUNC void MTX_MultVec43(struct Vecx32 *vec, struct Mtx43 *mtx, struct Vecx32
x = vec->x;
y = vec->y;
z = vec->z;
- dst->x = ((fx64)x * mtx->_[0] + (fx64)y * mtx->_[3] + (fx64)z * mtx->_[6]) >> FX32_INT_SHIFT;
+ dst->x = (fx32)(((fx64)x * mtx->_[0] + (fx64)y * mtx->_[3] + (fx64)z * mtx->_[6]) >> FX32_INT_SHIFT);
dst->x += mtx->_[9];
- dst->y = ((fx64)x * mtx->_[1] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[7]) >> FX32_INT_SHIFT;
+ dst->y = (fx32)(((fx64)x * mtx->_[1] + (fx64)y * mtx->_[4] + (fx64)z * mtx->_[7]) >> FX32_INT_SHIFT);
dst->y += mtx->_[10];
- dst->z = ((fx64)x * mtx->_[2] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[8]) >> FX32_INT_SHIFT;
+ dst->z = (fx32)(((fx64)x * mtx->_[2] + (fx64)y * mtx->_[5] + (fx64)z * mtx->_[8]) >> FX32_INT_SHIFT);
dst->z += mtx->_[11];
}
diff --git a/arm9/lib/src/FX_vec.c b/arm9/lib/src/FX_vec.c
index 95805f33..891b980a 100644
--- a/arm9/lib/src/FX_vec.c
+++ b/arm9/lib/src/FX_vec.c
@@ -15,13 +15,13 @@ ARM_FUNC void VEC_Subtract(struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *ds
}
ARM_FUNC void VEC_Fx16Add(struct Vecx16 *a, struct Vecx16 *b, struct Vecx16 *dst){
- dst->x = a->x + b->x;
- dst->y = a->y + b->y;
- dst->z = a->z + b->z;
+ dst->x = (s16)(a->x + b->x);
+ dst->y = (s16)(a->y + b->y);
+ dst->z = (s16)(a->z + b->z);
}
ARM_FUNC fx32 VEC_DotProduct(struct Vecx32 *a, struct Vecx32 *b){
- return ((fx64)a->x * b->x + (fx64)a->y * b->y + (fx64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT;
+ return (fx32)(((fx64)a->x * b->x + (fx64)a->y * b->y + (fx64)a->z * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT);
}
ARM_FUNC fx32 VEC_Fx16DotProduct(struct Vecx16 *a, struct Vecx16 *b){
@@ -46,9 +46,9 @@ ARM_FUNC void VEC_Fx16CrossProduct(struct Vecx16 *a, struct Vecx16 *b, struct Ve
x = ((a->y * b->z - a->z * b->y + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT);
y = ((a->z * b->x - a->x * b->z + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT);
z = ((a->x * b->y - a->y * b->x + (1 << (FX64_INT_SHIFT - 1))) >> FX64_INT_SHIFT);
- dst->x = x;
- dst->y = y;
- dst->z = z;
+ dst->x = (fx16)x;
+ dst->y = (fx16)y;
+ dst->z = (fx16)z;
}
ARM_FUNC fx32 VEC_Mag(struct Vecx32 *a){
@@ -56,8 +56,8 @@ ARM_FUNC fx32 VEC_Mag(struct Vecx32 *a){
l2 += (fx64)a->y * a->y;
l2 += (fx64)a->z * a->z;
reg_CP_SQRTCNT = 0x1;
- reg_CP_SQRT_PARAM = l2 * 4;
- while (reg_CP_SQRTCNT & 0x8000); //wait for coprocessor to finish
+ reg_CP_SQRT_PARAM = (u64)(l2 * 4);
+ while (reg_CP_SQRTCNT & 0x8000) {} //wait for coprocessor to finish
return ((fx32)reg_CP_SQRT_RESULT + 1) >> 1;
}
@@ -68,17 +68,17 @@ ARM_FUNC void VEC_Normalize(struct Vecx32 *a, struct Vecx32 *dst){
//1/sqrt(l) is computed by calculating sqrt(l)*(1/l)
reg_CP_DIVCNT = 0x2;
reg_CP_DIV_NUMER = 0x0100000000000000;
- reg_CP_DIV_DENOM = l2;
+ reg_CP_DIV_DENOM = (u64)l2;
reg_CP_SQRTCNT = 0x1;
- reg_CP_SQRT_PARAM = l2 * 4;
- while (reg_CP_SQRTCNT & 0x8000); //wait for sqrt to finish
- fx32 sqrtresult = reg_CP_SQRT_RESULT;
- while (reg_CP_DIVCNT & 0x8000); //wait for division to finish
- l2 = reg_CP_DIV_RESULT;
+ reg_CP_SQRT_PARAM = (u64)(l2 * 4);
+ while (reg_CP_SQRTCNT & 0x8000) {} //wait for sqrt to finish
+ fx32 sqrtresult = (fx32)reg_CP_SQRT_RESULT;
+ while (reg_CP_DIVCNT & 0x8000) {} //wait for division to finish
+ l2 = (fx64)reg_CP_DIV_RESULT;
l2 = sqrtresult * l2;
- dst->x = (l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D;
- dst->y = (l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D;
- dst->z = (l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D;
+ dst->x = (fx32)((l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D);
+ dst->y = (fx32)((l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D);
+ dst->z = (fx32)((l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D);
}
ARM_FUNC void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){
@@ -88,17 +88,17 @@ ARM_FUNC void VEC_Fx16Normalize(struct Vecx16 *a, struct Vecx16 *dst){
//1/sqrt(l) is computed by calculating sqrt(l)*(1/l)
reg_CP_DIVCNT = 0x2;
reg_CP_DIV_NUMER = 0x0100000000000000;
- reg_CP_DIV_DENOM = l2;
+ reg_CP_DIV_DENOM = (u64)l2;
reg_CP_SQRTCNT = 0x1;
- reg_CP_SQRT_PARAM = l2 * 4;
- while (reg_CP_SQRTCNT & 0x8000); //wait for sqrt to finish
- fx32 sqrtresult = reg_CP_SQRT_RESULT;
- while (reg_CP_DIVCNT & 0x8000); //wait for division to finish
- l2 = reg_CP_DIV_RESULT;
+ reg_CP_SQRT_PARAM = (u64)(l2 * 4);
+ while (reg_CP_SQRTCNT & 0x8000) {} //wait for sqrt to finish
+ fx32 sqrtresult = (fx32)reg_CP_SQRT_RESULT;
+ while (reg_CP_DIVCNT & 0x8000) {} //wait for division to finish
+ l2 = (fx64)reg_CP_DIV_RESULT;
l2 = sqrtresult * l2;
- dst->x = (l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D;
- dst->y = (l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D;
- dst->z = (l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D;
+ dst->x = (fx16)((l2 * a->x + (1LL << (0x2D - 1))) >> 0x2D);
+ dst->y = (fx16)((l2 * a->y + (1LL << (0x2D - 1))) >> 0x2D);
+ dst->z = (fx16)((l2 * a->z + (1LL << (0x2D - 1))) >> 0x2D);
}
ARM_FUNC void VEC_MultAdd(fx32 factor, struct Vecx32 *a, struct Vecx32 *b, struct Vecx32 *dst){
diff --git a/arm9/lib/src/GX_g3imm.c b/arm9/lib/src/GX_g3imm.c
index 579032a6..bacd395a 100644
--- a/arm9/lib/src/GX_g3imm.c
+++ b/arm9/lib/src/GX_g3imm.c
@@ -2,6 +2,8 @@
#include "main.h"
#include "GX.h"
+void MI_Copy36B(void *src, void *dst);
+
ARM_FUNC void G3_LoadMtx43(struct Mtx43 *mtx){
reg_G3X_GXFIFO = 0x17;
GX_SendFifo48B(mtx, (void *)&reg_G3X_GXFIFO);
diff --git a/arm9/lib/src/GX_g3x.c b/arm9/lib/src/GX_g3x.c
index 31508e06..ed84f58b 100644
--- a/arm9/lib/src/GX_g3x.c
+++ b/arm9/lib/src/GX_g3x.c
@@ -4,6 +4,8 @@
extern u32 GXi_DmaId;
+void MI_Copy36B(void *src, void *dst);
+
ARM_FUNC asm void GXi_NopClearFifo128_(void *reg){
mov r1, #0x0
mov r2, #0x0
@@ -47,15 +49,15 @@ ARM_FUNC asm void GXi_NopClearFifo128_(void *reg){
ARM_FUNC void G3X_Init(){
G3X_ClearFifo();
reg_G3_END_VTXS = 0x0;
- while (reg_G3X_GXSTAT & 0x8000000); //wait for geometry engine to not be busy
+ while (reg_G3X_GXSTAT & 0x8000000) {} //wait for geometry engine to not be busy
reg_G3X_DISP3DCNT = 0x0;
reg_G3X_GXSTAT = 0x0;
reg_G2_BG0OFS = 0x0;
reg_G3X_DISP3DCNT |= 0x2000;
reg_G3X_DISP3DCNT |= 0x1000;
reg_G3X_DISP3DCNT &= ~0x3002;
- reg_G3X_DISP3DCNT = reg_G3X_DISP3DCNT & ~0x3000 | 0x10;
- reg_G3X_DISP3DCNT = reg_G3X_DISP3DCNT & (u16)~0x3004;
+ reg_G3X_DISP3DCNT = (u16)(reg_G3X_DISP3DCNT & ~0x3000 | 0x10);
+ reg_G3X_DISP3DCNT = (u16)(reg_G3X_DISP3DCNT & (u16)~0x3004);
reg_G3X_GXSTAT |= 0x8000;
reg_G3X_GXSTAT = reg_G3X_GXSTAT & ~0xC0000000 | 0x80000000;
G3X_InitMtxStack();
@@ -72,7 +74,7 @@ ARM_FUNC void G3X_Init(){
}
ARM_FUNC void G3X_ResetMtxStack(){
- while (reg_G3X_GXSTAT & 0x8000000);
+ while (reg_G3X_GXSTAT & 0x8000000) {}
reg_G3X_GXSTAT |= 0x8000;
reg_G3X_DISP3DCNT |= 0x2000;
reg_G3X_DISP3DCNT |= 0x1000;
@@ -84,14 +86,14 @@ ARM_FUNC void G3X_ResetMtxStack(){
ARM_FUNC void G3X_ClearFifo(){
GXi_NopClearFifo128_((void *)&reg_G3X_GXFIFO);
- while (reg_G3X_GXSTAT & 0x8000000);
+ while (reg_G3X_GXSTAT & 0x8000000) {}
}
ARM_FUNC void G3X_InitMtxStack(){
u32 PV_level, PJ_level;
reg_G3X_GXSTAT |= 0x8000;
- while (G3X_GetMtxStackLevelPV(&PV_level));
- while (G3X_GetMtxStackLevelPJ(&PJ_level));
+ while (G3X_GetMtxStackLevelPV(&PV_level)) {}
+ while (G3X_GetMtxStackLevelPJ(&PJ_level)) {}
reg_G3_MTX_MODE = 0x3;
reg_G3_MTX_IDENTITY = 0x0;
reg_G3_MTX_MODE = 0x0;
@@ -108,8 +110,8 @@ ARM_FUNC void G3X_InitMtxStack(){
ARM_FUNC void G3X_ResetMtxStack_2(){
u32 PV_level, PJ_level;
reg_G3X_GXSTAT |= 0x8000;
- while (G3X_GetMtxStackLevelPV(&PV_level));
- while (G3X_GetMtxStackLevelPJ(&PJ_level));
+ while (G3X_GetMtxStackLevelPV(&PV_level)) {}
+ while (G3X_GetMtxStackLevelPJ(&PJ_level)) {}
reg_G3_MTX_MODE = 0x3;
reg_G3_MTX_IDENTITY = 0x0;
reg_G3_MTX_MODE = 0x0;
@@ -127,20 +129,20 @@ ARM_FUNC void G3X_ResetMtxStack_2(){
ARM_FUNC void G3X_SetFog(u32 enable, u32 alphamode, u32 depth, s32 offset){
if (enable)
{
- reg_G3X_FOG_OFFSET = offset;
- reg_G3X_DISP3DCNT = (reg_G3X_DISP3DCNT &~0x3f40) | (((depth << 0x8)| (alphamode << 0x6)|0x80 ));
+ reg_G3X_FOG_OFFSET = (u16)offset;
+ reg_G3X_DISP3DCNT = (u16)((reg_G3X_DISP3DCNT &~0x3f40) | (((depth << 0x8)| (alphamode << 0x6)|0x80 )));
}
else
{
- reg_G3X_DISP3DCNT = reg_G3X_DISP3DCNT & (u16)~0x3080;
+ reg_G3X_DISP3DCNT = (u16)(reg_G3X_DISP3DCNT & (u16)~0x3080);
}
}
ARM_FUNC u32 G3X_GetClipMtx(struct Mtx44 *dst){
if (reg_G3X_GXSTAT & 0x8000000)
{
- return -1;
+ return (u32)-1;
}
else
{
@@ -152,7 +154,7 @@ ARM_FUNC u32 G3X_GetClipMtx(struct Mtx44 *dst){
ARM_FUNC u32 G3X_GetVectorMtx(struct Mtx33 *dst){
if (reg_G3X_GXSTAT & 0x8000000)
{
- return -1;
+ return (u32)-1;
}
else
{
@@ -174,7 +176,7 @@ ARM_FUNC void G3X_SetClearColor(u32 col, u32 alpha, u32 depth, u32 polygon_id, u
if (enable_fog)
temp |= 0x8000;
reg_G3X_CLEAR_COLOR = temp;
- reg_G3X_CLEAR_DEPTH = depth;
+ reg_G3X_CLEAR_DEPTH = (u16)depth;
}
ARM_FUNC void G3X_InitTable(){
@@ -197,7 +199,7 @@ ARM_FUNC void G3X_InitTable(){
ARM_FUNC u32 G3X_GetMtxStackLevelPV(u32 *level){
if (reg_G3X_GXSTAT & 0x4000)
{
- return -1;
+ return (u32)-1;
}
else
{
@@ -209,7 +211,7 @@ ARM_FUNC u32 G3X_GetMtxStackLevelPV(u32 *level){
ARM_FUNC u32 G3X_GetMtxStackLevelPJ(u32 *level){
if (reg_G3X_GXSTAT & 0x4000)
{
- return -1;
+ return (u32)-1;
}
else
{
@@ -221,7 +223,7 @@ ARM_FUNC u32 G3X_GetMtxStackLevelPJ(u32 *level){
ARM_FUNC u32 G3X_GetBoxTestResult(u32 *result){
if (reg_G3X_GXSTAT & 0x1)
{
- return -1;
+ return (u32)-1;
}
else
{
diff --git a/arm9/lib/src/OS_arena.c b/arm9/lib/src/OS_arena.c
index 31796771..9e7d3223 100644
--- a/arm9/lib/src/OS_arena.c
+++ b/arm9/lib/src/OS_arena.c
@@ -17,7 +17,7 @@ extern void SDK_SECTION_ARENA_DTCM_START(); // TODO: technically this should be
extern void SDK_IRQ_STACKSIZE(); // TODO: technically this should be defined in the lcf
extern void SDK_SYS_STACKSIZE(); // TODO: technically this should be defined in the lcf
-ARM_FUNC void OS_InitArena() {
+ARM_FUNC void OS_InitArena(void) {
if (OSi_Initialized) {
return;
}
@@ -42,7 +42,7 @@ ARM_FUNC void OS_InitArena() {
OS_SetArenaLo(OS_ARENA_WRAM_MAIN, OS_GetInitArenaLo(OS_ARENA_WRAM_MAIN));
}
-ARM_FUNC void OS_InitArenaEx() {
+ARM_FUNC void OS_InitArenaEx(void) {
OS_SetArenaHi(2, OS_GetInitArenaHi(OS_ARENA_MAINEX));
OS_SetArenaLo(2, OS_GetInitArenaLo(OS_ARENA_MAINEX));
@@ -73,22 +73,22 @@ ARM_FUNC void* OS_GetInitArenaHi(OSArenaId id) {
case OS_ARENA_ITCM:
return (void *)HW_ITCM_ARENA_HI_DEFAULT;
case OS_ARENA_DTCM:
- u32 irqStackLo = (u32)HW_DTCM_IRQ_STACK_END - (s32)SDK_IRQ_STACKSIZE;
+ {
+ u32 irqStackLo = (u32) HW_DTCM_IRQ_STACK_END - (s32) SDK_IRQ_STACKSIZE;
u32 sysStackLo;
- if (!(s32)SDK_SYS_STACKSIZE) {
+ if (!(s32) SDK_SYS_STACKSIZE) {
sysStackLo = HW_DTCM;
- if (sysStackLo < (u32)SDK_SECTION_ARENA_DTCM_START) {
- sysStackLo = (u32)SDK_SECTION_ARENA_DTCM_START;
+ if (sysStackLo < (u32) SDK_SECTION_ARENA_DTCM_START) {
+ sysStackLo = (u32) SDK_SECTION_ARENA_DTCM_START;
}
+ } else if ((s32) SDK_SYS_STACKSIZE < 0) {
+ sysStackLo = (u32) SDK_SECTION_ARENA_DTCM_START - (s32) SDK_SYS_STACKSIZE;
+ } else {
+ sysStackLo = irqStackLo - (s32) SDK_SYS_STACKSIZE;
}
- else if ((s32)SDK_SYS_STACKSIZE < 0) {
- sysStackLo = (u32)SDK_SECTION_ARENA_DTCM_START - (s32)SDK_SYS_STACKSIZE;
- }
- else {
- sysStackLo = irqStackLo - (s32)SDK_SYS_STACKSIZE;
- }
- return (void*)sysStackLo;
+ return (void *) sysStackLo;
+ }
case OS_ARENA_SHARED:
return (void *)HW_SHARED_ARENA_HI_DEFAULT;
case OS_ARENA_WRAM_MAIN:
diff --git a/arm9/lib/src/OS_emulator.c b/arm9/lib/src/OS_emulator.c
index c138b2bc..e92a7d9d 100644
--- a/arm9/lib/src/OS_emulator.c
+++ b/arm9/lib/src/OS_emulator.c
@@ -5,13 +5,13 @@
#include "OS_emulator.h"
#include "function_target.h"
-u32 OSi_ConsoleTypeCache = -1u; //todo fix bss
+u32 OSi_ConsoleTypeCache = -1u;
-ARM_FUNC BOOL OS_IsRunOnEmulator() {
+ARM_FUNC BOOL OS_IsRunOnEmulator(void) {
return FALSE;
}
-ARM_FUNC u32 OS_GetConsoleType() {
+ARM_FUNC u32 OS_GetConsoleType(void) {
OSi_ConsoleTypeCache = OS_CONSOLE_NITRO | OS_CONSOLE_DEV_CARD | OS_CONSOLE_SIZE_4MB;
return OSi_ConsoleTypeCache;
diff --git a/arm9/lib/src/OS_init.c b/arm9/lib/src/OS_init.c
index a34196f4..e1c7e63a 100644
--- a/arm9/lib/src/OS_init.c
+++ b/arm9/lib/src/OS_init.c
@@ -5,15 +5,15 @@
#include "function_target.h"
#include "OS_init.h"
-extern void PXI_Init();
-extern void OS_InitException();
-extern void MI_Init();
-extern void OS_InitVAlarm();
-extern void OSi_InitVramExclusive();
-extern void OS_InitThread();
-extern void CTRDG_Init();
-extern void CARD_Init();
-extern void PM_Init();
+extern void PXI_Init(void);
+extern void OS_InitException(void);
+extern void MI_Init(void);
+extern void OS_InitVAlarm(void);
+extern void OSi_InitVramExclusive(void);
+extern void OS_InitThread(void);
+extern void CTRDG_Init(void);
+extern void CARD_Init(void);
+extern void PM_Init(void);
ARM_FUNC void OS_Init(void) {
OS_InitArena();
diff --git a/arm9/lib/src/OS_interrupt.c b/arm9/lib/src/OS_interrupt.c
index 76deb069..4692fd54 100644
--- a/arm9/lib/src/OS_interrupt.c
+++ b/arm9/lib/src/OS_interrupt.c
@@ -11,7 +11,7 @@
extern OSThreadQueue OSi_IrqThreadQueue;
-ARM_FUNC void OS_InitIrqTable() {
+ARM_FUNC void OS_InitIrqTable(void) {
OS_InitThreadQueue(&OSi_IrqThreadQueue);
}
diff --git a/arm9/lib/src/OS_protectionUnit.c b/arm9/lib/src/OS_protectionUnit.c
new file mode 100644
index 00000000..be57dcd6
--- /dev/null
+++ b/arm9/lib/src/OS_protectionUnit.c
@@ -0,0 +1,21 @@
+//
+// Created by red031000 on 2020-05-24.
+//
+
+#include "function_target.h"
+
+ARM_FUNC asm void OS_EnableProtectionUnit(void)
+{
+ mrc p15, 0x0, r0, c1, c0, 0x0
+ orr r0, r0, #0x1
+ mcr p15, 0x0, r0, c1, c0, 0x0
+ bx lr
+}
+
+ARM_FUNC asm void OS_DisableProtectionUnit(void)
+{
+ mrc p15, 0x0, r0, c1, c0, 0x0
+ bic r0, r0, #0x1
+ mcr p15, 0x0, r0, c1, c0, 0x0
+ bx lr
+}
diff --git a/arm9/lib/src/OS_reset.c b/arm9/lib/src/OS_reset.c
index 02498962..e051f6ff 100644
--- a/arm9/lib/src/OS_reset.c
+++ b/arm9/lib/src/OS_reset.c
@@ -11,15 +11,15 @@
static u16 OSi_IsInitReset = 0;
vu16 OSi_IsResetOccurred = 0;
-extern void PXI_Init();
+extern void PXI_Init(void);
extern u32 PXI_IsCallbackReady(u32 param1, u32 param2);
extern void PXI_SetFifoRecvCallback(u32 param1, void* callback);
extern u32 PXI_SendWordByFifo(u32 param1, u32 data, u32 param2);
extern void CARD_LockRom(u16 lockId);
extern void MI_StopDma(u32 dma);
-extern void OSi_DoResetSystem(); //in itcm, should technically be in this file
+extern void OSi_DoResetSystem(void); //in itcm, should technically be in this file
-ARM_FUNC void OS_InitReset() {
+ARM_FUNC void OS_InitReset(void) {
if (OSi_IsInitReset) {
return;
}
diff --git a/arm9/lib/src/OS_system.c b/arm9/lib/src/OS_system.c
index 5379433b..1d257679 100644
--- a/arm9/lib/src/OS_system.c
+++ b/arm9/lib/src/OS_system.c
@@ -5,7 +5,7 @@
#include "OS_system.h"
#include "syscall.h"
-ARM_FUNC asm OSIntrMode OS_EnableInterrupts() {
+ARM_FUNC asm OSIntrMode OS_EnableInterrupts(void) {
mrs r0, cpsr
bic r1, r0, #HW_PSR_DISABLE_IRQ
msr cpsr_c, r1
@@ -13,7 +13,7 @@ ARM_FUNC asm OSIntrMode OS_EnableInterrupts() {
bx lr
}
-ARM_FUNC asm OSIntrMode OS_DisableInterrupts() {
+ARM_FUNC asm OSIntrMode OS_DisableInterrupts(void) {
mrs r0, cpsr
orr r1, r0, #HW_PSR_DISABLE_IRQ
msr cpsr_c, r1
@@ -30,7 +30,7 @@ ARM_FUNC asm OSIntrMode OS_RestoreInterrupts(OSIntrMode state) {
bx lr
}
-ARM_FUNC asm OSIntrMode OS_DisableInterrupts_IrqAndFiq() {
+ARM_FUNC asm OSIntrMode OS_DisableInterrupts_IrqAndFiq(void) {
mrs r0, cpsr
orr r1, r0, #HW_PSR_DISABLE_IRQ_FIQ
msr cpsr_c, r1
@@ -47,25 +47,25 @@ ARM_FUNC asm OSIntrMode OS_RestoreInterrupts_IrqAndFiq(OSIntrMode state) {
bx lr
}
-ARM_FUNC asm OSIntrMode OS_GetCpsrIrq() {
+ARM_FUNC asm OSIntrMode OS_GetCpsrIrq(void) {
mrs r0, cpsr
and r0, r0, #HW_PSR_DISABLE_IRQ
bx lr
}
-ARM_FUNC asm OSProcMode OS_GetProcMode() {
+ARM_FUNC asm OSProcMode OS_GetProcMode(void) {
mrs r0, cpsr
and r0, r0, #HW_PSR_CPU_MODE_MASK
bx lr
}
-ARM_FUNC asm void OS_SpinWait() {
+ARM_FUNC asm void OS_SpinWait(void) {
subs r0, r0, #0x4
bhs OS_SpinWait
bx lr
}
-ARM_FUNC void OS_WaitVBlankIntr() {
+ARM_FUNC void OS_WaitVBlankIntr(void) {
SVC_WaitByLoop(0x1);
OS_WaitIrq(TRUE, OS_IE_V_BLANK);
}
diff --git a/arm9/lib/src/OS_tcm.c b/arm9/lib/src/OS_tcm.c
index 5a168c58..fa06e345 100644
--- a/arm9/lib/src/OS_tcm.c
+++ b/arm9/lib/src/OS_tcm.c
@@ -5,7 +5,7 @@
#include "OS_tcm.h"
#include "function_target.h"
-ARM_FUNC asm u32 OS_GetDTCMAddress() {
+ARM_FUNC asm u32 OS_GetDTCMAddress(void) {
mrc p15, 0x0, r0, c9, c1, 0x0
ldr r1, =OSi_TCM_REGION_BASE_MASK
and r0, r0, r1
diff --git a/arm9/lib/src/OS_terminate_proc.c b/arm9/lib/src/OS_terminate_proc.c
index eb267c6b..40b015d9 100644
--- a/arm9/lib/src/OS_terminate_proc.c
+++ b/arm9/lib/src/OS_terminate_proc.c
@@ -7,14 +7,14 @@
#include "function_target.h"
#include "OS_system.h"
-ARM_FUNC void OS_Terminate() {
+ARM_FUNC void OS_Terminate(void) {
while (TRUE) {
(void)OS_DisableInterrupts();
OS_Halt();
}
}
-ARM_FUNC asm void OS_Halt() {
+ARM_FUNC asm void OS_Halt(void) {
mov r0, #0x0
mcr p15, 0x0, r0, c7, c0, 0x4
bx lr
diff --git a/arm9/src/main.c b/arm9/src/main.c
index bc3ca71a..a038cd9a 100644
--- a/arm9/src/main.c
+++ b/arm9/src/main.c
@@ -1,6 +1,5 @@
#include "global.h"
#include "SPI_pm.h"
-#include "OS_interrupt.h"
#include "OS_system.h"
#include "CARD_backup.h"
#include "CARD_pullOut.h"
@@ -14,27 +13,22 @@ FS_EXTERN_OVERLAY(MODULE_63);
#define SOFT_RESET_KEY (PAD_BUTTON_L | PAD_BUTTON_R | PAD_BUTTON_START | PAD_BUTTON_SELECT)
-extern struct Unk21C48B8 gUnknown21C48B8;
-
struct Unk2106FA0 gBacklightTop;
extern BOOL FUN_02006234(struct Unk21DBE18 *, s32 *, int);
extern BOOL FUN_02006290(int);
extern void FUN_02006260(int);
extern BOOL FUN_02033678(void);
-extern int FUN_020335B8(void);
+extern u32 FUN_020335B8(void);
extern BOOL FUN_0202FB80(void);
-extern void FUN_02000FE8(void);
extern void FUN_02016464(void);
-extern void OS_WaitIrq();
extern void FUN_02016438(s32);
extern void InitSystemForTheGame(void);
extern void InitGraphicMemory(void);
extern void FUN_020163BC(void);
extern void FUN_02022294(void);
extern void FUN_0201259C(void);
-extern void FUN_02000DF4(void);
extern void FUN_02002C14(void);
extern void FUN_02002C50(int, int);
extern struct UnkStruct_021C59C8 * FUN_0202254C(void);
@@ -46,14 +40,8 @@ extern int FUN_020337E8(int);
extern void FUN_02034188(int, int);
extern int FUN_020227FC(struct UnkStruct_021C59C8 *);
extern void FUN_02089D90(int);
-extern void FUN_02000E7C(FSOverlayID, struct Unk21DBE18 *);
-extern void InitializeMainRNG(void);
extern void FUN_0200A2AC(void);
extern void FUN_02015E30(void);
-extern void FUN_02000EE8(void);
-void DoSoftReset(u32 parameter);
-extern BOOL FUN_0202FB80(void);
-extern void FUN_02000E0C(void);
extern void FUN_0201B5CC(int);
extern void FUN_020125D4(void);
extern void FUN_02015E60(void);
@@ -61,11 +49,6 @@ extern void FUN_020222C4(void);
extern void FUN_0200A318(void);
extern void FUN_0200E2D8(void);
extern void FUN_02003C10(void);
-extern void FUN_02000FE8(void);
-extern void FUN_02016464(void);
-
-void FUN_02000F4C(int arg0, int arg1);
-void FUN_02000FE8(void);
extern struct Unk21DBE18 MOD63_UNK_021DBE18;
extern struct Unk21DBE18 MOD52_UNK_021D76C8;
@@ -162,9 +145,9 @@ THUMB_FUNC void NitroMain(void)
THUMB_FUNC void FUN_02000DF4(void)
{
- gBacklightTop.unk8 = -1;
+ gBacklightTop.unk8 = (FSOverlayID)-1;
gBacklightTop.unkC = 0;
- gBacklightTop.unk10 = -1; // overlay invalid
+ gBacklightTop.unk10 = (FSOverlayID)-1; // overlay invalid
gBacklightTop.unk14 = NULL;
}
@@ -219,7 +202,7 @@ THUMB_FUNC void FUN_02000EC8(u32 parameter)
THUMB_FUNC void FUN_02000EE8(void)
{
- int r1 = FUN_020335B8();
+ u32 r1 = FUN_020335B8();
switch (r1)
{
case 1:
@@ -258,7 +241,7 @@ THUMB_FUNC void DoSoftReset(u32 parameter)
extern void FUN_02033F70(int, int, int);
-THUMB_FUNC void FUN_02000F4C(int arg0, int arg1)
+THUMB_FUNC void FUN_02000F4C(u32 arg0, u32 arg1)
{
if (arg1 == 3)
{
@@ -285,17 +268,17 @@ THUMB_FUNC void FUN_02000F4C(int arg0, int arg1)
}
extern void FUN_0201265C(struct Unk21C4818 *, struct Unk21C4828 *);
-extern void seedr_MT(int);
-extern void seedr_LC(int);
+extern void seedr_MT(u32);
+extern void seedr_LC(u32);
-void InitializeMainRNG(void)
+THUMB_FUNC void InitializeMainRNG(void)
{
struct Unk21C4818 spC;
struct Unk21C4828 sp0;
FUN_0201265C(&spC, &sp0);
{
- int r4 = gUnknown21C48B8.unk2C;
- int r5 = ((sp0.unk4 + sp0.unk8) << 24) + (spC.unk0 + ((256 * spC.unk4 * spC.unk8) << 16) + (sp0.unk0 << 16));
+ u32 r4 = gUnknown21C48B8.unk2C;
+ u32 r5 = ((sp0.unk4 + sp0.unk8) << 24) + (spC.unk0 + ((256 * spC.unk4 * spC.unk8) << 16) + (sp0.unk0 << 16));
seedr_MT(r4 + r5);
seedr_LC(r4 + r5);
}
@@ -304,7 +287,7 @@ void InitializeMainRNG(void)
extern void FUN_0201CE04(void);
extern void FUN_0201CDD0(void);
-void FUN_02000FE8(void)
+THUMB_FUNC void FUN_02000FE8(void)
{
PMBackLightSwitch top, bottom;
if (PAD_DetectFold())
diff --git a/arm9/src/poke_overlay.c b/arm9/src/poke_overlay.c
index 787cd65a..237cdc26 100644
--- a/arm9/src/poke_overlay.c
+++ b/arm9/src/poke_overlay.c
@@ -1,23 +1,11 @@
#include "global.h"
#include "nitro.h"
#include "FS_file.h"
+#include "FS_rom.h"
#include "poke_overlay.h"
-struct LoadedOverlay {
- FSOverlayID id;
- BOOL active;
-};
-
static struct LoadedOverlay gLoadedOverlays[3][8];
-struct LoadedOverlay* GetLoadedOverlaysInRegion(int);
-BOOL GetOverlayRamBounds(FSOverlayID, void**, void**);
-BOOL CanOverlayBeLoaded(FSOverlayID);
-int GetOverlayLoadDestination(FSOverlayID);
-BOOL LoadOverlayNormal(MIProcessor, FSOverlayID);
-BOOL LoadOverlayNoInit(MIProcessor, FSOverlayID);
-BOOL LoadOverlayNoInitAsync(MIProcessor, FSOverlayID);
-
THUMB_FUNC void FreeOverlayAllocation(struct LoadedOverlay * loaded)
{
if (loaded->active != TRUE)
@@ -41,7 +29,7 @@ THUMB_FUNC void UnloadOverlayByID(FSOverlayID id)
}
}
-THUMB_FUNC int GetOverlayLoadDestination(FSOverlayID id)
+THUMB_FUNC s32 GetOverlayLoadDestination(FSOverlayID id)
{
FSOverlayInfo info;
u8 *end;
@@ -59,7 +47,7 @@ THUMB_FUNC int GetOverlayLoadDestination(FSOverlayID id)
return OVERLAY_LOAD_WRAM;
}
-THUMB_FUNC BOOL HandleLoadOverlay(FSOverlayID id, int a1)
+THUMB_FUNC BOOL HandleLoadOverlay(FSOverlayID id, s32 a1)
{
u32 sp0 = FS_DMA_NOT_USE;
struct LoadedOverlay *r3;
@@ -140,7 +128,7 @@ THUMB_FUNC BOOL CanOverlayBeLoaded(FSOverlayID id)
return TRUE;
}
-THUMB_FUNC struct LoadedOverlay* GetLoadedOverlaysInRegion(int a0)
+THUMB_FUNC struct LoadedOverlay* GetLoadedOverlaysInRegion(s32 a0)
{
switch (a0)
{
diff --git a/arm9/src/script.c b/arm9/src/script.c
index 8a36f924..23515e5f 100644
--- a/arm9/src/script.c
+++ b/arm9/src/script.c
@@ -1,8 +1,5 @@
-#include "global.h"
#include "script.h"
-u16 ScriptReadHalfword(struct ScriptContext *ctx);
-
THUMB_FUNC void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTableEnd)
{
u32 i;
@@ -42,9 +39,9 @@ THUMB_FUNC void StopScript(struct ScriptContext *ctx)
ctx->scriptPtr = 0;
}
-THUMB_FUNC void FUN_02038B6C(struct ScriptContext *ctx, int r1)
+THUMB_FUNC void FUN_02038B6C(struct ScriptContext *ctx, s32 r1)
{
- ctx->unk74 = r1;
+ ctx->unk74 = (u32)r1;
}
THUMB_FUNC u8 RunScriptCommand(struct ScriptContext *ctx)
diff --git a/arm9/src/string_util.c b/arm9/src/string_util.c
index e6ea85de..e36f1a30 100644
--- a/arm9/src/string_util.c
+++ b/arm9/src/string_util.c
@@ -1,4 +1,4 @@
-#include "global.h"
+#include "string_util.h"
#define EOS 0xFFFF
#define NON_DIGIT 0xE2
@@ -124,23 +124,17 @@ THUMB_FUNC u16 *StringFillEOS(u16 *dest, u32 num)
return StringFill(dest, EOS, num);
}
-enum PrintingMode {
- NORMAL,
- PAD_SPACE,
- PAD_ZEROES
-};
-
THUMB_FUNC u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n)
{
- for (u32 x = gPowersOfTen[n - 1]; x != 0; x = x / 10) {
- u16 res = value / x;
+ for (u32 x = (u32)gPowersOfTen[n - 1]; x != 0; x = x / 10) {
+ u16 res = (u16)(value / x);
value = value - x * res;
if (mode == PAD_ZEROES) {
- *dest = res >= 10 ? NON_DIGIT : gDigitTable[res];
+ *dest = res >= 10 ? (u16)NON_DIGIT : gDigitTable[res];
dest++;
} else if (res != 0 || x == 1) {
mode = PAD_ZEROES;
- *dest = res >= 10 ? NON_DIGIT : gDigitTable[res];
+ *dest = res >= 10 ? (u16)NON_DIGIT : gDigitTable[res];
dest++;
} else if (mode == PAD_SPACE) {
*dest = 1;
diff --git a/include/main.h b/include/main.h
index 92456092..ff710655 100644
--- a/include/main.h
+++ b/include/main.h
@@ -51,7 +51,7 @@ struct Unk21C48B8
s32 unk20;
s32 unk24;
s32 unk28;
- s32 unk2C;
+ u32 unk2C;
s32 unk30;
s32 unk34;
s32 unk38;
@@ -68,6 +68,7 @@ struct UnkStruct_021C4918 {
u8 unk6;
u8 unk7;
u8 unk8;
+ u8 padding[3];
};
extern struct UnkStruct_021C4918 gUnk021C4918;
@@ -75,4 +76,19 @@ extern struct UnkStruct_021C4918 gUnk021C4918;
extern struct Unk2106FA0 gBacklightTop;
extern struct Unk2106FA0 gBacklightTop_2; // same as the first one, it's referenced twice in the constant pool...
+void NitroMain(void);
+
+extern struct Unk21C48B8 gUnknown21C48B8;
+
+void FUN_02000DF4(void);
+void FUN_02000E0C(void);
+void FUN_02000E7C(FSOverlayID id, struct Unk21DBE18 * arg1);
+void FUN_02000E9C(void);
+void FUN_02000EC8(u32 parameter);
+void FUN_02000EE8(void);
+void DoSoftReset(u32 parameter);
+void FUN_02000F4C(u32 arg0, u32 arg1);
+void InitializeMainRNG(void);
+void FUN_02000FE8(void);
+
#endif //GUARD_MAIN_H
diff --git a/include/poke_overlay.h b/include/poke_overlay.h
index 5ee9073a..400f600e 100644
--- a/include/poke_overlay.h
+++ b/include/poke_overlay.h
@@ -7,7 +7,20 @@
#define OVERLAY_LOAD_ITCM 1
#define OVERLAY_LOAD_DTCM 2
+struct LoadedOverlay {
+ FSOverlayID id;
+ BOOL active;
+};
+
+void FreeOverlayAllocation(struct LoadedOverlay * loaded);
void UnloadOverlayByID(FSOverlayID id);
-BOOL HandleLoadOverlay(FSOverlayID id, int a1);
+s32 GetOverlayLoadDestination(FSOverlayID id);
+BOOL HandleLoadOverlay(FSOverlayID id, s32 a1);
+BOOL CanOverlayBeLoaded(FSOverlayID id);
+struct LoadedOverlay* GetLoadedOverlaysInRegion(s32 a0);
+BOOL GetOverlayRamBounds(FSOverlayID id, void ** start, void ** end);
+BOOL LoadOverlayNormal(MIProcessor target, FSOverlayID id);
+BOOL LoadOverlayNoInit(MIProcessor target, FSOverlayID id);
+BOOL LoadOverlayNoInitAsync(MIProcessor target, FSOverlayID id);
#endif //GUARD_POKE_OVERLAY_H
diff --git a/include/pokemon.h b/include/pokemon.h
index a350d1a1..8886c47c 100644
--- a/include/pokemon.h
+++ b/include/pokemon.h
@@ -112,6 +112,7 @@ typedef struct {
u8 friendship;
u8 ability;
u8 circleMarking:1, triangleMarking:1, squareMarking:1, heartMarking:1, starMarking:1, diamondMarking:1;
+ u8 padding;
OriginLanguage originLanguage;
u8 hpEV;
u8 atkEV;
@@ -179,9 +180,11 @@ typedef struct {
u8 pokerus;
u8 pokeball;
u8 flags;
+ u8 padding[3];
EncounterType encounterType;
u8 HGSS_Pokeball;
u8 HGSS_Performance;
+ u8 padding2[2];
} PokemonDataBlockD;
typedef union {
diff --git a/include/script.h b/include/script.h
index 2ecc8e28..0a69f7dd 100644
--- a/include/script.h
+++ b/include/script.h
@@ -1,6 +1,8 @@
#ifndef _SCRIPT_H_
#define _SCRIPT_H_
+#include "global.h"
+
struct ScriptContext;
typedef u8 (*ScrCmdFunc)(struct ScriptContext *);
@@ -22,6 +24,18 @@ struct ScriptContext
#define ScriptReadByte(ctx) (*(ctx->scriptPtr++))
+void InitScriptContext(struct ScriptContext *ctx, void *cmdTable, void *cmdTableEnd);
+u8 SetupBytecodeScript(struct ScriptContext *ctx, const u8 *ptr);
+void SetupNativeScript(struct ScriptContext *ctx, u8 (*ptr)(struct ScriptContext *));
+void StopScript(struct ScriptContext *ctx);
+void FUN_02038B6C(struct ScriptContext *ctx, s32 r1);
+u8 RunScriptCommand(struct ScriptContext *ctx);
+u8 ScriptPush(struct ScriptContext *ctx, const u8 *ptr);
+const u8 *ScriptPop(struct ScriptContext *ctx);
+void ScriptJump(struct ScriptContext *ctx, const u8 *ptr);
+u8 ScriptCall(struct ScriptContext *ctx, const u8 *ptr);
+void ScriptReturn(struct ScriptContext *ctx);
u16 ScriptReadHalfword(struct ScriptContext *ctx);
+u32 ScriptReadWord(struct ScriptContext *ctx);
#endif // _SCRIPT_H_
diff --git a/include/string_util.h b/include/string_util.h
new file mode 100644
index 00000000..53d4e5f4
--- /dev/null
+++ b/include/string_util.h
@@ -0,0 +1,25 @@
+//
+// Created by red031000 on 2020-05-24.
+//
+
+#ifndef POKEDIAMOND_STRING_UTIL_H
+#define POKEDIAMOND_STRING_UTIL_H
+
+#include "global.h"
+
+enum PrintingMode {
+ NORMAL,
+ PAD_SPACE,
+ PAD_ZEROES
+};
+
+void StringCopy(u16 *dest, const u16 *src);
+u16 *StringCopyN(u16 *dest, const u16 *src, u32 num);
+u32 StringLength(const u16 *s);
+BOOL StringNotEqual(const u16 *s1, const u16 *s2);
+BOOL StringNotEqualN(const u16 *s1, const u16 *s2, u32 num);
+u16 *StringFill(u16 *dest, u16 value, u32 num);
+u16 *StringFillEOS(u16 *dest, u32 num);
+u16 *ConvertUIntToDecimalString(u16 *dest, u32 value, enum PrintingMode mode, u32 n);
+
+#endif //POKEDIAMOND_STRING_UTIL_H
diff --git a/include/structs.h b/include/structs.h
index 8c9657be..fbcf6e0c 100644
--- a/include/structs.h
+++ b/include/structs.h
@@ -17,11 +17,13 @@ struct UnkStruct_021C59C8_Sub20224 {
struct UnkStruct_021C59C8_Sub_20464 {
u8 unk_0;
+ u8 padding[3];
int unk_4;
int unk_8;
u8 unk_C;
u8 unk_D;
u8 unk_E;
+ u8 padding2;
};
struct UnkStruct_021C59C8 {