From 10c0566121cb923b7f4e6c1a97a1df8ad70cb327 Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Tue, 19 Jan 2021 11:43:50 -0500 Subject: [PATCH 01/18] Don't keep temporary C build files by default. --- Makefile | 10 ++++++++ tools/preproc/c_file.cpp | 54 +++++++++++++++++++++++++++++---------- tools/preproc/c_file.h | 5 +++- tools/preproc/preproc.cpp | 22 +++++++++++----- 4 files changed, 70 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 3bb5161e31..3383cb14dd 100644 --- a/Makefile +++ b/Makefile @@ -283,10 +283,15 @@ override CFLAGS += -g endif $(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $$(c_dep) +ifeq (,$(KEEP_TEMPS)) + @echo "$(CC1) -o $@ $<" + @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | { $(CC1) $(CFLAGS) -o - -; echo -e ".text\n\t.align\t2, 0"; } | $(AS) $(ASFLAGS) -o $@ - +else @$(CPP) $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i @$(PREPROC) $(C_BUILDDIR)/$*.i charmap.txt | $(CC1) $(CFLAGS) -o $(C_BUILDDIR)/$*.s @echo -e ".text\n\t.align\t2, 0\n" >> $(C_BUILDDIR)/$*.s $(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s +endif ifeq ($(NODEP),1) $(GFLIB_BUILDDIR)/%.o: c_dep := @@ -295,10 +300,15 @@ $(GFLIB_BUILDDIR)/%.o: c_dep = $(shell [[ -f $(GFLIB_SUBDIR)/$*.c ]] && $(SCANIN endif $(GFLIB_BUILDDIR)/%.o : $(GFLIB_SUBDIR)/%.c $$(c_dep) +ifeq (,$(KEEP_TEMPS)) + @echo "$(CC1) -o $@ $<" + @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | { $(CC1) $(CFLAGS) -o - -; echo -e ".text\n\t.align\t2, 0"; } | $(AS) $(ASFLAGS) -o $@ - +else @$(CPP) $(CPPFLAGS) $< -o $(GFLIB_BUILDDIR)/$*.i @$(PREPROC) $(GFLIB_BUILDDIR)/$*.i charmap.txt | $(CC1) $(CFLAGS) -o $(GFLIB_BUILDDIR)/$*.s @echo -e ".text\n\t.align\t2, 0\n" >> $(GFLIB_BUILDDIR)/$*.s $(AS) $(ASFLAGS) -o $@ $(GFLIB_BUILDDIR)/$*.s +endif ifeq ($(NODEP),1) $(C_BUILDDIR)/%.o: c_asm_dep := diff --git a/tools/preproc/c_file.cpp b/tools/preproc/c_file.cpp index b996a048c7..f7ca4365cc 100644 --- a/tools/preproc/c_file.cpp +++ b/tools/preproc/c_file.cpp @@ -23,32 +23,58 @@ #include #include #include +#include #include "preproc.h" #include "c_file.h" #include "char_util.h" #include "utf8.h" #include "string_parser.h" -CFile::CFile(std::string filename) : m_filename(filename) +CFile::CFile(const char * filenameCStr, bool isStdin) { - FILE *fp = std::fopen(filename.c_str(), "rb"); + FILE *fp; + + if (isStdin) { + fp = stdin; + m_filename = std::string{"/"}.append(filenameCStr); + } else { + fp = std::fopen(filenameCStr, "rb"); + m_filename = std::string(filenameCStr); + } + + std::string& filename = m_filename; if (fp == NULL) FATAL_ERROR("Failed to open \"%s\" for reading.\n", filename.c_str()); - std::fseek(fp, 0, SEEK_END); + m_size = 0; + m_buffer = (char *)malloc(CHUNK_SIZE + 1); + if (m_buffer == NULL) { + FATAL_ERROR("Failed to allocate memory to process file \"%s\"!", filename.c_str()); + } - m_size = std::ftell(fp); + std::size_t numAllocatedBytes = CHUNK_SIZE + 1; + std::size_t bufferOffset = 0; + std::size_t count; - if (m_size < 0) - FATAL_ERROR("File size of \"%s\" is less than zero.\n", filename.c_str()); + while ((count = std::fread(m_buffer + bufferOffset, 1, CHUNK_SIZE, fp)) != 0) { + if (!std::ferror(fp)) { + m_size += count; - m_buffer = new char[m_size + 1]; + if (std::feof(fp)) { + break; + } - std::rewind(fp); - - if (std::fread(m_buffer, m_size, 1, fp) != 1) - FATAL_ERROR("Failed to read \"%s\".\n", filename.c_str()); + numAllocatedBytes += CHUNK_SIZE; + bufferOffset += CHUNK_SIZE; + m_buffer = (char *)realloc(m_buffer, numAllocatedBytes); + if (m_buffer == NULL) { + FATAL_ERROR("Failed to allocate memory to process file \"%s\"!", filename.c_str()); + } + } else { + FATAL_ERROR("Failed to read \"%s\". (error: %s)", filename.c_str(), std::strerror(errno)); + } + } m_buffer[m_size] = 0; @@ -56,6 +82,7 @@ CFile::CFile(std::string filename) : m_filename(filename) m_pos = 0; m_lineNum = 1; + m_isStdin = isStdin; } CFile::CFile(CFile&& other) : m_filename(std::move(other.m_filename)) @@ -64,13 +91,14 @@ CFile::CFile(CFile&& other) : m_filename(std::move(other.m_filename)) m_pos = other.m_pos; m_size = other.m_size; m_lineNum = other.m_lineNum; + m_isStdin = other.m_isStdin; - other.m_buffer = nullptr; + other.m_buffer = NULL; } CFile::~CFile() { - delete[] m_buffer; + free(m_buffer); } void CFile::Preproc() diff --git a/tools/preproc/c_file.h b/tools/preproc/c_file.h index 7369aba852..49e633a18d 100644 --- a/tools/preproc/c_file.h +++ b/tools/preproc/c_file.h @@ -30,7 +30,7 @@ class CFile { public: - CFile(std::string filename); + CFile(const char * filenameCStr, bool isStdin); CFile(CFile&& other); CFile(const CFile&) = delete; ~CFile(); @@ -42,6 +42,7 @@ private: long m_size; long m_lineNum; std::string m_filename; + bool m_isStdin; bool ConsumeHorizontalWhitespace(); bool ConsumeNewline(); @@ -55,4 +56,6 @@ private: void RaiseWarning(const char* format, ...); }; +#define CHUNK_SIZE 4096 + #endif // C_FILE_H diff --git a/tools/preproc/preproc.cpp b/tools/preproc/preproc.cpp index c9c6042df1..02950a2963 100644 --- a/tools/preproc/preproc.cpp +++ b/tools/preproc/preproc.cpp @@ -103,9 +103,9 @@ void PreprocAsmFile(std::string filename) } } -void PreprocCFile(std::string filename) +void PreprocCFile(const char * filename, bool isStdin) { - CFile cFile(filename); + CFile cFile(filename, isStdin); cFile.Preproc(); } @@ -132,9 +132,9 @@ char* GetFileExtension(char* filename) int main(int argc, char **argv) { - if (argc != 3) + if (argc < 3 || argc > 4) { - std::fprintf(stderr, "Usage: %s SRC_FILE CHARMAP_FILE", argv[0]); + std::fprintf(stderr, "Usage: %s SRC_FILE CHARMAP_FILE [-i]\nwhere -i denotes if input is from stdin", argv[0]); return 1; } @@ -147,9 +147,17 @@ int main(int argc, char **argv) if ((extension[0] == 's') && extension[1] == 0) PreprocAsmFile(argv[1]); - else if ((extension[0] == 'c' || extension[0] == 'i') && extension[1] == 0) - PreprocCFile(argv[1]); - else + else if ((extension[0] == 'c' || extension[0] == 'i') && extension[1] == 0) { + if (argc == 4) { + if (argv[3][0] == '-' && argv[3][1] == 'i' && argv[3][2] == '\0') { + PreprocCFile(argv[1], true); + } else { + FATAL_ERROR("unknown argument flag \"%s\".\n", argv[3]); + } + } else { + PreprocCFile(argv[1], false); + } + } else FATAL_ERROR("\"%s\" has an unknown file extension of \"%s\".\n", argv[1], extension); return 0; From 57bc32e300b7e23886337e244a3522e1e1bec04f Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Wed, 27 Jan 2021 09:57:50 -0500 Subject: [PATCH 02/18] Fix templess builds from not exiting on error. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3383cb14dd..bb65aed74a 100644 --- a/Makefile +++ b/Makefile @@ -285,7 +285,7 @@ endif $(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $$(c_dep) ifeq (,$(KEEP_TEMPS)) @echo "$(CC1) -o $@ $<" - @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | { $(CC1) $(CFLAGS) -o - -; echo -e ".text\n\t.align\t2, 0"; } | $(AS) $(ASFLAGS) -o $@ - + @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ - else @$(CPP) $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i @$(PREPROC) $(C_BUILDDIR)/$*.i charmap.txt | $(CC1) $(CFLAGS) -o $(C_BUILDDIR)/$*.s @@ -302,7 +302,7 @@ endif $(GFLIB_BUILDDIR)/%.o : $(GFLIB_SUBDIR)/%.c $$(c_dep) ifeq (,$(KEEP_TEMPS)) @echo "$(CC1) -o $@ $<" - @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | { $(CC1) $(CFLAGS) -o - -; echo -e ".text\n\t.align\t2, 0"; } | $(AS) $(ASFLAGS) -o $@ - + @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ - else @$(CPP) $(CPPFLAGS) $< -o $(GFLIB_BUILDDIR)/$*.i @$(PREPROC) $(GFLIB_BUILDDIR)/$*.i charmap.txt | $(CC1) $(CFLAGS) -o $(GFLIB_BUILDDIR)/$*.s From 9da2142a391d991490a7a9de9ada6f12868049a4 Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Tue, 4 May 2021 10:08:54 -0400 Subject: [PATCH 03/18] Scan all deps of time, also prevent deps from being scanned twice for compare and modern. --- Makefile | 88 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index bb65aed74a..6842d3fd75 100644 --- a/Makefile +++ b/Makefile @@ -143,12 +143,27 @@ infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst # Build tools when building the rom # Disable dependency scanning for clean/tidy/tools -ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall,$(MAKECMDGOALS))) +# Don't build tools yet for modern because we perform a recursive make +ifeq (,$(filter-out all rom berry_fix libagbsyscall,$(MAKECMDGOALS))) $(call infoshell, $(MAKE) tools) else NODEP := 1 endif +# check if we need to scan dependencies based on the rule +ifeq (,$(MAKECMDGOALS)) + SCAN_DEPS := 1 +else + # compare and modern perform recursive calls, so don't scan dependencies yet + # clean, tidy, tools, mostlyclean, clean-tools, $(TOOLDIRS), tidymodern, tidynonmodern don't even build the ROM + # berry_fix and libagbsyscall do their own thing + ifeq (,$(filter-out clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix libagbsyscall modern tidymodern tidynonmodern,$(MAKECMDGOALS))) + SCAN_DEPS := 0 + else + SCAN_DEPS := 1 + endif +endif + C_SRCS_IN := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c) C_SRCS := $(foreach src,$(C_SRCS_IN),$(if $(findstring .inc.c,$(src)),,$(src))) C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS)) @@ -272,17 +287,21 @@ else $(C_BUILDDIR)/librfu_intr.o: CFLAGS := -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast endif -ifeq ($(NODEP),1) -$(C_BUILDDIR)/%.o: c_dep := -else -$(C_BUILDDIR)/%.o: c_dep = $(shell [[ -f $(C_SUBDIR)/$*.c ]] && $(SCANINC) -I include -I tools/agbcc/include -I gflib $(C_SUBDIR)/$*.c) -endif - ifeq ($(DINFO),1) override CFLAGS += -g endif -$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c $$(c_dep) +# 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. + +# ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall,$(MAKECMDGOALS))) + +#$(info MAKECMDGOALS - $(MAKECMDGOALS)) + +ifeq ($(SCAN_DEPS),1) +ifeq ($(NODEP),1) +$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c ifeq (,$(KEEP_TEMPS)) @echo "$(CC1) -o $@ $<" @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ - @@ -292,13 +311,25 @@ else @echo -e ".text\n\t.align\t2, 0\n" >> $(C_BUILDDIR)/$*.s $(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s endif - -ifeq ($(NODEP),1) -$(GFLIB_BUILDDIR)/%.o: c_dep := else -$(GFLIB_BUILDDIR)/%.o: c_dep = $(shell [[ -f $(GFLIB_SUBDIR)/$*.c ]] && $(SCANINC) -I include -I tools/agbcc/include -I gflib $(GFLIB_SUBDIR)/$*.c) +define C_DEP +$1: $2 $$(shell $(SCANINC) -I include -I tools/agbcc/include -I gflib $2) +ifeq (,$$(KEEP_TEMPS)) + @echo "$$(CC1) -o $$@ $$<" + @$$(CPP) $$(CPPFLAGS) $$< | $$(PREPROC) $$< charmap.txt -i | $$(CC1) $$(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $$(AS) $$(ASFLAGS) -o $$@ - +else + @$$(CPP) $$(CPPFLAGS) $$< -o $$(C_BUILDDIR)/$$*.i + @$$(PREPROC) $$(C_BUILDDIR)/$$*.i charmap.txt | $$(CC1) $$(CFLAGS) -o $$(C_BUILDDIR)/$$*.s + @echo -e ".text\n\t.align\t2, 0\n" >> $$(C_BUILDDIR)/$$*.s + $$(AS) $$(ASFLAGS) -o $$@ $$(C_BUILDDIR)/$$*.s +endif +endef +#$(info C_DEP) +$(foreach src, $(C_SRCS), $(eval $(call C_DEP,$(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o, $(src)),$(src)))) +#$(error done C_DEP) endif +ifeq ($(NODEP),1) $(GFLIB_BUILDDIR)/%.o : $(GFLIB_SUBDIR)/%.c $$(c_dep) ifeq (,$(KEEP_TEMPS)) @echo "$(CC1) -o $@ $<" @@ -309,20 +340,32 @@ else @echo -e ".text\n\t.align\t2, 0\n" >> $(GFLIB_BUILDDIR)/$*.s $(AS) $(ASFLAGS) -o $@ $(GFLIB_BUILDDIR)/$*.s endif - -ifeq ($(NODEP),1) -$(C_BUILDDIR)/%.o: c_asm_dep := else -$(C_BUILDDIR)/%.o: c_asm_dep = $(shell [[ -f $(C_SUBDIR)/$*.s ]] && $(SCANINC) -I "" $(C_SUBDIR)/$*.s) +define GFLIB_DEP +$1: $2 $$(shell $(SCANINC) -I include -I tools/agbcc/include -I gflib $2) +ifeq (,$$(KEEP_TEMPS)) + @echo "$$(CC1) -o $$@ $$<" + @$$(CPP) $$(CPPFLAGS) $$< | $$(PREPROC) $$< charmap.txt -i | $$(CC1) $$(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $$(AS) $$(ASFLAGS) -o $$@ - +else + @$$(CPP) $$(CPPFLAGS) $$< -o $$(GFLIB_BUILDDIR)/$$*.i + @$$(PREPROC) $$(GFLIB_BUILDDIR)/$$*.i charmap.txt | $$(CC1) $$(CFLAGS) -o $$(GFLIB_BUILDDIR)/$$*.s + @echo -e ".text\n\t.align\t2, 0\n" >> $$(GFLIB_BUILDDIR)/$$*.s + $$(AS) $$(ASFLAGS) -o $$@ $$(GFLIB_BUILDDIR)/$$*.s +endif +endef +$(foreach src, $(GFLIB_SRCS), $(eval $(call GFLIB_DEP,$(patsubst $(GFLIB_SUBDIR)/%.c,$(GFLIB_BUILDDIR)/%.o, $(src)),$(src)))) endif -$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s $$(c_asm_dep) +ifeq ($(NODEP),1) +$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s $(AS) $(ASFLAGS) -o $@ $< - -# 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. - +else +define C_ASM_DEP +$1: $2 $$(shell $(SCANINC) -I "" $2) + $$(AS) $$(ASFLAGS) -o $$@ $$< +endef +$(foreach src, $(C_ASM_SRCS), $(eval $(call C_ASM_DEP,$(patsubst $(C_SUBDIR)/%.s,$(C_BUILDDIR)/%.o, $(src)),$(src)))) +endif ifeq ($(NODEP),1) $(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s @@ -345,6 +388,7 @@ $1: $2 $$(shell $(SCANINC) -I include -I "" $2) endef $(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call DATA_ASM_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src)))) endif +endif $(SONG_BUILDDIR)/%.o: $(SONG_SUBDIR)/%.s $(AS) $(ASFLAGS) -I sound -o $@ $< From a839463c849679974c986bf9c9c260eff0e94cb7 Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Tue, 1 Jun 2021 20:40:11 -0400 Subject: [PATCH 04/18] Optimize Makefile. Don't do recursive makes for COMPARE and MODERN, use minimal makefile for making tools. --- Makefile | 38 +++++++++++++++++++++++--------------- make_tools.mk | 12 ++++++++++++ 2 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 make_tools.mk diff --git a/Makefile b/Makefile index 6842d3fd75..4b36feec8e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,11 @@ +$(info start $(shell date +%s%3N)) TOOLCHAIN := $(DEVKITARM) COMPARE ?= 0 +ifeq (compare,$(MAKECMDGOALS)) + COMPARE := 1 +endif + # don't use dkP's base_tools anymore # because the redefinition of $(CC) conflicts # with when we want to use $(CC) to preprocess files @@ -36,6 +41,10 @@ MAKER_CODE := 01 REVISION := 0 MODERN ?= 0 +ifeq (modern,$(MAKECMDGOALS)) + MODERN := 1 +endif + # use arm-none-eabi-cpp for macOS # as macOS's default compiler is clang # and clang's preprocessor will warn on \u @@ -143,9 +152,10 @@ infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst # Build tools when building the rom # Disable dependency scanning for clean/tidy/tools -# Don't build tools yet for modern because we perform a recursive make -ifeq (,$(filter-out all rom berry_fix libagbsyscall,$(MAKECMDGOALS))) -$(call infoshell, $(MAKE) 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 modern berry_fix libagbsyscall,$(MAKECMDGOALS))) +$(call infoshell, $(MAKE) -f make_tools.mk) else NODEP := 1 endif @@ -154,16 +164,17 @@ endif ifeq (,$(MAKECMDGOALS)) SCAN_DEPS := 1 else - # compare and modern perform recursive calls, so don't scan dependencies yet # clean, tidy, tools, mostlyclean, clean-tools, $(TOOLDIRS), tidymodern, tidynonmodern don't even build the ROM # berry_fix and libagbsyscall do their own thing - ifeq (,$(filter-out clean compare tidy tools mostlyclean clean-tools $(TOOLDIRS) berry_fix libagbsyscall modern tidymodern tidynonmodern,$(MAKECMDGOALS))) + ifeq (,$(filter-out clean tidy tools mostlyclean clean-tools $(TOOLDIRS) tidymodern tidynonmodern berry_fix libagbsyscall,$(MAKECMDGOALS))) SCAN_DEPS := 0 else SCAN_DEPS := 1 endif endif +$(info scanfiles $(shell date +%s%3N)) +ifeq ($(SCAN_DEPS),1) C_SRCS_IN := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c) C_SRCS := $(foreach src,$(C_SRCS_IN),$(if $(findstring .inc.c,$(src)),,$(src))) C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS)) @@ -193,11 +204,12 @@ OBJS := $(C_OBJS) $(GFLIB_OBJS) $(C_ASM_OBJS) $(ASM_OBJS) $(DATA_ASM_OBJS) $ OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS)) SUBDIRS := $(sort $(dir $(OBJS))) +$(shell mkdir -p $(SUBDIRS)) +endif +$(info scanfiles done $(shell date +%s%3N)) AUTO_GEN_TARGETS := -$(shell mkdir -p $(SUBDIRS)) - all: rom tools: $(TOOLDIRS) @@ -211,7 +223,7 @@ ifeq ($(COMPARE),1) endif # For contributors to make sure a change didn't affect the contents of the ROM. -compare: ; @$(MAKE) COMPARE=1 +compare: all clean: mostlyclean clean-tools @@ -295,11 +307,8 @@ endif # 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. -# ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall,$(MAKECMDGOALS))) - -#$(info MAKECMDGOALS - $(MAKECMDGOALS)) - ifeq ($(SCAN_DEPS),1) +$(info Scanning deps start $(shell date +%s%3N)) ifeq ($(NODEP),1) $(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c ifeq (,$(KEEP_TEMPS)) @@ -324,9 +333,7 @@ else $$(AS) $$(ASFLAGS) -o $$@ $$(C_BUILDDIR)/$$*.s endif endef -#$(info C_DEP) $(foreach src, $(C_SRCS), $(eval $(call C_DEP,$(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o, $(src)),$(src)))) -#$(error done C_DEP) endif ifeq ($(NODEP),1) @@ -388,6 +395,7 @@ $1: $2 $$(shell $(SCANINC) -I include -I "" $2) endef $(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call DATA_ASM_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src)))) endif +$(info Scanning deps end $(shell date +%s%3N)) endif $(SONG_BUILDDIR)/%.o: $(SONG_SUBDIR)/%.s @@ -422,7 +430,7 @@ $(ROM): $(ELF) $(OBJCOPY) -O binary $< $@ $(FIX) $@ -p --silent -modern: ; @$(MAKE) MODERN=1 +modern: all berry_fix/berry_fix.gba: berry_fix diff --git a/make_tools.mk b/make_tools.mk new file mode 100644 index 0000000000..82a482bca7 --- /dev/null +++ b/make_tools.mk @@ -0,0 +1,12 @@ + +TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*)) +TOOLBASE = $(TOOLDIRS:tools/%=%) +TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE)) + +.PHONY: all $(TOOLDIRS) + +all: $(TOOLDIRS) + @: + +$(TOOLDIRS): + @$(MAKE) -C $@ From 92152e45e226b797a5ca10cff0e9e55d2a66a3d8 Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Tue, 1 Jun 2021 23:22:15 -0400 Subject: [PATCH 05/18] Fixes to makefile. Merge C_ASM_DEP and DATA_ASM_DEP, NODEP and SCAN_DEPS can be overridden, add --no-print-directory to MAKEFLAGS in make_tools.mk (also removed some unused variables), add newline to help message in preproc. --- Makefile | 23 +++++++++-------------- make_tools.mk | 5 ++--- tools/preproc/preproc.cpp | 2 +- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index a2b0139269..5741977ec5 100644 --- a/Makefile +++ b/Makefile @@ -157,19 +157,19 @@ infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall,$(MAKECMDGOALS))) $(call infoshell, $(MAKE) -f make_tools.mk) else -NODEP := 1 +NODEP ?= 1 endif # check if we need to scan dependencies based on the rule ifeq (,$(MAKECMDGOALS)) - SCAN_DEPS := 1 + SCAN_DEPS ?= 1 else # clean, tidy, tools, mostlyclean, clean-tools, $(TOOLDIRS), tidymodern, tidynonmodern don't even build the ROM # berry_fix and libagbsyscall do their own thing ifeq (,$(filter-out clean tidy tools mostlyclean clean-tools $(TOOLDIRS) tidymodern tidynonmodern berry_fix libagbsyscall,$(MAKECMDGOALS))) - SCAN_DEPS := 0 + SCAN_DEPS ?= 0 else - SCAN_DEPS := 1 + SCAN_DEPS ?= 1 endif endif @@ -365,11 +365,11 @@ ifeq ($(NODEP),1) $(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s $(AS) $(ASFLAGS) -o $@ $< else -define C_ASM_DEP -$1: $2 $$(shell $(SCANINC) -I "" $2) - $$(AS) $$(ASFLAGS) -o $$@ $$< +define SRC_ASM_DATA_DEP +$1: $2 $$(shell $(SCANINC) -I include -I "" $2) + $$(PREPROC) $$< charmap.txt | $$(CPP) -I include - | $$(AS) $$(ASFLAGS) -o $$@ endef -$(foreach src, $(C_ASM_SRCS), $(eval $(call C_ASM_DEP,$(patsubst $(C_SUBDIR)/%.s,$(C_BUILDDIR)/%.o, $(src)),$(src)))) +$(foreach src, $(C_ASM_SRCS), $(eval $(call SRC_ASM_DATA_DEP,$(patsubst $(C_SUBDIR)/%.s,$(C_BUILDDIR)/%.o, $(src)),$(src)))) endif ifeq ($(NODEP),1) @@ -387,12 +387,7 @@ ifeq ($(NODEP),1) $(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s $(PREPROC) $< charmap.txt | $(CPP) -I include - | $(AS) $(ASFLAGS) -o $@ else -define DATA_ASM_DEP -$1: $2 $$(shell $(SCANINC) -I include -I "" $2) - $$(PREPROC) $$< charmap.txt | $$(CPP) -I include - | $$(AS) $$(ASFLAGS) -o $$@ -endef -$(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call DATA_ASM_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src)))) -$(foreach src, $(C_ASM_SRCS), $(eval $(call DATA_ASM_DEP,$(patsubst $(C_SUBDIR)/%.s,$(C_BUILDDIR)/%.o, $(src)),$(src)))) +$(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call SRC_ASM_DATA_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src)))) endif $(info Scanning deps end $(shell date +%s%3N)) endif diff --git a/make_tools.mk b/make_tools.mk index 82a482bca7..697897a693 100644 --- a/make_tools.mk +++ b/make_tools.mk @@ -1,12 +1,11 @@ +MAKEFLAGS += --no-print-directory + TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*)) -TOOLBASE = $(TOOLDIRS:tools/%=%) -TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE)) .PHONY: all $(TOOLDIRS) all: $(TOOLDIRS) - @: $(TOOLDIRS): @$(MAKE) -C $@ diff --git a/tools/preproc/preproc.cpp b/tools/preproc/preproc.cpp index 02950a2963..eb2d4c8a23 100644 --- a/tools/preproc/preproc.cpp +++ b/tools/preproc/preproc.cpp @@ -134,7 +134,7 @@ int main(int argc, char **argv) { if (argc < 3 || argc > 4) { - std::fprintf(stderr, "Usage: %s SRC_FILE CHARMAP_FILE [-i]\nwhere -i denotes if input is from stdin", argv[0]); + std::fprintf(stderr, "Usage: %s SRC_FILE CHARMAP_FILE [-i]\nwhere -i denotes if input is from stdin\n", argv[0]); return 1; } From 4687847acea342d34985c195a8e7463fdefc4cc4 Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Thu, 3 Jun 2021 17:46:09 -0400 Subject: [PATCH 06/18] Fix building with KEEP_TEMPS=1, and NODEP=1. KEEP_TEMPS=1 not working was due to the pattern substitution in the old makefile rules for compiling C files ($*) not working with the explicit generation of dependencies. NODEP=1 not working was due to the NODEP rule for src/%.s not being updated to use preproc and cpp. --- Makefile | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 5741977ec5..69173a556d 100644 --- a/Makefile +++ b/Makefile @@ -308,7 +308,7 @@ endif ifeq ($(SCAN_DEPS),1) $(info Scanning deps start $(shell date +%s%3N)) ifeq ($(NODEP),1) -$(C_BUILDDIR)/%.o : $(C_SUBDIR)/%.c +$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.c ifeq (,$(KEEP_TEMPS)) @echo "$(CC1) -o $@ $<" @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ - @@ -325,17 +325,17 @@ ifeq (,$$(KEEP_TEMPS)) @echo "$$(CC1) -o $$@ $$<" @$$(CPP) $$(CPPFLAGS) $$< | $$(PREPROC) $$< charmap.txt -i | $$(CC1) $$(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $$(AS) $$(ASFLAGS) -o $$@ - else - @$$(CPP) $$(CPPFLAGS) $$< -o $$(C_BUILDDIR)/$$*.i - @$$(PREPROC) $$(C_BUILDDIR)/$$*.i charmap.txt | $$(CC1) $$(CFLAGS) -o $$(C_BUILDDIR)/$$*.s - @echo -e ".text\n\t.align\t2, 0\n" >> $$(C_BUILDDIR)/$$*.s - $$(AS) $$(ASFLAGS) -o $$@ $$(C_BUILDDIR)/$$*.s + @$$(CPP) $$(CPPFLAGS) $$< -o $$(C_BUILDDIR)/$3.i + @$$(PREPROC) $$(C_BUILDDIR)/$3.i charmap.txt | $$(CC1) $$(CFLAGS) -o $$(C_BUILDDIR)/$3.s + @echo -e ".text\n\t.align\t2, 0\n" >> $$(C_BUILDDIR)/$3.s + $$(AS) $$(ASFLAGS) -o $$@ $$(C_BUILDDIR)/$3.s endif endef -$(foreach src, $(C_SRCS), $(eval $(call C_DEP,$(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o, $(src)),$(src)))) +$(foreach src, $(C_SRCS), $(eval $(call C_DEP,$(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(src)),$(src),$(patsubst $(C_SUBDIR)/%.c,%,$(src))))) endif ifeq ($(NODEP),1) -$(GFLIB_BUILDDIR)/%.o : $(GFLIB_SUBDIR)/%.c $$(c_dep) +$(GFLIB_BUILDDIR)/%.o: $(GFLIB_SUBDIR)/%.c $$(c_dep) ifeq (,$(KEEP_TEMPS)) @echo "$(CC1) -o $@ $<" @$(CPP) $(CPPFLAGS) $< | $(PREPROC) $< charmap.txt -i | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ - @@ -352,18 +352,18 @@ ifeq (,$$(KEEP_TEMPS)) @echo "$$(CC1) -o $$@ $$<" @$$(CPP) $$(CPPFLAGS) $$< | $$(PREPROC) $$< charmap.txt -i | $$(CC1) $$(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $$(AS) $$(ASFLAGS) -o $$@ - else - @$$(CPP) $$(CPPFLAGS) $$< -o $$(GFLIB_BUILDDIR)/$$*.i - @$$(PREPROC) $$(GFLIB_BUILDDIR)/$$*.i charmap.txt | $$(CC1) $$(CFLAGS) -o $$(GFLIB_BUILDDIR)/$$*.s - @echo -e ".text\n\t.align\t2, 0\n" >> $$(GFLIB_BUILDDIR)/$$*.s - $$(AS) $$(ASFLAGS) -o $$@ $$(GFLIB_BUILDDIR)/$$*.s + @$$(CPP) $$(CPPFLAGS) $$< -o $$(GFLIB_BUILDDIR)/$3.i + @$$(PREPROC) $$(GFLIB_BUILDDIR)/$3.i charmap.txt | $$(CC1) $$(CFLAGS) -o $$(GFLIB_BUILDDIR)/$3.s + @echo -e ".text\n\t.align\t2, 0\n" >> $$(GFLIB_BUILDDIR)/$3.s + $$(AS) $$(ASFLAGS) -o $$@ $$(GFLIB_BUILDDIR)/$3.s endif endef -$(foreach src, $(GFLIB_SRCS), $(eval $(call GFLIB_DEP,$(patsubst $(GFLIB_SUBDIR)/%.c,$(GFLIB_BUILDDIR)/%.o, $(src)),$(src)))) +$(foreach src, $(GFLIB_SRCS), $(eval $(call GFLIB_DEP,$(patsubst $(GFLIB_SUBDIR)/%.c,$(GFLIB_BUILDDIR)/%.o, $(src)),$(src),$(patsubst $(GFLIB_SUBDIR)/%.c,%, $(src))))) endif ifeq ($(NODEP),1) $(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s - $(AS) $(ASFLAGS) -o $@ $< + $(PREPROC) $< charmap.txt | $(CPP) -I include - | $(AS) $(ASFLAGS) -o $@ else define SRC_ASM_DATA_DEP $1: $2 $$(shell $(SCANINC) -I include -I "" $2) From 7e1ae9f95d41f46abd5888a63fec09664ac89d5a Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Thu, 3 Jun 2021 18:22:49 -0400 Subject: [PATCH 07/18] Remove debug print statements in Makefile. --- Makefile | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Makefile b/Makefile index 69173a556d..d7d4b9566c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ -$(info start $(shell date +%s%3N)) TOOLCHAIN := $(DEVKITARM) COMPARE ?= 0 @@ -173,7 +172,6 @@ else endif endif -$(info scanfiles $(shell date +%s%3N)) ifeq ($(SCAN_DEPS),1) C_SRCS_IN := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c) C_SRCS := $(foreach src,$(C_SRCS_IN),$(if $(findstring .inc.c,$(src)),,$(src))) @@ -206,7 +204,6 @@ OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS)) SUBDIRS := $(sort $(dir $(OBJS))) $(shell mkdir -p $(SUBDIRS)) endif -$(info scanfiles done $(shell date +%s%3N)) AUTO_GEN_TARGETS := @@ -306,7 +303,6 @@ endif # It doesn't look like $(shell) can be deferred so there might not be a better way. ifeq ($(SCAN_DEPS),1) -$(info Scanning deps start $(shell date +%s%3N)) ifeq ($(NODEP),1) $(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.c ifeq (,$(KEEP_TEMPS)) @@ -389,7 +385,6 @@ $(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s else $(foreach src, $(REGULAR_DATA_ASM_SRCS), $(eval $(call SRC_ASM_DATA_DEP,$(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o, $(src)),$(src)))) endif -$(info Scanning deps end $(shell date +%s%3N)) endif $(SONG_BUILDDIR)/%.o: $(SONG_SUBDIR)/%.s From 7189e4e26f3da36ed9d373f77a9f51a36fc8ddaf Mon Sep 17 00:00:00 2001 From: luckytyphlosion <10688458+luckytyphlosion@users.noreply.github.com> Date: Thu, 3 Jun 2021 21:05:56 -0400 Subject: [PATCH 08/18] Fix build on macos. Needs include in tools/preproc/c_file.cpp --- tools/preproc/c_file.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/preproc/c_file.cpp b/tools/preproc/c_file.cpp index f7ca4365cc..17a08cc9f7 100644 --- a/tools/preproc/c_file.cpp +++ b/tools/preproc/c_file.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "preproc.h" #include "c_file.h" #include "char_util.h" From 0a94dba4a7dab779937ba3afd29932aa8d5b535f Mon Sep 17 00:00:00 2001 From: SphericalIce Date: Sun, 13 Jun 2021 13:21:23 +0100 Subject: [PATCH 09/18] Rename item script labels to fit the established name scheme --- data/maps/MagmaHideout_2F_2R/map.json | 2 +- data/maps/MagmaHideout_4F/map.json | 2 +- data/scripts/item_ball_scripts.inc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data/maps/MagmaHideout_2F_2R/map.json b/data/maps/MagmaHideout_2F_2R/map.json index 4aa6896f6e..968c07fb7f 100644 --- a/data/maps/MagmaHideout_2F_2R/map.json +++ b/data/maps/MagmaHideout_2F_2R/map.json @@ -50,7 +50,7 @@ "movement_range_y": 1, "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", - "script": "MagmaHideout_2F_2R_EventScript_MaxElixir", + "script": "MagmaHideout_2F_2R_EventScript_ItemMaxElixir", "flag": "FLAG_ITEM_MAGMA_HIDEOUT_2F_2R_MAX_ELIXIR" }, { diff --git a/data/maps/MagmaHideout_4F/map.json b/data/maps/MagmaHideout_4F/map.json index 94cf295e02..67c11481fb 100644 --- a/data/maps/MagmaHideout_4F/map.json +++ b/data/maps/MagmaHideout_4F/map.json @@ -115,7 +115,7 @@ "movement_range_y": 1, "trainer_type": "TRAINER_TYPE_NONE", "trainer_sight_or_berry_tree_id": "0", - "script": "MagmaHideout_4F_EventScript_MaxRevive", + "script": "MagmaHideout_4F_EventScript_ItemMaxRevive", "flag": "FLAG_ITEM_MAGMA_HIDEOUT_4F_MAX_REVIVE" } ], diff --git a/data/scripts/item_ball_scripts.inc b/data/scripts/item_ball_scripts.inc index 82633f77c0..f9228134c8 100644 --- a/data/scripts/item_ball_scripts.inc +++ b/data/scripts/item_ball_scripts.inc @@ -634,7 +634,7 @@ MagmaHideout_1F_EventScript_ItemRareCandy:: @ 82914DE finditem ITEM_RARE_CANDY end -MagmaHideout_2F_2R_EventScript_MaxElixir:: @ 82914EB +MagmaHideout_2F_2R_EventScript_ItemMaxElixir:: @ 82914EB finditem ITEM_MAX_ELIXIR end @@ -650,7 +650,7 @@ MagmaHideout_3F_2R_EventScript_ItemPPMax:: @ 8291512 finditem ITEM_PP_MAX end -MagmaHideout_4F_EventScript_MaxRevive:: @ 829151F +MagmaHideout_4F_EventScript_ItemMaxRevive:: @ 829151F finditem ITEM_MAX_REVIVE end From b6b0062bd60eb57d66b6c79fc48bdbb55d8a5bf5 Mon Sep 17 00:00:00 2001 From: ExpoSeed <43502820+ExpoSeed@users.noreply.github.com> Date: Sun, 13 Jun 2021 16:32:00 -0500 Subject: [PATCH 10/18] Change map header flags to use a bitfield --- include/global.fieldmap.h | 16 ++++++---------- src/bike.c | 2 +- src/item_use.c | 2 +- src/overworld.c | 6 +++--- src/region_map.c | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index a3d99ee212..6bafa97479 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -142,19 +142,15 @@ struct MapHeader /* 0x16 */ u8 weather; /* 0x17 */ u8 mapType; /* 0x18 */ u8 filler_18[2]; - /* 0x1A */ u8 flags; + // fields correspond to the arguments in the map_header_flags macro + /* 0x1A */ bool8 allowCycling:1; + bool8 allowEscaping:1; // Escape Rope and Dig + bool8 allowRunning:1; + bool8 showMapName:5; // the last 4 bits are unused + // but the 5 bit sized bitfield is required to match /* 0x1B */ u8 battleType; }; -// Flags for gMapHeader.flags, as defined in the map_header_flags macro -#define MAP_ALLOW_CYCLING (1 << 0) -#define MAP_ALLOW_ESCAPING (1 << 1) // Escape Rope and Dig -#define MAP_ALLOW_RUNNING (1 << 2) -#define MAP_SHOW_MAP_NAME (1 << 3) -#define UNUSED_MAP_FLAGS (1 << 4 | 1 << 5 | 1 << 6 | 1 << 7) - -#define SHOW_MAP_NAME_ENABLED ((gMapHeader.flags & (MAP_SHOW_MAP_NAME | UNUSED_MAP_FLAGS)) == MAP_SHOW_MAP_NAME) - struct ObjectEvent { diff --git a/src/bike.c b/src/bike.c index 62ce3cd446..e97a5e04e4 100644 --- a/src/bike.c +++ b/src/bike.c @@ -1053,7 +1053,7 @@ void Bike_HandleBumpySlopeJump(void) bool32 IsRunningDisallowed(u8 metatile) { - if (!(gMapHeader.flags & MAP_ALLOW_RUNNING) || IsRunningDisallowedByMetatile(metatile) == TRUE) + if (!gMapHeader.allowRunning || IsRunningDisallowedByMetatile(metatile) == TRUE) return TRUE; else return FALSE; diff --git a/src/item_use.c b/src/item_use.c index 19f50549e7..c9087e9290 100755 --- a/src/item_use.c +++ b/src/item_use.c @@ -910,7 +910,7 @@ static void ItemUseOnFieldCB_EscapeRope(u8 taskId) bool8 CanUseDigOrEscapeRopeOnCurMap(void) { - if (gMapHeader.flags & MAP_ALLOW_ESCAPING) + if (gMapHeader.allowEscaping) return TRUE; else return FALSE; diff --git a/src/overworld.c b/src/overworld.c index 600333a47a..979ebb74c4 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -962,7 +962,7 @@ static u16 GetCenterScreenMetatileBehavior(void) bool32 Overworld_IsBikingAllowed(void) { - if (!(gMapHeader.flags & MAP_ALLOW_CYCLING)) + if (!gMapHeader.allowCycling) return FALSE; else return TRUE; @@ -1687,7 +1687,7 @@ void CB2_ReturnToFieldFadeFromBlack(void) static void FieldCB_FadeTryShowMapPopup(void) { - if (SHOW_MAP_NAME_ENABLED && SecretBaseMapPopupEnabled() == TRUE) + if (gMapHeader.showMapName == TRUE && SecretBaseMapPopupEnabled() == TRUE) ShowMapNamePopup(); FieldCB_WarpExitFadeFromBlack(); } @@ -1933,7 +1933,7 @@ static bool32 LoadMapInStepsLocal(u8 *state, bool32 a2) (*state)++; break; case 11: - if (SHOW_MAP_NAME_ENABLED && SecretBaseMapPopupEnabled() == TRUE) + if (gMapHeader.showMapName == TRUE && SecretBaseMapPopupEnabled() == TRUE) ShowMapNamePopup(); (*state)++; break; diff --git a/src/region_map.c b/src/region_map.c index bec51ebf0c..27e0351998 100644 --- a/src/region_map.c +++ b/src/region_map.c @@ -1007,7 +1007,7 @@ static void InitMapBasedOnPlayerLocation(void) break; case MAP_TYPE_UNDERGROUND: case MAP_TYPE_UNKNOWN: - if (gMapHeader.flags & MAP_ALLOW_ESCAPING) + if (gMapHeader.allowEscaping) { mapHeader = Overworld_GetMapHeaderByGroupAndId(gSaveBlock1Ptr->escapeWarp.mapGroup, gSaveBlock1Ptr->escapeWarp.mapNum); gRegionMap->mapSecId = mapHeader->regionMapSectionId; From 5ccac26f2685aed0f0374d5999ce5506d5a69693 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 16 Jun 2021 11:03:23 -0400 Subject: [PATCH 11/18] Port symfile implementation from Ruby, FireRed --- .github/workflows/build.yml | 44 ++++++++++++++++++++++++++++++++----- Makefile | 13 ++++++++++- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 822b386eae..de3a35c405 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,11 +7,29 @@ on: jobs: build: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest + env: + GAME_VERSION: EMERALD + GAME_REVISION: 0 + GAME_LANGUAGE: ENGLISH + MODERN: 0 + COMPARE: 1 steps: - name: Checkout uses: actions/checkout@master + - name: Checkout syms + uses: actions/checkout@master + with: + path: symbols + ref: symbols + + - name: Checkout agbcc + uses: actions/checkout@master + with: + path: agbcc + repository: pret/agbcc + - name: Install binutils run: sudo apt install gcc-arm-none-eabi binutils-arm-none-eabi # build-essential, git, and libpng-dev are already installed @@ -20,16 +38,18 @@ jobs: - name: Install agbcc run: | - git clone https://github.com/pret/agbcc.git - cd agbcc ./build.sh ./install.sh ../ + working-directory: agbcc - name: Compare - run: make -j${nproc} compare + run: make -j${nproc} all syms - name: Modern - run: make -j${nproc} modern + env: + MODERN: 1 + COMPARE: 0 + run: make -j${nproc} all - name: Webhook if: ${{ github.event_name == 'push' }} @@ -38,3 +58,17 @@ jobs: CALCROM_DISCORD_WEBHOOK_AVATAR_URL: https://i.imgur.com/38BQHdd.png CALCROM_DISCORD_WEBHOOK_URL: ${{ secrets.CALCROM_DISCORD_WEBHOOK_URL }} run: sh .github/calcrom/webhook.sh pokeemerald + + - name: Move symfiles + if: ${{ github.event_name == 'push' }} + run: | + cp -v *.sym symbols/ + + - name: Update symfiles + if: ${{ github.event_name == 'push' }} + uses: EndBug/add-and-commit@v7 + with: + branch: symbols + cwd: "./symbols" + add: "*.sym" + message: ${{ github.event.commits[0].message }} diff --git a/Makefile b/Makefile index d7d4b9566c..89d4b7c941 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ endif PREFIX := arm-none-eabi- OBJCOPY := $(PREFIX)objcopy +OBJDUMP := $(PREFIX)objdump AS := $(PREFIX)as LD := $(PREFIX)ld @@ -75,6 +76,7 @@ SHELL := /bin/bash -o pipefail ELF = $(ROM:.gba=.elf) MAP = $(ROM:.gba=.map) +SYM = $(ROM:.gba=.sym) C_SUBDIR = src GFLIB_SUBDIR = gflib @@ -153,7 +155,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 modern berry_fix libagbsyscall,$(MAKECMDGOALS))) +ifeq (,$(filter-out all rom compare modern berry_fix libagbsyscall syms,$(MAKECMDGOALS))) $(call infoshell, $(MAKE) -f make_tools.mk) else NODEP ?= 1 @@ -211,6 +213,8 @@ all: rom tools: $(TOOLDIRS) +syms: $(SYM) + $(TOOLDIRS): @$(MAKE) -C $@ @@ -428,3 +432,10 @@ berry_fix: libagbsyscall: @$(MAKE) -C libagbsyscall TOOLCHAIN=$(TOOLCHAIN) MODERN=$(MODERN) + +################### +### Symbol file ### +################### + +$(SYM): $(ELF) + $(OBJDUMP) -t $< | sort -u | grep -E "^0[2389]" > $@ From ae8f6e29f8906d53172a05f7b7b497510fe7617c Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Wed, 16 Jun 2021 14:43:35 -0400 Subject: [PATCH 12/18] Symplifi symfiles --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 89d4b7c941..384f012d15 100644 --- a/Makefile +++ b/Makefile @@ -131,6 +131,8 @@ FIX := tools/gbafix/gbafix$(EXE) MAPJSON := tools/mapjson/mapjson$(EXE) JSONPROC := tools/jsonproc/jsonproc$(EXE) +PERL := perl + TOOLDIRS := $(filter-out tools/agbcc tools/binutils,$(wildcard tools/*)) TOOLBASE = $(TOOLDIRS:tools/%=%) TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE)) @@ -438,4 +440,4 @@ libagbsyscall: ################### $(SYM): $(ELF) - $(OBJDUMP) -t $< | sort -u | grep -E "^0[2389]" > $@ + $(OBJDUMP) -t $< | sort -u | grep -E "^0[2389]" | $(PERL) -p -e 's/^(\w{8}) (\w).{6} \S+\t(\w{8}) (\w+)$$/\1 \2 \3 \4/g' > $@ From d02be421bcc22bb3aea82c23a687120359a0b357 Mon Sep 17 00:00:00 2001 From: Sewef Date: Thu, 17 Jun 2021 14:06:40 +0200 Subject: [PATCH 13/18] Fix sATypeMove_Table definition --- src/battle_message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_message.c b/src/battle_message.c index 7ef5fe3210..ca87ced091 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1328,7 +1328,7 @@ static const u8 sText_SpaceIs[] = _(" is"); static const u8 sText_ApostropheS[] = _("'s"); // For displaying names of invalid moves -static const u8 sATypeMove_Table[][NUMBER_OF_MON_TYPES - 1] = +static const u8 sATypeMove_Table[NUMBER_OF_MON_TYPES][17 = { [TYPE_NORMAL] = _("a NORMAL move"), [TYPE_FIGHTING] = _("a FIGHTING move"), From fd55a0d0154242f155afd2981d64f3156d92d53d Mon Sep 17 00:00:00 2001 From: Sewef Date: Thu, 17 Jun 2021 14:12:06 +0200 Subject: [PATCH 14/18] Update src/battle_message.c Nothing happened. Co-authored-by: LOuroboros --- src/battle_message.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_message.c b/src/battle_message.c index ca87ced091..ae30a2a629 100644 --- a/src/battle_message.c +++ b/src/battle_message.c @@ -1328,7 +1328,7 @@ static const u8 sText_SpaceIs[] = _(" is"); static const u8 sText_ApostropheS[] = _("'s"); // For displaying names of invalid moves -static const u8 sATypeMove_Table[NUMBER_OF_MON_TYPES][17 = +static const u8 sATypeMove_Table[NUMBER_OF_MON_TYPES][17] = { [TYPE_NORMAL] = _("a NORMAL move"), [TYPE_FIGHTING] = _("a FIGHTING move"), From 6ca73737cf5142962e8c27d1b6750158c60676c6 Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Fri, 18 Jun 2021 12:53:15 -0400 Subject: [PATCH 15/18] Fix regex error --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 384f012d15..2e5afdf0c2 100644 --- a/Makefile +++ b/Makefile @@ -440,4 +440,4 @@ libagbsyscall: ################### $(SYM): $(ELF) - $(OBJDUMP) -t $< | sort -u | grep -E "^0[2389]" | $(PERL) -p -e 's/^(\w{8}) (\w).{6} \S+\t(\w{8}) (\w+)$$/\1 \2 \3 \4/g' > $@ + $(OBJDUMP) -t $< | sort -u | grep -E "^0[2389]" | $(PERL) -p -e 's/^(\w{8}) (\w).{6} \S+\t(\w{8}) (\S+)$$/\1 \2 \3 \4/g' > $@ From 9407a1ac76c03a09a91e204b3d8d40843f43be3b Mon Sep 17 00:00:00 2001 From: ultima-soul <33333039+ultima-soul@users.noreply.github.com> Date: Fri, 18 Jun 2021 19:20:05 -0700 Subject: [PATCH 16/18] Replace hardcoded number in MakeCaptureStars. --- src/battle_anim_throw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_anim_throw.c b/src/battle_anim_throw.c index 83768b4761..4064e250cb 100755 --- a/src/battle_anim_throw.c +++ b/src/battle_anim_throw.c @@ -1420,7 +1420,7 @@ static void MakeCaptureStars(struct Sprite *sprite) LoadBallParticleGfx(BALL_MASTER); for (i = 0; i < ARRAY_COUNT(sCaptureStars); i++) { - u8 spriteId = CreateSprite(&sBallParticleSpriteTemplates[4], sprite->pos1.x, sprite->pos1.y, subpriority); + u8 spriteId = CreateSprite(&sBallParticleSpriteTemplates[BALL_MASTER], sprite->pos1.x, sprite->pos1.y, subpriority); if (spriteId != MAX_SPRITES) { gSprites[spriteId].sDuration = 24; From 810b51f96c9f2043a726b782a4884a06430192f2 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 21 Jun 2021 13:48:03 -0400 Subject: [PATCH 17/18] Clarify contest heart tiles --- include/constants/contest.h | 1 + src/contest.c | 27 +++++++++++++++------------ src/pokemon_summary_screen.c | 20 +++++++++++++------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/include/constants/contest.h b/include/constants/contest.h index 28b02e9c0c..775dcbe62b 100644 --- a/include/constants/contest.h +++ b/include/constants/contest.h @@ -4,6 +4,7 @@ #define APPLAUSE_METER_SIZE 5 #define CONTEST_NUM_APPEALS 5 #define CONTEST_LAST_APPEAL (CONTEST_NUM_APPEALS - 1) +#define MAX_CONTEST_MOVE_HEARTS 8 #define LINK_CONTEST_FLAG_IS_LINK (1 << 0) #define LINK_CONTEST_FLAG_IS_WIRELESS (1 << 1) diff --git a/src/contest.c b/src/contest.c index dbbd6ef638..920c3bdd7c 100644 --- a/src/contest.c +++ b/src/contest.c @@ -258,6 +258,11 @@ enum { #define TAG_BLINK_EFFECT_CONTESTANT2 0x80EA #define TAG_BLINK_EFFECT_CONTESTANT3 0x80EB +#define TILE_FILLED_APPEAL_HEART 0x5012 +#define TILE_FILLED_JAM_HEART 0x5014 +#define TILE_EMPTY_APPEAL_HEART 0x5035 +#define TILE_EMPTY_JAM_HEART 0x5036 + enum { SLIDER_HEART_ANIM_NORMAL, SLIDER_HEART_ANIM_DISAPPEAR, @@ -3203,27 +3208,25 @@ static void PrintContestMoveDescription(u16 a) ContestBG_FillBoxWithIncrementingTile(0, categoryTile, 0x0b, 0x1f, 0x05, 0x01, 0x11, 0x01); ContestBG_FillBoxWithIncrementingTile(0, categoryTile + 0x10, 0x0b, 0x20, 0x05, 0x01, 0x11, 0x01); + // Appeal hearts if (gContestEffects[gContestMoves[a].effect].appeal == 0xFF) numHearts = 0; else numHearts = gContestEffects[gContestMoves[a].effect].appeal / 10; - if (numHearts > 8) - numHearts = 8; - // Filled-in hearts - ContestBG_FillBoxWithTile(0, 0x5035, 0x15, 0x1f, 0x08, 0x01, 0x11); - // Empty hearts - ContestBG_FillBoxWithTile(0, 0x5012, 0x15, 0x1f, numHearts, 0x01, 0x11); + if (numHearts > MAX_CONTEST_MOVE_HEARTS) + numHearts = MAX_CONTEST_MOVE_HEARTS; + ContestBG_FillBoxWithTile(0, TILE_EMPTY_APPEAL_HEART, 0x15, 0x1f, MAX_CONTEST_MOVE_HEARTS, 0x01, 0x11); + ContestBG_FillBoxWithTile(0, TILE_FILLED_APPEAL_HEART, 0x15, 0x1f, numHearts, 0x01, 0x11); + // Jam hearts if (gContestEffects[gContestMoves[a].effect].jam == 0xFF) numHearts = 0; else numHearts = gContestEffects[gContestMoves[a].effect].jam / 10; - if (numHearts > 8) - numHearts = 8; - // Filled-in hearts - ContestBG_FillBoxWithTile(0, 0x5036, 0x15, 0x20, 0x08, 0x01, 0x11); - // Empty hearts - ContestBG_FillBoxWithTile(0, 0x5014, 0x15, 0x20, numHearts, 0x01, 0x11); + if (numHearts > MAX_CONTEST_MOVE_HEARTS) + numHearts = MAX_CONTEST_MOVE_HEARTS; + ContestBG_FillBoxWithTile(0, TILE_EMPTY_JAM_HEART, 0x15, 0x20, MAX_CONTEST_MOVE_HEARTS, 0x01, 0x11); + ContestBG_FillBoxWithTile(0, TILE_FILLED_JAM_HEART, 0x15, 0x20, numHearts, 0x01, 0x11); FillWindowPixelBuffer(WIN_MOVE_DESCRIPTION, PIXEL_FILL(0)); Contest_PrintTextToBg0WindowStd(WIN_MOVE_DESCRIPTION, gContestEffectDescriptionPointers[gContestMoves[a].effect]); diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index 8f16321b2f..31505b7c9b 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -119,6 +119,11 @@ enum SPRITE_ARR_ID_COUNT = SPRITE_ARR_ID_MOVE_SELECTOR2 + MOVE_SELECTOR_SPRITES_COUNT }; +#define TILE_EMPTY_APPEAL_HEART 0x1039 +#define TILE_FILLED_APPEAL_HEART 0x103A +#define TILE_FILLED_JAM_HEART 0x103C +#define TILE_EMPTY_JAM_HEART 0x103D + static EWRAM_DATA struct PokemonSummaryScreenData { /*0x00*/ union { @@ -2645,29 +2650,30 @@ static void DrawContestMoveHearts(u16 move) if (move != MOVE_NONE) { + // Draw appeal hearts u8 effectValue = gContestEffects[gContestMoves[move].effect].appeal; if (effectValue != 0xFF) effectValue /= 10; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_CONTEST_MOVE_HEARTS; i++) { if (effectValue != 0xFF && i < effectValue) - tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = 0x103A; + tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = TILE_FILLED_APPEAL_HEART; else - tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = 0x1039; + tilemap[(i / 4 * 32) + (i & 3) + 0x1E6] = TILE_EMPTY_APPEAL_HEART; } + // Draw jam hearts effectValue = gContestEffects[gContestMoves[move].effect].jam; - if (effectValue != 0xFF) effectValue /= 10; - for (i = 0; i < 8; i++) + for (i = 0; i < MAX_CONTEST_MOVE_HEARTS; i++) { if (effectValue != 0xFF && i < effectValue) - tilemap[(i / 4 * 32) + (i & 3) + 0x226] = 0x103C; + tilemap[(i / 4 * 32) + (i & 3) + 0x226] = TILE_FILLED_JAM_HEART; else - tilemap[(i / 4 * 32) + (i & 3) + 0x226] = 0x103D; + tilemap[(i / 4 * 32) + (i & 3) + 0x226] = TILE_EMPTY_JAM_HEART; } } } From 6d92b466e75164fb025909bdd74d5071d5bf646b Mon Sep 17 00:00:00 2001 From: GriffinR Date: Fri, 25 Jun 2021 11:50:09 -0400 Subject: [PATCH 18/18] Add missing use of F_TRAINER_FEMALE --- src/battle_main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/battle_main.c b/src/battle_main.c index 001e2ec17c..977bcbd9c1 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -1961,10 +1961,10 @@ static u8 CreateNPCTrainerParty(struct Pokemon *party, u16 trainerNum, bool8 fir if (gTrainers[trainerNum].doubleBattle == TRUE) personalityValue = 0x80; - else if (gTrainers[trainerNum].encounterMusic_gender & 0x80) - personalityValue = 0x78; + else if (gTrainers[trainerNum].encounterMusic_gender & F_TRAINER_FEMALE) + personalityValue = 0x78; // Use personality more likely to result in a female Pokémon else - personalityValue = 0x88; + personalityValue = 0x88; // Use personality more likely to result in a male Pokémon for (j = 0; gTrainers[trainerNum].trainerName[j] != EOS; j++) nameHash += gTrainers[trainerNum].trainerName[j];