Skip to content
Closed
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ libagbsyscall/*.s
*.exe
*.dll
*.sdl
*.iso

# PSP build outputs
EBOOT.PBP
PARAM.SFO
sa2_debug.log

# third party deps
/ext
74 changes: 68 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ else ifeq ($(CPU_ARCH),i386)
TOOLCHAIN := /usr/x86_64-w64-mingw32/
PREFIX := x86_64-w64-mingw32-
endif
# PSP
else ifeq ($(PLATFORM),psp)
PSPDEV ?= $(HOME)/pspdev
PSPSDK := $(PSPDEV)/psp/sdk
export PATH := $(PSPDEV)/bin:$(PATH)
PREFIX := psp-
else ifeq ($(PLATFORM),ps2)
PREFIX := mips64r5900el-ps2-elf-
else
# Native
ifneq ($(PLATFORM),sdl)
Expand Down Expand Up @@ -120,6 +128,14 @@ else ifeq ($(PLATFORM),sdl)
ROM := $(BUILD_NAME).sdl
ELF := $(ROM).elf
MAP := $(ROM).map
else ifeq ($(PLATFORM),psp)
ROM := EBOOT.PBP
ELF := $(BUILD_NAME).psp.elf
MAP := $(BUILD_NAME).psp.map
else ifeq ($(PLATFORM),ps2)
ROM := $(BUILD_NAME).$(PLATFORM).iso
ELF := $(ROM:.iso=.elf)
MAP := $(ROM:.iso=.map)
else
ROM := $(BUILD_NAME).$(PLATFORM).exe
ELF := $(ROM:.exe=.elf)
Expand Down Expand Up @@ -156,11 +172,15 @@ TILESETS_SUBDIR = graphics/tilesets/
ifeq ($(PLATFORM),gba)
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/*")
else ifeq ($(PLATFORM),sdl)
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/win32/*" -not -path "*/platform/psp/*")
else ifeq ($(PLATFORM),psp)
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/win32/*")
else ifeq ($(PLATFORM),ps2)
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/win32/*" -not -path "*/platform/psp/*")
else ifeq ($(PLATFORM),sdl_win32)
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/win32/*")
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/win32/*" -not -path "*/platform/psp/*")
else ifeq ($(PLATFORM),win32)
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/pret_sdl/*")
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/pret_sdl/*" -not -path "*/platform/psp/*")
else
C_SRCS := $(shell find $(C_SUBDIR) -name "*.c")
endif
Expand Down Expand Up @@ -225,6 +245,12 @@ else
ifeq ($(PLATFORM),sdl)
CC1FLAGS += -Wno-parentheses-equality -Wno-unused-value
CPPFLAGS += -D TITLE_BAR=$(BUILD_NAME).$(PLATFORM) -D PLATFORM_GBA=0 -D PLATFORM_SDL=1 -D PLATFORM_WIN32=0 $(shell sdl2-config --cflags)
else ifeq ($(PLATFORM),psp)
CC1FLAGS += -G0
CPPFLAGS += -D PLATFORM_GBA=0 -D PLATFORM_SDL=1 -D PLATFORM_WIN32=0 -D SDL_MAIN_HANDLED -I$(PSPDEV)/psp/include/SDL2 -I$(PSPDEV)/psp/include -I$(PSPSDK)/include -D_PSP_FW_VERSION=600
else ifeq ($(PLATFORM),ps2)
CC1FLAGS += -G0 -Wno-parentheses-equality -Wno-unused-value -ffast-math
CPPFLAGS += -D PLATFORM_GBA=0 -D PLATFORM_SDL=1 -D PLATFORM_WIN32=0 -D SDL_MAIN_HANDLED -D_EE -D__PS2__ -I$(PS2SDK)/common/include -I$(PS2SDK)/ee/include -I$(PS2SDK)/ports/include $(shell $(PS2SDK)/ports/bin/sdl2-config --cflags)
else ifeq ($(PLATFORM),sdl_win32)
CPPFLAGS += -D TITLE_BAR=$(BUILD_NAME).$(PLATFORM) -D PLATFORM_GBA=0 -D PLATFORM_SDL=1 -D PLATFORM_WIN32=0 $(SDL_MINGW_FLAGS)
else ifeq ($(PLATFORM),win32)
Expand All @@ -249,6 +275,10 @@ else
# for modern we are using a modern compiler
# so instead of CPP we can use gcc -E to "preprocess only"
CPP := $(CC1) -E
else ifeq ($(PLATFORM), psp)
CPP := $(CC1) -E
else ifeq ($(PLATFORM), ps2)
ASFLAGS += -msingle-float
endif
# Allow file input through stdin on modern GCC and set it to "compile only"
CC1FLAGS += -x c -S
Expand All @@ -258,7 +288,14 @@ ifeq ($(DEBUG),1)
CC1FLAGS += -g3 -O0
CPPFLAGS += -D DEBUG=1
else
CC1FLAGS += -O2
ifeq ($(PLATFORM),psp)
# -O3 for PSP (Allegrex MIPS, small D-cache)
CC1FLAGS += -O3 -funroll-loops -fomit-frame-pointer
else ifeq ($(PLATFORM),ps2)
CC1FLAGS += -O3 -funroll-loops -fomit-frame-pointer
else
CC1FLAGS += -O2
endif
CPPFLAGS += -D DEBUG=0
endif

Expand Down Expand Up @@ -297,6 +334,11 @@ else ifeq ($(PLATFORM),sdl)
else
MAP_FLAG := -Xlinker -Map=
endif
# PSP
else ifeq ($(PLATFORM),psp)
MAP_FLAG := -Xlinker -Map=
else ifeq ($(PLATFORM),ps2)
MAP_FLAG := -Xlinker -Map=
# Win32
else
MAP_FLAG := -Xlinker -Map=
Expand All @@ -307,6 +349,10 @@ ifeq ($(PLATFORM),gba)
LIBS := $(ROOT_DIR)/tools/agbcc/lib/libgcc.a $(ROOT_DIR)/tools/agbcc/lib/libc.a $(LIBABGSYSCALL_LIBS)
else ifeq ($(PLATFORM),sdl)
LIBS := $(shell sdl2-config --cflags --libs)
else ifeq ($(PLATFORM),psp)
LIBS := -L$(PSPDEV)/psp/lib -L$(PSPSDK)/lib -lSDL2 -lm -lGL -lpspvram -lpspaudio -lpspvfpu -lpspdisplay -lpspgu -lpspge -lpsphprm -lpspctrl -lpsppower -lpspdebug -lpspnet -lpspnet_apctl -Wl,-zmax-page-size=128
else ifeq ($(PLATFORM),ps2)
LIBS := -lSDL2 $(shell $(PS2SDK)/ports/bin/sdl2-config --libs) -T$(PS2SDK)/ee/startup/linkfile -L$(PS2SDK)/common/lib -L$(PS2SDK)/ee/lib -L$(PS2DEV)/gsKit/lib -Wl,-zmax-page-size=128
else ifeq ($(PLATFORM),sdl_win32)
LIBS := -mwin32 -lkernel32 -lwinmm -lmingw32 -lxinput $(SDL_MINGW_LIBS)
else ifeq ($(PLATFORM), win32)
Expand All @@ -316,7 +362,7 @@ endif
#### MAIN TARGETS ####

# these commands will run regardless of deps being completed
.PHONY: clean tools tidy clean-tools $(TOOLDIRS) libagbsyscall
.PHONY: clean tools tidy clean-tools $(TOOLDIRS) libagbsyscall ps2

# Ensure required directories exist
$(shell mkdir -p $(C_BUILDDIR) $(ASM_BUILDDIR) $(DATA_ASM_BUILDDIR) $(SOUND_ASM_BUILDDIR) $(SONG_BUILDDIR) $(MID_BUILDDIR))
Expand Down Expand Up @@ -397,7 +443,8 @@ clean-tools:
tidy:
$(RM) -r build/*
$(RM) SDL2.dll
$(RM) $(BUILD_NAME)*.exe $(BUILD_NAME)*.elf $(BUILD_NAME)*.map $(BUILD_NAME)*.sdl $(BUILD_NAME)*.gba
$(RM) $(BUILD_NAME)*.exe $(BUILD_NAME)*.elf $(BUILD_NAME)*.map $(BUILD_NAME)*.sdl $(BUILD_NAME)*.gba $(BUILD_NAME)*.iso
$(RM) EBOOT.PBP PARAM.SFO

usa_beta: ; @$(MAKE) GAME_REGION=USA GAME_VARIANT=BETA

Expand All @@ -409,6 +456,10 @@ europe: ; @$(MAKE) GAME_REGION=EUROPE

sdl: ; @$(MAKE) PLATFORM=sdl

psp: ; @$(MAKE) PLATFORM=psp

ps2: ; @$(MAKE) PLATFORM=ps2

tas_sdl: ; @$(MAKE) sdl TAS_TESTING=1

sdl_win32:
Expand Down Expand Up @@ -459,7 +510,7 @@ data/mb_chao_garden_japan.gba.lz: data/mb_chao_garden_japan.gba

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

$(ELF): $(OBJS) libagbsyscall
$(ELF): $(OBJS)
ifeq ($(PLATFORM),gba)
@echo "$(LD) -T $(LDSCRIPT) $(MAP_FLAG) $(MAP) <objects> <lib> -o $@"
@$(CPP) -P $(CPPFLAGS) $(LDSCRIPT) > $(OBJ_DIR)/$(LDSCRIPT)
Expand All @@ -476,6 +527,17 @@ ifeq ($(PLATFORM),gba)
$(FIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent
else ifeq ($(PLATFORM),sdl)
cp $< $@
else ifeq ($(PLATFORM),psp)
psp-fixup-imports $<
mksfoex 'Sonic Advance 2' PARAM.SFO
psp-strip $< -o $(BUILD_NAME).psp_strip.elf
pack-pbp $@ PARAM.SFO NULL NULL NULL NULL NULL $(BUILD_NAME).psp_strip.elf NULL
-rm -f $(BUILD_NAME).psp_strip.elf
else ifeq ($(PLATFORM),ps2)
@echo Creating $(ROM) from $(ELF)
@cp -r ps2/ntsc $(OBJ_DIR)/iso
@cp $< $(OBJ_DIR)/iso/$(PS2_GAME_CODE)
@mkisofs -o $(ROM) $(OBJ_DIR)/iso/
else
$(OBJCOPY) -O pei-x86-64 $< $@
endif
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ It can also build:
* **sa2.sdl** `make sdl` (Linux/MacOS SDL 64bit port)
* **sa2.sdl_win32.exe** `make sdl_win32` (Windows SDL 64bit port)
* :construction: **sa2.win32.exe** `make win32` (Win32 native port, not functional)
* **EBOOT.PBP** `make psp` (PlayStation Portable homebrew port, requires [PSPDEV](https://github.com/pspdev/pspdev))

## Current state

Expand Down
2 changes: 2 additions & 0 deletions asm/macros/portable.inc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
.macro mPtr value
#if defined(__aarch64__) || defined(__x86_64__)
.quad \value
#elif defined(__mips__)
.4byte \value
#else
.int \value
#endif
Expand Down
1 change: 1 addition & 0 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ MAKER_CODE := 78
BUILD_NAME := sa2
TITLE := SONICADVANC2
GAME_CODE := A2N
PS2_GAME_CODE := SLUS_054.02


# Revision
Expand Down
14 changes: 10 additions & 4 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,20 @@

#define TAS_TESTING_WIDESCREEN_HACK 1

#define RENDERER_SOFTWARE 0
#define RENDERER_OPENGL 1
#define RENDERER_COUNT 2
#if PLATFORM_WIN32 && !PLATFORM_SDL
#define RENDERER_SOFTWARE 0
#define RENDERER_OPENGL 1
#define RENDERER_SOFTWARE_FAST 2
#define RENDERER_COUNT 3

#ifndef RENDERER
#if defined(__PSP__) || defined(__PS2__)
#define RENDERER RENDERER_SOFTWARE_FAST
#elif PLATFORM_WIN32 && !PLATFORM_SDL
// TODO: Only win32 for now
#define RENDERER RENDERER_OPENGL
#else
#define RENDERER RENDERER_SOFTWARE
#endif
#endif

#endif // GUARD_SA2_CONFIG_H
6 changes: 6 additions & 0 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,14 @@
#define OAM_ENTRY_COUNT 128
#if PORTABLE
// NOTE: Used in gba/types.h, so they have to be defined before the #include
#if defined(__PSP__)
// PSP: Use GBA-native resolution, SDL scales to 480x272
#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 160
#else
#define DISPLAY_WIDTH 426
#define DISPLAY_HEIGHT 240
#endif

// NOTE: We shouldn't consider WIDESCREEN_HACK a permanent thing.
// This hack should best be removed once there's a "native" platform layer.
Expand Down
4 changes: 4 additions & 0 deletions include/gba/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
typedef struct __attribute__((packed)) name struct_body name;
#endif

#ifdef __PS2__
#include <tamtypes.h>
#else
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
Expand All @@ -28,6 +31,7 @@ typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
#endif

#if (GAME == GAME_SA1)
typedef u8 MetatileIndexType;
Expand Down
64 changes: 64 additions & 0 deletions include/platform/shared/rendering/sw_renderer_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef GUARD_SW_RENDERER_COMMON_H
#define GUARD_SW_RENDERER_COMMON_H

// shared color math for the gba ppu blend unit
// used by both the normal (multi-pass) and fast (single-pass) software renderers

#include <stdint.h>

// bgr555 channel extraction
#define getAlphaBit(x) (((x) >> 15) & 1)
#define getRedChannel(x) (((x) >> 0) & 0x1F)
#define getGreenChannel(x) (((x) >> 5) & 0x1F)
#define getBlueChannel(x) (((x) >> 10) & 0x1F)
#define COLOR_OPAQUE 0x8000

static inline uint16_t alphaBlendColor(uint16_t targetA, uint16_t targetB, unsigned int eva, unsigned int evb)
{
unsigned int r = ((getRedChannel(targetA) * eva) + (getRedChannel(targetB) * evb)) >> 4;
unsigned int g = ((getGreenChannel(targetA) * eva) + (getGreenChannel(targetB) * evb)) >> 4;
unsigned int b = ((getBlueChannel(targetA) * eva) + (getBlueChannel(targetB) * evb)) >> 4;

if (r > 31)
r = 31;
if (g > 31)
g = 31;
if (b > 31)
b = 31;

return r | (g << 5) | (b << 10) | COLOR_OPAQUE;
}

static inline uint16_t alphaBrightnessIncrease(uint16_t targetA, unsigned int evy)
{
unsigned int r = getRedChannel(targetA) + (31 - getRedChannel(targetA)) * evy / 16;
unsigned int g = getGreenChannel(targetA) + (31 - getGreenChannel(targetA)) * evy / 16;
unsigned int b = getBlueChannel(targetA) + (31 - getBlueChannel(targetA)) * evy / 16;

if (r > 31)
r = 31;
if (g > 31)
g = 31;
if (b > 31)
b = 31;

return r | (g << 5) | (b << 10) | COLOR_OPAQUE;
}

static inline uint16_t alphaBrightnessDecrease(uint16_t targetA, unsigned int evy)
{
unsigned int r = getRedChannel(targetA) - getRedChannel(targetA) * evy / 16;
unsigned int g = getGreenChannel(targetA) - getGreenChannel(targetA) * evy / 16;
unsigned int b = getBlueChannel(targetA) - getBlueChannel(targetA) * evy / 16;

if (r > 31)
r = 31;
if (g > 31)
g = 31;
if (b > 31)
b = 31;

return r | (g << 5) | (b << 10) | COLOR_OPAQUE;
}

#endif // GUARD_SW_RENDERER_COMMON_H
4 changes: 4 additions & 0 deletions libagbsyscall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ else ifeq ($(CPU_ARCH),i386)
TOOLCHAIN := /usr/x86_64-w64-mingw32/
PREFIX := x86_64-w64-mingw32-
endif
else ifeq ($(PLATFORM),psp)
PSPDEV ?= $(HOME)/pspdev
export PATH := $(PSPDEV)/bin:$(PATH)
PREFIX := psp-
else ifneq ($(PLATFORM),sdl)
$(error Unknown CPU architecture $(CPU_ARCH))
endif # (PLATFORM == gba)
Expand Down
3 changes: 3 additions & 0 deletions ps2/ntsc/SYSTEM.CNF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BOOT2 = cdrom0:\SLUS_054.02;1
VER = 1.00
VMODE = NTSC
4 changes: 2 additions & 2 deletions src/background.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ END_NONMATCH

void UpdateBgAnimationTiles(Background *bg)
{
#if (RENDERER == RENDERER_SOFTWARE)
#if (RENDERER != RENDERER_OPENGL)
Tilemap *tilemap = gTilemapsRef[bg->tilemapId];
if (tilemap->animFrameCount > 0) {
if (tilemap->animDelay <= ++bg->animDelayCounter) {
Expand Down Expand Up @@ -872,7 +872,7 @@ NONMATCH("asm/non_matching/engine/sub_80039E4.inc", bool32 sub_80039E4(void))
return TRUE;
#endif

#if (RENDERER == RENDERER_SOFTWARE)
#if (RENDERER != RENDERER_OPENGL)
if (gBgSpritesCount != 0) {
OamDataShort oam;
s32 r5;
Expand Down
4 changes: 2 additions & 2 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ bool32 ProcessVramGraphicsCopyQueue(void)
if ((graphics->src != 0) && (graphics->dest != 0))
#endif
{
#if (RENDERER == RENDERER_SOFTWARE)
#if (RENDERER != RENDERER_OPENGL)
DmaCopy16(3, (void *)(graphics->src + offset), (void *)(graphics->dest + offset), COPY_CHUNK_SIZE);
#endif
graphics->size -= COPY_CHUNK_SIZE;
Expand All @@ -939,7 +939,7 @@ bool32 ProcessVramGraphicsCopyQueue(void)
if ((graphics->src != 0) && (graphics->dest != 0))
#endif
{
#if (RENDERER == RENDERER_SOFTWARE)
#if (RENDERER != RENDERER_OPENGL)
DmaCopy16(3, (void *)(graphics->src + offset), (void *)(graphics->dest + offset), graphics->size);
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib/m4a/m4a.c
Original file line number Diff line number Diff line change
Expand Up @@ -1377,9 +1377,10 @@ cond_true : {
return;
}

cond_false:
cond_false : {
track->cmdPtr += 4;
}
}

void MP2K_event_xcmd(struct MP2KPlayerState *mplayInfo, struct MP2KTrack *track)
{
Expand Down
Loading
Loading