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

Ps2 testing #174

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
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
20 changes: 17 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ libagbsyscall/*.s
*.exe
*.dll
*.sdl
*.iso

# third party deps
/ext
69 changes: 53 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)')
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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) <objects> <lib>"
@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)/$@
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion asm/macros/portable.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#if defined(__aarch64__) || defined(__x86_64__)
.quad \value
#else
.int \value
.4byte \value
#endif
.endm

Expand Down
10 changes: 7 additions & 3 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions include/game/sa1_leftovers/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/game/stage/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions include/gba/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 0 additions & 2 deletions include/gba/dma_macros.h
Original file line number Diff line number Diff line change
@@ -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) \
{ \
Expand Down
21 changes: 12 additions & 9 deletions include/gba/io_reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include <stdint.h>

#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];
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion include/gba/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
typedef struct __attribute__((packed)) name struct_body name;
#endif


#if _EE
#include <tamtypes.h>
#else
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
Expand All @@ -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.
Expand Down
7 changes: 0 additions & 7 deletions include/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions ps2/ntsc/SYSTEM.CNF
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BOOT2 = cdrom0:\SLUS_054.02;1
VER = 1.00
VMODE = NTSC

Loading
Loading