From ec5068c58d3c40d188c9a59791e5562bff38ce3e Mon Sep 17 00:00:00 2001 From: cadmic Date: Sat, 27 Jul 2024 21:46:55 -0700 Subject: [PATCH] Introduce OOT_VERSION and OOT_REGION defines for build info and ROM header (#2003) * Use version defines for build info and ROM header * Use existing REGION_ defines for OOT_REGION instead --- Makefile | 35 +++++++++++++++++++++++++++++------ include/macros.h | 10 ++++++++++ include/region.h | 9 +++++++++ include/z64.h | 8 -------- src/boot/build.c | 13 +++++++++---- src/boot/z_locale.c | 7 ++++--- src/makerom/rom_header.s | 11 +++++++++++ 7 files changed, 72 insertions(+), 21 deletions(-) create mode 100644 include/region.h diff --git a/Makefile b/Makefile index eedf572cf9..1633110862 100644 --- a/Makefile +++ b/Makefile @@ -53,18 +53,25 @@ endif # Version-specific settings ifeq ($(VERSION),gc-us) + REGION := US + PAL := 0 + MQ := 0 DEBUG := 0 - COMPARE := 0 - CPP_DEFINES += -DOOT_NTSC=1 -DOOT_PAL=0 -DOOT_MQ=0 else ifeq ($(VERSION),gc-eu) + REGION := EU + PAL := 1 + MQ := 0 DEBUG := 0 - CPP_DEFINES += -DOOT_NTSC=0 -DOOT_PAL=1 -DOOT_MQ=0 else ifeq ($(VERSION),gc-eu-mq) + REGION := EU + PAL := 1 + MQ := 1 DEBUG := 0 - CPP_DEFINES += -DOOT_NTSC=0 -DOOT_PAL=1 -DOOT_MQ=1 else ifeq ($(VERSION),gc-eu-mq-dbg) + REGION := EU + PAL := 1 + MQ := 1 DEBUG := 1 - CPP_DEFINES += -DOOT_NTSC=0 -DOOT_PAL=1 -DOOT_MQ=1 else $(error Unsupported version $(VERSION)) endif @@ -79,11 +86,27 @@ VENV := .venv MAKE = make CPPFLAGS += -P -xc -fno-dollars-in-identifiers +# Converts e.g. ntsc-1.0 to OOT_NTSC_1_0 +CPP_DEFINES += -DOOT_VERSION=OOT_$(shell echo $(VERSION) | tr a-z-. A-Z__) +CPP_DEFINES += -DOOT_REGION=REGION_$(REGION) + +ifeq ($(PAL),0) + CPP_DEFINES += -DOOT_NTSC=1 +else + CPP_DEFINES += -DOOT_PAL=1 +endif + +ifeq ($(MQ),0) + CPP_DEFINES += -DOOT_MQ=0 +else + CPP_DEFINES += -DOOT_MQ=1 +endif + ifeq ($(DEBUG),1) CPP_DEFINES += -DOOT_DEBUG=1 OPTFLAGS := -O2 else - CPP_DEFINES += -DNDEBUG -DOOT_DEBUG=0 + CPP_DEFINES += -DOOT_DEBUG=0 -DNDEBUG OPTFLAGS := -O2 -g3 endif diff --git a/include/macros.h b/include/macros.h index e135934060..ed67abc4ac 100644 --- a/include/macros.h +++ b/include/macros.h @@ -1,6 +1,16 @@ #ifndef MACROS_H #define MACROS_H +// OOT versions in build order +#define OOT_GC_JP 1 +#define OOT_GC_JP_MQ 2 +#define OOT_GC_US 3 +#define OOT_GC_US_MQ 4 +#define OOT_GC_EU_MQ_DBG 5 +#define OOT_GC_EU 6 +#define OOT_GC_EU_MQ 7 +#define OOT_GC_JP_CE 8 + #ifndef AVOID_UB #define BAD_RETURN(type) type #else diff --git a/include/region.h b/include/region.h new file mode 100644 index 0000000000..b33375e6f5 --- /dev/null +++ b/include/region.h @@ -0,0 +1,9 @@ +#ifndef REGION_H +#define REGION_H + +#define REGION_NULL 0 +#define REGION_JP 1 +#define REGION_US 2 +#define REGION_EU 3 + +#endif diff --git a/include/z64.h b/include/z64.h index 03ef633b7f..7e0b60ee5e 100644 --- a/include/z64.h +++ b/include/z64.h @@ -70,11 +70,6 @@ #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 -#define REGION_NULL 0 -#define REGION_JP 1 -#define REGION_US 2 -#define REGION_EU 3 - #define THREAD_PRI_IDLE_INIT 10 #define THREAD_PRI_MAIN_INIT 10 #define THREAD_PRI_DMAMGR_LOW 10 // Used when decompressing files @@ -104,9 +99,6 @@ #define STACK_TOP(stack) \ ((u8*)(stack) + sizeof(stack)) -// NOTE: Once we start supporting other builds, this can be changed with an ifdef -#define REGION_NATIVE REGION_EU - typedef struct { /* 0x00 */ void* loadedRamAddr; /* 0x04 */ RomFile file; diff --git a/src/boot/build.c b/src/boot/build.c index d2fb891c0c..a69c28d1f3 100644 --- a/src/boot/build.c +++ b/src/boot/build.c @@ -1,12 +1,17 @@ +#include "macros.h" + const char gBuildTeam[] = "zelda@srd022j"; -// TODO: Use per-version preprocessor defines -#if OOT_DEBUG // gc-eu-mq-dbg +#if OOT_VERSION == OOT_GC_US +const char gBuildDate[] = "02-12-19 13:28:09"; +#elif OOT_VERSION == OOT_GC_EU_MQ_DBG const char gBuildDate[] = "03-02-21 00:16:31"; -#elif !OOT_MQ // gc-eu +#elif OOT_VERSION == OOT_GC_EU const char gBuildDate[] = "03-02-21 20:12:23"; -#else // gc-eu-mq +#elif OOT_VERSION == OOT_GC_EU_MQ const char gBuildDate[] = "03-02-21 20:37:19"; +#else +#error "Unsupported OOT_VERSION" #endif const char gBuildMakeOption[] = ""; diff --git a/src/boot/z_locale.c b/src/boot/z_locale.c index abff2ba77e..acd151ce40 100644 --- a/src/boot/z_locale.c +++ b/src/boot/z_locale.c @@ -1,4 +1,5 @@ #include "global.h" +#include "region.h" #include "terminal.h" u32 gCurrentRegion = 0; @@ -35,7 +36,7 @@ void Locale_ResetRegion(void) { #if OOT_DEBUG u32 func_80001F48(void) { - if (gCurrentRegion == REGION_NATIVE) { + if (gCurrentRegion == OOT_REGION) { return 0; } @@ -47,7 +48,7 @@ u32 func_80001F48(void) { } u32 func_80001F8C(void) { - if (gCurrentRegion == REGION_NATIVE) { + if (gCurrentRegion == OOT_REGION) { return 0; } @@ -60,6 +61,6 @@ u32 func_80001F8C(void) { // This function appears to be unused? u32 Locale_IsRegionNative(void) { - return gCurrentRegion == REGION_NATIVE; + return gCurrentRegion == OOT_REGION; } #endif diff --git a/src/makerom/rom_header.s b/src/makerom/rom_header.s index ec243cc9cb..06694ae35e 100644 --- a/src/makerom/rom_header.s +++ b/src/makerom/rom_header.s @@ -1,4 +1,5 @@ #include "rom_header.h" +#include "region.h" /* 0x00 */ ENDIAN_IDENTIFIER /* 0x01 */ PI_DOMAIN_1_CFG(64, 18, 7, 3) @@ -9,7 +10,17 @@ /* 0x18 */ PADDING(8) /* 0x20 */ ROM_NAME("THE LEGEND OF ZELDA") /* 0x34 */ PADDING(7) +#if OOT_NTSC +/* 0x3B */ MEDIUM(CARTRIDGE_EXPANDABLE) +#else /* 0x3B */ MEDIUM(CARTRIDGE) +#endif /* 0x3C */ GAME_ID("ZL") +#if OOT_REGION == REGION_US +/* 0x3E */ REGION(US) +#elif OOT_REGION == REGION_JP +/* 0x3E */ REGION(JP) +#elif OOT_REGION == REGION_EU /* 0x3E */ REGION(PAL) +#endif /* 0x3F */ GAME_REVISION(15)