Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of common syms #2040

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,20 @@ ifneq (,$(MAKECMDGOALS))
endif
endif

.SHELLSTATUS ?= 0

ifeq ($(SETUP_PREREQS),1)
# If set on: Default target or a rule requiring a scan
# Forcibly execute `make tools` since we need them for what we are doing.
$(call infoshell, $(MAKE) -f make_tools.mk)
$(foreach line, $(shell $(MAKE) -f make_tools.mk | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
ifneq ($(.SHELLSTATUS),0)
$(error Errors occurred while building tools. See error messages above for more details)
endif
# Oh and also generate mapjson sources before we use `SCANINC`.
$(call infoshell, $(MAKE) generated)
$(foreach line, $(shell $(MAKE) generated | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
ifneq ($(.SHELLSTATUS),0)
$(error Errors occurred while generating map-related sources. See error messages above for more details)
endif
endif

# Collect sources
Expand Down Expand Up @@ -255,6 +263,8 @@ include spritesheet_rules.mk
include json_data_rules.mk
include audio_rules.mk

# NOTE: Tools must have been built prior (FIXME)
# so you can't really call this rule directly
generated: $(AUTO_GEN_TARGETS)

%.s: ;
Expand All @@ -270,8 +280,6 @@ generated: $(AUTO_GEN_TARGETS)
%.lz: % ; $(GFX) $< $@
%.rl: % ; $(GFX) $< $@

# NOTE: Tools must have been built prior (FIXME)
generated: tools $(AUTO_GEN_TARGETS)
clean-generated:
-rm -f $(AUTO_GEN_TARGETS)

Expand Down Expand Up @@ -390,6 +398,7 @@ libagbsyscall:
# Elf from object files
$(ELF): $(LD_SCRIPT) $(LD_SCRIPT_DEPS) $(OBJS) libagbsyscall
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ $(OBJS_REL) $(LIB) | cat
@echo "cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ <objs> <libs> | cat"
$(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent

# Builds the rom from the elf file
Expand Down
1 change: 0 additions & 1 deletion common_syms/AgbRfu_LinkManager.txt

This file was deleted.

10 changes: 0 additions & 10 deletions common_syms/agb_flash.txt

This file was deleted.

3 changes: 0 additions & 3 deletions common_syms/apprentice.txt

This file was deleted.

3 changes: 0 additions & 3 deletions common_syms/battle_anim_throw.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/battle_factory_screen.txt

This file was deleted.

9 changes: 0 additions & 9 deletions common_syms/battle_main.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/battle_tower.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/berry_blender.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/bg.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/contest.txt

This file was deleted.

4 changes: 0 additions & 4 deletions common_syms/contest_painting.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/ereader_screen.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/evolution_scene.txt

This file was deleted.

3 changes: 0 additions & 3 deletions common_syms/faraway_island.txt

This file was deleted.

3 changes: 0 additions & 3 deletions common_syms/field_camera.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/field_control_avatar.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/field_specials.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/fieldmap.txt

This file was deleted.

10 changes: 0 additions & 10 deletions common_syms/image_processing_effects.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/intro.txt

This file was deleted.

5 changes: 0 additions & 5 deletions common_syms/librfu_rfu.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/librfu_sio32id.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/librfu_stwi.txt

This file was deleted.

35 changes: 0 additions & 35 deletions common_syms/link.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/link_rfu_2.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/list_menu.txt

This file was deleted.

4 changes: 0 additions & 4 deletions common_syms/load_save.txt

This file was deleted.

12 changes: 0 additions & 12 deletions common_syms/m4a.txt

This file was deleted.

9 changes: 0 additions & 9 deletions common_syms/main.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/mauville_old_man.txt

This file was deleted.

8 changes: 0 additions & 8 deletions common_syms/overworld.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/party_menu.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/pokedex.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/pokedex_cry_screen.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/random.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/rtc.txt

This file was deleted.

13 changes: 0 additions & 13 deletions common_syms/save.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/sound.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/sprite.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/start_menu.txt

This file was deleted.

1 change: 0 additions & 1 deletion common_syms/task.txt

This file was deleted.

4 changes: 0 additions & 4 deletions common_syms/text.txt

This file was deleted.

5 changes: 0 additions & 5 deletions common_syms/trainer_see.txt

This file was deleted.

4 changes: 0 additions & 4 deletions common_syms/tv.txt

This file was deleted.

2 changes: 0 additions & 2 deletions common_syms/window.txt

This file was deleted.

1 change: 1 addition & 0 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define IWRAM_DATA __attribute__((section("iwram_data")))
#define EWRAM_DATA __attribute__((section("ewram_data")))
#define COMMON_DATA __attribute__((section("common_data")))
#define UNUSED __attribute__((unused))

#if MODERN
Expand Down
1 change: 1 addition & 0 deletions ld_script.ld
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ SECTIONS {

/* COMMON starts at 0x30022A8 */
INCLUDE "sym_common.ld"
src/*.o(COMMON);
Comment on lines 44 to +45
Copy link
Member

@GriffinRichards GriffinRichards Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't include any COMMON_DATA symbols that users add to new files if they aren't explicitly included (i.e. we should wildcard common_data here too).

fwiw we had to revert wildcarding COMMON last time it was introduced here, I don't remember what the problem was specifically but I recall people with certain linker versions having issues with it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can imagine wildcarding COMMON not working previously because of the way that common symbols were previously included in the build (extracting them from the object files and then re-ordering them with alignment). However, since no variables in src/ use common variables anymore, we don't run into this problem.

The problem with wildcarding COMMON however occurs with common_data. src/*.o(common_data); in the linkerscript will cause the link process to run out of IWRAM, probably because the wildcarding isn't excluding files already in the build.

*libc.a:sbrkr.o(COMMON);
} > IWRAM

Expand Down
1 change: 1 addition & 0 deletions ld_script_modern.ld
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SECTIONS {

src/m4a.o(.bss.code);

src/*.o(common_data);
src/*.o(COMMON);
*libc.a:*.o(COMMON);
*libnosys.a:*.o(COMMON);
Expand Down
2 changes: 1 addition & 1 deletion src/AgbRfu_LinkManager.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define FSP_ON 0x01
#define FSP_START 0x02

LINK_MANAGER lman;
COMMON_DATA LINK_MANAGER lman = {0};

static void rfu_LMAN_clearVariables(void);
static void rfu_LMAN_settingPCSWITCH(u32 rand);
Expand Down
20 changes: 10 additions & 10 deletions src/agb_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ static u16 sTimerCount;
static vu16 *sTimerReg;
static u16 sSavedIme;

u8 gFlashTimeoutFlag;
u8 (*PollFlashStatus)(u8 *);
u16 (*WaitForFlashWrite)(u8 phase, u8 *addr, u8 lastData);
u16 (*ProgramFlashSector)(u16 sectorNum, u8 *src);
const struct FlashType *gFlash;
u16 (*ProgramFlashByte)(u16 sectorNum, u32 offset, u8 data);
u16 gFlashNumRemainingBytes;
u16 (*EraseFlashChip)();
u16 (*EraseFlashSector)(u16 sectorNum);
const u16 *gFlashMaxTime;
COMMON_DATA u8 gFlashTimeoutFlag = 0;
COMMON_DATA u8 (*PollFlashStatus)(u8 *) = NULL;
COMMON_DATA u16 (*WaitForFlashWrite)(u8 phase, u8 *addr, u8 lastData) = NULL;
COMMON_DATA u16 (*ProgramFlashSector)(u16 sectorNum, u8 *src) = NULL;
COMMON_DATA const struct FlashType *gFlash = NULL;
COMMON_DATA u16 (*ProgramFlashByte)(u16 sectorNum, u32 offset, u8 data) = NULL;
COMMON_DATA u16 gFlashNumRemainingBytes = 0;
COMMON_DATA u16 (*EraseFlashChip)() = NULL;
COMMON_DATA u16 (*EraseFlashSector)(u16 sectorNum) = 0;
COMMON_DATA const u16 *gFlashMaxTime = NULL;

void SetReadFlash1(u16 *dest);

Expand Down
6 changes: 3 additions & 3 deletions src/apprentice.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ struct ApprenticeQuestionData
};

// IWRAM common
struct ApprenticePartyMovesData *gApprenticePartyMovesData;
struct ApprenticeQuestionData *gApprenticeQuestionData;
void (*gApprenticeFunc)(void);
COMMON_DATA struct ApprenticePartyMovesData *gApprenticePartyMovesData = NULL;
COMMON_DATA struct ApprenticeQuestionData *gApprenticeQuestionData = NULL;
COMMON_DATA void (*gApprenticeFunc)(void) = NULL;

// This file's functions.
static u16 GetRandomAlternateMove(u8 monId);
Expand Down
6 changes: 3 additions & 3 deletions src/battle_anim_throw.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
#include "constants/rgb.h"

// iwram
u32 gMonShrinkDuration;
u16 gMonShrinkDelta;
u16 gMonShrinkDistance;
COMMON_DATA u32 gMonShrinkDuration = 0;
COMMON_DATA u16 gMonShrinkDelta = 0;
COMMON_DATA u16 gMonShrinkDistance = 0;

enum {
BALL_ROLL_1,
Expand Down
2 changes: 1 addition & 1 deletion src/battle_factory_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static struct FactorySelectScreen *sFactorySelectScreen;
static void (*sSwap_CurrentOptionFunc)(u8 taskId);
static struct FactorySwapScreen *sFactorySwapScreen;

u8 (*gFactorySelect_CurrentOptionFunc)(void);
COMMON_DATA u8 (*gFactorySelect_CurrentOptionFunc)(void) = NULL;

static const u16 sPokeballGray_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/pokeball_gray.gbapal");
static const u16 sPokeballSelected_Pal[] = INCBIN_U16("graphics/battle_frontier/factory_screen/pokeball_selected.gbapal");
Expand Down
18 changes: 9 additions & 9 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ EWRAM_DATA u16 gBattleMovePower = 0;
EWRAM_DATA u16 gMoveToLearn = 0;
EWRAM_DATA u8 gBattleMonForms[MAX_BATTLERS_COUNT] = {0};

void (*gPreBattleCallback1)(void);
void (*gBattleMainFunc)(void);
struct BattleResults gBattleResults;
u8 gLeveledUpInBattle;
void (*gBattlerControllerFuncs[MAX_BATTLERS_COUNT])(void);
u8 gHealthboxSpriteIds[MAX_BATTLERS_COUNT];
u8 gMultiUsePlayerCursor;
u8 gNumberOfMovesToChoose;
u8 gBattleControllerData[MAX_BATTLERS_COUNT]; // Used by the battle controllers to store misc sprite/task IDs for each battler
COMMON_DATA void (*gPreBattleCallback1)(void) = NULL;
COMMON_DATA void (*gBattleMainFunc)(void) = NULL;
COMMON_DATA struct BattleResults gBattleResults = {0};
COMMON_DATA u8 gLeveledUpInBattle = 0;
COMMON_DATA void (*gBattlerControllerFuncs[MAX_BATTLERS_COUNT])(void) = {0};
COMMON_DATA u8 gHealthboxSpriteIds[MAX_BATTLERS_COUNT] = {0};
COMMON_DATA u8 gMultiUsePlayerCursor = 0;
COMMON_DATA u8 gNumberOfMovesToChoose = 0;
COMMON_DATA u8 gBattleControllerData[MAX_BATTLERS_COUNT] = {0}; // Used by the battle controllers to store misc sprite/task IDs for each battler

static const struct ScanlineEffectParams sIntroScanlineParams16Bit =
{
Expand Down
Loading