diff --git a/Makefile b/Makefile index 6f8951d378..52bfe1e93f 100644 --- a/Makefile +++ b/Makefile @@ -41,11 +41,16 @@ REVISION := 0 TEST ?= 0 ANALYZE ?= 0 UNUSED_ERROR ?= 0 +DEBUG ?= 0 ifeq (check,$(MAKECMDGOALS)) TEST := 1 endif +ifeq (debug,$(MAKECMDGOALS)) + DEBUG := 1 +endif + CPP := $(PREFIX)cpp ROM_NAME := pokeemerald.gba @@ -60,6 +65,7 @@ MAP = $(ROM:.gba=.map) SYM = $(ROM:.gba=.sym) TEST_OBJ_DIR_NAME := build/modern-test +DEBUG_OBJ_DIR_NAME := build/modern-debug TESTELF = $(ROM:.gba=-test.elf) HEADLESSELF = $(ROM:.gba=-test-headless.elf) @@ -86,7 +92,8 @@ TEST_BUILDDIR = $(OBJ_DIR)/$(TEST_SUBDIR) ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=1 CC1 = $(shell $(PATH_ARMCC) --print-prog-name=cc1) -quiet -override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -std=gnu17 -Werror -Wall -Wno-strict-aliasing -Wno-attribute-alias -Woverride-init +override CFLAGS += -mthumb -mthumb-interwork -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast -std=gnu17 -Werror -Wall -Wno-strict-aliasing -Wno-attribute-alias -Woverride-init + ifeq ($(ANALYZE),1) override CFLAGS += -fanalyzer endif @@ -101,6 +108,12 @@ OBJ_DIR := $(OBJ_DIR_NAME) LIBPATH := -L "$(dir $(shell $(PATH_ARMCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(PATH_ARMCC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(PATH_ARMCC) -mthumb -print-file-name=libc.a))" LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall +ifeq ($(DEBUG),1) +override CFLAGS += -Og -g +else +override CFLAGS += -O2 +endif + ifeq ($(TESTELF),$(MAKECMDGOALS)) TEST := 1 endif @@ -108,6 +121,10 @@ endif ifeq ($(TEST),1) OBJ_DIR := $(TEST_OBJ_DIR_NAME) endif +ifeq ($(DEBUG),1) +OBJ_DIR := $(DEBUG_OBJ_DIR_NAME) +endif + CPPFLAGS := -iquote include -iquote $(GFLIB_SUBDIR) -Wno-trigraphs -DMODERN=1 -DTESTING=$(TEST) @@ -146,7 +163,7 @@ MAKEFLAGS += --no-print-directory # Secondary expansion is required for dependency variables in object rules. .SECONDEXPANSION: -.PHONY: all rom clean compare tidy tools check-tools mostlyclean clean-tools clean-check-tools $(TOOLDIRS) $(CHECKTOOLDIRS) libagbsyscall agbcc modern tidymodern tidynonmodern check history +.PHONY: all rom clean compare tidy tools check-tools mostlyclean clean-tools clean-check-tools $(TOOLDIRS) $(CHECKTOOLDIRS) libagbsyscall agbcc modern tidymodern tidynonmodern check history debug infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line)))) @@ -154,7 +171,7 @@ infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst # Disable dependency scanning for clean/tidy/tools # Use a separate minimal makefile for speed # Since we don't need to reload most of this makefile -ifeq (,$(filter-out all rom compare agbcc modern check libagbsyscall syms $(TESTELF),$(MAKECMDGOALS))) +ifeq (,$(filter-out all rom compare agbcc modern check libagbsyscall syms $(TESTELF) debug,$(MAKECMDGOALS))) $(call infoshell, $(MAKE) -f make_tools.mk) else NODEP ?= 1 @@ -246,7 +263,7 @@ clean-tools: clean-check-tools: @$(foreach tooldir,$(CHECKTOOLDIRS),$(MAKE) clean -C $(tooldir);) -mostlyclean: tidynonmodern tidymodern tidycheck +mostlyclean: tidynonmodern tidymodern tidycheck tidydebug find sound -iname '*.bin' -exec rm {} + rm -f $(MID_SUBDIR)/*.s find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.rl' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} + @@ -256,7 +273,7 @@ mostlyclean: tidynonmodern tidymodern tidycheck rm -f $(AUTO_GEN_TARGETS) @$(MAKE) clean -C libagbsyscall -tidy: tidymodern tidycheck +tidy: tidymodern tidycheck tidydebug tidymodern: rm -f $(ROM_NAME) $(ELF_NAME) $(MAP_NAME) @@ -266,6 +283,8 @@ tidycheck: rm -f $(TESTELF) $(HEADLESSELF) rm -rf $(TEST_OBJ_DIR_NAME) +tidydebug: + rm -rf $(DEBUG_OBJ_DIR_NAME) include graphics_file_rules.mk include map_data_rules.mk @@ -305,6 +324,11 @@ ifeq ($(DINFO),1) override CFLAGS += -g endif +ifeq ($(NOOPT),1) +override CFLAGS := $(filter-out -O1 -Og -O2,$(CFLAGS)) +override CFLAGS += -O0 +endif + # The dep rules have to be explicit or else missing files won't be reported. # As a side effect, they're evaluated immediately instead of when the rule is invoked. # It doesn't look like $(shell) can be deferred so there might not be a better way. @@ -443,6 +467,8 @@ agbcc: modern: all +debug: all + LD_SCRIPT_TEST := ld_script_test.ld $(OBJ_DIR)/ld_script_test.ld: $(LD_SCRIPT_TEST) $(LD_SCRIPT_DEPS) diff --git a/data/scripts/debug.inc b/data/scripts/debug.inc index 12dc693fd0..4851c87c40 100644 --- a/data/scripts/debug.inc +++ b/data/scripts/debug.inc @@ -1,4 +1,3 @@ -.if DEBUG_OVERWORLD_MENU == TRUE Debug_MessageEnd: waitmessage waitbuttonpress @@ -448,5 +447,3 @@ Debug_EventScript_EWRAMCounters:: Debug_EventScript_EWRAMCounters_Text:: .string "Follower Steps: {STR_VAR_1}.\n" .string "Fishing Chain: {STR_VAR_2}.$" - -.endif diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index ffaa058a08..f554da437d 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -196,14 +196,12 @@ void BattleAI_SetupFlags(void) else AI_THINKING_STRUCT->aiFlags[B_POSITION_PLAYER_LEFT] = 0; // player has no AI -#if DEBUG_OVERWORLD_MENU == TRUE - if (gIsDebugBattle) + if (DEBUG_OVERWORLD_MENU && gIsDebugBattle) { AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_LEFT] = gDebugAIFlags; AI_THINKING_STRUCT->aiFlags[B_POSITION_OPPONENT_RIGHT] = gDebugAIFlags; return; } -#endif if (IsWildMonSmart() && !(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_TRAINER))) { diff --git a/src/battle_main.c b/src/battle_main.c index 319c26bcfa..c77c325db2 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -517,9 +517,7 @@ static void CB2_InitBattleInternal(void) gBattle_BG3_X = 0; gBattle_BG3_Y = 0; -#if DEBUG_OVERWORLD_MENU == TRUE - if (!gIsDebugBattle) -#endif + if (!DEBUG_OVERWORLD_MENU || (DEBUG_OVERWORLD_MENU && !gIsDebugBattle)) { gBattleTerrain = BattleSetup_GetTerrainId(); } @@ -552,9 +550,7 @@ static void CB2_InitBattleInternal(void) else SetMainCallback2(CB2_HandleStartBattle); -#if DEBUG_OVERWORLD_MENU == TRUE - if (!gIsDebugBattle) -#endif + if (!DEBUG_OVERWORLD_MENU || (DEBUG_OVERWORLD_MENU && !gIsDebugBattle)) { if (!(gBattleTypeFlags & (BATTLE_TYPE_LINK | BATTLE_TYPE_RECORDED))) { diff --git a/src/debug.c b/src/debug.c index a2bf55d95a..a3978fbd40 100644 --- a/src/debug.c +++ b/src/debug.c @@ -68,7 +68,6 @@ #include "constants/weather.h" #include "save.h" -#if DEBUG_OVERWORLD_MENU == TRUE // ******************************* enum DebugMenu { @@ -5129,5 +5128,3 @@ static void DebugAction_Util_CheckEWRAMCounters(u8 taskId) { Debug_DestroyMenu_Full_Script(taskId, Debug_EventScript_EWRAMCounters); } - -#endif //DEBUG_OVERWORLD_MENU == TRUE diff --git a/src/field_control_avatar.c b/src/field_control_avatar.c index 582617d555..9452e1273e 100644 --- a/src/field_control_avatar.c +++ b/src/field_control_avatar.c @@ -135,13 +135,14 @@ void FieldGetPlayerInput(struct FieldInput *input, u16 newKeys, u16 heldKeys) else if (heldKeys & DPAD_RIGHT) input->dpadDirection = DIR_EAST; -#if DEBUG_OVERWORLD_MENU == TRUE && DEBUG_OVERWORLD_IN_MENU == FALSE - if ((heldKeys & DEBUG_OVERWORLD_HELD_KEYS) && input->DEBUG_OVERWORLD_TRIGGER_EVENT) + if(DEBUG_OVERWORLD_MENU && !DEBUG_OVERWORLD_IN_MENU) { - input->input_field_1_2 = TRUE; - input->DEBUG_OVERWORLD_TRIGGER_EVENT = FALSE; + if ((heldKeys & DEBUG_OVERWORLD_HELD_KEYS) && input->DEBUG_OVERWORLD_TRIGGER_EVENT) + { + input->input_field_1_2 = TRUE; + input->DEBUG_OVERWORLD_TRIGGER_EVENT = FALSE; + } } -#endif } int ProcessPlayerFieldInput(struct FieldInput *input) @@ -201,15 +202,13 @@ int ProcessPlayerFieldInput(struct FieldInput *input) if (input->pressedSelectButton && UseRegisteredKeyItemOnField() == TRUE) return TRUE; -#if DEBUG_OVERWORLD_MENU == TRUE && DEBUG_OVERWORLD_IN_MENU == FALSE - if (input->input_field_1_2) + if(input->input_field_1_2 && DEBUG_OVERWORLD_MENU && !DEBUG_OVERWORLD_IN_MENU) { PlaySE(SE_WIN_OPEN); FreezeObjectEvents(); Debug_ShowMainMenu(); return TRUE; } -#endif return FALSE; } diff --git a/src/librfu_rfu.c b/src/librfu_rfu.c index 152bb716e9..cd7cb6cc5a 100644 --- a/src/librfu_rfu.c +++ b/src/librfu_rfu.c @@ -762,7 +762,7 @@ static void rfu_CB_pollConnectParent(u8 reqCommand, u16 reqResult) u16 id; u8 slot; u8 bm_slot_flag, i; - struct RfuTgtData *target_p; + struct RfuTgtData *target_p = NULL; struct RfuTgtData target_local; if (reqResult == 0) diff --git a/src/pokemon_sprite_visualizer.c b/src/pokemon_sprite_visualizer.c index c83716aeda..a0b7ddabc2 100644 --- a/src/pokemon_sprite_visualizer.c +++ b/src/pokemon_sprite_visualizer.c @@ -41,7 +41,6 @@ #include "constants/items.h" #include "constants/event_objects.h" -#if DEBUG_POKEMON_SPRITE_VISUALIZER == TRUE extern const struct BattleBackground sBattleTerrainTable[]; extern const struct CompressedSpriteSheet gSpriteSheet_EnemyShadow; extern const struct SpriteTemplate gSpriteTemplate_EnemyShadow; @@ -1763,5 +1762,3 @@ static void Exit_PokemonSpriteVisualizer(u8 taskId) m4aMPlayVolumeControl(&gMPlayInfo_BGM, TRACKS_ALL, 0x100); } } - -#endif diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index a1ebc2b188..bf6ab45a2a 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -1640,15 +1640,13 @@ static void Task_HandleInput(u8 taskId) PlaySE(SE_SELECT); BeginCloseSummaryScreen(taskId); } - #if DEBUG_POKEMON_SPRITE_VISUALIZER == TRUE - else if (JOY_NEW(SELECT_BUTTON) && !gMain.inBattle) + else if (DEBUG_POKEMON_SPRITE_VISUALIZER && JOY_NEW(SELECT_BUTTON) && !gMain.inBattle) { sMonSummaryScreen->callback = CB2_Pokemon_Sprite_Visualizer; StopPokemonAnimations(); PlaySE(SE_SELECT); CloseSummaryScreen(taskId); } - #endif } } diff --git a/src/start_menu.c b/src/start_menu.c index 0525ccf70d..71ab87363c 100644 --- a/src/start_menu.c +++ b/src/start_menu.c @@ -784,10 +784,11 @@ static bool8 StartMenuDebugCallback(void) RemoveExtraStartMenuWindows(); HideStartMenuDebug(); // Hide start menu without enabling movement -#if DEBUG_OVERWORLD_MENU == TRUE - FreezeObjectEvents(); - Debug_ShowMainMenu(); -#endif + if (DEBUG_OVERWORLD_MENU) + { + FreezeObjectEvents(); + Debug_ShowMainMenu(); + } return TRUE; }