From c643999c778a413be9d2dc9c85719965e666cc0e Mon Sep 17 00:00:00 2001 From: David Date: Sat, 17 Jun 2023 16:43:20 -0500 Subject: [PATCH] Added syntax to RAM_POS for conditionally including a source file --- Makefile | 2 +- include/config.h | 9 +++++++++ src/memory.c | 9 ++------- src/memory.h | 7 ++++++- tools/python/generate_ld.py | 27 +++++++++++++++++++++++++-- 5 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 include/config.h diff --git a/Makefile b/Makefile index 0c2d8599..8379b389 100755 --- a/Makefile +++ b/Makefile @@ -147,7 +147,7 @@ endif AS = $(CROSS)as CC := $(RECOMP_DIR)cc -CPP := cpp -P -Wno-trigraphs +CPP := cpp -P -Wno-trigraphs -I include LD = $(CROSS)ld OBJDUMP = $(CROSS)objdump # Pad to 12MB if matching, otherwise build to a necessary minimum of 1.04KB diff --git a/include/config.h b/include/config.h new file mode 100644 index 00000000..fdccf88e --- /dev/null +++ b/include/config.h @@ -0,0 +1,9 @@ +#ifndef CONFIG_H +#define CONFIG_H + +/*** This file should contain defines used for modded repos. ***/ + +/* -------------------------Memory------------------------ */ +//#define EXPANSION_PAK_SUPPORT // Allow the game to use the expansion pak if it's inserted. + +#endif // CONFIG_H diff --git a/src/memory.c b/src/memory.c index d12cacb3..534152b5 100644 --- a/src/memory.c +++ b/src/memory.c @@ -50,14 +50,9 @@ extern MemoryPoolSlot gMainMemoryPool; * Official Name: mmInit */ void init_main_memory_pool(void) { - s32 ramEnd; gNumberOfMemoryPools = -1; - if (FALSE) { - ramEnd = EXTENDED_RAM_END; //Value from JFG, not required to match - } else { - ramEnd = RAM_END; - } - new_memory_pool(&gMainMemoryPool, ramEnd - (s32)(&gMainMemoryPool), MAIN_POOL_SLOT_COUNT); + if (1) {} // Fakematch + new_memory_pool(&gMainMemoryPool, RAM_END - (s32)(&gMainMemoryPool), MAIN_POOL_SLOT_COUNT); set_free_queue_state(2); gFreeQueueCount = 0; } diff --git a/src/memory.h b/src/memory.h index e410caa8..6c27f9ed 100644 --- a/src/memory.h +++ b/src/memory.h @@ -4,9 +4,14 @@ #include "structs.h" #include "types.h" #include "macros.h" +#include "config.h" +#ifdef EXPANSION_PAK_SUPPORT +#define RAM_END 0x80800000 +#else #define RAM_END 0x80400000 -#define EXTENDED_RAM_END 0x80800000 +#endif + #define MAIN_POOL_SLOT_COUNT 1600 // Animation related? diff --git a/tools/python/generate_ld.py b/tools/python/generate_ld.py index ef951d60..91cc362e 100644 --- a/tools/python/generate_ld.py +++ b/tools/python/generate_ld.py @@ -46,6 +46,8 @@ class GenerateLD: self.gen_comment('linker script generated by generate_ld.py') self.gen_comment('If you want to make any changes, then edit the generate_ld.py script!') self.gen_newline() + self.gen_line('#include "config.h"') + self.gen_newline() self.gen_line('OUTPUT_ARCH (mips)') self.gen_newline() self.gen_sections() @@ -85,7 +87,12 @@ class GenerateLD: self.gen_line('.main __FUNC_RAM_START : AT(romPos) SUBALIGN(16)') self.gen_open_block() for file in self.files: + condition = file[4] + if condition != None: + self.gen_line('#if ' + condition) self.gen_line(file[0] + '(.text);') + if condition != None: + self.gen_line('#endif') self.gen_close_block() self.gen_line('romPos += SIZEOF(.main);') self.gen_newline() @@ -102,8 +109,13 @@ class GenerateLD: self.gen_line('.data . : AT(romPos) SUBALIGN(16)') self.gen_open_block() for file in self.files: + condition = file[4] if file[0] not in LATE_DATA_FILES: + if condition != None: + self.gen_line('#if ' + condition) self.gen_line(file[0] + '(.data);') + if condition != None: + self.gen_line('#endif') for file in LATE_DATA_FILES: self.gen_line(file + '(.data);') self.gen_close_block() @@ -115,12 +127,17 @@ class GenerateLD: self.gen_open_block() for file in self.files: f = file[0] + condition = file[4] if f not in LATE_DATA_FILES: + if condition != None: + self.gen_line('#if ' + condition) self.gen_line(f + '(.rodata);') fname = f[f.rindex('/')+1:f.rindex('.')] testName = DATA_DIR + '/' + fname + '.rodata.s' if FileUtil.does_file_exist(testName): self.gen_line(BUILD_DIR + '/data/' + fname + '.rodata.o(.rodata);') + if condition != None: + self.gen_line('#endif') for f in LATE_DATA_FILES: self.gen_line(f + '(.rodata);') fname = f[f.rindex('/')+1:f.rindex('.')] @@ -145,8 +162,13 @@ class GenerateLD: self.gen_line('.bss.noload . (NOLOAD): SUBALIGN(4)') self.gen_open_block() for file in self.files: + condition = file[4] if file[0] not in BSS_LIB_ORDER_FILES: + if condition != None: + self.gen_line('#if ' + condition) self.gen_line(file[0] + '(.bss);') + if condition != None: + self.gen_line('#endif') for file in BSS_LIB_ORDER_FILES: self.gen_line(file + '(.bss);') self.gen_close_block() @@ -205,7 +227,7 @@ class GenerateLD: def append_files(self, files, extensions, directory, outputDir): filenames = FileUtil.get_filenames_from_directory_recursive(directory, extensions) - regex = r'[\/][*]+\s*RAM_POS:\s*((?:0x)[0-9a-fA-F]+|(?:[Aa][Uu][Tt][Oo]))\s*[*]+[\/]' + regex = r'[\/][*]+\s*RAM_POS:\s*((?:0x)[0-9a-fA-F]+|(?:[Aa][Uu][Tt][Oo]))\s*(?:if\s*(.*))?\s*[*]+[\/]' for filename in filenames: with open(directory + '/' + filename, 'r') as inFile: notDone = True @@ -217,9 +239,10 @@ class GenerateLD: continue matchedGroups = matches.groups() ramPos = matchedGroups[0] + condition = matchedGroups[1] if ramPos.lower() == 'auto': ramPos = '800FFFF0' - files.append((outputDir + filename[:-2] + '.o', '', ramPos, 0)) + files.append((outputDir + filename[:-2] + '.o', '', ramPos, 0, condition)) break def get_code_files(self):