Skip to content

Commit 5737609

Browse files
authored
Various RAM map documentation and alignment with SA3 (#175)
* Various documentation and alignment with SA3 * Extract input_recorder.c .data section from core.c, as in SA3 * Align multi_sio.c with SA3 * Document parameters of DisplaySprites * Document centerOffsetX/Y in DisplaySprites * Only display copyright note * Split GAME_ and ENGINE_ macros * Use ENGINE macros in core.c * Rename game<->engine interface procedures * Remove searching in /src for header files in genctx.py * Fix global.h<->config.h dependency in genctx.py * Only enable Task logging in debug versions * Fix uses of DEBUG, remove TEST_GFX_POINTERS because current gfx copy implementation already makes it redundant * Use 64bit as default target in Win SDL * Align some files with sa1 and sa3 * Align sprite.c and other files closer with sa1 and sa3 * Various documentation * Some dodumentation and cleanup from SA1 core.c integration * Rename sa1_leftovers/ -> sa1_sa2_shared/ * Put gEwramHeap into ewram_data section
1 parent 3cc9f44 commit 5737609

File tree

193 files changed

+853
-598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+853
-598
lines changed

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ ifeq ($(PLATFORM),gba)
3030
PREFIX := arm-none-eabi-
3131
else ifeq ($(CPU_ARCH),i386)
3232
ifeq ($(PLATFORM),sdl_win32)
33-
TOOLCHAIN := /usr/i686-w64-mingw32/
34-
PREFIX := i686-w64-mingw32-
33+
TOOLCHAIN := /usr/x86_64-w64-mingw32/
34+
PREFIX := x86_64-w64-mingw32-
3535
else ifeq ($(PLATFORM),win32)
36-
TOOLCHAIN := /usr/i686-w64-mingw32/
37-
PREFIX := i686-w64-mingw32-
36+
TOOLCHAIN := /usr/x86_64-w64-mingw32/
37+
PREFIX := x86_64-w64-mingw32-
3838
endif
3939
else
4040
ifneq ($(PLATFORM),sdl)
@@ -90,7 +90,7 @@ TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE))
9090
CPPFLAGS ?= -iquote include -D $(GAME_REGION)
9191
CC1FLAGS ?= -Wimplicit -Wparentheses -Werror
9292

93-
SDL_MINGW_PKG := ext/SDL2-2.30.3/i686-w64-mingw32
93+
SDL_MINGW_PKG := ext/SDL2-2.30.3/x86_64-w64-mingw32
9494
SDL_MINGW_INCLUDE := $(SDL_MINGW_PKG)/include/SDL2
9595
SDL_MINGW_BIN := $(SDL_MINGW_PKG)/bin
9696
SDL_MINGW_SDL_DLL := $(SDL_MINGW_PKG)/bin/SDL2.dll
@@ -146,6 +146,7 @@ ifeq ($(DEBUG),1)
146146
CPPFLAGS += -D DEBUG=1
147147
else
148148
CC1FLAGS += -O2
149+
CPPFLAGS += -D DEBUG=0
149150
endif
150151

151152
ifeq ($(PORTABLE),1)
@@ -435,7 +436,7 @@ ifeq ($(PLATFORM),sdl)
435436
else ifeq ($(PLATFORM),sdl_win32)
436437
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -lmingw32 -L$(ROOT_DIR)/$(SDL_MINGW_LIB) -lSDL2main -lSDL2.dll -lwinmm -lkernel32 -lxinput -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
437438
else
438-
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -lkernel32 -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
439+
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -lkernel32 -lgdi32 -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
439440
endif
440441
endif
441442

@@ -446,7 +447,7 @@ ifeq ($(PLATFORM),gba)
446447
else ifeq ($(PLATFORM),sdl)
447448
cp $< $@
448449
else
449-
$(OBJCOPY) -O pei-i386 $< $@
450+
$(OBJCOPY) -O pei-x86-64 $< $@
450451
ifeq ($(CREATE_PDB),1)
451452
$(CV2PDB) $@
452453
endif

asm/macros/c_decl.inc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
21
// NOTE:
32
// For this to work, the file that is including this file HAS to be passed through the C preprocessor before assembling!
43

54
// 32bit Windows and MacOS versions prefix labels using an underscore.
65
// For interoperability we need to replicate that behavior here.
7-
#if ( (CPU_ARCH_X86 && defined(__WIN32)) || defined(__APPLE__) )
6+
#if ( (CPU_ARCH_X86 && defined(_WIN32) && !defined(_WIN64)) || defined(__APPLE__) )
87
#define C_DECL(label) _##label
98
#else
109
#define C_DECL(label) label

asm/non_matching/game/sa1_leftovers/coll__sub_800C4FC.inc renamed to asm/non_matching/game/sa1_sa2_shared/coll__sub_800C4FC.inc

File renamed without changes.

asm/non_matching/game/sa1_leftovers/input_buf__sub_800DF8C.inc renamed to asm/non_matching/game/sa1_sa2_shared/input_buf__sub_800DF8C.inc

File renamed without changes.

asm/non_matching/game/sa1_leftovers/interactables/.gitkeep renamed to asm/non_matching/game/sa1_sa2_shared/interactables/.gitkeep

File renamed without changes.

asm/non_matching/game/sa1_leftovers/interactables/CreatePlatformBreakParticles.inc renamed to asm/non_matching/game/sa1_sa2_shared/interactables/CreatePlatformBreakParticles.inc

File renamed without changes.

genctx.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,32 @@
2525
def search_directories(*patterns):
2626
return it.chain.from_iterable(glob.iglob(pattern,recursive=True) for pattern in patterns)
2727

28-
for filename in search_directories('./src/**/*.h', './include/**/*.h'):
28+
for filename in search_directories('./include/**/*.h'):
2929
with open(filename) as header:
3030
header_name = "/".join(filename.split('/')[2:])
31-
32-
# not needed for decomp work
33-
if header_name.startswith("platform"):
34-
continue
3531

3632
if not header_name in depends_on:
3733
depends_on[header_name] = set()
38-
if not header_name.startswith("gba/") and header_name != "global.h" and header_name != "functions.h":
39-
depends_on[header_name].add("global.h")
40-
41-
if header_name.startswith("gba/") and not header_name.endswith("types.h") and not header_name.endswith("defines.h"):
42-
depends_on[header_name].add("gba/types.h")
34+
35+
if not header_name.startswith("gba/"):
36+
if header_name != "global.h" \
37+
and header_name != "config.h" \
38+
and header_name != "functions.h":
39+
depends_on[header_name].add("global.h")
4340

44-
if header_name.startswith("gba/") and not header_name.endswith("multiboot.h") and not header_name.endswith("types.h"):
45-
depends_on[header_name].add("gba/multiboot.h")
41+
else: # header_name.startswith("gba/")
42+
if not header_name.endswith("types.h") \
43+
and not header_name.endswith("defines.h"):
44+
depends_on[header_name].add("gba/types.h")
45+
elif not header_name.endswith("multiboot.h") \
46+
and not header_name.endswith("types.h"):
47+
depends_on[header_name].add("gba/multiboot.h")
4648

4749
data[header_name] = ""
4850
for line in header.readlines():
49-
if "#include" in line and not line.startswith("//") and '<' not in line:
51+
if "#include" in line \
52+
and not line.startswith("//") \
53+
and '<' not in line:
5054
requires = line.split('"')[1]
5155
depends_on[header_name].add(requires)
5256
continue
@@ -58,7 +62,6 @@ def search_directories(*patterns):
5862
print_order = tuple(ts.static_order())
5963

6064
with open('ctx.c', 'w') as context:
61-
context.write("#define PLATFORM_GBA 1\n")
6265
for header in print_order:
6366
exclude = False
6467
for e in excluded:

include/animation_commands_bg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,4 @@ void UpdateBgAnimationTiles(Background *);
88

99
s32 RenderText(void *dest, const void *font, u16 x, u16 y, u8 bg, const char *text, u8 palette);
1010

11-
void numToASCII(u8 digits[5], u16 number);
12-
1311
#endif // GUARD_ANIMATION_COMMANDS_EXTRA_H

include/config.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33

44
/* TODO: Move config.h into a different location? */
55

6-
#define GAME_SA1 1
7-
#define GAME_SA2 2
8-
#define GAME_SA3 3
6+
#define GAME_SA1 1
7+
#define GAME_SA2 2
8+
#define GAME_SA3 3
9+
#define GAME_KATAM 4
910

10-
// TODO: Define this in Makefile through a compiler macro!
11+
#define ENGINE_1 1
12+
#define ENGINE_2 2
13+
#define ENGINE_3 3
14+
#define ENGINE_4 4
15+
16+
// TODO: Define this in Makefile through a compiler macro?
1117
#define GAME GAME_SA2
1218

19+
// TODO: Do SA1 and SA2 use the same engine ver?
20+
// TODO: Do SA3 and KATAM use the same engine ver?
21+
#define ENGINE GAME
22+
1323
// TODO: Put somewhere else?
1424
#if PLATFORM_GBA
1525
#define USE_NEW_DMA 0

include/core.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ extern u8 gNumHBlankCallbacks;
224224
extern u8 gNumHBlankIntrs;
225225

226226
extern u8 gIwramHeap[0x2204];
227-
extern u8 gEwramHeap[0x20080];
228227

229228
extern void *gVramHeapStartAddr;
230229
extern u16 gVramHeapMaxTileSlots;
@@ -273,7 +272,7 @@ extern u16 gUnknown_03001944;
273272
extern u8 gUnknown_03001948;
274273
extern u16 gUnknown_0300194C;
275274

276-
extern Tilemap **gTilemapsRef; // TODO: make this an array and add size
275+
extern Tilemap **gTilemapsRef;
277276
extern u8 gUnknown_03002280[4][4];
278277
extern u8 gUnknown_03004D80[16]; // TODO: Is this 4 (# backgrounds), instead of 16?
279278

@@ -294,17 +293,6 @@ extern u8 gVramGraphicsCopyQueueIndex;
294293

295294
#define INC_GRAPHICS_QUEUE_CURSOR(cursor) cursor = (cursor + 1) % ARRAY_COUNT(gVramGraphicsCopyQueue);
296295

297-
/* Make sure that both pointers are valid */
298-
#ifndef DEBUG
299-
#define TEST_GFX_POINTERS(gfx)
300-
#else
301-
#define TEST_GFX_POINTERS(gfx) \
302-
{ \
303-
volatile u8 testVarDst = *(u8 *)((gfx)->dest); \
304-
volatile u8 testVarSrc = *(u8 *)((gfx)->src); \
305-
}
306-
#endif
307-
308296
#if PORTABLE
309297
// On the GBA we use a fixed heap to allocate memory
310298
// but on other OS's we malloc and free memory which
@@ -315,15 +303,13 @@ extern u8 gVramGraphicsCopyQueueIndex;
315303
// has not happened we don't get invalid memory access
316304
extern struct GraphicsData gVramGraphicsCopyQueueBuffer[32];
317305
#define ADD_TO_GRAPHICS_QUEUE(gfx) \
318-
TEST_GFX_POINTERS(gfx); \
319306
memcpy(&gVramGraphicsCopyQueueBuffer[gVramGraphicsCopyQueueIndex], gfx, sizeof(struct GraphicsData)); \
320307
gVramGraphicsCopyQueue[gVramGraphicsCopyQueueIndex] = &gVramGraphicsCopyQueueBuffer[gVramGraphicsCopyQueueIndex]; \
321308
/* Log has to happen before gVramGraphicsCopyQueueIndex increment */ \
322309
GFX_QUEUE_LOG_ADD(gfx) \
323310
INC_GRAPHICS_QUEUE_CURSOR(gVramGraphicsCopyQueueIndex);
324311
#else
325312
#define ADD_TO_GRAPHICS_QUEUE(gfx) \
326-
TEST_GFX_POINTERS(gfx); \
327313
gVramGraphicsCopyQueue[gVramGraphicsCopyQueueIndex] = gfx; \
328314
/* Log has to happen before gVramGraphicsCopyQueueIndex increment */ \
329315
GFX_QUEUE_LOG_ADD(gfx) \
@@ -368,7 +354,7 @@ extern struct MultiBootParam gMultiBootParam;
368354

369355
extern const struct SpriteTables *gRefSpriteTables;
370356

371-
void GameInit(void);
372-
void GameLoop(void);
357+
void EngineInit(void);
358+
void EngineMainLoop(void);
373359

374360
#endif

0 commit comments

Comments
 (0)