![]() |
SH4ZAM! 0.7.0
Fast math library for the Sega Dreamcast's SH4 CPU
|
SH4ZAM is a hand-optimized, general-purpose math and linear algebra library for harnessing the floating-point power of the SH4 processor in the Sega Dreamcast. It originally began as a collection of inline assembly routines developed specifically to accelerate the math in the Grand Theft Auto 3 and Vice City DC ports. These routines, along with many others from various contributors, have been separated and combined into a single standalone library, which can be leveraged to bring gainz to the Dreamcast and SuperH communities at large.
<math.h> replacementsFor C code, include the header files with the .h extensions or sh4zam/shz_sh4zam.h to include everything.
NOTE: Where applicable, the C API also includes a variety of type-generic routines which will automatically resolve to calling the proper functions based on argument type. for example, shz_vec_dot() will automatically forward to the proper routine based on the type of vectors passed to it.
For C++ code, include the header files with the .hpp extensions or sh4zam/shz_sh4zam.hpp to include everything.
NOTE: C++ can still use the C API by design, and every C++ type is also compatible with its corresponding C types and C API, so you can mix and match.
SH4ZAM is now an official part of kos-ports, meaning that it is now directly integrated within the KallistiOS ecosystem and will be automatically set up as part of the regular KOS installation process. If you're following the standard community guide for Setting up KallistiOS, SH4ZAM will be installed as part of the Building KOS Ports step. If you're using DreamSDK to manage your KallistiOS development environment, SH4ZAM may be installed from the KallistiOS Ports tab.
To quickly build the project with CMake in any environment, independently of KOS, run the following from the repo root:
This will build and install the statically linked library as well as the public headers.
If you would like to also build and run the unit tests, include -DSHZ_ENABLE_TESTS=on within the cmake command. Now a separate binary for the unit test executable should be built as well.
NOTE: For KOS users, use kos-cmake instead of your system cmake command!
Examples can be found within the example subdirectory. New examples are always welcome to be contributed!
| Example | Description |
|---|---|
| Bruce's Balls | Pushes up to 4.5 million PPS, rendering Bruce's balls. |
| PVR DMA | Real-world, complex renderer using KOS's PVR DMA API. |
NOTE: If you've installed SH4ZAM through KOS-ports, the examples should get installed to kos-ports/examples/sh4zam.
The following projects have been successfully accelerated with SH4ZAM and make great references:
| Project | Description |
|---|---|
| SH4ZAM PVR | Advanced PVR DR rendering examples with SH4ZAM acceleration. |
| Mario Kart 64 DC | jnmartin's Mario Kart 64 DC port with SH4ZAM acceleration. |
| Star Fox 64 DC | jnmartin's Star Fox 64 DC port with SH4ZAM acceleration. |
| Super Mario 64 DC | Super Mario 64 DC port with SH4ZAM acceleration. |
| FFFFTT | Audio signal visualizations, with SH4ZAM accelerated FFT and more. |
| Sonic Mania DC | Sonic Mania DC port with SH4ZAM acceleration. |
| Simulant Engine | General-purpose cross-platform engine backed by SH4ZAM math. |
| Meese Engine | An open-world voxel game built for the GameCube, using the SH4ZAM SW back-end. |
| Quake 2 DC | Port of Quake 2 to the DC, with SH4ZAM accelerated matrix math. |
| DCSinge | Singe API + FMV playback engine on DC using SH4ZAM memory routines. |
The following conventions are used throughout the API by default, unless otherwise specified:
| Convention | Description |
|---|---|
| Coordinates | Right-handed for world/view space, Left-handed for screen/clip-space, as with GL. |
| Matrices | Stored in column-major order, as with GL. |
| Quaternions | Stored in <W, X, Y, Z> order. |
The #sh4zam channel within the Simulant Discord Server for Dreamcast development is the best place to ask questions, get help, give feedback, or discuss anything relating to SH4ZAM. Also, feel free to open tickets for any issues or feature requests!
Special thanks to the following individuals who have either directly or indirectly contributed to SH4ZAM: