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

Various RAM map documentation and alignment with SA3 #175

Merged
merged 31 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e89c35c
Various documentation and alignment with SA3
JaceCear Dec 9, 2024
71ecccb
Format
JaceCear Dec 9, 2024
c250823
Extract input_recorder.c .data section from core.c, as in SA3
JaceCear Dec 9, 2024
8a947c6
Align multi_sio.c with SA3
JaceCear Dec 9, 2024
7fdb4af
Format
JaceCear Dec 9, 2024
6cda527
Document parameters of DisplaySprites
JaceCear Dec 9, 2024
bcf1acc
Document centerOffsetX/Y in DisplaySprites
JaceCear Dec 9, 2024
04a48f0
Only display copyright note
JaceCear Dec 9, 2024
eddb0ba
Split GAME_ and ENGINE_ macros
JaceCear Dec 10, 2024
1a49900
Use ENGINE macros in core.c
JaceCear Dec 10, 2024
d4fd416
Rename game<->engine interface procedures
JaceCear Dec 10, 2024
cf83fc3
Remove searching in /src for header files in genctx.py
JaceCear Dec 12, 2024
77b1713
Fix global.h<->config.h dependency in genctx.py
JaceCear Dec 12, 2024
db26dbc
Address review comments
JaceCear Dec 19, 2024
cdb71c9
Only enable Task logging in debug versions
JaceCear Dec 19, 2024
4df35ab
Fix build
JaceCear Dec 19, 2024
c16600c
Fix uses of DEBUG, remove TEST_GFX_POINTERS because current gfx copy …
JaceCear Dec 19, 2024
6f5691e
Use 64bit as default target in Win SDL
JaceCear Dec 21, 2024
df12bd3
Align some files with sa1 and sa3
JaceCear Dec 24, 2024
e75b4f0
Align sprite.c and other files closer with sa1 and sa3
JaceCear Dec 24, 2024
e511be4
Fix build
JaceCear Dec 24, 2024
8a2e826
Various documentation
JaceCear Dec 26, 2024
fd791ff
Formatter
JaceCear Dec 26, 2024
3a2b369
Add small player note
JaceCear Dec 27, 2024
c613909
Some dodumentation and cleanup from SA1 core.c integration
JaceCear Dec 27, 2024
71951d7
Fix build
JaceCear Dec 27, 2024
57cd202
Rename sa1_leftovers/ -> sa1_sa2_shared/
JaceCear Dec 27, 2024
e760e92
Maybe fix build
JaceCear Dec 27, 2024
6db20a7
Formatter...
JaceCear Dec 27, 2024
c9f34ca
Three time's the charm?
JaceCear Dec 27, 2024
68ebace
Put gEwramHeap into ewram_data section
JaceCear Dec 28, 2024
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
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ ifeq ($(PLATFORM),gba)
PREFIX := arm-none-eabi-
else ifeq ($(CPU_ARCH),i386)
ifeq ($(PLATFORM),sdl_win32)
TOOLCHAIN := /usr/i686-w64-mingw32/
PREFIX := i686-w64-mingw32-
TOOLCHAIN := /usr/x86_64-w64-mingw32/
PREFIX := x86_64-w64-mingw32-
else ifeq ($(PLATFORM),win32)
TOOLCHAIN := /usr/i686-w64-mingw32/
PREFIX := i686-w64-mingw32-
TOOLCHAIN := /usr/x86_64-w64-mingw32/
PREFIX := x86_64-w64-mingw32-
endif
else
ifneq ($(PLATFORM),sdl)
Expand Down Expand Up @@ -90,7 +90,7 @@ TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE))
CPPFLAGS ?= -iquote include -D $(GAME_REGION)
CC1FLAGS ?= -Wimplicit -Wparentheses -Werror

SDL_MINGW_PKG := ext/SDL2-2.30.3/i686-w64-mingw32
SDL_MINGW_PKG := ext/SDL2-2.30.3/x86_64-w64-mingw32
SDL_MINGW_INCLUDE := $(SDL_MINGW_PKG)/include/SDL2
SDL_MINGW_BIN := $(SDL_MINGW_PKG)/bin
SDL_MINGW_SDL_DLL := $(SDL_MINGW_PKG)/bin/SDL2.dll
Expand Down Expand Up @@ -146,6 +146,7 @@ ifeq ($(DEBUG),1)
CPPFLAGS += -D DEBUG=1
else
CC1FLAGS += -O2
CPPFLAGS += -D DEBUG=0
endif

ifeq ($(PORTABLE),1)
Expand Down Expand Up @@ -435,7 +436,7 @@ ifeq ($(PLATFORM),sdl)
else ifeq ($(PLATFORM),sdl_win32)
@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)"
else
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -lkernel32 -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
@cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -lkernel32 -lgdi32 -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)"
endif
endif

Expand All @@ -446,7 +447,7 @@ ifeq ($(PLATFORM),gba)
else ifeq ($(PLATFORM),sdl)
cp $< $@
else
$(OBJCOPY) -O pei-i386 $< $@
$(OBJCOPY) -O pei-x86-64 $< $@
ifeq ($(CREATE_PDB),1)
$(CV2PDB) $@
endif
Expand Down
3 changes: 1 addition & 2 deletions asm/macros/c_decl.inc
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

// 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(__APPLE__) )
#if ( (CPU_ARCH_X86 && defined(_WIN32) && !defined(_WIN64)) || defined(__APPLE__) )
#define C_DECL(label) _##label
#else
#define C_DECL(label) label
Expand Down
31 changes: 17 additions & 14 deletions genctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,32 @@
def search_directories(*patterns):
return it.chain.from_iterable(glob.iglob(pattern,recursive=True) for pattern in patterns)

for filename in search_directories('./src/**/*.h', './include/**/*.h'):
for filename in search_directories('./include/**/*.h'):
with open(filename) as header:
header_name = "/".join(filename.split('/')[2:])

# not needed for decomp work
if header_name.startswith("platform"):
continue

if not header_name in depends_on:
depends_on[header_name] = set()
if not header_name.startswith("gba/") and header_name != "global.h" and header_name != "functions.h":
depends_on[header_name].add("global.h")

if header_name.startswith("gba/") and not header_name.endswith("types.h") and not header_name.endswith("defines.h"):
depends_on[header_name].add("gba/types.h")

if not header_name.startswith("gba/"):
if header_name != "global.h" \
and header_name != "config.h" \
and header_name != "functions.h":
depends_on[header_name].add("global.h")

if header_name.startswith("gba/") and not header_name.endswith("multiboot.h") and not header_name.endswith("types.h"):
depends_on[header_name].add("gba/multiboot.h")
else: # header_name.startswith("gba/")
if not header_name.endswith("types.h") \
and not header_name.endswith("defines.h"):
depends_on[header_name].add("gba/types.h")
elif not header_name.endswith("multiboot.h") \
and not header_name.endswith("types.h"):
depends_on[header_name].add("gba/multiboot.h")

data[header_name] = ""
for line in header.readlines():
if "#include" in line and not line.startswith("//") and '<' not in line:
if "#include" in line \
and not line.startswith("//") \
and '<' not in line:
requires = line.split('"')[1]
depends_on[header_name].add(requires)
continue
Expand All @@ -58,7 +62,6 @@ def search_directories(*patterns):
print_order = tuple(ts.static_order())

with open('ctx.c', 'w') as context:
context.write("#define PLATFORM_GBA 1\n")
for header in print_order:
exclude = False
for e in excluded:
Expand Down
2 changes: 0 additions & 2 deletions include/animation_commands_bg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ void UpdateBgAnimationTiles(Background *);

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

void numToASCII(u8 digits[5], u16 number);

#endif // GUARD_ANIMATION_COMMANDS_EXTRA_H
18 changes: 14 additions & 4 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,23 @@

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

#define GAME_SA1 1
#define GAME_SA2 2
#define GAME_SA3 3
#define GAME_SA1 1
#define GAME_SA2 2
#define GAME_SA3 3
#define GAME_KATAM 4

// TODO: Define this in Makefile through a compiler macro!
#define ENGINE_1 1
#define ENGINE_2 2
#define ENGINE_3 3
#define ENGINE_4 4

// TODO: Define this in Makefile through a compiler macro?
#define GAME GAME_SA2

// TODO: Do SA1 and SA2 use the same engine ver?
// TODO: Do SA3 and KATAM use the same engine ver?
#define ENGINE GAME

// TODO: Put somewhere else?
#if PLATFORM_GBA
#define USE_NEW_DMA 0
Expand Down
20 changes: 3 additions & 17 deletions include/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ extern u8 gNumHBlankCallbacks;
extern u8 gNumHBlankIntrs;

extern u8 gIwramHeap[0x2204];
extern u8 gEwramHeap[0x20080];

extern void *gVramHeapStartAddr;
extern u16 gVramHeapMaxTileSlots;
Expand Down Expand Up @@ -273,7 +272,7 @@ extern u16 gUnknown_03001944;
extern u8 gUnknown_03001948;
extern u16 gUnknown_0300194C;

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

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

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

/* Make sure that both pointers are valid */
#ifndef DEBUG
#define TEST_GFX_POINTERS(gfx)
#else
#define TEST_GFX_POINTERS(gfx) \
{ \
volatile u8 testVarDst = *(u8 *)((gfx)->dest); \
volatile u8 testVarSrc = *(u8 *)((gfx)->src); \
}
#endif

#if PORTABLE
// On the GBA we use a fixed heap to allocate memory
// but on other OS's we malloc and free memory which
Expand All @@ -315,15 +303,13 @@ extern u8 gVramGraphicsCopyQueueIndex;
// has not happened we don't get invalid memory access
extern struct GraphicsData gVramGraphicsCopyQueueBuffer[32];
#define ADD_TO_GRAPHICS_QUEUE(gfx) \
TEST_GFX_POINTERS(gfx); \
memcpy(&gVramGraphicsCopyQueueBuffer[gVramGraphicsCopyQueueIndex], gfx, sizeof(struct GraphicsData)); \
gVramGraphicsCopyQueue[gVramGraphicsCopyQueueIndex] = &gVramGraphicsCopyQueueBuffer[gVramGraphicsCopyQueueIndex]; \
/* Log has to happen before gVramGraphicsCopyQueueIndex increment */ \
GFX_QUEUE_LOG_ADD(gfx) \
INC_GRAPHICS_QUEUE_CURSOR(gVramGraphicsCopyQueueIndex);
#else
#define ADD_TO_GRAPHICS_QUEUE(gfx) \
TEST_GFX_POINTERS(gfx); \
gVramGraphicsCopyQueue[gVramGraphicsCopyQueueIndex] = gfx; \
/* Log has to happen before gVramGraphicsCopyQueueIndex increment */ \
GFX_QUEUE_LOG_ADD(gfx) \
Expand Down Expand Up @@ -368,7 +354,7 @@ extern struct MultiBootParam gMultiBootParam;

extern const struct SpriteTables *gRefSpriteTables;

void GameInit(void);
void GameLoop(void);
void EngineInit(void);
void EngineMainLoop(void);

#endif
6 changes: 0 additions & 6 deletions include/functions.h

This file was deleted.

4 changes: 2 additions & 2 deletions include/game/entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "gba/types.h"
#include "sprite.h"

#include "game/sa1_leftovers/globals.h"
#include "game/sa1_leftovers/collision.h"
#include "game/sa1_sa2_shared/globals.h"
#include "game/sa1_sa2_shared/collision.h"

#include "game/stage/collision.h"
#include "game/player_callbacks.h"
Expand Down
2 changes: 1 addition & 1 deletion include/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#include "global.h"

void GameStart(void);
void GameInit(void);

#endif // GUARD_GAME_H
2 changes: 1 addition & 1 deletion include/game/multiplayer/player_unk_1.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "global.h"
#include "core.h" // for MultiSioData

#include "game/sa1_leftovers/globals.h"
#include "game/sa1_sa2_shared/globals.h"

void sub_8019240(union MultiSioData *, u8);
void sub_80192A8(union MultiSioData *, u8);
Expand Down
2 changes: 2 additions & 0 deletions include/game/parameters/characters.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "constants/zones.h"

// TODO: Be consistent about whether these are Q() or I() values!

/*** Common ***/
#define PLAYER_FLYING_END_GRAVITY (0.033) // = (8. / 256.)
#define PLAYER_GRAVITY 42.0 / 256.0
Expand Down
2 changes: 1 addition & 1 deletion include/game/player_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define GUARD_player_callbacks_H

#include "core.h"
#include "game/sa1_leftovers/player.h"
#include "game/sa1_sa2_shared/player.h"

struct Task *Player_SonicAmy_InitSkidAttackGfxTask(s32 x, s32 y, u16 p2);
void Player_SonicAmy_InitSkidAttack(Player *);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "core.h"
#include "rect.h"
#include "game/sa1_leftovers/player.h"
#include "game/sa1_sa2_shared/player.h"

#define COLL_NONE 0
#define COLL_FLAG_1 0x00000001
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef GUARD_SA2_INPUT_BUFFER
#define GUARD_SA2_INPUT_BUFFER

#include "game/sa1_leftovers/player.h"
#include "game/sa1_sa2_shared/player.h"

void sub_800E0C0(u16 param0, u16 param1);
void sub_800DF8C(Player *p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
typedef struct {
/*0x00 */ SpriteTransform transform;
/*0x0C */ Sprite s;
/*0x3C */ Hitbox reserved;
/*0x3C */ Hitbox reserved; // TODO: Maybe 3 hitboxes (Player, Action, Shield)?
} PlayerSpriteInfo; /* size: 0x44 */

extern PlayerSpriteInfo gUnknown_03005AA0;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion include/game/save.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "global.h"

#include "game/sa1_leftovers/globals.h"
#include "game/sa1_sa2_shared/globals.h"

#include "game/stage/player_controls.h"
#include "constants/zones.h"
Expand Down
2 changes: 1 addition & 1 deletion include/game/stage/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "global.h"
#include "core.h"

#include "game/sa1_leftovers/camera.h"
#include "game/sa1_sa2_shared/camera.h"

#define CAMBG_MAP_FRONT_LAYER 0
#define CAMBG_MAP_BACK_LAYER 1
Expand Down
2 changes: 1 addition & 1 deletion include/game/stage/player.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef GUARD_STAGE_PLAYER_H
#define GUARD_STAGE_PLAYER_H

#include "game/sa1_leftovers/player.h"
#include "game/sa1_sa2_shared/player.h"

// TODO: merge these
#include "constants/characters.h"
Expand Down
2 changes: 1 addition & 1 deletion include/game/stage/underwater_effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define GUARD_UNDERWATER_EFFECTS_H

#include "core.h"
#include "game/sa1_leftovers/player.h"
#include "game/sa1_sa2_shared/player.h"

struct Task *SpawnDrowningCountdownNum(Player *p, s32 countdown);
struct Task *SpawnAirBubbles(s32 p0, s32 p1, s32 p2, s32 p3);
Expand Down
3 changes: 1 addition & 2 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

#if !PLATFORM_GBA
#ifdef _WIN32
Expand All @@ -39,7 +38,7 @@ typedef void (*VoidFn)(void);
#if !(defined NON_MATCHING)
#define NON_MATCHING 1
#endif
#elif defined(DEBUG)
#elif (DEBUG)
#define NON_MATCHING 1
#endif

Expand Down
9 changes: 9 additions & 0 deletions include/malloc_vram.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
#define VRAM_HEAP_SEGMENT_SIZE 0x80
#define VRAM_TILE_SLOTS_PER_SEGMENT (VRAM_HEAP_SEGMENT_SIZE / TILE_SIZE_4BPP)

// TODO: Find out where these numbers come from
#if (ENGINE == ENGINE_1)
#define VRAM_TILE_SEGMENTS 156
#define VRAM_HEAP_TILE_COUNT 112
#elif (ENGINE == ENGINE_2)
#define VRAM_TILE_SEGMENTS 140
#define VRAM_HEAP_TILE_COUNT 48
#endif

void *VramMalloc(u32);
void VramResetHeapState(void);
void VramFree(void *);
Expand Down
30 changes: 30 additions & 0 deletions include/platform/shared/dma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef GUARD_PLATFORM_SHARED_DMA_H
#define GUARD_PLATFORM_SHARED_DMA_H

#define DMA_DEST_MASK 0x0060
#define DMA_SRC_MASK 0x0180

#define DMA_COUNT 4

typedef struct DMATransfer {
union {
const void *src;
const u16 *src16;
const u32 *src32;
};
union {
void *dst;
vu16 *dst16;
vu32 *dst32;
};
u32 size;
u16 control;
} DMATransfer;

extern struct DMATransfer DMAList[DMA_COUNT];

typedef enum { DMA_NOW, DMA_VBLANK, DMA_HBLANK, DMA_SPECIAL } DmaStartTypes;

void RunDMAs(DmaStartTypes type);

#endif // GUARD_PLATFORM_SHARED_DMA_H
Loading