Skip to content

Commit

Permalink
Integrate SA2's Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
JaceCear committed Jan 31, 2025
1 parent 4032ab9 commit fccc022
Show file tree
Hide file tree
Showing 199 changed files with 1,208 additions and 843 deletions.
581 changes: 423 additions & 158 deletions Makefile

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions asm/game__mp__results.s
Original file line number Diff line number Diff line change
Expand Up @@ -2938,8 +2938,8 @@ sub_8019D9C: @ 0x08019D9C
pop {r0}
bx r0

thumb_func_start sub_8019DB0
sub_8019DB0: @ 0x08019DB0
thumb_func_start sa2__sub_8019F08
sa2__sub_8019F08: @ 0x08019DB0
push {r4, r5, r6, r7, lr}
mov r7, sb
mov r6, r8
Expand Down
4 changes: 2 additions & 2 deletions asm/game__stage__stage.s
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ _0803D500:
adds r0, r2, #0
orrs r0, r4
strh r0, [r3]
bl sub_8019DB0
bl sa2__sub_8019F08
b _0803D586
_0803D50C:
ldr r0, _0803D54C @ =gCourseTime
Expand Down Expand Up @@ -870,7 +870,7 @@ _0803D57C:
adds r0, r2, #0
orrs r0, r4
strh r0, [r3]
bl sub_8019DB0
bl sa2__sub_8019F08
_0803D586:
add sp, #4
pop {r4, r5, r6, r7}
Expand Down
2 changes: 1 addition & 1 deletion asm/ia_stage_goal.s
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ _0801FD18:
ldr r1, [r0]
ldr r0, _0801FD5C @ =Task_StageGoal6
str r0, [r1, #8]
bl sub_8019DB0
bl sa2__sub_8019F08
b _0801FD8E
.align 2, 0
_0801FD2C: .4byte 0x04000128
Expand Down
10 changes: 10 additions & 0 deletions asm/macros/c_decl.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// NOTE:
// For this to work, the file that is including this file HAS to be passed through the C preprocessor before assembling!

// 32bit Windows and MacOS versions prefix labels using an underscore.
// For interoperability we need to replicate that behavior here.
#if ( (CPU_ARCH_X86 && defined(_WIN32) && !defined(_WIN64)) || defined(__APPLE__) )
#define C_DECL(label) _##label
#else
#define C_DECL(label) label
#endif
29 changes: 29 additions & 0 deletions asm/macros/portable.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.macro mSectionRodata
#if (!CPU_ARCH_X86 && defined(__APPLE__)) // On macos, native compilation uses this name for the rodata section
.section __DATA,__data
#else
.section .rodata
#endif
.endm

// Used so that we can have cross platform (32bit or 64bit) pointers
.macro mPtr value
#if defined(__aarch64__) || defined(__x86_64__)
.quad \value
#else
.int \value
#endif
.endm

// Used for cross platform aligning of labels
.macro mAlignWord
#if defined(__APPLE__) && (defined(__aarch64__) || defined(__x86_64__))
.align 3 // Align to 8 bytes on macOS (2^3 = 8)
#elif defined(__aarch64__) || defined(__x86_64__)
.align 8 // Align to 8 bytes on other platforms
#elif defined(PLATFORM_GBA)
.align 2 // Align to 4 bytes on GBA
#else
.align 4 // Default alignment to 4 bytes
#endif
.endm
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ _080181DA:
ldr r1, [sp, #8]
cmp r1, #0
bne _080181E4
bl sub_8019DB0
bl sa2__sub_8019F08
_080181E4:
add sp, #0x14
pop {r3, r4, r5}
Expand Down
60 changes: 57 additions & 3 deletions config.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
### Build Configuration ###

# Default variables
# Default platform variables
PLATFORM ?= gba
CPU_ARCH ?= arm
MIDI_COMMENTS := "arm"
THUMB_SUPPORT ?= 1 # Supports ARM's Thumb instruction set
COMPARE ?= 1


ifeq ($(CPU_ARCH),arm)
ifneq ($(PLATFORM),gba)
THUMB_SUPPORT ?= 0
endif

MIDI_COMMENTS := "arm"
# This is 'i386' because that's the arch's name in GNU Linker scripts
else ifeq ($(CPU_ARCH),i386)
THUMB_SUPPORT ?= 0
MIDI_COMMENTS := "x86"
else
$(error unknown arch: $(CPU_ARCH))
endif

LDSCRIPT := ldscript

NON_MATCHING ?= 0
ifeq ($(PLATFORM),gba)
ifeq ($(DEBUG),1)
# Debug
PORTABLE := 0
NON_MATCHING := 1
ENABLE_DECOMP_CREDITS := 1
COMPARE ?= 0
LDSCRIPT := $(LDSCRIPT).txt
else
# Original
PORTABLE := 0
NON_MATCHING := 0
ENABLE_DECOMP_CREDITS := 0
COMPARE ?= 1
LDSCRIPT := $(LDSCRIPT).txt
endif
else
# Other
PORTABLE := 1
NON_MATCHING := 1
ENABLE_DECOMP_CREDITS := 1
COMPARE ?= 0
LDSCRIPT := $(LDSCRIPT).txt
endif

# Default game variables
GAME_REVISION ?= 0
GAME_REGION ?= EUROPE
DEBUG ?= 0
COMPARE ?= 1

# For gbafix
MAKER_CODE := 6W
Expand All @@ -26,7 +75,6 @@ endif
ifeq ($(GAME_REGION), USA)
BUILD_NAME := $(BUILD_NAME)_usa
GAME_CODE := $(GAME_CODE)E

else
ifeq ($(GAME_REGION), EUROPE)
BUILD_NAME := $(BUILD_NAME)
Expand All @@ -36,6 +84,12 @@ else
endif
endif

ifeq ($(CREATE_PDB),1)
# If the user wants a PDB, the output needs to include debug info
# TODO: Is there a way to ECHO here?
DEBUG := 1
endif

# Debug
ifeq ($(DEBUG), 1)
COMPARE := 0
Expand Down
2 changes: 1 addition & 1 deletion include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ extern u8 sa2__gUnknown_03004D60[0x20];
extern u8 sa2__gUnknown_03005390;
extern u16 sa2__gUnknown_03005394;
extern u16 sa2__gUnknown_03005398;
extern FuncType_030053A0 sa2__gUnknown_030053A0[4];
extern FuncType_030053A0 gVBlankIntrs[4];
extern s32 gPseudoRandom;
extern u8 sa2__gUnknown_03002710[128];
// extern struct MultiBootParam gMultiBootParam;
Expand Down
2 changes: 1 addition & 1 deletion include/game/multiplayer/finish.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
#include "global.h"

void sa2__sub_8019CCC(u8 sioId, u8 count);
void sub_8019F08(void);
void sa2__sub_8019F08(void);

#endif // GUARD_MULTIPLAYER_FINISH_H
46 changes: 40 additions & 6 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,51 @@
#include "config.h"
#include "gba/gba.h"

#if PLATFORM_GBA
#define ENABLE_AUDIO TRUE
#else
#define ENABLE_AUDIO TRUE
#define ENABLE_VRAM_VIEW !TRUE
#endif

#define CONST_DATA __attribute__((section(".data")))

// #include "types.h"
// #include "variables.h"

#if !PLATFORM_GBA
#ifdef _WIN32
void *Platform_malloc(int numBytes);
void Platform_free(void *ptr);
#define malloc(numBytes) Platform_malloc(numBytes)
#define calloc(count, size) Platform_malloc(count *size)
#define free(numBytes) Platform_free(numBytes)
#endif
#endif

#define SIO_MULTI_CNT ((volatile struct SioMultiCnt *)REG_ADDR_SIOCNT)

typedef void (*VoidFn)(void);

// helper macros

#if ((defined PORTABLE) || (defined NON_MATCHING))
#if (PORTABLE)
#define BUG_FIX
#define UB_FIX
#endif

#if ((defined PORTABLE) && !(defined NON_MATCHING))
#if !(defined NON_MATCHING)
#define NON_MATCHING 1
#endif
#elif (DEBUG)
#define NON_MATCHING 1
#endif

#ifdef NON_MATCHING
#define ASM_FUNC(path, decl)
#define TEMP_FIX 1
#else
#define ASM_FUNC(path, decl) \
NAKED decl { asm(".include " #path); }
#define TEMP_FIX 0
#endif

#ifdef NON_MATCHING
Expand Down Expand Up @@ -60,6 +80,14 @@ typedef void (*VoidFn)(void);
#define INCBIN_S32 INCBIN
#endif // IDE support

// Use STR(<macro>) to turn the macro's *content* into a string
#define STR_(x) #x
#define STR(x) STR_(x)

// NOTE: This has to be kept as-is.
// If casted it to be signed,
// dataIndex = (dataIndex + 1) % ARRAY_COUNT(data)
// wouldn't match.
#define ARRAY_COUNT(array) (sizeof(array) / sizeof((array)[0]))

// Converts a number to Q8.8 fixed-point format
Expand All @@ -78,7 +106,8 @@ typedef void (*VoidFn)(void);
#define Q_20_12(n) ((s32)((n)*4096))

// Converts a number to Q24.8 fixed-point format
#define Q_24_8(n) ((s32)((n)*256))
#define Q_24_8(n) ((s32)((n)*256))
#define Q_24_8_FRAC(n) ((u8)(n))

// This may be the "real" version as we are seeing better matches with
// it in some cases
Expand All @@ -105,7 +134,12 @@ typedef void (*VoidFn)(void);
// Converts a Q2.12 fixed-point format number to a Q24.8 fixed point number
#define Q_2_14_TO_Q_24_8(n) ((int)((n) >> 6))

#define Q_24_8_MULTIPLY(intVal, floatVal) Q_24_8_TO_INT((intVal)*Q_24_8(floatVal))
// Multiplies two Q values
#define Q_MUL(qValA, qValB) ((qValA * qValB) >> 8)
#define Q_SQUARE(qVal) Q_MUL(qVal, qVal)
#define Q_DIV(qValA, qValB) Div((qValA << 8), qValB)
#define Q_DIV2(qValA, qValB) ((qValA << 8) / qValB)
#define Q_MUL_Q_F32(qVal, floatVal) Q_MUL(qVal, Q(floatVal))

/*
* Aliases for common macros
Expand Down
Loading

0 comments on commit fccc022

Please sign in to comment.