Skip to content

Commit

Permalink
Merge pull request #364 from lhearachel/boot-and-system
Browse files Browse the repository at this point in the history
Document boot.c and system.c
  • Loading branch information
lhearachel authored Feb 8, 2025
2 parents d88cd7f + a6fc5c9 commit 3bf7b14
Show file tree
Hide file tree
Showing 263 changed files with 2,440 additions and 2,542 deletions.
6 changes: 3 additions & 3 deletions docs/3d_rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ angle = (angle + 100) % 0xFFFF;
Easy3DObject_SetRotation(&giratinaObj, angle, ROTATION_AXIS_Y);
// Resize using L and R
if (gCoreSys.heldKeys & PAD_BUTTON_R) {
if (gSystem.heldKeys & PAD_BUTTON_R) {
VecFx32 scale;
Easy3DObject_GetScale(&giratinaObj, &scale.x, &scale.y, &scale.z);
scale.x = FX_Mul(scale.x, FX32_CONST(1.01));
scale.y = FX_Mul(scale.y, FX32_CONST(1.01));
scale.z = FX_Mul(scale.z, FX32_CONST(1.01));
Easy3DObject_SetScale(&giratinaObj, scale.x, scale.y, scale.z);
} else if (gCoreSys.heldKeys & PAD_BUTTON_L) {
} else if (gSystem.heldKeys & PAD_BUTTON_L) {
VecFx32 scale;
Easy3DObject_GetScale(&giratinaObj, &scale.x, &scale.y, &scale.z);
scale.x = FX_Mul(scale.x, FX32_CONST(0.99));
scale.y = FX_Mul(scale.y, FX32_CONST(0.99));
scale.z = FX_Mul(scale.z, FX32_CONST(0.99));
Easy3DObject_SetScale(&giratinaObj, scale.x, scale.y, scale.z);
}
```
```
7 changes: 7 additions & 0 deletions include/boot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef POKEPLATINUM_BOOT_H
#define POKEPLATINUM_BOOT_H

void CheckForMemoryTampering(void);
void RebootAndLoadROM(const char *filesystemPath);

#endif // POKEPLATINUM_BOOT_H
7 changes: 7 additions & 0 deletions include/constants/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ enum HeapId {
HEAP_ID_GAME_START = 77,

HEAP_ID_LIBRARY_TV = 120,

HEAP_ID_MAX = 123,
};

enum HeapSize {
HEAP_SIZE_SYSTEM = 0xD200,
HEAP_SIZE_SAVE = 0x20E00,
HEAP_SIZE_DEBUG = 0x10,
HEAP_SIZE_APPLICATION = 0x10D800,

HEAP_SIZE_POKETCH_MAIN = 0xC000,
HEAP_SIZE_POKETCH_APP = 0xC000,

Expand Down
62 changes: 0 additions & 62 deletions include/core_sys.h

This file was deleted.

8 changes: 5 additions & 3 deletions include/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

#include <nnsys.h>

#include "constants/heap.h"

#include "struct_defs/struct_02017E74.h"
typedef struct HeapParam {
u32 size;
OSArenaId arena;
} HeapParam;

void Heap_InitSystem(const HeapParam *templates, u32 nTemplates, u32 totalNumHeaps, u32 preSize);
BOOL Heap_Create(u32 parent, u32 child, u32 size);
BOOL Heap_CreateAtEnd(u32 parent, u32 child, u32 size);
void Heap_Destroy(u32 heapID);
Expand Down
4 changes: 2 additions & 2 deletions include/overlay021/ov21_021D423C.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef POKEPLATINUM_OV21_021D423C_H
#define POKEPLATINUM_OV21_021D423C_H

#include "constants/heap.h"

#include "overlay021/struct_ov21_021D423C_decl.h"
#include "overlay021/struct_ov21_021D4660.h"

#include "heap.h"

UnkStruct_ov21_021D423C *ov21_021D423C(enum HeapId heapID);
void ov21_021D426C(UnkStruct_ov21_021D423C *param0, UnkStruct_ov21_021D4660 *param1, int param2);
const UnkStruct_ov21_021D4660 *ov21_021D4284(UnkStruct_ov21_021D423C *param0, int param1);
Expand Down
4 changes: 2 additions & 2 deletions include/overlay021/ov21_021D4340.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#ifndef POKEPLATINUM_OV21_021D4340_H
#define POKEPLATINUM_OV21_021D4340_H

#include "constants/heap.h"

#include "overlay021/struct_ov21_021D0F60_decl.h"
#include "overlay021/struct_ov21_021D4340_1.h"
#include "overlay021/struct_ov21_021D4660.h"

#include "heap.h"

BOOL ov21_021D4340(UnkStruct_ov21_021D4340_1 *param0);
BOOL ov21_021D43A8(UnkStruct_ov21_021D4340_1 *param0);
BOOL ov21_021D4434(UnkStruct_ov21_021D4340_1 *param0);
Expand Down
4 changes: 2 additions & 2 deletions include/overlay021/ov21_021D4EE4.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef POKEPLATINUM_OV21_021D4EE4_H
#define POKEPLATINUM_OV21_021D4EE4_H

#include "constants/heap.h"

#include "overlay021/struct_ov21_021D4EE4_decl.h"
#include "overlay021/struct_ov21_021D4FE4.h"

#include "heap.h"

UnkStruct_ov21_021D4EE4 *ov21_021D4EE4(enum HeapId heapID);
void ov21_021D4EFC(UnkStruct_ov21_021D4EE4 *param0);
void ov21_021D4F04(UnkStruct_ov21_021D4EE4 *param0, const UnkStruct_ov21_021D4FE4 *param1, int param2, int param3);
Expand Down
3 changes: 2 additions & 1 deletion include/overlay021/pokedex_sort.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef POKEPLATINUM_POKEDEXSORT_H
#define POKEPLATINUM_POKEDEXSORT_H

#include "constants/heap.h"

#include "overlay021/species_caught_status.h"
#include "overlay021/struct_ov21_021D3208.h"
#include "overlay021/struct_ov21_021D3320.h"

#include "heap.h"
#include "strbuf.h"

enum SortOrder {
Expand Down
3 changes: 2 additions & 1 deletion include/overlay021/pokedex_text.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#ifndef POKEPLATINUM_POKEDEX_TEXT_H
#define POKEPLATINUM_POKEDEX_TEXT_H

#include "heap.h"
#include "constants/heap.h"

#include "strbuf.h"

void PokedexText_Free(Strbuf *strbuf);
Expand Down
6 changes: 0 additions & 6 deletions include/overlay023/funcptr_ov23_022537D4.h

This file was deleted.

11 changes: 0 additions & 11 deletions include/struct_defs/struct_02017E74.h

This file was deleted.

88 changes: 88 additions & 0 deletions include/system.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef POKEPLATINUM_SYSTEM_H
#define POKEPLATINUM_SYSTEM_H

#include "constants/heap.h"

#include "sys_task_manager.h"

typedef void (*Callback)(void *);
typedef void (*UnkCallback)(void);

enum ButtonMode {
BUTTON_MODE_NORMAL = 0,
BUTTON_MODE_START_IS_X = 1,
BUTTON_MODE_SWAP_XY = 2,
BUTTON_MODE_L_IS_A = 3,
};

enum SleepType {
SLEEP_TYPE_SAVE_DATA = 1,
};

#define PAD_KEY (PAD_KEY_UP | PAD_KEY_DOWN | PAD_KEY_LEFT | PAD_KEY_RIGHT)
#define JOY_NEW(buttons) (gSystem.pressedKeys & (buttons))
#define JOY_HELD(buttons) (gSystem.heldKeys & (buttons))
#define JOY_REPEAT(buttons) (gSystem.pressedKeysRepeatable & (buttons))

typedef struct System {
Callback vblankCallback;
void *vblankCallbackData;
Callback hblankCallback;
void *hblankCallbackData;
UnkCallback dummyCallback_10;
UnkCallback dummyCallback_14;
SysTaskManager *mainTaskMgr;
SysTaskManager *vBlankTaskMgr;
SysTaskManager *postVBlankTaskMgr;
SysTaskManager *printTaskMgr;
u32 *unused_28;
u32 vblankCounter;
u32 frameCounter;
enum ButtonMode buttonMode;
u32 heldKeysRaw;
u32 pressedKeysRaw;
u32 pressedKeysRepeatableRaw;
u32 heldKeys;
u32 pressedKeys;
u32 pressedKeysRepeatable;
int autorepeatTimer;
int autorepeatRate;
int autorepeatDelay;
u16 touchX;
u16 touchY;
u16 touchPressed;
u16 touchHeld;
u8 touchAutoSampling;
u8 whichScreenIs3D;
u8 gbaCartridgeVersion;
u8 inhibitSleep;
u8 inhibitReset;
u8 padding_69[3];
BOOL unk_6C;
u32 *heapCanary;
} System;

extern System gSystem;

void SetDummyVBlankIntr(void);
void SetVBlankCallback(Callback cb, void *data);
void DisableHBlank(void);
BOOL SetHBlankCallback(Callback cb, void *data);
void InitSystem(void);
void InitVRAM(void);
void *ReadFileToHeap(int heapID, const char *filename);
void ReadFileToBuffer(const char *filename, void **buf);
void ClearUnusedSystemCache(void);
void InitKeypadAndTouchpad(void);
void SetGBACartridgeVersion(int version);
void SleepLock(u8 mask);
void SleepUnlock(u8 mask);
void ReadKeypadAndTouchpad(void);
void SetAutorepeat(int rate, int delay);
void ResetLock(u8 mask);
void ResetUnlock(u8 mask);
void InitHeapCanary(enum HeapId param0);
void FreeHeapCanary(void);
BOOL HeapCanaryOK(void);

#endif // POKEPLATINUM_SYSTEM_H
27 changes: 0 additions & 27 deletions include/unk_02017728.h

This file was deleted.

7 changes: 0 additions & 7 deletions include/unk_02024358.h

This file was deleted.

4 changes: 2 additions & 2 deletions platinum.us/main.lsf
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Static main
Object main.nef.p/src_easy3d_object.c.o
Object main.nef.p/src_unk_02017428.c.o
Object main.nef.p/src_unk_02017498.c.o
Object main.nef.p/src_unk_02017728.c.o
Object main.nef.p/src_system.c.o
Object main.nef.p/src_heap.c.o
Object main.nef.p/src_bg_window.c.o
Object main.nef.p/src_easy3d.c.o
Expand Down Expand Up @@ -101,7 +101,7 @@ Static main
Object main.nef.p/src_unk_0202419C.c.o
Object main.nef.p/src_hardware_palette.c.o
Object main.nef.p/src_unk_02024220.c.o
Object main.nef.p/src_unk_02024358.c.o
Object main.nef.p/src_boot.c.o
Object main.nef.p/src_savedata_save_table.c.o
Object main.nef.p/src_savedata.c.o
Object main.nef.p/src_system_data.c.o
Expand Down
Loading

0 comments on commit 3bf7b14

Please sign in to comment.