commit 6893ef4c4df7bed9fe9a5b6061ecbee4a82ea8e4 Author: modeco80 Date: Sat Jun 18 01:54:01 2022 -0500 Repo init :) diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d810301 --- /dev/null +++ b/.clang-format @@ -0,0 +1,16 @@ +BasedOnStyle: WebKit + +# :( This is most of the style, tbh. +BreakBeforeBraces: Allman +DerivePointerAlignment: false +PointerAlignment: Right + +TabWidth: 4 +IndentWidth: 4 +UseTab: Always + +AllowShortBlocksOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +Cpp11BracedListStyle: true +PenaltyReturnTypeOnItsOwnLine: 500 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f4f5f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +build/ +cmake-build-* diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..372258c --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.19) + +# Prohibit in-source tree builds. +if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}") + message(FATAL_ERROR "In-source-tree builds are strictly prohibited. Please don't do them.") +endif() + +include(${CMAKE_SOURCE_DIR}/cmake/Policies.cmake) +project(ssxog LANGUAGES C CXX) + +add_subdirectory(src/bx) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..4962413 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,17 @@ +# Contributing to the SSX Decompilation + +# Commit message formatting + +``` +(optional: [ci skip]) Some small commit description here + +A longer description of what this commit does, +alongside any description of unrelated changes, +if applicable. +``` + +# Code formatting + +We use clang-format. Pretty much, just make sure you run `clang-format` on any PR code. + +Please also look at the styleguide for naming concerns. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..677b660 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright © 2022 modeco80 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a25a862 --- /dev/null +++ b/README.md @@ -0,0 +1,62 @@ +# SSX (2000) Decompilation + +This repository contains a work-in-progress functional decompilation of SSX (2000) on the PlayStation 2. + +The binary being used is the US game binary, original filename `SLUS_200.95`, however multiple game builds might be considered later. + +**NOTICE:** NO DATA FILES TO PLAY THE GAME ARE PROVIDED IN THIS REPOSITORY. THEY ARE PROTECTED BY COPYRIGHT. DO NOT REQUEST FOR THEM TO BE PROVIDED. + +# FAQ + +## Why not a matching decompilation? + +While this was briefly considered, the time it would take is far greater, let alone the fact that tooling for matching decompilations +is nearly nonexistant and would have to be written from scratch specifically for this project. + +Later on, it might be worth considering again, however, for now, a functional decompilation will mean faster, more promising results. + +## How can I help? + +Contributions are greatly accepted, if not valued in the early stage of this project. + +Documentation for the styleguide used in the project is below, and a Ghidra server for the project is also available. + +# Building + +You will need: + +- A Linux machine +- CMake +- the SCE PS2 SDK (PS2SDK support may be considered later), 2.5.5 at least. + +You'll need to export SCE to point to your SCE root. This is always /usr/local/sce, and some of the scripts assume so, but for posterity, I don't hardcode it. + +The SCE EE and IOP tools will also need to be in your PATH. + +## Build Hacks + +The crt0.s needs to be built in $SCE/ee/lib, due to a weird issue (and CMake building binaries before the actual compilation stage). + +This can be done like so (do not run this as root. You should have $SCE chowned to yourself.): + +```bash +$ ee-gcc -c -xassembler-with-cpp crt0.s -o crt0.o +``` + +Finally, you'll need to then edit app.cmd (in the same directory) to replace all indirect mentions of `crt0.o` with the path to the crt0.o you just assembled. This is the final hack in the build process. + +## Actually Building + +Then, it's as easy as: + +```bash +$ cmake -Bbuild --toolchain cmake/Toolchain/ps2.cmake +$ cd build +$ make +``` + +Note that the Ninja CMake generator does not work with the SCE SDK, and should not be used if using it. + +# Documentation + +[Style Guide](docs/styleguide.md) diff --git a/cmake/Policies.cmake b/cmake/Policies.cmake new file mode 100644 index 0000000..0fd01de --- /dev/null +++ b/cmake/Policies.cmake @@ -0,0 +1,45 @@ +# CMake policy configuration + +if(POLICY CMP0026) + cmake_policy(SET CMP0026 NEW) +endif() + +if(POLICY CMP0042) + cmake_policy(SET CMP0042 NEW) # CMake 3.0+ (2.8.12): MacOS "@rpath" in target's install name +endif() + +if(POLICY CMP0046) + cmake_policy(SET CMP0046 NEW) # warn about non-existed dependencies +endif() + +if(POLICY CMP0051) + cmake_policy(SET CMP0051 NEW) +endif() + +if(POLICY CMP0054) # CMake 3.1: Only interpret if() arguments as variables or keywords when unquoted. + cmake_policy(SET CMP0054 NEW) +endif() + +if(POLICY CMP0056) + cmake_policy(SET CMP0056 NEW) # try_compile(): link flags +endif() + +if(POLICY CMP0066) + cmake_policy(SET CMP0066 NEW) # CMake 3.7: try_compile(): use per-config flags, like CMAKE_CXX_FLAGS_RELEASE +endif() + +if(POLICY CMP0067) + cmake_policy(SET CMP0067 NEW) # CMake 3.8: try_compile(): honor language standard variables (like C++11) +endif() + +if(POLICY CMP0068) + cmake_policy(SET CMP0068 NEW) # CMake 3.9+: `RPATH` settings on macOS do not affect `install_name`. +endif() + +if(POLICY CMP0075) + cmake_policy(SET CMP0075 NEW) # CMake 3.12+: Include file check macros honor `CMAKE_REQUIRED_LIBRARIES` +endif() + +if(POLICY CMP0077) + cmake_policy(SET CMP0077 NEW) # CMake 3.13+: option() honors normal variables. +endif() \ No newline at end of file diff --git a/cmake/Toolchain/Platform/Playstation2.cmake b/cmake/Toolchain/Platform/Playstation2.cmake new file mode 100644 index 0000000..cdd8a71 --- /dev/null +++ b/cmake/Toolchain/Platform/Playstation2.cmake @@ -0,0 +1,15 @@ +# CMake platform settings for PlayStation 2 + +set(CMAKE_EXECUTABLE_SUFFIX ".elf") +set(CMAKE_EXECUTABLE_SUFFIX_C "${CMAKE_EXECUTABLE_SUFFIX}") +set(CMAKE_EXECUTABLE_SUFFIX_CXX "${CMAKE_EXECUTABLE_SUFFIX}") + +# Don't want prefixes for ERL's +#set(CMAKE_SHARED_LIBRARY_PREFIX "") +#set(CMAKE_SHARED_LIBRARY_PREFIX_C "") +#set(CMAKE_SHARED_LIBRARY_PREFIX_CXX "") + +#set(CMAKE_SHARED_LIBRARY_SUFFIX ".erl") +#set(CMAKE_SHARED_LIBRARY_SUFFIX_C "${CMAKE_SHARED_LIBRARY_SUFFIX}") +#set(CMAKE_SHARED_LIBRARY_SUFFIX_CXX "${CMAKE_SHARED_LIBRARY_SUFFIX}") + diff --git a/cmake/Toolchain/ps2-ps2sdk.cmake b/cmake/Toolchain/ps2-ps2sdk.cmake new file mode 100644 index 0000000..f0795cb --- /dev/null +++ b/cmake/Toolchain/ps2-ps2sdk.cmake @@ -0,0 +1,33 @@ +# Based off the shipped ps2dev.cmake toolchain file +# in the ps2sdk source tree, modified for more idiomatic CMake + +# This is unused atm, and not supported yet. Might be later. + +set(CMAKE_SYSTEM_NAME Playstation2) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR "mips64r5900el") + +# Make it so cmake sees modules here, so it can import +# our PlayStation2 platform. Otherwise, CMake will yell +# and complain (rightfully.) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +# C/C++ compiler + +set(CMAKE_C_COMPILER mips64r5900el-ps2-elf-gcc) +set(CMAKE_CXX_COMPILER mips64r5900el-ps2-elf-g++) + +# You may wanna edit these. + +set(CMAKE_C_FLAGS_INIT "-I$ENV{PS2SDK}/ee/include -I$ENV{PS2SDK}/common/include -D_EE -DPLATFORM_PS2 -G0 -fno-stack-protector -fno-ident") +set(CMAKE_C_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_INIT} -fomit-frame-pointer") +set(CMAKE_CXX_FLAGS_INIT "${CMAKE_C_FLAGS_INIT} -fno-threadsafe-statics") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT} ${CMAKE_CXX_FLAGS_INIT}") +set(CMAKE_EXE_LINKER_FLAGS_INIT " -L$ENV{PS2SDK}/ee/lib") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "-s") + + +set(CMAKE_FIND_ROOT_PATH $ENV{PS2DEV} $ENV{PS2DEV}/ee $ENV{PS2DEV}/ee/ee $ENV{PS2SDK} $ENV{PS2SDK}/ports) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/Toolchain/ps2.cmake b/cmake/Toolchain/ps2.cmake new file mode 100644 index 0000000..86293fe --- /dev/null +++ b/cmake/Toolchain/ps2.cmake @@ -0,0 +1,36 @@ +# Based off the shipped ps2dev.cmake toolchain file +# in the ps2sdk source tree, modified for more idiomatic CMake + +set(CMAKE_SYSTEM_NAME Playstation2) +set(CMAKE_SYSTEM_VERSION 1) +set(CMAKE_SYSTEM_PROCESSOR "ee") + + +# Make it so cmake sees modules here, so it can import +# our PlayStation2 platform. Otherwise, CMake will yell +# and complain (rightfully.) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + +# C/C++ compiler + +set(CMAKE_C_COMPILER ee-gcc) +set(CMAKE_CXX_COMPILER ee-g++) + +# We can't use the compiler generated dependency files, +# since it adds flags GCC 2.9 doesn't understand. +# While it understands -MD, it does not understand -MD or -MF, +# which causes the build to fail. +set(CMAKE_DEPENDS_USE_COMPILER OFF) + +set(CMAKE_C_FLAGS_INIT "-I$ENV{SCE}/ee/include -I$ENV{SCE}/common/include -DPLATFORM_PS2 -DPS2_SONYSDK -fno-exceptions -fno-common") +set(CMAKE_C_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_INIT}") +set(CMAKE_CXX_FLAGS_INIT "${CMAKE_C_FLAGS_INIT}") +set(CMAKE_CXX_FLAGS_RELEASE_INIT "${CMAKE_C_FLAGS_RELEASE_INIT} ${CMAKE_CXX_FLAGS_INIT}") +set(CMAKE_EXE_LINKER_FLAGS_INIT " -L$ENV{SCE}/ee/lib -mno-crt0 -T $ENV{SCE}/ee/lib/app.cmd") +set(CMAKE_EXE_LINKER_FLAGS_RELEASE_INIT "") + + +set(CMAKE_FIND_ROOT_PATH $ENV{SCE} $ENV{SCE}/ee) +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/docs/styleguide.md b/docs/styleguide.md new file mode 100644 index 0000000..9909c23 --- /dev/null +++ b/docs/styleguide.md @@ -0,0 +1,135 @@ +# SSX Decompilation Style Guide + +Most of the documentation here is enforced by [clang-format](https://clang.llvm.org/docs/ClangFormat.html), however I've written things down to make it more obvious. + +# Code Style + +## Indentation & Braces + +Any block scopes should have the brace on the next line, like so: + +```cpp +if(1) +{ + // do something +} + +try +{ +} +catch(...) +{ + // An error occured +} +``` + +Tabs are used for indentation throughout the codebase. + +## Naming + +### Variables + +Variable names should loosely follow Hungarian Notation. + +For quick reference: + +| Prefix | Type | +| -------- | ---------------------------------------------- | +| `b` | byte (unsigned char, don't do `uc`) | +| `c` | char | +| `u` | Unsigned (prefixed before `i` or `s`) | +| `s` | Short | +| `i` | Integer | +| `p` | Pointer to (add for every \*) | +| `v` | `void`; should only ever be used for pointers | +| `sz` | Null terminated string | +| `fl` | Float | +| `d` | Double | + +Additionally, there are also the following special prefixes: + +| Name | Meaning | +| ------- | --------------------------------------- | +| `m` | Class member variable. | + +### Types + +Types have a prefix before them. + +Legacy types (REAL/SND) won't need this due diligence, so it's ok to omit with those (as a matter of fact, it'd be more correct). + +| Prefix | C++ Type +| -------- | ------------------------------------------------ | +| `t` | `typedef struct` | +| `c` | `class` | +| `T` | `template<> class/struct` (* Only seen in SSX3) | + +### Pointer/Reference Types + +The pointer/reference goes on the side of the name, ala `T *name` and `T &name`. + +### Functions + +Function naming is PascalCase wherever possible, except for legacy code (specifically SND & REAL). + +In this case, REAL functions follow the following standard: + +`[component as uppercase]_[lowercase name]`. + +No functions should be annotated as `(void)` unless explicitly decompiled as C , as C++ ensures `()` is not surprising. + +Member functions can use the longer `this->` access pattern for members if desired, but you don't have to unless you.. well, *have* to. + +## Comments + +Don't really care. If you think something might not be obvious, feel free to comment describing it. + +If there's something surprising (or repulsive, considering 2000 C++), do so too. + +## Example + +Provided is an example of the code style guide, to hopefully visualize things better. + +```cpp + +// A basic object. +class cBxObject +{ +public: + int miCounter; + static int miVar; + uint32_t muiUnsignedValue; + + uint16_t musShort; + int16_t msSignedShort; + + static uint16_t musStaticValue; + static int16_t msStaticSignedValue; + + int *mpiVar; + + // Morph + void Morph(); + + void NotImplemented(int &iOutput); // only for reference output +}; + +// TODO: probably won't advocate for this unless +// I have to since structs are types in C++ +typedef struct +{ + int iNumber; +} tBxStructure; + +// example of a legacy function and type name +FILEOP *FILE_dothing(); + +void cBxObject::Morph() +{ + miCounter++; + if(miCounter == 32) + { + // Do something important. + } +} +``` diff --git a/src/bx/CMakeLists.txt b/src/bx/CMakeLists.txt new file mode 100644 index 0000000..3dc1ac1 --- /dev/null +++ b/src/bx/CMakeLists.txt @@ -0,0 +1,36 @@ +add_executable(ssx + # TODO: seperate this into another target_sources(ssx) call later + $ENV{SCE}/ee/lib/crt0.s + + + main.cpp +) + + +# maybe later: ps2sdk support +# for now I don't care + +target_link_libraries(ssx + + # System libraries + #kernel + + # Project libraries (by alias) +) + +set_target_properties(ssx PROPERTIES + # Binary output in the root. + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} + + # This is just for the base branch, and to hopefully + # make sure we can actually compile the code with + # ee-gcc. + # + # Later on a "modernization" branch could + # be forked off to get the game compiling as + # clean C++20, before the PC port. + + CXX_STANDARD 98 + CXX_EXTENSIONS ON + CXX_STANDARD_REQUIRED ON +) diff --git a/src/bx/main.cpp b/src/bx/main.cpp new file mode 100644 index 0000000..7c054a4 --- /dev/null +++ b/src/bx/main.cpp @@ -0,0 +1,8 @@ +// sample main() just to get the project building. +// will be replaced with real code later +#include + +int main() +{ + printf("Hello World!\n"); +} diff --git a/src/snd/iop/TODO.txt b/src/snd/iop/TODO.txt new file mode 100644 index 0000000..8ab3715 --- /dev/null +++ b/src/snd/iop/TODO.txt @@ -0,0 +1,3 @@ +- superbuild this using another Playstation2IOP toolchain + +either that or Hope & Pray :tm: