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

Keep consistency between SA1 and SA2 #201

Merged
merged 21 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Thumbs.db
ehthumbs.db

# Visual Studio folder
.vs
*.pdb

# Folder config file
Desktop.ini

Expand Down Expand Up @@ -67,8 +71,6 @@ tools/agbcc
/ctx.c
reports
.vscode/*.log
.vs/
*.pdb
*.gbapal
*.lz
*.rl
Expand Down
70 changes: 44 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ endif
SHELL := /bin/bash -o pipefail
SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c

DEFAULT_CC1 := tools/agbcc/bin/agbcc$(EXE)
ifeq ($(PLATFORM),gba)
CC1 := tools/agbcc/bin/agbcc$(EXE)
CC1 := $(DEFAULT_CC1)
freshollie marked this conversation as resolved.
Show resolved Hide resolved
CC1_OLD := tools/agbcc/bin/old_agbcc$(EXE)
else
CC1 := $(PREFIX)gcc$(EXE)
Expand Down Expand Up @@ -133,6 +134,9 @@ INCLUDE_DIRS = include
INCLUDE_CPP_ARGS := $(INCLUDE_DIRS:%=-iquote %)
INCLUDE_SCANINC_ARGS := $(INCLUDE_DIRS:%=-I %)

ASM_SUBDIR = asm
ASM_BUILDDIR = $(OBJ_DIR)/$(ASM_SUBDIR)

C_SUBDIR = src
C_BUILDDIR = $(OBJ_DIR)/$(C_SUBDIR)

Expand Down Expand Up @@ -172,6 +176,9 @@ C_HEADERS := $(shell find $(INCLUDE_DIRS) -name "*.h" -not -path "*/platform/*")
ifeq ($(PLATFORM),gba)
C_ASM_SRCS := $(shell find $(C_SUBDIR) -name "*.s")
C_ASM_OBJS := $(patsubst $(C_SUBDIR)/%.s,$(C_BUILDDIR)/%.o,$(C_ASM_SRCS))

ASM_SRCS := $(wildcard $(ASM_SUBDIR)/*.s)
ASM_OBJS := $(patsubst $(ASM_SUBDIR)/%.s,$(ASM_BUILDDIR)/%.o,$(ASM_SRCS))
endif

DATA_ASM_SRCS := $(wildcard $(DATA_ASM_SUBDIR)/*.s)
Expand All @@ -186,7 +193,7 @@ MID_OBJS := $(patsubst $(MID_SUBDIR)/%.mid,$(MID_BUILDDIR)/%.o,$(MID_SRCS))
SOUND_ASM_SRCS := $(wildcard $(SOUND_ASM_SUBDIR)/*.s)
SOUND_ASM_OBJS := $(patsubst $(SOUND_ASM_SUBDIR)/%.s,$(SOUND_ASM_BUILDDIR)/%.o,$(SOUND_ASM_SRCS))

OBJS := $(C_OBJS) $(C_ASM_OBJS) $(DATA_ASM_OBJS) $(SONG_OBJS) $(MID_OBJS)
OBJS := $(C_OBJS) $(ASM_OBJS) $(C_ASM_OBJS) $(DATA_ASM_OBJS) $(SONG_OBJS) $(MID_OBJS)
OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS))

FORMAT_SRC_PATHS := $(shell find . -name "*.c" ! -path '*/src/data/*' ! -path '*/build/*' ! -path '*/ext/*')
Expand Down Expand Up @@ -304,7 +311,7 @@ endif
.PHONY: clean tools tidy clean-tools $(TOOLDIRS) libagbsyscall

# Ensure required directories exist
$(shell mkdir -p $(C_BUILDDIR) $(DATA_ASM_BUILDDIR) $(SOUND_ASM_BUILDDIR) $(SONG_BUILDDIR) $(MID_BUILDDIR))
$(shell mkdir -p $(C_BUILDDIR) $(ASM_BUILDDIR) $(DATA_ASM_BUILDDIR) $(SOUND_ASM_BUILDDIR) $(SONG_BUILDDIR) $(MID_BUILDDIR))
freshollie marked this conversation as resolved.
Show resolved Hide resolved

# a special command which ensures that stdout and stderr
# get printed instead of output into the makefile
Expand Down Expand Up @@ -337,12 +344,32 @@ ifneq ($(NODEP),1)
export MACOSX_DEPLOYMENT_TARGET := 11
endif

# TODO: Find a better way to limit this to SA1!
ifeq ($(BUILD_NAME), sa1)
ifeq ($(CC1), $(DEFAULT_CC1))
freshollie marked this conversation as resolved.
Show resolved Hide resolved
PROLOGUE_FIX := -fprologue-bugfix
else
PROLOGUE_FIX :=
endif
endif

ifeq ($(PLATFORM),gba)
# Use the old compiler for m4a, as it was prebuilt and statically linked to the original codebase
# PROLOGUE_FIX has to be set to nothing, since -fprologue-bugfix does not work with oldagbcc
$(C_BUILDDIR)/lib/m4a/m4a.o: CC1 := $(CC1_OLD)
$(C_BUILDDIR)/lib/m4a/m4a.o: PROLOGUE_FIX :=
# Use `-O1` for agb_flash libs, as these were also prebuilt
$(C_BUILDDIR)/lib/agb_flash/agb_flash.o: CC1FLAGS := -O1 -mthumb-interwork -Werror
$(C_BUILDDIR)/lib/agb_flash/agb_flash%.o: CC1FLAGS := -O1 -mthumb-interwork -Werror
endif

#### Main Targets ####

ifeq ($(PLATFORM),gba)
all: compare

compare: rom
$(SHA1) $(BUILD_NAME).sha1

else
all: rom
endif
Expand Down Expand Up @@ -377,15 +404,14 @@ japan: ; @$(MAKE) GAME_REGION=JAPAN

europe: ; @$(MAKE) GAME_REGION=EUROPE


sdl: ; @$(MAKE) PLATFORM=sdl

sdl_win32:
@$(MAKE) PLATFORM=sdl_win32 CPU_ARCH=i386

win32: ; @$(MAKE) PLATFORM=win32 CPU_ARCH=i386

#### Recipes ####
#### RECIPES ####

include songs.mk
include graphics.mk
Expand All @@ -400,9 +426,9 @@ include graphics.mk
%.gbapal: %.pal ; $(GFX) $< $@
%.gbapal: %.png ; $(GFX) $< $@

chao_garden/mb_chao_garden.gba.lz: chao_garden/mb_chao_garden.gba
chao_garden/mb_chao_garden.gba.lz: chao_garden/mb_chao_garden.gba
$(GFX) $< $@ -search 1

data/mb_chao_garden_japan.gba.lz: data/mb_chao_garden_japan.gba
$(GFX) $< $@ -search 1

Expand All @@ -428,7 +454,7 @@ data/mb_chao_garden_japan.gba.lz: data/mb_chao_garden_japan.gba

%.bin: %.aif ; $(AIF) $< $@

$(ELF): $(OBJS) libagbsyscall
$(ELF): $(OBJS) $(LDSCRIPT) libagbsyscall
freshollie marked this conversation as resolved.
Show resolved Hide resolved
ifeq ($(PLATFORM),gba)
@echo "$(LD) -T $(LDSCRIPT) $(MAP_FLAG) $(MAP) <objects> <lib> -o $@"
@$(CPP) -P $(CPPFLAGS) $(LDSCRIPT) > $(OBJ_DIR)/$(LDSCRIPT)
Expand All @@ -452,21 +478,12 @@ ifeq ($(CREATE_PDB),1)
endif
endif

ifeq ($(PLATFORM),gba)
# Use the old compiler for m4a, as it was prebuilt and statically linked
# to the original codebase
$(C_BUILDDIR)/lib/m4a/m4a.o: CC1 := $(CC1_OLD)
# Use `-O1` for agb_flash libs, as these were also prebuilt
$(C_BUILDDIR)/lib/agb_flash/agb_flash.o: CC1FLAGS := -O1 -mthumb-interwork -Werror
$(C_BUILDDIR)/lib/agb_flash/agb_flash%.o: CC1FLAGS := -O1 -mthumb-interwork -Werror
endif

# Build c sources, and ensure alignment
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.c
@echo "$(CC1) <flags> -o $@ $<"
@$(shell mkdir -p $(shell dirname '$(C_BUILDDIR)/$*.i'))
@$(CPP) $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i
@$(PREPROC) $(C_BUILDDIR)/$*.i | $(CC1) $(CC1FLAGS) -o $(C_BUILDDIR)/$*.s -
@$(PREPROC) $(C_BUILDDIR)/$*.i | $(CC1) $(PROLOGUE_FIX) $(CC1FLAGS) -o $(C_BUILDDIR)/$*.s -
ifeq ($(PLATFORM), gba)
@printf ".text\n\t.align\t2, 0\n" >> $(C_BUILDDIR)/$*.s
endif
Expand All @@ -477,24 +494,25 @@ $(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.c
@$(shell mkdir -p $(shell dirname '$(C_BUILDDIR)/$*.d'))
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) $<

ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(C_SRCS:.c=.d))
endif

# rule for sources from the src dir (parts of libraries)
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s
@echo "$(AS) <flags> -o $@ $<"
@$(AS) $(ASFLAGS) -o $@ $<

$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $$(asm_dep)
@echo "$(AS) <flags> -o $@ $<"
@$(AS) $(ASFLAGS) -o $@ $<

$(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s
@echo "$(AS) <flags> -o $@ $<"
@$(PREPROC) $< "" | $(CPP) $(CPPFLAGS) - | $(AS) $(ASFLAGS) -o $@ -

# Scan the ASM data dependencies to determine if any .inc files have changed
$(DATA_ASM_BUILDDIR)/%.d: $(DATA_ASM_SUBDIR)/%.s
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<

ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(C_SRCS:.c=.d))
-include $(addprefix $(OBJ_DIR)/,$(DATA_ASM_SRCS:.s=.d))
endif

Expand All @@ -514,7 +532,7 @@ endif

chao_garden: tools
@$(MAKE) -C chao_garden DEBUG=0

# Dependency here is already explicit, but we sometimes get a race condition if this
# is not specified
multi_boot/subgame_bootstrap/subgame_bootstrap.gba: multi_boot/programs/subgame_loader/subgame_loader.bin
Expand Down Expand Up @@ -558,7 +576,7 @@ bribasa:

$(TOOLDIRS): tool_libs
@$(MAKE) -C $@

### DEPS INSTALL COMMANDS ###

$(SDL_MINGW_LIB):
Expand Down
3 changes: 2 additions & 1 deletion include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ extern u16 gBgCntRegs[4];
// [4]{s16 x, s16 y}
extern s16 gBgScrollRegs[NUM_BACKGROUNDS][2];

extern OamData gUnknown_030022C8;
extern OamData gOamBuffer2[OAM_ENTRY_COUNT];
extern OamData gOamBuffer[OAM_ENTRY_COUNT];

Expand Down Expand Up @@ -340,8 +339,10 @@ extern struct GraphicsData gVramGraphicsCopyQueueBuffer[32];

extern void *gUnknown_030022AC;
extern void *gUnknown_030022C0;
#if (GAME == GAME_SA2)
extern s16 gMosaicReg;
extern u8 gUnknown_030026F4;
#endif
extern u16 gUnknown_03002820;
extern u8 gUnknown_03002874;
extern void *gUnknown_03002878;
Expand Down
2 changes: 1 addition & 1 deletion include/game/sa1_sa2_shared/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ extern u8 gMultiplayerConnections;
// Only set after the player passed it, used to determine extra score
extern s32 gStageGoalX;

extern u8 gUnknown_03005428[4];
extern u8 gMPRingCollectWins[4];
extern u8 gMultiplayerCharRings[MULTI_SIO_PLAYERS_MAX];

extern RoomEvent gRoomEventQueue[16];
Expand Down
24 changes: 12 additions & 12 deletions multi_boot/roms/collect_rings/asm/code.s
Original file line number Diff line number Diff line change
Expand Up @@ -24212,7 +24212,7 @@ sub_0200BEA8: @ 0x0200BEA8
asrs r1, r0, #0x18
cmp r1, #0x1c
bne _0200BED0
ldr r0, _0200BEEC @ =gUnknown_03005428
ldr r0, _0200BEEC @ =gMPRingCollectWins
ldrb r0, [r0]
cmp r0, #0
beq _0200BF3C
Expand All @@ -24230,7 +24230,7 @@ _0200BED0:
.align 2, 0
_0200BEE4: .4byte gUnknown_03005444
_0200BEE8: .4byte gUnknown_03005524
_0200BEEC: .4byte gUnknown_03005428
_0200BEEC: .4byte gMPRingCollectWins
_0200BEF0: .4byte gUnknown_03005548
_0200BEF4:
ldr r0, _0200BF44 @ =sub_0200BF54
Expand Down Expand Up @@ -29385,7 +29385,7 @@ _0200E4BA:
asrs r1, r0, #0x18
cmp r1, #0x1c
bne _0200E4D6
ldr r0, _0200E4F4 @ =gUnknown_03005428
ldr r0, _0200E4F4 @ =gMPRingCollectWins
ldrb r0, [r0]
cmp r0, #0
beq _0200E4DA
Expand All @@ -29403,7 +29403,7 @@ _0200E4E4: .4byte gUnknown_03005650
_0200E4E8: .4byte 0x80000080
_0200E4EC: .4byte 0x0000FB20
_0200E4F0: .4byte gUnknown_03005524
_0200E4F4: .4byte gUnknown_03005428
_0200E4F4: .4byte gMPRingCollectWins
_0200E4F8: .4byte gUnknown_030053F4
_0200E4FC: .4byte gUnknown_03005434
_0200E500:
Expand Down Expand Up @@ -29961,7 +29961,7 @@ _0200E904:
asrs r1, r0, #0x18
cmp r1, #0x1c
bne _0200E920
ldr r0, _0200E98C @ =gUnknown_03005428
ldr r0, _0200E98C @ =gMPRingCollectWins
ldrb r0, [r0]
cmp r0, #0
beq _0200E924
Expand Down Expand Up @@ -30020,7 +30020,7 @@ _0200E95A:
b _0200E9A6
.align 2, 0
_0200E988: .4byte gUnknown_03005524
_0200E98C: .4byte gUnknown_03005428
_0200E98C: .4byte gMPRingCollectWins
_0200E990: .4byte gUnknown_03005650
_0200E994: .4byte gUnknown_030026D0
_0200E998: .4byte sub_0200E7F8
Expand Down Expand Up @@ -32219,7 +32219,7 @@ _0200FA22:
asrs r1, r0, #0x18
cmp r1, #0x1c
bne _0200FA8A
ldr r0, _0200FAC8 @ =gUnknown_03005428
ldr r0, _0200FAC8 @ =gMPRingCollectWins
ldrb r0, [r0]
cmp r0, #0
beq _0200FA8E
Expand Down Expand Up @@ -32254,7 +32254,7 @@ _0200FA9A:
.align 2, 0
_0200FAC0: .4byte gUnknown_02014FB8
_0200FAC4: .4byte gUnknown_03005524
_0200FAC8: .4byte gUnknown_03005428
_0200FAC8: .4byte gMPRingCollectWins
_0200FACC: .4byte gUnknown_03005650
_0200FAD0: .4byte 0xFFFFBFFF
_0200FAD4: .4byte gUnknown_030056C0
Expand Down Expand Up @@ -37628,7 +37628,7 @@ sub_02012308: @ 0x02012308
strb r4, [r0]
ldr r0, _02012434 @ =gUnknown_0300546C
strb r4, [r0]
ldr r0, _02012438 @ =gUnknown_03005428
ldr r0, _02012438 @ =gMPRingCollectWins
strb r4, [r0]
ldr r5, _0201243C @ =gUnknown_030053D4
ldrh r0, [r5]
Expand Down Expand Up @@ -37750,7 +37750,7 @@ _02012428: .4byte sub_020127B4
_0201242C: .4byte gUnknown_030057D0
_02012430: .4byte gUnknown_030053CC
_02012434: .4byte gUnknown_0300546C
_02012438: .4byte gUnknown_03005428
_02012438: .4byte gMPRingCollectWins
_0201243C: .4byte gUnknown_030053D4
_02012440: .4byte 0x0000FF7F
_02012444: .4byte gUnknown_030053E4
Expand Down Expand Up @@ -38038,7 +38038,7 @@ sub_020126AC: @ 0x020126AC
ldr r0, _020126DC @ =gUnknown_03005404
movs r1, #0
str r1, [r0]
ldr r0, _020126E0 @ =gUnknown_03005428
ldr r0, _020126E0 @ =gMPRingCollectWins
strb r1, [r0]
ldr r1, _020126E4 @ =gUnknown_030053FC
movs r0, #3
Expand All @@ -38059,7 +38059,7 @@ _020126CA:
bx r0
.align 2, 0
_020126DC: .4byte gUnknown_03005404
_020126E0: .4byte gUnknown_03005428
_020126E0: .4byte gMPRingCollectWins
_020126E4: .4byte gUnknown_030053FC
_020126E8: .4byte gUnknown_03005444

Expand Down
2 changes: 1 addition & 1 deletion multi_boot/roms/collect_rings/sym_iwram.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
. = 0x00005404; gUnknown_03005404 = .;
. = 0x00005408; gUnknown_03005408 = .;
. = 0x00005418; gUnknown_03005418 = .;
. = 0x00005428; gUnknown_03005428 = .;
. = 0x00005428; gMPRingCollectWins = .;
. = 0x0000542C; gUnknown_0300542C = .;
. = 0x00005430; gUnknown_03005430 = .;
. = 0x00005434; gUnknown_03005434 = .;
Expand Down
4 changes: 2 additions & 2 deletions src/game/multiboot/collect_rings/results.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,10 +509,10 @@ void sub_8082788(void)
UpdateSpriteAnimation(s);
DisplaySprite(s);

if (gUnknown_03005428[i] > 99) {
if (gMPRingCollectWins[i] > 99) {
temp = 99;
} else {
temp = Base10DigitsToHexNibbles(gUnknown_03005428[i]);
temp = Base10DigitsToHexNibbles(gMPRingCollectWins[i]);
}

s = &resultsScreen->unk160[((temp) >> 4)];
Expand Down
4 changes: 2 additions & 2 deletions src/game/multiboot/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void sub_80818B8(void)
if (recv->pat0.unk0 == 0x4010) {
for (j = 0; j < 4; j++) {
gMultiplayerCharacters[j] = 0;
gUnknown_03005428[j] = 0;
gMPRingCollectWins[j] = 0;
gUnknown_030054B4[j] = j;
gMultiplayerMissingHeartbeats[j] = 0;
}
Expand Down Expand Up @@ -519,7 +519,7 @@ void ShowSinglePakResults(void)
u32 i;
for (i = 0; i < MULTI_SIO_PLAYERS_MAX; i++) {
gMultiplayerCharacters[i] = 0;
gUnknown_03005428[i] = 0;
gMPRingCollectWins[i] = 0;
gUnknown_030054B4[i] = i;
gMultiplayerMissingHeartbeats[i] = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/multiplayer/finish.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void Task_TransitionToResultsScreen(void)
gMultiplayerCharacters[sp00[i]] = 2;
} else {
gUnknown_030054B4[sp00[0]] = i;
gUnknown_03005428[sp00[0]]++;
gMPRingCollectWins[sp00[0]]++;
gMultiplayerCharacters[sp00[0]] = i;
}
}
Expand Down
Loading