2022-01-01 17:45:41 +00:00
|
|
|
#ifndef COMMON_H
|
|
|
|
#define COMMON_H
|
|
|
|
|
2023-05-04 22:32:35 +00:00
|
|
|
#if defined(_internal_version_us)
|
|
|
|
#define VERSION_US
|
2023-06-12 18:59:48 +00:00
|
|
|
#define VERSION "us"
|
2023-05-04 22:32:35 +00:00
|
|
|
#elif defined(_internal_version_hd)
|
|
|
|
#define VERSION_HD
|
2023-06-12 18:59:48 +00:00
|
|
|
#define VERSION "hd"
|
Add TT_000 overlay from PSP (#1113)
TT_000 is the first overlay from PlayStation 1 that we are now able to
compile from the source and produce a 1:1 binary. This lead me to start
exploring the same overlay from the game Castlevania: Dracula X
Chronicles, which contains a PSP re-build of Symphony of the Night.
This PR adds all the infrastructure to add the same flow for a PSP
matching decomp. Use `export VERSION=pspeu` and then the usual `sotn`
command to splat the overlay, build it and check if it matches. Running
`make extract_disk` should not be necessary as the same ISO used from
`VERSION=hd` is also used for `pspeu`, so you will probably have it
extracted already.
Some important notes about the PSP build:
* The whole PSP build seems to be compiled with `-O0`, which makes it
much easier to decompile
* Having ŧhe PSX, PSP and Saturn builds will allow to easily
cross-reference the code and reduce fake matches
* `disks/pspeu/PSP_GAME/USRDIR/res/ps/hdbin/tt_000.bin` is the HD PSX
build
* `disks/pspeu/PSP_GAME/USRDIR/res/ps/PSPBIN/tt_000.bin` has the same
code from the HD build, but for PSP
* `disks/pspeu/PSP_GAME/USRDIR/res/ps/PACK_E/TP00.BIN` is the same as
above, but it packs both overlay and graphics. This is the file the PSP
game seems to actually use
* The PSP build uses the Metrowerk CodeWarrior's C compiler, which is
very different from the GCC one used on PSX.
* Thanks to @mkst lead, we found a way to still use the GNU assembler
and linker
* MWCC uses [wibo](https://github.com/decompals/WiBo/), a think
compatibility layer to run Windows CLI tools on Linux. It is much more
lightweight than Wine.
* MWCC does not support the `INCLUDE_ASM` dialect, so the custom
pre-processor `tools/mwcpp` had to be created
* The exact MWCC compiler version is unknown, but I suspect it is `build
147`
* I am not yet sure of any implications for using GNU AS and GNU LD
instead of the MW correspondent tools
* Not all the functions can be correctly disassembled, spimdisasm will
just produce a bunch of `.word 0x________` due to the in-progress effort
of adding the Allegrex-specific opcodes support
---
TO-DO list before marking the PR as ready:
- [X] Add PSP build to the CI
- [x] Add progress reporting to the PSP build
- [x] Integrate source file from `src/servant/tt_000_psp` to
`src/servant/tt_000` to promote the psp build as first-citizen
---
TO-DO in a follow-up PR:
* Figure out what `header` is: can we extract it as assembly code? or
maybe as custom re-compilable asset via splat? Is it a MW stuff or a
Castlevania-specific file?
* Get rid of the last line in `Makefile.psp.mk`
2024-04-21 01:18:10 +00:00
|
|
|
#elif defined(_internal_version_pspeu)
|
|
|
|
#define VERSION_PSP
|
|
|
|
#define VERSION "psp"
|
2023-08-31 21:55:23 +00:00
|
|
|
#elif defined(_internal_version_beta)
|
|
|
|
#define VERSION_BETA
|
|
|
|
#define VERSION "beta"
|
2023-05-04 22:32:35 +00:00
|
|
|
#else
|
|
|
|
#warning "Version not specified. Falling back to the US version."
|
|
|
|
#define VERSION_US
|
2023-06-12 18:59:48 +00:00
|
|
|
#define VERSION "us"
|
2023-05-04 22:32:35 +00:00
|
|
|
#endif
|
|
|
|
|
2024-05-18 20:09:03 +00:00
|
|
|
#include "include_asm.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "types.h"
|
|
|
|
|
2023-03-24 12:42:41 +00:00
|
|
|
#define LEN(x) ((s32)(sizeof(x) / sizeof(*(x))))
|
2024-01-19 03:07:13 +00:00
|
|
|
#define OFF(type, field) ((size_t)(&((type*)0)->field))
|
2023-03-28 12:14:13 +00:00
|
|
|
#define STRCPY(dst, src) __builtin_memcpy(dst, src, sizeof(src))
|
2024-05-19 18:16:56 +00:00
|
|
|
#define SQ(x) ((x) * (x))
|
|
|
|
#define MIN(a, b) ((a) > (b) ? (b) : (a))
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (b) : (a))
|
2023-03-24 12:29:18 +00:00
|
|
|
|
2023-12-27 09:24:00 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define __builtin_memcpy memcpy
|
|
|
|
#endif
|
|
|
|
|
2024-08-18 13:03:35 +00:00
|
|
|
#if defined(VERSION_PC)
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
#define STATIC_ASSERT _Static_assert
|
|
|
|
#define PACKED __attribute__((packed))
|
|
|
|
#else
|
|
|
|
#define STATIC_ASSERT(x, ...)
|
|
|
|
#define PACKED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#elif defined(VERSION_PSP)
|
|
|
|
#define STATIC_ASSERT(x)
|
|
|
|
#define PACKED
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define STATIC_ASSERT(x, ...)
|
|
|
|
#define PACKED
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2023-03-04 01:26:05 +00:00
|
|
|
#define LOH(x) (*(s16*)&(x))
|
2024-01-10 19:47:15 +00:00
|
|
|
#define HIH(x) (((s16*)&(x))[1])
|
2023-07-06 11:20:53 +00:00
|
|
|
#define LOHU(x) (*(u16*)&(x))
|
2023-05-27 10:13:49 +00:00
|
|
|
#define LOW(x) (*(s32*)&(x))
|
2023-07-06 11:20:53 +00:00
|
|
|
#define LOWU(x) (*(u32*)&(x))
|
2023-05-27 10:13:49 +00:00
|
|
|
|
2023-03-13 01:43:07 +00:00
|
|
|
#if defined(HACKS) && !defined(PERMUTER)
|
2023-03-12 00:13:28 +00:00
|
|
|
#define ALIGNED4 __attribute__((aligned(4)))
|
2023-03-12 00:11:04 +00:00
|
|
|
#else
|
|
|
|
#define ALIGNED4
|
|
|
|
#endif
|
2023-03-04 01:26:05 +00:00
|
|
|
|
2024-01-11 09:23:41 +00:00
|
|
|
#ifndef __clang__
|
2022-12-22 10:32:56 +00:00
|
|
|
int sprintf(char* dst, const char* fmt, ...);
|
2024-01-11 09:23:41 +00:00
|
|
|
#endif
|
2022-12-22 10:32:56 +00:00
|
|
|
|
2024-07-17 20:58:31 +00:00
|
|
|
// Converts a given value to a fixed-point value, where
|
|
|
|
// 16 bits represents the integer part and 16 bits for fractional part
|
2024-06-04 20:07:50 +00:00
|
|
|
#define FIX(x) ((s32)((x) * 65536.0))
|
2024-07-17 20:58:31 +00:00
|
|
|
// Get the integer part of such a fixed-point value
|
2023-08-08 17:12:53 +00:00
|
|
|
#define FIX_TO_I(x) ((s32)((x) >> 16))
|
2024-07-17 20:58:31 +00:00
|
|
|
// Get the fractional part of such a fixed-point value
|
|
|
|
#define FIX_FRAC(x) (*(s16*)&(x))
|
2023-07-30 16:44:26 +00:00
|
|
|
|
2023-11-18 02:39:10 +00:00
|
|
|
// The second argument to CreateEntFactoryFromEntity has weird bit packing,
|
|
|
|
// this takes the 2 relevant inputs and packs them up.
|
2024-09-07 00:29:56 +00:00
|
|
|
// id is which blueprint gets loaded from g_FactoryBlueprints.
|
|
|
|
#define FACTORY(id, param) ((id) + (param << 16))
|
|
|
|
|
2023-11-18 23:53:38 +00:00
|
|
|
// Tests multiple bits of x being set, based on the bitmask defined in y.
|
|
|
|
#define TEST_BITS(x, y) ((x & y) == y)
|
2023-11-18 02:39:10 +00:00
|
|
|
|
2023-10-09 23:05:57 +00:00
|
|
|
// PSX SDK libraries do not use float. Instead they use a fix-point number
|
|
|
|
// where 4096 is equal to 1.0.
|
2024-06-04 20:07:50 +00:00
|
|
|
#define FLT(x) ((s32)((x) * 4096.0))
|
2023-10-09 23:05:57 +00:00
|
|
|
|
2024-05-27 00:30:40 +00:00
|
|
|
// Access to the Scratchpad memory. Different on different systems.
|
2024-06-02 19:52:27 +00:00
|
|
|
#if defined(VERSION_PC)
|
|
|
|
#define SP_LEN 0x400
|
|
|
|
#define SP(x) (&sp[x])
|
|
|
|
#elif defined(VERSION_PSP)
|
2024-06-05 19:40:23 +00:00
|
|
|
#define SP(x) (0x00010000 + (x))
|
2024-06-02 19:52:27 +00:00
|
|
|
#else
|
2024-06-05 19:40:23 +00:00
|
|
|
#define SP(x) (0x1F800000 + (x))
|
2024-06-02 19:52:27 +00:00
|
|
|
#endif
|
2024-05-27 00:30:40 +00:00
|
|
|
|
2024-08-01 16:14:52 +00:00
|
|
|
#define CLAMP_MIN(v, min) ((v) < (min) ? (min) : (v))
|
|
|
|
#define CLAMP_MAX(v, max) ((v) > (max) ? (max) : (v))
|
|
|
|
|
2024-08-11 14:49:53 +00:00
|
|
|
// Creates padding between variables with a unique name and file
|
|
|
|
// visibility. On versions where this padding is unnecessary, these
|
|
|
|
// macros expand to nothing. "Critical" versions of these macros
|
|
|
|
// ensure that the padding is provided, regardless of version, useful
|
|
|
|
// for when locations are accessed using a variety of sizes so
|
|
|
|
// field offset needs to be maintained. The unknown critical versions
|
|
|
|
// expand identically to the critical versions but indicate that it
|
|
|
|
// is not known whether or not the padding is necessary outside of
|
|
|
|
// reproducing an original binary.
|
|
|
|
#define __INDIRECT_CRITICAL_PAD_TYPE_FIELD(type, size, line, counter) \
|
|
|
|
type __pad__##size##__##line##__##counter[size]
|
|
|
|
#define __CRITICAL_PAD_TYPE_FIELD(type, size, line, counter) \
|
|
|
|
__INDIRECT_CRITICAL_PAD_TYPE_FIELD(type, size, line, counter)
|
|
|
|
#define CRITICAL_PAD_TYPE_FIELD(type, size) \
|
|
|
|
__CRITICAL_PAD_TYPE_FIELD(type, size, __LINE__, __COUNTER__)
|
|
|
|
#define CRITICAL_PAD_FIELD(size) CRITICAL_PAD_TYPE_FIELD(uint8_t, size)
|
|
|
|
|
|
|
|
#define UNKNOWN_CRITICAL_PAD_TYPE(type, size) \
|
|
|
|
CRITICAL_PAD_TYPE_FIELD(type, size)
|
|
|
|
#define UNKNOWN_CRITICAL_PAD_FIELD(size) CRITICAL_PAD_FIELD(size)
|
|
|
|
|
|
|
|
#ifndef VERSION_PC
|
|
|
|
#define PAD_FIELD(size) const CRITICAL_PAD_FIELD(size)
|
|
|
|
#define STATIC_PAD_BSS(size) static CRITICAL_PAD_FIELD(size)
|
|
|
|
#define STATIC_PAD_DATA(size) STATIC_PAD_BSS(size) = {0}
|
2024-08-27 17:18:26 +00:00
|
|
|
#define STATIC_PAD_RODATA(size) const STATIC_PAD_BSS(size) = {0}
|
2024-08-11 14:49:53 +00:00
|
|
|
#else
|
|
|
|
#define PAD_FIELD(size)
|
|
|
|
#define STATIC_PAD_BSS(size)
|
|
|
|
#define STATIC_PAD_DATA(size)
|
|
|
|
#define STATIC_PAD_RODATA(size)
|
|
|
|
#endif
|
|
|
|
|
2022-01-01 17:45:41 +00:00
|
|
|
#endif
|