diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | arm9/Makefile | 27 | ||||
-rw-r--r-- | arm9/arm9.lcf | 56 | ||||
-rw-r--r-- | arm9/lib/include/FS_overlay.h | 25 | ||||
-rw-r--r-- | arm9/modules/00/asm/module_00_dummy.s | 2 | ||||
-rw-r--r-- | arm9/modules/01/src/module_01.c | 12 | ||||
-rw-r--r-- | arm9/modules/01/src/module_01.cpp | 11 | ||||
-rw-r--r-- | arm9/modules/02/asm/module_02_dummy.s | 2 | ||||
-rw-r--r-- | arm9/modules/03/asm/module_03_dummy.s | 2 | ||||
-rw-r--r-- | arm9/modules/04/asm/arm_04.s | 7 | ||||
-rw-r--r-- | tools/scaninc/source_file.cpp | 2 |
11 files changed, 108 insertions, 40 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index d7525783..f2537aad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(PokeDiamond) enable_language(ASM) -file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c") +file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR} "*.c" "*.cpp") add_executable(PokeDiamond ${SOURCES}) target_include_directories(PokeDiamond PRIVATE include include-mw arm9/lib/include) diff --git a/arm9/Makefile b/arm9/Makefile index bc8c8491..16fd7371 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -23,9 +23,9 @@ endif ifeq ($(OS),Windows_NT) EXE := .exe -WINE := +WINE := else -EXE := +EXE := WINE := wine endif @@ -49,12 +49,16 @@ LD_TEMPLATE := ARM9-TS.lcf.template SRC_DIRS := src lib lib/src $(wildcard modules/*/src) ASM_DIRS := asm data files $(wildcard modules/*/asm) -C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) -S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s)) +C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) +CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp)) +S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s)) + +C_OBJS = $(C_FILES:%.c=$(BUILD_DIR)/%.o) +CXX_OBJS = $(CXX_FILES:%.cpp=$(BUILD_DIR)/%.o) +S_OBJS = $(S_FILES:%.s=$(BUILD_DIR)/%.o) # Object files -O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \ - $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \ +O_FILES := $(C_OBJS) $(CXX_OBJS) $(S_OBJS) # Overlay modules # FIXME: lcf doesn't like this @@ -83,6 +87,7 @@ MAKELSF_FLAGS := -DCONST_34=0x34 -DCONST_3F=0x3F AS = $(WINE) $(MWASMARM) CC = $(WINE) $(MWCCARM) +CXX = $(WINE) $(MWCCARM) CPP := cpp -P LD = $(WINE) $(MWLDARM) AR := $(CROSS)ar @@ -92,6 +97,7 @@ OBJCOPY := $(CROSS)objcopy # ./tools/mwccarm/2.0/base/mwasmarm.exe -proc arm5te asm/arm9_thumb.s -o arm9.o ASFLAGS = -proc arm5te -i .. CFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -ir ../include -ir ../include-mw -ir lib/include -interworking -DFS_IMPLEMENT -enum int +CXXFLAGS = -O4,p -proc arm946e -fp soft -lang c99 -Cpp_exceptions off -ir ../include -ir ../include-mw -ir lib/include -interworking -DFS_IMPLEMENT -enum int LDFLAGS = -map -nodead -w off -proc v5te -interworking -map -symtab -m _start ####################### Other Tools ######################### @@ -157,15 +163,18 @@ build/src/FUN_020910A4.o: MWCCVERSION = 1.2/sp2p3 ####################### Everything Else ###################### ifeq (,$(NODEP)) -$(BUILD_DIR)/%.o: dep = $(shell $(SCANINC) -I ../include -I ../include-mw -I lib/include $*.[cs]) +$(BUILD_DIR)/%.o: dep = $(shell $(SCANINC) -I ../include -I ../include-mw -I lib/include $(filter $*.c,$(C_FILES)) $(filter $*.cpp,$(CXX_FILES)) $(filter $*.s,$(S_FILES))) else $(BUILD_DIR)/%.o: dep := endif -$(BUILD_DIR)/%.o: %.c $$(dep) +$(C_OBJS): $(BUILD_DIR)/%.o: %.c $$(dep) $(CC) -c $(CFLAGS) -o $@ $< -$(BUILD_DIR)/%.o: %.s $$(dep) +$(CXX_OBJS): $(BUILD_DIR)/%.o: %.cpp $$(dep) + $(CXX) -c $(CXXFLAGS) -o $@ $< + +$(S_OBJS): $(BUILD_DIR)/%.o: %.s $$(dep) $(AS) $(ASFLAGS) -o $@ $< $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) $(LD_TEMPLATE) undefined_syms.txt macros.lcf.inc diff --git a/arm9/arm9.lcf b/arm9/arm9.lcf index f42348be..0269d601 100644 --- a/arm9/arm9.lcf +++ b/arm9/arm9.lcf @@ -410,6 +410,14 @@ SECTIONS { ALIGNALL(4); . = ALIGN(32); SDK_OVERLAY.MODULE_00.START = .; module_00_dummy.o (.text) + module_00_dummy.o (.rodata) + module_00_dummy.o (.init) + SDK_OVERLAY.MODULE_00.SINIT_START = .; + module_00_dummy.o (.ctor) + module_00_dummy.o (.sinit) + WRITEW 0; + SDK_OVERLAY.MODULE_00.SINIT_END = .; + . = ALIGN(32); module_00_dummy.o (.sdata) module_00_dummy.o (.data) SDK_OVERLAY.MODULE_00.END = .; @@ -430,8 +438,17 @@ SECTIONS { ALIGNALL(4); . = ALIGN(32); SDK_OVERLAY.MODULE_01.START = .; module_01.o (.text) + module_01.o (.rodata) + module_01.o (.init) + SDK_OVERLAY.MODULE_01.SINIT_START = .; + module_01.o (.ctor) + module_01.o (.sinit) + WRITEW 0; + SDK_OVERLAY.MODULE_01.SINIT_END = .; + . = ALIGN(32); module_01.o (.sdata) module_01.o (.data) + . = ALIGN(32); SDK_OVERLAY.MODULE_01.END = .; SDK_OVERLAY.MODULE_01.SIZE = SDK_OVERLAY.MODULE_01.END - SDK_OVERLAY.MODULE_01.START; } > MODULE_01 @@ -441,6 +458,7 @@ SECTIONS { SDK_OVERLAY.MODULE_01.BSS_START = .; module_01.o (.sbss) module_01.o (.bss) + . = ALIGN(32); SDK_OVERLAY.MODULE_01.BSS_END = .; SDK_OVERLAY.MODULE_01.BSS_SIZE = SDK_OVERLAY.MODULE_01.BSS_END - SDK_OVERLAY.MODULE_01.BSS_START; } >> MODULE_01 @@ -450,6 +468,13 @@ SECTIONS { ALIGNALL(4); . = ALIGN(32); SDK_OVERLAY.MODULE_02.START = .; module_02_dummy.o (.text) + module_02_dummy.o (.rodata) + SDK_OVERLAY.MODULE_02.SINIT_START = .; + module_02_dummy.o (.ctor) + module_02_dummy.o (.sinit) + WRITEW 0; + SDK_OVERLAY.MODULE_02.SINIT_END = .; + . = ALIGN(32); module_02_dummy.o (.sdata) module_02_dummy.o (.data) SDK_OVERLAY.MODULE_02.END = .; @@ -470,6 +495,14 @@ SECTIONS { ALIGNALL(4); . = ALIGN(32); SDK_OVERLAY.MODULE_03.START = .; module_03_dummy.o (.text) + module_03_dummy.o (.rodata) + module_03_dummy.o (.init) + SDK_OVERLAY.MODULE_03.SINIT_START = .; + module_03_dummy.o (.ctor) + module_03_dummy.o (.sinit) + WRITEW 0; + SDK_OVERLAY.MODULE_03.SINIT_END = .; + . = ALIGN(32); module_03_dummy.o (.sdata) module_03_dummy.o (.data) SDK_OVERLAY.MODULE_03.END = .; @@ -491,10 +524,20 @@ SECTIONS { SDK_OVERLAY.MODULE_04.START = .; thumb_04.o (.text) arm_04.o (.text) - thumb_04.o (.sdata) - arm_04.o (.sdata) thumb_04.o (.rodata) arm_04.o (.rodata) + thumb_04.o (.init) + arm_04.o (.init) + SDK_OVERLAY.MODULE_04.SINIT_START = .; + thumb_04.o (.ctor) + arm_04.o (.ctor) + thumb_04.o (.sinit) + arm_04.o (.sinit) + WRITEW 0; + SDK_OVERLAY.MODULE_04.SINIT_END = .; + . = ALIGN(32); + thumb_04.o (.sdata) + arm_04.o (.sdata) thumb_04.o (.data) arm_04.o (.data) SDK_OVERLAY.MODULE_04.END = .; @@ -2264,7 +2307,14 @@ SECTIONS { .arm9_table : { OVERLAY_TABLE(MODULE_00, 0) - OVERLAY_TABLE(MODULE_01, 1) + WRITEW SDK_OVERLAY_MODULE_01_ID; + WRITEW SDK_OVERLAY.MODULE_01.START; + WRITEW SDK_OVERLAY.MODULE_01.SIZE; + WRITEW SDK_OVERLAY.MODULE_01.BSS_SIZE; + WRITEW SDK_OVERLAY.MODULE_01.SINIT_START; + WRITEW SDK_OVERLAY.MODULE_01.SINIT_END; + WRITEW SDK_OVERLAY_MODULE_01_ID; + WRITEW 0; OVERLAY_TABLE(MODULE_02, 2) OVERLAY_TABLE(MODULE_03, 3) OVERLAY_TABLE(MODULE_04, 4) diff --git a/arm9/lib/include/FS_overlay.h b/arm9/lib/include/FS_overlay.h index 6025d04a..fd1e2900 100644 --- a/arm9/lib/include/FS_overlay.h +++ b/arm9/lib/include/FS_overlay.h @@ -1,6 +1,10 @@ #ifndef NITRO_FS_OVERLAY_H_ #define NITRO_FS_OVERLAY_H_ +#if defined(__cplusplus) +extern "C" { +#endif + #include "nitro.h" #include "MI_exMemory.h" #include "FS_file.h" @@ -8,7 +12,7 @@ typedef u32 FSOverlayID; -typedef void (*FSOverlayInitFunc) (void); +typedef void (*FSOverlayInitFunc)(void); typedef struct FSOverlayInfoHeader { @@ -19,8 +23,8 @@ typedef struct FSOverlayInfoHeader FSOverlayInitFunc *sinit_init; FSOverlayInitFunc *sinit_init_end; u32 file_id; - u32 compressed:24; - u32 flag:8; + u32 compressed: 24; + u32 flag: 8; } FSOverlayInfoHeader; typedef struct FSOverlayInfo @@ -30,26 +34,35 @@ typedef struct FSOverlayInfo CARDRomRegion file_pos; } FSOverlayInfo; -static inline u8 *const FS_GetOverlayAddress(FSOverlayInfo * p_ovi) +static inline u8 *const FS_GetOverlayAddress(FSOverlayInfo *p_ovi) { return p_ovi->header.ram_address; } -static inline u32 const FS_GetOverlayImageSize(FSOverlayInfo * p_ovi) +static inline u32 const FS_GetOverlayImageSize(FSOverlayInfo *p_ovi) { return p_ovi->header.ram_size; } -static inline u32 const FS_GetOverlayTotalSize(FSOverlayInfo * p_ovi) +static inline u32 const FS_GetOverlayTotalSize(FSOverlayInfo *p_ovi) { return p_ovi->header.ram_size + p_ovi->header.bss_size; } BOOL FS_LoadOverlayInfo(FSOverlayInfo *p_ovi, MIProcessor target, FSOverlayID id); + BOOL FS_LoadOverlay(MIProcessor target, FSOverlayID id); + BOOL FS_UnloadOverlay(MIProcessor target, FSOverlayID id); + BOOL FS_LoadOverlayImage(FSOverlayInfo *p_ovi); + void FS_StartOverlay(FSOverlayInfo *p_ovi); + BOOL FS_LoadOverlayImageAsync(FSOverlayInfo *p_ovi, FSFile *p_file); +#if defined(__cplusplus) +}; +#endif + #endif //NITRO_FS_OVERLAY_H_ diff --git a/arm9/modules/00/asm/module_00_dummy.s b/arm9/modules/00/asm/module_00_dummy.s index e8a42167..e69de29b 100644 --- a/arm9/modules/00/asm/module_00_dummy.s +++ b/arm9/modules/00/asm/module_00_dummy.s @@ -1,2 +0,0 @@ - .section .data - .space 32 diff --git a/arm9/modules/01/src/module_01.c b/arm9/modules/01/src/module_01.c deleted file mode 100644 index ae2e9d1f..00000000 --- a/arm9/modules/01/src/module_01.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "global.h" - -u32 UNK_021D7500[8]; - -THUMB_FUNC void MOD01_021D74E0(void) -{ - UNK_021D7500[1]++; -} - -THUMB_FUNC void (*UNK_021D74F0[4])(void) = { - MOD01_021D74E0 -}; diff --git a/arm9/modules/01/src/module_01.cpp b/arm9/modules/01/src/module_01.cpp new file mode 100644 index 00000000..21b371e0 --- /dev/null +++ b/arm9/modules/01/src/module_01.cpp @@ -0,0 +1,11 @@ +#include "global.h" +#include "FS_overlay.h" + +class Unk021D7500 { + u32 unk0; + u32 unk4; +public: + THUMB_FUNC Unk021D7500() { unk4++; } +}; + +static class Unk021D7500 UNK_021D7500; diff --git a/arm9/modules/02/asm/module_02_dummy.s b/arm9/modules/02/asm/module_02_dummy.s index e8a42167..e69de29b 100644 --- a/arm9/modules/02/asm/module_02_dummy.s +++ b/arm9/modules/02/asm/module_02_dummy.s @@ -1,2 +0,0 @@ - .section .data - .space 32 diff --git a/arm9/modules/03/asm/module_03_dummy.s b/arm9/modules/03/asm/module_03_dummy.s index e8a42167..e69de29b 100644 --- a/arm9/modules/03/asm/module_03_dummy.s +++ b/arm9/modules/03/asm/module_03_dummy.s @@ -1,2 +0,0 @@ - .section .data - .space 32 diff --git a/arm9/modules/04/asm/arm_04.s b/arm9/modules/04/asm/arm_04.s index 8d1d699b..9928ef16 100644 --- a/arm9/modules/04/asm/arm_04.s +++ b/arm9/modules/04/asm/arm_04.s @@ -58938,9 +58938,12 @@ _0220BAB8: mov r0, r2 bx lr - .section .data + .section .rodata ; 0x0220BAC0 - .incbin "baserom.nds", 0x1411e0, 0x4100 + .incbin "baserom.nds", 0x1411e0, 0x3D4 + + .section .data + .incbin "baserom.nds", 0x1415C0, 0x3D20 .section .bss ; 0x0220FBC0 diff --git a/tools/scaninc/source_file.cpp b/tools/scaninc/source_file.cpp index f23ff6db..5d0281a4 100644 --- a/tools/scaninc/source_file.cpp +++ b/tools/scaninc/source_file.cpp @@ -31,7 +31,7 @@ SourceFileType GetFileType(std::string& path) std::string extension = path.substr(pos + 1); - if (extension == "c") + if (extension == "c" || extension == "cpp") return SourceFileType::Cpp; else if (extension == "s") return SourceFileType::Asm; |