diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 8e03ecf80..af13f9dc6 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,10 +2,24 @@ # [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04, ubuntu-18.04 ARG VARIANT -FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} +FROM mcr.microsoft.com/vscode/devcontainers/base:0-ubuntu-22.04 RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ - && apt-get -y install --no-install-recommends binutils-arm-none-eabi gcc-arm-none-eabi libpng-dev build-essential clang-format-13 xorg-dev libsdl2-dev gcc-mingw-w64 + && apt-get -y install --no-install-recommends binutils-arm-none-eabi \ + gcc-arm-none-eabi libpng-dev build-essential clang-format-13 xorg-dev \ + libsdl2-dev gcc-mingw-w64 texinfo flex bison gettext libgsl-dev libgmp3-dev \ + libmpfr-dev libmpc-dev zlib1g-dev autopoint cmake automake patch mkisofs WORKDIR /deps -RUN git clone https://github.com/pret/agbcc.git && cd agbcc && ./build.sh +RUN git clone https://github.com/SAT-R/agbcc.git && cd agbcc && ./build.sh + +ENV PS2DEV=/usr/local/ps2dev + +RUN mkdir -p $PS2DEV && chown -R $USER: $PS2DEV + +ENV PS2DEV=/usr/local/ps2dev +ENV PS2SDK=$PS2DEV/ps2sdk +ENV GSKIT=$PS2DEV/gsKit +ENV PATH=$PATH:$PS2DEV/bin:$PS2DEV/ee/bin:$PS2DEV/iop/bin:$PS2DEV/dvp/bin:$PS2SDK/bin + +RUN git clone https://github.com/ps2dev/ps2dev && cd ps2dev && ./build-all.sh diff --git a/.gitignore b/.gitignore index 8ed183732..8038fb5ea 100644 --- a/.gitignore +++ b/.gitignore @@ -81,6 +81,7 @@ libagbsyscall/*.s *.exe *.dll *.sdl +*.iso # third party deps /ext diff --git a/Makefile b/Makefile index 632d08a97..720a9bc13 100644 --- a/Makefile +++ b/Makefile @@ -30,12 +30,16 @@ 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- else ifeq ($(PLATFORM),win32) - TOOLCHAIN := /usr/i686-w64-mingw32/ PREFIX := i686-w64-mingw32- endif +else ifeq ($(CPU_ARCH),MIPS) + ifeq ($(PLATFORM),sdl_ps2) + PREFIX := mips64r5900el-ps2-elf- + else + $(error Unsupported CPU arch for platform '$(CPU_ARCH)', '$(PLATFORM)') + endif else ifneq ($(PLATFORM),sdl) $(error Unsupported CPU arch for platform '$(CPU_ARCH)', '$(PLATFORM)') @@ -98,6 +102,8 @@ SDL_MINGW_LIB := $(SDL_MINGW_PKG)/lib SDL_MINGW_LINKER_FLAGS := -L$(SDL_MINGW_LIB) -lSDL2main -lSDL2.dll SDL_MINGW_FLAGS := -I$(SDL_MINGW_INCLUDE) -D_THREAD_SAFE +SDL2_PS2_PKG ?= ext/SDL2-PS2/ + # These have to(?) be defined this way, because # the C-preprocessor cannot resolve stuff like: # #if (PLATFORM == gba), where PLATFORM is defined via -D. @@ -108,20 +114,25 @@ 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),sdl_ps2) + CC1FLAGS += -Wno-parentheses-equality -Wno-unused-value -ffast-math + CPPFLAGS += -I$(PS2SDK)/common/include -I$(PS2SDK)/ee/include -I$(PS2SDK)/ports/include $(shell $(PS2SDK)/ports/bin/sdl2-config --cflags) + CPPFLAGS += -D TITLE_BAR=$(BUILD_NAME).$(PLATFORM) -D PLATFORM_GBA=0 -D PLATFORM_SDL=1 -D PLATFORM_WIN32=0 -D_EE -DPS2 -D__PS2__ 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) CPPFLAGS += -D TITLE_BAR=$(BUILD_NAME).$(PLATFORM) -D PLATFORM_GBA=0 -D PLATFORM_SDL=0 -D PLATFORM_WIN32=1 endif - ifeq ($(CPU_ARCH),i386) - CPPFLAGS += -D CPU_ARCH_X86=1 -D CPU_ARCH_ARM=0 - + ifeq ($(CPU_ARCH),i386) + CPPFLAGS += -D CPU_ARCH_X86=1 -D CPU_ARCH_ARM=0 -D CPU_ARCH_MIPS=0 # Use the more legible Intel dialect for x86, without underscores CC1FLAGS += -masm=intel - else - CPPFLAGS += -D CPU_ARCH_X86=0 -D CPU_ARCH_ARM=0 - endif + else ifeq ($(CPU_ARCH),MIPS) + CPPFLAGS += -D CPU_ARCH_X86=0 -D CPU_ARCH_ARM=0 -D CPU_ARCH_MIPS=1 + else + CPPFLAGS += -D CPU_ARCH_X86=0 -D CPU_ARCH_ARM=0 -D CPU_ARCH_MIPS=0 + endif endif ifeq ($(PLATFORM),gba) @@ -136,6 +147,9 @@ 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), sdl_ps2) + # the linker complains if we don't set this + ASFLAGS += -msingle-float endif # Allow file input through stdin on modern GCC and set it to "compile only" CC1FLAGS += -x c -S @@ -145,7 +159,11 @@ ifeq ($(DEBUG),1) CC1FLAGS += -g3 -O0 CPPFLAGS += -D DEBUG=1 else +ifeq ($(PLATFORM), gba) CC1FLAGS += -O2 +else + CC1FLAGS += -O3 +endif endif ifeq ($(PORTABLE),1) @@ -221,6 +239,10 @@ else ifeq ($(PLATFORM),sdl) ROM := $(BUILD_NAME).sdl ELF := $(ROM).elf MAP := $(ROM).map +else ifeq ($(PLATFORM),sdl_ps2) +ROM := $(BUILD_NAME).$(PLATFORM).iso +ELF := $(ROM:.iso=.elf) +MAP := $(ROM:.iso=.map) else ROM := $(BUILD_NAME).$(PLATFORM).exe ELF := $(ROM:.exe=.elf) @@ -261,11 +283,13 @@ $(shell mkdir -p $(C_BUILDDIR) $(ASM_BUILDDIR) $(DATA_ASM_BUILDDIR) $(SOUND_ASM_ 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/*") +C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/win32/*" -not -path "*/platform/ps2/*") +else ifeq ($(PLATFORM),sdl_ps2) +C_SRCS := $(shell find $(C_SUBDIR) -name "*.c" -not -path "*/platform/win32/*" -not -path "*/platform/ps2/*") 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/ps2/*") 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/ps2/*") else C_SRCS := $(shell find $(C_SUBDIR) -name "*.c") endif @@ -363,13 +387,17 @@ clean-tools: tidy: $(RM) $(ROM) $(ELF) $(MAP) - $(RM) $(BUILD_NAME)_europe.gba $(BUILD_NAME)_europe.elf $(BUILD_NAME)_europe.map - $(RM) $(BUILD_NAME)_japan.gba $(BUILD_NAME)_japan.elf $(BUILD_NAME)_japan.map - $(RM) -r build/* + $(RM) -r $(OBJ_DIR) +ifeq ($(PLATFORM), sdl_win32) $(RM) SDL2.dll -ifeq ($(PLATFORM), GBA) +else ifeq ($(PLATFORM), gba) +ifeq ($(GAME_REGION), USA) + $(MAKE) tidy GAME_REGION=JAPAN + $(MAKE) tidy GAME_REGION=EUROPE +endif $(MAKE) tidy PLATFORM=win32 CPU_ARCH=i386 $(MAKE) tidy PLATFORM=sdl_win32 CPU_ARCH=i386 + $(MAKE) tidy PLATFORM=sdl_ps2 CPU_ARCH=MIPS $(MAKE) tidy PLATFORM=sdl endif @@ -423,7 +451,7 @@ PROCESSED_LDSCRIPT := $(OBJ_DIR)/$(LDSCRIPT) $(PROCESSED_LDSCRIPT): $(LDSCRIPT) $(CPP) -P $(CPPFLAGS) $(LDSCRIPT) > $(PROCESSED_LDSCRIPT) -$(ELF): $(OBJS) $(PROCESSED_LDSCRIPT) libagbsyscall +$(ELF): $(OBJS) $(PROCESSED_LDSCRIPT) ifeq ($(PLATFORM),gba) @echo "$(LD) -T $(LDSCRIPT) -Map $(MAP) " @cd $(OBJ_DIR) && $(LD) -A CPU_ARCH -T $(LDSCRIPT) -Map "$(ROOT_DIR)/$(MAP)" $(OBJS_REL) "$(ROOT_DIR)/tools/agbcc/lib/libgcc.a" "$(ROOT_DIR)/tools/agbcc/lib/libc.a" -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -o $(ROOT_DIR)/$@ @@ -434,6 +462,8 @@ ifeq ($(PLATFORM),sdl) @cd $(OBJ_DIR) && $(CC1) $(OBJS_REL) $(shell sdl2-config --cflags --libs) $(LINKER_MAP_FLAGS) -o $(ROOT_DIR)/$@ 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 ifeq ($(PLATFORM),sdl_ps2) + @cd $(OBJ_DIR) && $(CC1) $(OBJS_REL) -lSDL2 $(shell $(PS2SDK)/ports/bin/sdl2-config --libs) $(LINKER_MAP_FLAGS) -T$(PS2SDK)/ee/startup/linkfile -L$(PS2SDK)/common/lib -L$(PS2SDK)/ee/lib -L$(PS2DEV)/gsKit/lib -Wl,-zmax-page-size=128 -o $(ROOT_DIR)/$@ else @cd $(OBJ_DIR) && $(CC1) -mwin32 $(OBJS_REL) -L$(ROOT_DIR)/libagbsyscall -lagbsyscall -lkernel32 -o $(ROOT_DIR)/$@ -Xlinker -Map "$(ROOT_DIR)/$(MAP)" endif @@ -445,6 +475,11 @@ 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),sdl_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-i386 $< $@ ifeq ($(CREATE_PDB),1) @@ -511,6 +546,8 @@ europe: ; @$(MAKE) GAME_REGION=EUROPE sdl: ; @$(MAKE) PLATFORM=sdl +sdl_ps2: ; @$(MAKE) CPU_ARCH=MIPS PLATFORM=sdl_ps2 + sdl_win32: SDL2.dll $(SDL_MINGW_LIB) @$(MAKE) PLATFORM=sdl_win32 CPU_ARCH=i386 diff --git a/asm/macros/portable.inc b/asm/macros/portable.inc index b389fb26a..3eadcd08d 100644 --- a/asm/macros/portable.inc +++ b/asm/macros/portable.inc @@ -11,7 +11,7 @@ #if defined(__aarch64__) || defined(__x86_64__) .quad \value #else - .int \value + .4byte \value #endif .endm diff --git a/config.mk b/config.mk index 30782695f..77139afc0 100644 --- a/config.mk +++ b/config.mk @@ -18,6 +18,9 @@ ifeq ($(CPU_ARCH),arm) else ifeq ($(CPU_ARCH),i386) THUMB_SUPPORT ?= 0 MIDI_COMMENTS := "x86" +else ifeq ($(CPU_ARCH),MIPS) + THUMB_SUPPORT ?= 0 + MIDI_COMMENTS := "x86" else $(error unknown arch: $(CPU_ARCH)) endif @@ -59,9 +62,10 @@ DEBUG ?= 0 MAKER_CODE := 78 # Version -BUILD_NAME := sa2 -TITLE := SONICADVANC2 -GAME_CODE := A2N +BUILD_NAME := sa2 +TITLE := SONICADVANC2 +GAME_CODE := A2N +PS2_GAME_CODE := SLUS_054.02 # Revision diff --git a/include/config.h b/include/config.h index afadc0557..88d1d21a5 100644 --- a/include/config.h +++ b/include/config.h @@ -17,7 +17,20 @@ #define USE_NEW_DMA 1 #endif -#define TAS_TESTING 0 +#define TAS_TESTING 1 #define TAS_TESTING_WIDESCREEN_HACK 1 +#if PLATFORM_GBA +#define ENABLE_AUDIO TRUE +#else +#ifdef PS2 +#define ENABLE_AUDIO TRUE +#define ENABLE_VRAM_VIEW FALSE +#else +#define ENABLE_AUDIO TRUE +#define ENABLE_VRAM_VIEW FALSE +#endif + +#endif + #endif // GUARD_SA2_CONFIG_H diff --git a/include/game/sa1_leftovers/player.h b/include/game/sa1_leftovers/player.h index 4b0841e23..8ae877273 100644 --- a/include/game/sa1_leftovers/player.h +++ b/include/game/sa1_leftovers/player.h @@ -169,8 +169,7 @@ typedef struct Player_ { // Alternatively, some of the following data might be a union /* 0x94 */ PlayerSpriteInfo *unk94; /* 0x98 */ u8 unk98; // Multiplayer var. TODO: check sign! - /* 0x99 */ s8 unk99[15]; - /* 0xA8 */ u8 unkA8; + /* 0x99 */ s8 unk99[16]; /* 0x9A */ u8 fillerA9[0x3]; // Cream's framecounter for flying diff --git a/include/game/stage/player.h b/include/game/stage/player.h index 29ecea13f..1bbd7e16f 100644 --- a/include/game/stage/player.h +++ b/include/game/stage/player.h @@ -39,7 +39,7 @@ void Player_DisableInputAndBossTimer_FinalBoss(void); void SetStageSpawnPos(u32 character, u32 level, u32 p2, Player *player); void CallSetStageSpawnPos(u32 character, u32 level, u32 p2, Player *p); -s32 sub_8029B88(Player *player, u8 *p1, int *out); +s32 sub_8029B88(Player *player, u8 *p1, s32 *out); s32 sub_8029AC0(Player *player, u8 *p1, s32 *out); s32 sub_8029B0C(Player *player, u8 *p1, s32 *out); diff --git a/include/gba/defines.h b/include/gba/defines.h index 057138435..165ce41ed 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -37,8 +37,8 @@ #define OAM_ENTRY_COUNT 128 #if PORTABLE // NOTE: Used in gba/types.h, so they have to be defined before the #include -#define DISPLAY_WIDTH 426 -#define DISPLAY_HEIGHT 240 +#define DISPLAY_WIDTH 240 +#define DISPLAY_HEIGHT 160 //#include "gba/types.h" // TODO: Fix #define OAM_SIZE (OAM_ENTRY_COUNT*sizeof(OamData)) diff --git a/include/gba/dma_macros.h b/include/gba/dma_macros.h index cae132972..e99fac488 100644 --- a/include/gba/dma_macros.h +++ b/include/gba/dma_macros.h @@ -1,8 +1,6 @@ #ifndef GUARD_GBA_DMA_MACROS_H #define GUARD_GBA_DMA_MACROS_H -#include "config.h" - #if PLATFORM_GBA #define DmaSet(dmaNum, src, dest, control) \ { \ diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h index 3348fb083..f694c78b5 100644 --- a/include/gba/io_reg.h +++ b/include/gba/io_reg.h @@ -4,8 +4,9 @@ #include #define IO_SIZE 0x400 -#if !PORTABLE -#define REG_BASE 0x4000000 // I/O register base address +#if PLATFORM_GBA +// I/O register base address +#define REG_BASE 0x4000000 #else // TODO: Needs to be u8 because of the address macros extern unsigned char REG_BASE[IO_SIZE]; @@ -160,7 +161,9 @@ extern unsigned char REG_BASE[IO_SIZE]; #define REG_OFFSET_DMA3CNT_H (REG_OFFSET_DMA3CNT_L + sizeof(uint16_t)) #endif -#define REG_OFFSET_TMCNT 0x100 +#define REG_OFFSET_DMA_END REG_OFFSET_DMA3CNT_H + sizeof(uint16_t) + +#define REG_OFFSET_TMCNT REG_OFFSET_DMA_END + 0x10 #define REG_OFFSET_TMCNT_L 0x100 #define REG_OFFSET_TMCNT_H 0x102 #define REG_OFFSET_TM0CNT 0x100 @@ -186,8 +189,8 @@ extern unsigned char REG_BASE[IO_SIZE]; #define REG_OFFSET_SIOMULTI2 0x124 #define REG_OFFSET_SIOMULTI3 0x126 -#define REG_OFFSET_KEYINPUT 0x130 -#define REG_OFFSET_KEYCNT 0x132 +#define REG_OFFSET_KEYINPUT REG_OFFSET_TMCNT + 0x30 +#define REG_OFFSET_KEYCNT REG_OFFSET_TMCNT + 0x32 #define REG_OFFSET_RCNT 0x134 @@ -200,11 +203,11 @@ extern unsigned char REG_BASE[IO_SIZE]; #define REG_OFFSET_JOY_TRANS_L 0x154 #define REG_OFFSET_JOY_TRANS_H 0x156 -#define REG_OFFSET_IME 0x208 -#define REG_OFFSET_IE 0x200 -#define REG_OFFSET_IF 0x202 +#define REG_OFFSET_IME REG_OFFSET_TMCNT + 0x108 +#define REG_OFFSET_IE REG_OFFSET_TMCNT + 0x100 +#define REG_OFFSET_IF REG_OFFSET_TMCNT + 0x102 -#define REG_OFFSET_WAITCNT 0x204 +#define REG_OFFSET_WAITCNT REG_OFFSET_TMCNT + 0x104 // I/O register addresses diff --git a/include/gba/types.h b/include/gba/types.h index db818abdc..c7bb2b8e2 100644 --- a/include/gba/types.h +++ b/include/gba/types.h @@ -17,7 +17,9 @@ typedef struct __attribute__((packed)) name struct_body name; #endif - +#if _EE +#include +#else typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; @@ -26,6 +28,7 @@ typedef int8_t s8; typedef int16_t s16; typedef int32_t s32; typedef int64_t s64; +#endif // If the DISPLAY_HEIGHT was >255, scanline effects would break, // so we have to make this variable bigger. diff --git a/include/global.h b/include/global.h index f6c2d08d3..172c3eb70 100644 --- a/include/global.h +++ b/include/global.h @@ -4,13 +4,6 @@ #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" diff --git a/ps2/ntsc/SYSTEM.CNF b/ps2/ntsc/SYSTEM.CNF new file mode 100644 index 000000000..d5c3d9821 --- /dev/null +++ b/ps2/ntsc/SYSTEM.CNF @@ -0,0 +1,4 @@ +BOOT2 = cdrom0:\SLUS_054.02;1 +VER = 1.00 +VMODE = NTSC + diff --git a/src/core.c b/src/core.c index dfe1ce94f..988ce6ede 100644 --- a/src/core.c +++ b/src/core.c @@ -596,6 +596,8 @@ static void UpdateScreenCpuSet(void) } } +void somefunc(void) { } + static void VBlankIntr(void) { u16 keys; @@ -633,6 +635,7 @@ static void VBlankIntr(void) if (!(gFlagsPreVBlank & FLAGS_8000)) { keys = ~REG_KEYINPUT & (START_BUTTON | SELECT_BUTTON | B_BUTTON | A_BUTTON); if (keys == (START_BUTTON | SELECT_BUTTON | B_BUTTON | A_BUTTON)) { + somefunc(); gFlags |= FLAGS_8000; REG_IE = 0; REG_IME = 0; diff --git a/src/game/game.c b/src/game/game.c index fa0bfd94c..40edfa286 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -97,7 +97,9 @@ void GameStart(void) // GameStageStart(); #elif ENABLE_DECOMP_CREDITS - CreateDecompCreditsScreen(hasProfile); + gCurrentLevel = LEVEL_INDEX(ZONE_2, ACT_1); + ApplyGameStageSettings(); + GameStageStart(); #else if (gFlags & FLAGS_NO_FLASH_MEMORY) { CreateTitleScreen(); diff --git a/src/game/stage/background/zone_7_2.c b/src/game/stage/background/zone_7_2.c index 34c6ce8fc..84d858068 100644 --- a/src/game/stage/background/zone_7_2.c +++ b/src/game/stage/background/zone_7_2.c @@ -37,6 +37,6 @@ NONMATCH("asm/non_matching/game/stage/background/StageBgUpdate_Zone7Acts12.inc", Zone7BgUpdate_Outside(x, y); } - gPlayer.unkA8 = bgId; + gPlayer.unk99[15] = bgId; } END_NONMATCH diff --git a/src/game/stage/collision.c b/src/game/stage/collision.c index 13a098e34..7b8a2905d 100644 --- a/src/game/stage/collision.c +++ b/src/game/stage/collision.c @@ -618,6 +618,11 @@ s32 sub_801ED24(s32 p0, s32 p1, s32 p2, u8 *p3) // (100.00%) https://decomp.me/scratch/sJY4g s32 sub_801EE64(s32 p0in, s32 p1in, s32 p2in, u8 *p3in) { +#ifdef BUG_FIX + if (!gRefCollision) { + return 0; + } +#endif #ifndef NON_MATCHING register u32 r0 asm("r0"); register u32 r1 asm("r1"); diff --git a/src/game/stage/player.c b/src/game/stage/player.c index f52301cd4..177d189c3 100644 --- a/src/game/stage/player.c +++ b/src/game/stage/player.c @@ -763,7 +763,7 @@ NONMATCH("asm/non_matching/game/InitializePlayer.inc", void InitializePlayer(Pla sub_8015750(); sub_801561C(); sub_802989C(p); - +#ifndef NON_MATCHING { // This smells like a memset macro. // Nonmatching reg-alloc between r4 & r6 here u32 *u99 = (void *)p->unk99; @@ -773,6 +773,9 @@ NONMATCH("asm/non_matching/game/InitializePlayer.inc", void InitializePlayer(Pla *u99++ = 0; } } +#else + memset(p->unk99, 0, sizeof(p->unk99)); +#endif p->unk99[0] = 0x7F; @@ -6314,8 +6317,8 @@ s32 sub_8029A28(Player *p, u8 *p1, s32 *out) u8 dummy; // TODO: Why is dummyInt unused? - int dummyInt; - int p1Value; + s32 dummyInt; + s32 p1Value; if (p1 == NULL) p1 = &dummy; @@ -6377,8 +6380,8 @@ s32 sub_8029AC0(Player *p, u8 *p1, s32 *out) u8 dummy; // TODO: Why is dummyInt unused? - int dummyInt; - int p1Value; + s32 dummyInt; + s32 p1Value; if (p1 == NULL) p1 = &dummy; @@ -6409,8 +6412,8 @@ s32 sub_8029B0C(Player *p, u8 *p1, s32 *out) u8 dummy; // TODO: Why is dummyInt unused? - int dummyInt; - int p1Value; + s32 dummyInt; + s32 p1Value; if (p1 == NULL) p1 = &dummy; @@ -6434,7 +6437,7 @@ s32 sub_8029B0C(Player *p, u8 *p1, s32 *out) return result; } -s32 sub_8029B58(Player *p, u8 *p1, int *out) +s32 sub_8029B58(Player *p, u8 *p1, s32 *out) { s32 result; @@ -6447,7 +6450,7 @@ s32 sub_8029B58(Player *p, u8 *p1, int *out) return result; } -s32 sub_8029B88(Player *p, u8 *p1, int *out) +s32 sub_8029B88(Player *p, u8 *p1, s32 *out) { s32 result; diff --git a/src/platform/pret_sdl/sdl2.c b/src/platform/pret_sdl/sdl2.c index 138bed81a..990613270 100644 --- a/src/platform/pret_sdl/sdl2.c +++ b/src/platform/pret_sdl/sdl2.c @@ -9,6 +9,10 @@ #include #endif +#ifdef PS2 +#define SDL_MAIN_HANDLED +#endif + #include #include "global.h" @@ -137,8 +141,39 @@ void *Platform_malloc(int numBytes) { return HeapAlloc(GetProcessHeap(), HEAP_GE void Platform_free(void *ptr) { HeapFree(GetProcessHeap(), 0, ptr); } #endif +#ifdef PS2 +// TODO: clean these for what is needed +#include +#include +#include + +#include +#include +#include +#include +#include + +__attribute__((weak)) void reset_IOP(void) +{ + SifInitRpc(0); + while (!SifIopReset(NULL, 0)) { } + while (!SifIopSync()) { } +} + +static void prepare_IOP(void) +{ + reset_IOP(); + SifInitRpc(0); + sbv_patch_enable_lmb(); +} +#endif + int main(int argc, char **argv) { +#if PS2 + prepare_IOP(); +#endif + // Open an output console on Windows #ifdef _WIN32 AllocConsole(); @@ -146,9 +181,11 @@ int main(int argc, char **argv) freopen("CON", "w", stdout); #endif +#ifndef PS2 ReadSaveFile("sa2.sav"); +#endif - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) { fprintf(stderr, "SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); return 1; } @@ -159,12 +196,17 @@ int main(int argc, char **argv) const char *title = "SAT-R sa2"; #endif +#ifdef PS2 + sdlWindow = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); +#else sdlWindow = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, DISPLAY_WIDTH * videoScale, DISPLAY_HEIGHT * videoScale, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); +#endif if (sdlWindow == NULL) { fprintf(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError()); return 1; } + printf("CREATED!\n"); #if ENABLE_VRAM_VIEW int mainWindowX; @@ -182,7 +224,7 @@ int main(int argc, char **argv) } #endif - sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_PRESENTVSYNC); + sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (sdlRenderer == NULL) { fprintf(stderr, "Renderer could not be created! SDL_Error: %s\n", SDL_GetError()); return 1; @@ -220,6 +262,11 @@ int main(int argc, char **argv) } #endif +#ifdef PS2 + SDL_SetTextureScaleMode(sdlTexture, SDL_ScaleModeLinear); + SDL_SetTextureColorMod(sdlTexture, 140, 140, 140); +#endif + #if ENABLE_AUDIO SDL_AudioSpec want; @@ -230,6 +277,7 @@ int main(int argc, char **argv) want.samples = (want.freq / 60); cgb_audio_init(want.freq); + SDL_InitSubSystem(SDL_INIT_AUDIO); if (SDL_OpenAudio(&want, 0) < 0) SDL_Log("Failed to open audio: %s", SDL_GetError()); else { @@ -245,7 +293,7 @@ int main(int argc, char **argv) #endif // Prevent the multiplayer screen from being drawn ( see core.c:GameInit() ) REG_RCNT = 0x8000; - REG_KEYINPUT = 0x3FF; + REG_KEYINPUT = KEYS_MASK; AgbMain(); @@ -267,6 +315,12 @@ void VBlankIntrWait(void) double deltaTime = 0; curGameTime = SDL_GetPerformanceCounter(); + +// For now the PS2 renders too slowly so we just +// have to render as far as we can +#ifdef PS2 + deltaTime = dt; +#else if (stepOneFrame) { deltaTime = dt; } else { @@ -274,6 +328,8 @@ void VBlankIntrWait(void) if (deltaTime > (dt * 5)) deltaTime = dt * 5; } +#endif + lastGameTime = curGameTime; accumulator += deltaTime; @@ -281,6 +337,7 @@ void VBlankIntrWait(void) while (accumulator >= dt) { REG_KEYINPUT = KEYS_MASK ^ Platform_GetKeyInput(); if (frameAvailable) { + // The draw function is super slow on constrained hardware VDraw(sdlTexture); frameAvailable = FALSE; @@ -293,10 +350,13 @@ void VBlankIntrWait(void) if (REG_DISPSTAT & DISPSTAT_VBLANK_INTR) gIntrTable[INTR_INDEX_VBLANK](); REG_DISPSTAT &= ~INTR_FLAG_VBLANK; - accumulator -= dt; } else { - // Get another frame + // remove this once the PS2 renders fast enough +#ifdef PS2 + accumulator -= dt; +#endif + // Get another frame; return; } } @@ -314,10 +374,12 @@ void VBlankIntrWait(void) SDL_RenderClear(vramRenderer); SDL_RenderCopy(vramRenderer, vramTexture, NULL, NULL); #endif + if (videoScaleChanged) { SDL_SetWindowSize(sdlWindow, DISPLAY_WIDTH * videoScale, DISPLAY_HEIGHT * videoScale); videoScaleChanged = false; } + SDL_RenderPresent(sdlRenderer); #if ENABLE_VRAM_VIEW SDL_RenderPresent(vramRenderer); @@ -330,7 +392,6 @@ void VBlankIntrWait(void) SDL_Quit(); exit(0); } - static void ReadSaveFile(char *path) { // Check whether the saveFile exists, and create it if not @@ -401,6 +462,7 @@ static SDL_DisplayMode sdlDispMode = { 0 }; void Platform_QueueAudio(const void *data, uint32_t bytesCount) { +#if ENABLE_AUDIO // Reset the audio buffer if we are 10 frames out of sync // If this happens it suggests there was some OS level lag // in playing audio. The queue length should remain stable at < 10 otherwise @@ -410,6 +472,7 @@ void Platform_QueueAudio(const void *data, uint32_t bytesCount) SDL_QueueAudio(1, data, bytesCount); // printf("Queueing %d\n, QueueSize %d\n", bytesCount, SDL_GetQueuedAudioSize(1)); +#endif } void ProcessSDLEvents(void) diff --git a/src/platform/shared/audio/cgb_audio.c b/src/platform/shared/audio/cgb_audio.c index 787a65f43..3f6ec93d5 100644 --- a/src/platform/shared/audio/cgb_audio.c +++ b/src/platform/shared/audio/cgb_audio.c @@ -103,6 +103,9 @@ void cgb_trigger_note(u8 channel) void cgb_audio_generate(u16 samplesPerFrame) { +#if !ENABLE_AUDIO + return; +#endif float *outBuffer = gb.outBuffer; switch (REG_NR11 & 0xC0) { case 0x00: diff --git a/tools/mid2agb/agb.cpp b/tools/mid2agb/agb.cpp index a92807093..dddd96d0b 100644 --- a/tools/mid2agb/agb.cpp +++ b/tools/mid2agb/agb.cpp @@ -564,5 +564,6 @@ void PrintAgbFooter() for (int i = 1; i <= trackCount; i++) std::fprintf(g_outputFile, "\tmPtr\t%s_%u\n", g_asmLabel.c_str(), i); + // TODO: is this needed? std::fprintf(g_outputFile, "\n\t.end\n"); }