summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/global.h6
-rw-r--r--include/main.h40
-rw-r--r--include/map.h22
-rw-r--r--include/nitro/consts.h20
-rw-r--r--include/nitro/mmap.h12
-rw-r--r--include/nitro/nitro.h18
-rw-r--r--include/nitro/os.c201
-rw-r--r--include/nitro/os.h69
-rw-r--r--include/nitro/types.h40
-rw-r--r--include/pokemon.h204
-rw-r--r--include/script.h27
-rw-r--r--include/structs.h7
12 files changed, 666 insertions, 0 deletions
diff --git a/include/global.h b/include/global.h
new file mode 100644
index 00000000..33880ca1
--- /dev/null
+++ b/include/global.h
@@ -0,0 +1,6 @@
+#ifndef GUARD_GLOBAL_H
+#define GUARD_GLOBAL_H
+
+#include "nitro/nitro.h"
+
+#endif //GUARD_GLOBAL_H
diff --git a/include/main.h b/include/main.h
new file mode 100644
index 00000000..0df94795
--- /dev/null
+++ b/include/main.h
@@ -0,0 +1,40 @@
+#ifndef GUARD_MAIN_H
+#define GUARD_MAIN_H
+
+struct Unk2106FA0
+{
+ s32 unk0;
+ s32 unk4;
+ s32 unk8;
+ s32 unkC;
+ s32 unk10;
+ s32 unk14;
+ s32 unk18;
+ s32 unk1C;
+ s32 unk20;
+};
+
+struct Unk21C48B8
+{
+ void (*unk0)(s32);
+ s32 unk4;
+ s32 unk8;
+ s32 unkC;
+ s32 unk10;
+ s32 unk14;
+ s32 unk18;
+ s32 unk1C;
+ s32 unk20;
+ s32 unk24;
+ s32 unk28;
+ s32 unk2C;
+ s32 unk30;
+ s32 unk34;
+ s32 unk38;
+ u8 filler3C[0xC];
+ s32 unk48;
+ u8 filler4C[0x20];
+ s32 unk6C;
+};
+
+#endif //GUARD_MAIN_H
diff --git a/include/map.h b/include/map.h
new file mode 100644
index 00000000..18b8c1d1
--- /dev/null
+++ b/include/map.h
@@ -0,0 +1,22 @@
+#ifndef POKEDIAMOND_MAP_H
+#define POKEDIAMOND_MAP_H
+
+typedef struct {
+ u8 MapAreaData;
+ u8 field_0x1;
+ u16 Matrix;
+ u16 MapScripts;
+ u16 MapLevelScripts;
+ u16 MapTexts;
+ u16 DayMusic;
+ u16 NightMusic;
+ u16 WildPokemonData;
+ u16 MapEvents;
+ u16 MapName;
+ u8 WeatherType;
+ u8 field_0x15;
+ u8 field_0x16;
+ u8 field_0x17;
+} MapHeader;
+
+#endif //POKEDIAMOND_MAP_H
diff --git a/include/nitro/consts.h b/include/nitro/consts.h
new file mode 100644
index 00000000..3592500a
--- /dev/null
+++ b/include/nitro/consts.h
@@ -0,0 +1,20 @@
+//
+// Created by mart on 4/15/20.
+//
+
+#ifndef POKEDIAMOND_CONSTS_H
+#define POKEDIAMOND_CONSTS_H
+
+#include "mmap.h"
+
+#define HW_PSR_CPU_MODE_MASK 0x1f // CPU mode
+
+#define HW_PSR_FIQ_DISABLE 0x40 // Disable FIQ
+#define HW_PSR_IRQ_DISABLE 0x80 // Disable IRQ
+#define HW_PSR_IRQ_FIQ_DISABLE 0xc0 // Disable FIQ and IRQ
+
+#define OSi_GetArenaInfo() (*(OSArenaInfo*)HW_ARENA_INFO_BUF)
+#define OSi_TRUNC(n, a) (((u32) (n)) & ~((a) - 1))
+#define OSi_ROUND(n, a) (((u32) (n) + (a) - 1) & ~((a) - 1))
+
+#endif //POKEDIAMOND_CONSTS_H
diff --git a/include/nitro/mmap.h b/include/nitro/mmap.h
new file mode 100644
index 00000000..4c781d5f
--- /dev/null
+++ b/include/nitro/mmap.h
@@ -0,0 +1,12 @@
+#ifndef NITRO_MMAP_H
+#define NITRO_MMAP_H
+
+#define HW_MAIN_MEM 0x02000000
+#define HW_MAIN_MEM_SIZE 0x00400000
+#define HW_MAIN_MEM_EX_SIZE 0x00800000
+
+#define HW_ARENA_INFO_BUF (HW_MAIN_MEM + 0x007ffda0) // Arena data structure
+#define HW_ROM_HEADER_BUF (HW_MAIN_MEM + 0x007ffe00) // ROM registration area data buffer
+
+
+#endif \ No newline at end of file
diff --git a/include/nitro/nitro.h b/include/nitro/nitro.h
new file mode 100644
index 00000000..8cf603f5
--- /dev/null
+++ b/include/nitro/nitro.h
@@ -0,0 +1,18 @@
+#ifndef POKEDIAMOND_NITRO_H
+#define POKEDIAMOND_NITRO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// Include all nitro files
+#include "types.h"
+#include "consts.h"
+#include "os.h"
+#include "mmap.h"
+
+#ifdef __cplusplus
+};
+#endif
+
+#endif //POKEDIAMOND_NITRO_H
diff --git a/include/nitro/os.c b/include/nitro/os.c
new file mode 100644
index 00000000..3ecffb34
--- /dev/null
+++ b/include/nitro/os.c
@@ -0,0 +1,201 @@
+//
+// Created by mart on 4/12/20.
+//
+
+#include "os.h"
+#include "consts.h"
+
+OSProcMode OS_GetProcMode() {
+ __asm {
+ mrs r0, cpsr
+ and r0, r0, #HW_PSR_CPU_MODE_MASK
+ bx lr
+ }
+}
+
+OSIntrMode OS_DisableInterrupts() {
+ __asm {
+ mrs r0, cpsr
+ orr r1, r0, #HW_PSR_IRQ_DISABLE
+ msr cpsr_c, r1
+ and r0, r0, #HW_PSR_IRQ_DISABLE
+ bx lr
+ }
+}
+
+OSIntrMode OS_RestoreInterrupts(OSIntrMode state) {
+ __asm {
+ mrs r1, cpsr
+ bic r2, r1, #HW_PSR_IRQ_DISABLE
+ orr r2, r2, r0
+ msr cpsr_c, r2
+ and r0, r1, #HW_PSR_IRQ_DISABLE
+ bx lr
+ }
+}
+
+void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align) {
+#ifdef MATCH_ASM
+ __asm {
+ stmdb sp!,{ r4 r5 r6 r7 lr }
+ sub sp,sp,#0x4
+ mov r7,r0
+ mov r6,r1
+ mov r5,r2
+ bl OS_GetArenaLo
+ cmp r0,#0x0
+ addeq sp,sp,#0x4
+ moveq r0,#0x0
+ ldmeqia sp!,{ r4 r5 r6 r7 lr }
+ bxeq lr
+ add r0,r0,r5
+ sub r1,r5,#0x1
+ mvn r2,r1
+ sub r0,r0,#0x1
+ and r4,r2,r0
+ add r0,r4,r6
+ add r0,r0,r5
+ sub r1,r0,#0x1
+ mov r0,r7
+ and r5,r2,r1
+ bl OS_GetArenaHi
+ cmp r5,r0
+ addhi sp,sp,#0x4
+ movhi r0,#0x0
+ ldmhiia sp!,{ r4 r5 r6 r7 lr }
+ bxhi lr
+ mov r0,r7
+ mov r1,r5
+ bl OS_SetArenaLo
+ mov r0,r4
+ add sp,sp,#0x4
+ ldmia sp!,{ r4 r5 r6 r7 lr }
+ bx lr
+ }
+#else
+ void* ptr;
+ u8* arenaLo;
+ ptr = OS_GetArenaLo(id);
+ if (!ptr) {
+ return NULL;
+ }
+ arenaLo = ptr = (void *)OSi_ROUND(ptr, align);
+ arenaLo += size;
+ arenaLo = (u8 *)OSi_ROUND(arenaLo, align);
+ if (arenaLo > (u8*)OS_GetArenaHi(id)) {
+ return NULL;
+ }
+ OS_SetArenaLo(id, arenaLo);
+
+ return ptr;
+#endif
+}
+
+void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align) {
+#ifdef MATCH_ASM
+ __asm {
+ stmdb sp!,{ r4 r5 r6 lr }
+ mov r4,r0
+ mov r6,r1
+ mov r5,r2
+ bl OS_GetArenaHi
+ cmp r0,#0x0
+ moveq r0,#0x0
+ ldmeqia sp!,{ r4 r5 r6 lr }
+ bxeq lr
+ sub r1,r5,#0x1
+ mvn r2,r1
+ and r0,r0,r2
+ sub r1,r0,r6
+ mov r0,r4
+ and r5,r1,r2
+ bl OS_GetArenaLo
+ cmp r5,r0
+ movcc r0,#0x0
+ ldmccia sp!,{ r4 r5 r6 lr }
+ bxcc lr
+ mov r0,r4
+ mov r1,r5
+ bl OS_SetArenaHi
+ mov r0,r5
+ ldmia sp!,{ r4 r5 r6 lr }
+ bx lr
+ };
+#else
+ void* ptr;
+ u8* arenaHi;
+
+ arenaHi = OS_GetArenaHi(id);
+ if (!arenaHi) {
+ return NULL;
+ }
+
+ arenaHi = (u8 *)OSi_TRUNC(arenaHi, align);
+ arenaHi -= size;
+ arenaHi = ptr = (void *)OSi_TRUNC(arenaHi, align);
+
+ if (arenaHi < (u8*)OS_GetArenaLo(id)) {
+ return NULL;
+ }
+
+ OS_SetArenaHi(id, arenaHi);
+
+ return ptr;
+#endif
+}
+
+void OS_SetArenaHi(OSArenaId id, void *newHi) {
+#ifdef MATCH_ASM
+ __asm {
+ mov r0,r0, lsl #0x2
+ add r0,r0,#0x2700000
+ add r0,r0,#0xff000
+ str r1,[r0,#0xdc4]
+ bx lr
+ }
+#else
+ OSi_GetArenaInfo().lo[id] = newHi;
+#endif
+}
+
+void OS_SetArenaLo(OSArenaId id, void *newLo) {
+#ifdef MATCH_ASM
+ __asm {
+ mov r0,r0, lsl #0x2
+ add r0,r0,#0x2700000
+ add r0,r0,#0xff000
+ str r1,[r0,#0xda0]
+ bx lr
+ }
+#else
+ OSi_GetArenaInfo().lo[id] = newLo;
+#endif
+}
+
+void* OS_GetArenaHi(OSArenaId id) {
+#ifdef MATCH_ASM
+ __asm {
+ mov r0,r0, lsl #0x2
+ add r0,r0,#0x2700000
+ add r0,r0,#0xff000
+ ldr r0,[r0,#0xdc4]
+ bx lr
+ }
+#else
+ return OSi_GetArenaInfo().hi[id];
+#endif
+}
+
+void* OS_GetArenaLo(OSArenaId id) {
+#ifdef MATCH_ASM
+ __asm {
+ mov r0,r0, lsl #0x2
+ add r0,r0,#0x2700000
+ add r0,r0,#0xff000
+ ldr r0,[r0,#0xda0]
+ bx lr
+ }
+#else
+ return OSi_GetArenaInfo().lo[id];
+#endif
+}
diff --git a/include/nitro/os.h b/include/nitro/os.h
new file mode 100644
index 00000000..84425631
--- /dev/null
+++ b/include/nitro/os.h
@@ -0,0 +1,69 @@
+//
+// Created by mart on 4/12/20.
+//
+
+#ifndef POKEDIAMOND_OS_H
+#define POKEDIAMOND_OS_H
+
+#include "types.h"
+#include "consts.h"
+
+typedef enum {
+ OS_PROCMODE_USER=16,
+ OS_PROCMODE_FIQ=17,
+ OS_PROCMODE_IRQ=18,
+ OS_PROCMODE_SVC=19,
+ OS_PROCMODE_ABORT=23,
+ OS_PROCMODE_UNDEF=27,
+ OS_PROCMODE_SYS=31
+} OSProcMode;
+
+typedef enum {
+ OS_ARENA_MAIN = 0,
+ OS_ARENA_MAIN_SUBPRIV = 1,
+ OS_ARENA_MAINEX = 2,
+ OS_ARENA_ITCM = 3,
+ OS_ARENA_DTCM = 4,
+ OS_ARENA_SHARED = 5,
+ OS_ARENA_WRAM_MAIN = 6,
+ OS_ARENA_WRAM_SUB = 7,
+ OS_ARENA_WRAM_SUBPRIV = 8,
+ OS_ARENA_MAX = 9
+} OSArenaId;
+
+typedef enum {
+ OS_INTRMODE_IRQ_DISABLE = HW_PSR_IRQ_DISABLE,
+ OS_INTRMODE_IRQ_ENABLE = 0
+} OSIntrMode_Irq;
+
+typedef enum {
+ OS_INTRMODE_FIQ_DISABLE = HW_PSR_FIQ_DISABLE,
+ OS_INTRMODE_FIQ_ENABLE = 0
+} OSIntrMode_Fiq;
+
+typedef union {
+ OSIntrMode_Fiq mode_fiq;
+ OSIntrMode_Irq mode_irq;
+} OSIntrMode;
+
+typedef struct {
+ void *lo[OS_ARENA_MAX];
+ void *hi[OS_ARENA_MAX];
+ u16 initialized;
+ u8 padding[2];
+} OSArenaInfo;
+
+OSProcMode OS_GetProcMode();
+OSIntrMode OS_DisableInterrupts();
+OSIntrMode OS_RestoreInterrupts(register OSIntrMode state);
+
+void* OS_AllocFromArenaLo(OSArenaId id, u32 size, u32 align);
+void* OS_AllocFromArenaHi(OSArenaId id, u32 size, u32 align);
+
+void OS_SetArenaHi(OSArenaId id, void *newHi);
+void OS_SetArenaLo(OSArenaId id, void *newLo);
+
+void* OS_GetArenaHi(OSArenaId id);
+void* OS_GetArenaLo(OSArenaId id);
+
+#endif //POKEDIAMOND_OS_H
diff --git a/include/nitro/types.h b/include/nitro/types.h
new file mode 100644
index 00000000..5ad2c75e
--- /dev/null
+++ b/include/nitro/types.h
@@ -0,0 +1,40 @@
+#ifndef POKEDIAMOND_NITRO_TYPES_H
+#define POKEDIAMOND_NITRO_TYPES_H
+
+typedef unsigned char u8;
+typedef unsigned short int u16;
+typedef unsigned long u32;
+
+typedef signed char s8;
+typedef signed short int s16;
+typedef signed long s32;
+
+typedef unsigned long long int u64;
+typedef signed long long int s64;
+
+typedef volatile u8 vu8;
+typedef volatile u16 vu16;
+typedef volatile u32 vu32;
+typedef volatile u64 vu64;
+
+typedef volatile s8 vs8;
+typedef volatile s16 vs16;
+typedef volatile s32 vs32;
+typedef volatile s64 vs64;
+
+typedef float f32;
+typedef volatile f32 vf32;
+
+typedef int BOOL;
+#define TRUE 1
+#define FALSE 0
+
+#ifndef NULL
+#ifdef __cplusplus
+#define NULL 0
+#else // __cplusplus
+#define NULL ((void *)0)
+#endif // __cplusplus
+#endif
+
+#endif //POKEDIAMOND_NITRO_TYPES_H
diff --git a/include/pokemon.h b/include/pokemon.h
new file mode 100644
index 00000000..b466a11c
--- /dev/null
+++ b/include/pokemon.h
@@ -0,0 +1,204 @@
+#ifndef POKEDIAMOND_POKEMON_H
+#define POKEDIAMOND_POKEMON_H
+
+#include "nitro/types.h"
+
+// Enums
+
+typedef enum {
+ EGG = 0,
+ EVENT = 0,
+ HATCHED = 0,
+ PAL_PARK = 0,
+ TALL_GRASS = 2,
+ DIALGA_GAME_EVENT = 4,
+ PALKIA_GAME_EVENT = 4,
+ CAVE = 5,
+ HALL_OF_ORIGIN = 5,
+ SURFING = 7,
+ FISHING = 7,
+ BUILDING = 9,
+ SAFARI_ZONE = 10,
+ STARTER = 12,
+ FOSSIL = 12,
+ GIFT_EEVEE = 12
+} EncounterType;
+
+typedef enum {
+ JAPANESE = 1,
+ ENGLISH = 2,
+ FRENCH = 3,
+ ITALIAN = 4,
+ GERMAN = 5,
+ SPANISH = 7,
+ KOREAN = 8
+} OriginLanguage;
+
+typedef enum {
+ ARCEUS_NORMAL = 0,
+ ARCEUS_FIST = 8,
+ ARCEUS_SKY = 16,
+ ARCEUS_TOXIC = 24,
+ ARCEUS_EARTH = 32,
+ ARCEUS_STONE = 40,
+ ARCEUS_INSECT = 48,
+ ARCEUS_SPOOKY = 56,
+ ARCEUS_IRON = 64,
+ ARCEUS_FLAME = 72,
+ ARCEUS_SPLASH = 80,
+ ARCEUS_MEADOW = 88,
+ ARCEUS_ZAP = 96,
+ ARCEUS_MIND = 104,
+ ARCEUS_ICICLE = 112,
+ ARCEUS_DRACO = 120,
+ ARCEUS_DREAD = 128,
+ BURMY_PLANT = 0,
+ BURMY_SANDY = 8,
+ BURMY_TRASH = 16,
+ DEOXYS_NORMAL = 0,
+ DEOXYS_ATTACK = 8,
+ DEOXYS_DEFENSE = 16,
+ DEOXYS_SPEED = 24,
+ GIRATINA_ALTERED = 0,
+ GIRATINA_ORIGIN = 8,
+ ROTOM_NORMAL = 0,
+ ROTOM_HEAT = 8,
+ ROTOM_WASH = 16,
+ ROTOM_FROST = 24,
+ ROTOM_FAN = 32,
+ ROTOM_MOW = 40,
+ SHAYMIN_LAND = 0,
+ SHAYMIN_SKY = 8,
+ SHELLOS_WEST = 0,
+ SHELLOS_EAST = 8,
+ UNOWN_A = 0,
+ UNOWN_B = 8,
+ UNOWN_C = 16,
+ UNOWN_D = 24,
+ UNOWN_E = 32,
+ UNOWN_F = 40,
+ UNOWN_G = 48,
+ UNOWN_H = 56,
+ UNOWN_I = 64,
+ UNOWN_J = 72,
+ UNOWN_K = 80,
+ UNOWN_L = 88,
+ UNOWN_M = 96,
+ UNOWN_N = 104,
+ UNOWN_O = 112,
+ UNOWN_P = 120,
+ UNOWN_Q = 128,
+ UNOWN_R = 136,
+ UNOWN_S = 144,
+ UNOWN_T = 152,
+ UNOWN_U = 160,
+ UNOWN_V = 168,
+ UNOWN_W = 176,
+ UNOWN_X = 184,
+ UNOWN_Y = 192,
+ UNOWN_Z = 200,
+ UNOWN_EXCLAMATION_MARK = 208,
+ UNOWN_QUESTION_MARK = 216
+} AlternateForms;
+
+// Structs
+
+typedef struct {
+ u16 species;
+ u16 heldItem;
+ u16 otID;
+ u16 otSecretID;
+ u32 exp;
+ u8 friendship;
+ u8 ability;
+ u8 circleMarking:1, triangleMarking:1, squareMarking:1, heartMarking:1, starMarking:1, diamondMarking:1;
+ OriginLanguage originLanguage;
+ u8 hpEV;
+ u8 atkEV;
+ u8 defEV;
+ u8 spdEV;
+ u8 spatkEV;
+ u8 spdefEV;
+ u8 coolStat;
+ u8 beautyStat;
+ u8 cuteStat;
+ u8 smartStat;
+ u8 toughStat;
+ u8 sheen;
+ // TODO: Finish SinnohRibbonSet1
+ u8 sinnohChampRibbon:1, abilityRibbon:1;
+ u8 field_0x1d;
+ u8 gorgeousRoyalRibbon:1, footprintRibbon:1;
+ u8 field_0x1f;
+} PokemonDataBlockA;
+
+typedef struct {
+ u16 move1;
+ u16 move2;
+ u16 move3;
+ u16 move4;
+ u8 move1pp;
+ u8 move2pp;
+ u8 move3pp;
+ u8 move4pp;
+ u8 move1ppUps;
+ u8 move2ppUps;
+ u8 move3ppUps;
+ u8 move4ppUps;
+ u32 hpIV:5, atkIV:5, defIV:5, spdIV:5, spatkIV:5, spdefIV:5, isEgg:1, isNicknamed:1;
+ // TODO: Finish HoennRibbonSet
+ u8 coolRibbon:1;
+ u8 field_0x15;
+ u8 field_0x16;
+ u8 field_0x17;
+ u8 fatefulEncounter:1, female:1, genderless:1, alternateForm:5;
+ u8 HGSS_shinyLeaves; // TODO: Turn into bitfield
+ u16 Unused;
+ u16 Platinum_EggLocation;
+ u16 Platinum_MetLocation;
+} PokemonDataBlockB;
+
+typedef struct {
+ u16 nickname[11];
+ u8 Unused;
+ u8 originGame;
+ // TODO: Finish SinnohRibbonSet2
+ u8 coolRibbon:1;
+ u8 field_0x19;
+ u8 field_0x1a;
+ u8 field_0x1b;
+ u32 Unused2;
+} PokemonDataBlockC;
+
+typedef struct {
+ u16 otTrainerName[8];
+ u8 dateEggReceived[3];
+ u8 dateMet[3];
+ u16 DP_EggLocation;
+ u16 DP_MetLocation;
+ u8 pokerus;
+ u8 pokeball;
+ u8 flags;
+ EncounterType encounterType;
+ u8 HGSS_Pokeball;
+ u8 HGSS_Performance;
+} PokemonDataBlockD;
+
+typedef union {
+ PokemonDataBlockA blockA;
+ PokemonDataBlockB blockB;
+ PokemonDataBlockC blockC;
+ PokemonDataBlockD blockD;
+} PokemonDataBlock;
+
+struct PokemonData {
+ u32 personalityValue;
+ u16 Unused; // Might be used for validity checks
+ u16 checksum; // Stored checksum of pokemon
+ PokemonDataBlock block1; // Blocks A-D; Order based on personalityValue
+ PokemonDataBlock block2;
+ PokemonDataBlock block3;
+ PokemonDataBlock block4;
+};
+
+#endif //POKEDIAMOND_POKEMON_H
diff --git a/include/script.h b/include/script.h
new file mode 100644
index 00000000..2ecc8e28
--- /dev/null
+++ b/include/script.h
@@ -0,0 +1,27 @@
+#ifndef _SCRIPT_H_
+#define _SCRIPT_H_
+
+struct ScriptContext;
+
+typedef u8 (*ScrCmdFunc)(struct ScriptContext *);
+typedef u8 Script[];
+
+struct ScriptContext
+{
+ u8 stackDepth;
+ u8 mode;
+ u8 comparisonResult;
+ u8 (*nativePtr)(struct ScriptContext *);
+ const u8 *scriptPtr;
+ const u8 *stack[20];
+ ScrCmdFunc *cmdTable;
+ ScrCmdFunc *cmdTableEnd;
+ u32 data[4];
+ u32 unk74;
+};
+
+#define ScriptReadByte(ctx) (*(ctx->scriptPtr++))
+
+u16 ScriptReadHalfword(struct ScriptContext *ctx);
+
+#endif // _SCRIPT_H_
diff --git a/include/structs.h b/include/structs.h
new file mode 100644
index 00000000..8a34d299
--- /dev/null
+++ b/include/structs.h
@@ -0,0 +1,7 @@
+#ifndef POKEDIAMOND_STRUCTS_H
+#define POKEDIAMOND_STRUCTS_H
+
+#include "pokemon.h"
+#include "map.h"
+
+#endif //POKEDIAMOND_STRUCTS_H