From 3f859332c8e345ef3a35e24ab8ee3617cb477df7 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Tue, 11 Oct 2022 11:22:30 +0200 Subject: Bump required CMake version to 3.21 --- template/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'template') diff --git a/template/CMakeLists.txt b/template/CMakeLists.txt index 4aa648f..a3399db 100644 --- a/template/CMakeLists.txt +++ b/template/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) project( PSn00bSDK-template @@ -11,7 +11,7 @@ project( HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" ) -psn00bsdk_add_executable(template STATIC main.c) +psn00bsdk_add_executable(template GPREL main.c) psn00bsdk_add_cd_image( iso # Target name -- cgit v1.2.3 From 8e92156bc6a977651771d2cf91ac5800a0e9a913 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Tue, 11 Oct 2022 15:39:36 +0200 Subject: Update preset files, README, docs and changelog --- CHANGELOG.md | 32 +++ CMakePresets.json | 4 +- README.md | 66 +++-- cpack/setup.cmake | 4 +- doc/cmake_reference.md | 465 ++++++++++++++++++++++------------- doc/installation.md | 6 +- doc/known_bugs.md | 26 +- examples/README.md | 4 +- libpsn00b/cmake/internal_setup.cmake | 2 - template/CMakePresets.json | 25 +- 10 files changed, 399 insertions(+), 235 deletions(-) (limited to 'template') diff --git a/CHANGELOG.md b/CHANGELOG.md index f7f4f93..3f04108 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,38 @@ to ensure the changelog can be parsed correctly. ------------------------------------------------------------------------------- +## 2022-10-11: 0.21 + +spicyjpeg: + +- libpsn00b: Completely rewritten CMake scripts. Six copies of each library are + now built and installed, one for each combination of configuration (debug and + release) and target type (executable with/without $gp-relative addressing and + DLL). Library debug logging is now completely disabled when a project is + built in release mode (using `-DCMAKE_BUILD_TYPE=Release`). + +- libc: Replaced `memset()` with a much faster optimized implementation that + makes use of Duff's device. Added `GetHeapUsage()` and `TrackHeapUsage()`. + Removed `_mem_init()`. + +- psxetc: Fixed a critical bug in `DMACallback()` that would lead to the DMA + interrupt handler being disabled entirely in some edge cases. + +- psxgpu: Replaced the debug font with an improved one. No changes have been + made to the API. + +- psxcd: Added `CdGetSector2()` (asynchronous variant of `CdGetSector()`). + `CdControl()` can now take a `CdlLOC` as second argument when issuing a seek + command (previously the argument was ignored if the command was not `ReadN` + or `ReadS`). + +- Replaced the `DEBUG` macro with the standard C `NDEBUG` macro, which is only + defined if the project is being built in release mode. + +- Added `PSN00BSDK_*_LINK_LIBRARIES` CMake variables to control which SDK + libraries are linked to newly created executables and DLLs. Updated + `cmake_reference.md` to reflect the changes. + ## 2022-09-22 spicyjpeg: diff --git a/CMakePresets.json b/CMakePresets.json index 89002a3..eca1478 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -1,8 +1,8 @@ { - "version": 2, + "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 21, "patch": 0 }, "configurePresets": [ diff --git a/README.md b/README.md index e4a2d15..07ad738 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ and performance reasons. ## Notable features -As of March 28, 2022 +As of October 11, 2022: * Extensive GPU support with lines, flat shaded or textured polygon and sprite primitives, high-speed DMA for VRAM transfers and ordering tables. All video @@ -54,26 +54,24 @@ As of March 28, 2022 HLE BIOS implementations and loader/menu type homebrew programs. * BIOS controller functions for polling controller input work as intended - thanks to proper handling of hardware interrupts. No crude direct I/O polling - of controllers in the main loop. - -* Complete Serial I/O support with SIOCONS driver for tty stdin/stdout - console access. Hardware flow control supported. - -* Full CD-ROM support using libpsxcd featuring data read, CD audio and XA audio - playback, built-in ISO9660 file system parser with no file count limit - (classic ISO9660 only, no Rock Ridge or Joliet extensions) and multi-session. - -* Preliminary MDEC support implemented with libpsxpress (no VLC decoding yet). - Sample encoder included. - -* Can target Konami System 573 arcade hardware with limited support - (see examples/io/system573/main.c for details) - -* Experimental support for compiling separate sections of an executable into - shared library files (DLLs) and linking them dynamically at runtime, plus - support for function and variable introspection by loading a map file - generated at build time. + thanks to proper handling of hardware interrupts. Optional limited support + for manual polling. + +* Complete Serial I/O support and console driver to redirect standard input and + output to the serial port. Hardware flow control supported. + +* Full CD-ROM support using `libpsxcd` featuring data reading, CD-DA and XA + audio playback, a built-in ISO9660 file system parser with no file count + limit and support for multi-session discs. + +* MDEC support, lossy image decompression and video playback using + `libpsxpress` (currently only bitstream versions 1 and 2 are supported). + +* Preliminary limited support for Konami System 573 arcade hardware. + +* Experimental support for dynamic linking at runtime, with support for + function and variable introspection by loading a map file generated at build + time. * Uses Sony SDK library syntax for familiarity to experienced programmers and makes porting existing homebrew projects to PSn00bSDK easier. @@ -113,21 +111,21 @@ apply to PSn00bSDK. ## To-do List -* psxspu: Plenty of work to be done. Hardware timer driven sound/music - system may need to be implemented (an equivalent to the Ss* series of - functions in libspu basically). Functions that make use of the SPU RAM - interrupt feature to play or capture streamed audio should also be added. +* `libpsxspu`: Plenty of work to be done. Some kind of MIDI sequencer (similar + to the one present in the official SDK) should be added at some point, along + with a proper API for audio streaming. -* psxcd: Implement a command queue mechanism for the CD-ROM? +* `libpsxcd`: Implement a command queue mechanism for the CD-ROM. -* libc: Improve the memory allocation framework with multiple allocators, GC - and maybe helpers to manage swapping between main RAM and VRAM/SPU RAM. +* `libpsxpress`: Add support for version 3 and IKI frame bitstreams. -* Further support for MDEC, and tooling to transcode videos to .STR files - (either reimplementing the container and compression format used by the Sony - SDK, or a custom format with better compression). +* `libc`: Improve the memory allocation framework with multiple allocators, + replace the string functions with optimized implementations and maybe add + helpers to manage swapping between main RAM and VRAM/SPU RAM. -* Pad and memory card libraries that don't use the BIOS routines. +* Add a full controller and memory card API that does not depend on the BIOS + controller driver, and possibly a library for interfacing to IDE/ATAPI drives + to make development for arcade systems easier. ## Credits @@ -138,8 +136,8 @@ Main developer/author/whatever: Contributors: -* **spicyjpeg**: dynamic linker, CMake scripts, some docs and examples - (`system/dynlink`, `sound/spustream`, `io/pads`, `io/system573`). +* **spicyjpeg**: dynamic linker, `libpsxpress`, CMake scripts, some docs and + examples. * **Silent**, **G4Vi**, **Chromaryu**: `mkpsxiso` and `dumpsxiso` (maintained as a [separate repo](https://github.com/Lameguy64/mkpsxiso)). diff --git a/cpack/setup.cmake b/cpack/setup.cmake index eaf16f2..d585641 100644 --- a/cpack/setup.cmake +++ b/cpack/setup.cmake @@ -128,11 +128,11 @@ set(CPACK_PACKAGE_INSTALL_DIRECTORY PSn00bSDK) ## DEB/RPM variables -set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.28), cmake (>= 3.20)") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.28), cmake (>= 3.21)") set(CPACK_DEBIAN_PACKAGE_RECOMMENDS "ninja-build (>= 1.10)") set(CPACK_DEBIAN_PACKAGE_SUGGESTS "git (>= 2.25)") set(CPACK_DEBIAN_PACKAGE_SECTION devel) -set(CPACK_RPM_PACKAGE_REQUIRES "cmake >= 3.20") +set(CPACK_RPM_PACKAGE_REQUIRES "cmake >= 3.21") set(CPACK_RPM_PACKAGE_SUGGESTS "ninja-build >= 1.10, git >= 2.25") #set(CPACK_RPM_PACKAGE_RELOCATABLE ON) diff --git a/doc/cmake_reference.md b/doc/cmake_reference.md index 25a89ec..bceaac9 100644 --- a/doc/cmake_reference.md +++ b/doc/cmake_reference.md @@ -1,6 +1,15 @@ # PSn00bSDK CMake reference +- [Setup](#setup) +- [Targets](#targets) +- [Commands](#commands) +- [Target properties](#target-properties) +- [Preprocessor definitions](#preprocessor-definitions) +- [Cached settings](#cached-settings) +- [Internal settings](#internal-settings) +- [Read-only variables](#read-only-variables) + ## Setup The only requirement to use the SDK in CMake is to set the @@ -10,32 +19,35 @@ This can be done on the command line (`-DCMAKE_TOOLCHAIN_FILE=...`), in `CMakeLists.txt` (`set(CMAKE_TOOLCHAIN_FILE ...)` before `project()`) or using [presets](https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html). -It's suggested to have a default preset that sets `CMAKE_TOOLCHAIN_FILE` to +It's suggested to have a default preset that sets the toolchain file to `$env{PSN00BSDK_LIBS}/cmake/sdk.cmake`, taking advantage of the `PSN00BSDK_LIBS` environment variable (used by former PSn00bSDK versions) to -automatically find the SDK. Such a preset can be created by placing a +automatically find the SDK if set. Such a preset can be created by placing a `CMakePresets.json` file in the project's root with the following contents: ```json { - "version": 2, + "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 21, "patch": 0 }, "configurePresets": [ { - "name": "default", - "displayName": "Default configuration", - "description": "Use this preset to build the project using PSn00bSDK.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build", + "name": "default", + "displayName": "Default configuration", + "description": "Use this preset to build the project using PSn00bSDK.", + "generator": "Ninja", + "toolchainFile": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", + "binaryDir": "${sourceDir}/build", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_TOOLCHAIN_FILE": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", - "PSN00BSDK_TC": "", - "PSN00BSDK_TARGET": "mipsel-none-elf" + "CMAKE_BUILD_TYPE": "Debug", + "PSN00BSDK_TC": "", + "PSN00BSDK_TARGET": "mipsel-none-elf" + }, + "warnings": { + "dev": false } } ] @@ -43,230 +55,345 @@ automatically find the SDK. Such a preset can be created by placing a ``` To avoid having to pass variables to CMake each time the project is built, a -second presets file named `CMakeUserPresets.json` can be created and populated -with hardcoded values in the `cacheVariables` section. This file can be kept -private (e.g. by adding it to `.gitignore`); CMake will automatically load -presets from it instead of `CMakePresets.json` if it exists. +second file named `CMakeUserPresets.json` can be created and populated with +hardcoded values in the `cacheVariables` section. This file can be kept private +(e.g. by adding it to `.gitignore`), and CMake will automatically load presets +from it instead of `CMakePresets.json` if it exists. See the [template](../template/CMakeLists.txt) for an example CMake script showing how to build a simple project. ## Targets -These targets are defined when using PSn00bSDK. There is no need to explicitly -link against any of these, as the helper commands (see below) handle linking -behind the scenes. To avoid conflicts, however, no target should be given any -of these names. - -- `c`, `psxgpu`, `psxgte`, `psxspu`, `psxcd`, `psxsio`, `psxetc`, `psxapi`, `lzp` -- `psn00bsdk_common`, `psn00bsdk_object_lib` -- `psn00bsdk_static_exe` -- `psn00bsdk_dynamic_exe` -- `psn00bsdk_static_lib` -- `psn00bsdk_shared_lib`, `psn00bsdk_module_lib` +The toolchain script creates a target for each PSn00bSDK library. Currently +the following targets are defined: + +- `psxgpu` +- `psxgte` +- `psxspu` +- `psxcd` +- `psxpress` +- `psxsio` +- `psxetc` +- `psxapi` +- `lzp` +- `c` + +Note that these are not actual libraries but virtual targets that link to the +appropriate version of the respective library, depending on the value of the +`PSN00BSDK_TARGET_TYPE` property; refer to the target properties section for +more information. Linking manually using the `target_link_libraries()` command +is usually not necessary for executables as they are linked to all libraries +by default (see `PSN00BSDK_EXECUTABLE_LINK_LIBRARIES`). + +Additionally, two "hidden" libraries named `gcc` and `psn00bsdk` are linked by +default to all targets. The former is the GCC toolchain's `libgcc` (see +`PSN00BSDK_LIBGCC`) while the latter is a virtual target used to set compiler +flags and paths. ## Commands -- `psn00bsdk_add_executable( [EXCLUDE_FROM_ALL] [sources...])` +### `psn00bsdk_add_executable` - A wrapper around `add_executable()` to create PS1 executables. Three files - will be generated for each call to this function: +```cmake +psn00bsdk_add_executable( + + [EXCLUDE_FROM_ALL] + [sources...] +) +``` - - `.elf` (regular ELF executable) - - `.exe` (executable converted to the format expected by the PS1) - - `.map` (symbol map file for dynamic linking/introspection) +A wrapper around `add_executable()` to create PS1 executables. Three files will +be generated for each call to this function: - The `.exe` and `.map` extensions can be customized by overriding - `PSN00BSDK_EXECUTABLE_SUFFIX` and `PSN00BSDK_SYMBOL_MAP_SUFFIX` prior to - creating the executable. +- `.elf` (regular ELF executable) +- `.exe` (executable converted to the format expected by the PS1) +- `.map` (symbol map file for dynamic linking/introspection) - The second argument (mandatory) specifies whether the executable is going to - load DLLs at runtime. If set to `STATIC`, $gp-relative addressing (i.e. - reusing the $gp register normally used for DLL addressing) will be enabled, - slightly reducing executable size and RAM usage but breaking compatibility - with the dynamic linker. +The `.exe` and `.map` extensions can be customized by overriding +`PSN00BSDK_EXECUTABLE_SUFFIX` and `PSN00BSDK_SYMBOL_MAP_SUFFIX` prior to +creating the executable. -- `psn00bsdk_add_library( [EXCLUDE_FROM_ALL] [sources...])` +The second argument (mandatory) specifies whether the executable is going to +load DLLs at runtime. If set to `GPREL` or `STATIC`, $gp-relative addressing +(i.e. reusing the $gp register normally used for DLL addressing to reference +global variables) will be enabled, slightly reducing executable size and RAM +usage but breaking compatibility with the dynamic linker. - Wraps `add_library()` to create static libraries or dynamically-linked - libraries (DLLs). +All executables are automatically linked to the libraries listed in +`PSN00BSDK_EXECUTABLE_LINK_LIBRARIES` (all SDK libraries by default). This +variable can be modified prior to creating the executable to select which +libraries to link. - The second argument (mandatory, unlike `add_library()`) specifies the type of - library to create. `STATIC` will create a static library named `lib.a`. - `SHARED` and `MODULE` will compile a DLL, producing the following files (note - that there is no `lib` prefix for DLLs): +### `psn00bsdk_add_library` - - `.so` (regular ELF shared library) - - `.dll` (raw binary with some ELF headers prepended) +```cmake +psn00bsdk_add_library( + + [EXCLUDE_FROM_ALL] + [sources...] +) +``` - As with executables, the `.dll` extension can be customized by setting - `PSN00BSDK_SHARED_LIBRARY_SUFFIX`. +Wraps `add_library()` to create static libraries or dynamically-linked +libraries (DLLs). -- `psn00bsdk_add_cd_image( [DEPENDS ...] [...])` +The second argument (mandatory, unlike CMake's regular `add_library()`) +specifies the type of library to create. `STATIC` will create a static library +named `lib.a`. `SHARED` and `MODULE` will compile a DLL, producing +the following files (there is no `lib` prefix for DLLs): - Creates a new target that will build a CD image using `mkpsxiso`. +- `.so` (regular ELF shared library) +- `.dll` (raw binary with some ELF headers prepended) - The first argument is the name of the target to create; next up is the name - of the generated image file (`.bin` + `.cue`). The - third argument is the path to the XML file (relative to the source directory) - passed to `mkpsxiso`. +The `.dll` extension can be customized by setting +`PSN00BSDK_SHARED_LIBRARY_SUFFIX` prior to creating the DLL. - The XML file is "configured" by CMake, i.e. any `${var}` or `@var@` - expressions are replaced with the values of the respective variables. In - particular `${CD_IMAGE_NAME}` is replaced with the second argument passed to - `psn00bsdk_add_cd_image()`; the file must properly set the output file names - like this: +All DLLs are automatically linked to the libraries listed in +`PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES` (none by default). This variable can +be modified prior to creating the DLL to select which libraries to link. - ```xml - - - ``` +**IMPORTANT**: when adding a static library using this command (or CMake's +`add_library()`), the `PSN00BSDK_TARGET_TYPE` property **must** be set on it +afterwards in order to let CMake know whether the static library is going to be +linked to an executable or a DLL. See `PSN00BSDK_TARGET_TYPE` for more +information. - Any additional argument is passed through to the underlying call to - `add_custom_target()`, so most of the options supported by - `add_custom_target()` (including `DEPENDS`) are also supported here. +### `psn00bsdk_add_cd_image` -- `psn00bsdk_target_incbin( )` +```cmake +psn00bsdk_add_cd_image( + + + + [DEPENDS ] + [other options...] +) +``` - Embeds the contents of a binary file into an executable or a library. +Creates a new virtual target that will build a CD image using `mkpsxiso`. The +CD image will always be considered out-of-date and built, even if none of its +dependencies or any other files have been modified. + +The first argument is the name of the target to create; next up is the name of +the generated image file (`.bin` + `.cue`). The third +argument is the path to the XML file (relative to the source directory) passed +to `mkpsxiso`. + +The XML file is "configured" by CMake, i.e. any `${var}` or `@var@` expressions +are replaced with the values of the respective variables. In particular +`${CD_IMAGE_NAME}` is replaced with the second argument passed to +`psn00bsdk_add_cd_image()`; the file must properly set the output file names +like this: + +```xml + + + + +``` - A new symbol/object will be created with the given name, escaped by replacing - non-alphanumeric characters with underscores. The contents of the file will - be aligned to 4 bytes and placed in the `.data` section. An unsigned 32-bit - integer named `_size` will also be defined and set to the length - of the file in bytes (without taking alignment/padding into account). +Any additional argument is passed through to the underlying call to +`add_custom_target()`, so most of the options supported by +`add_custom_target()` (including `DEPENDS`) are also supported here. - Once added the file and its size can be accessed by C/C++ code by declaring - the respective symbols as an extern array and as an integer, like this: +### `psn00bsdk_target_incbin` - ```c - extern const uint8_t my_file[]; - extern const size_t my_file_size; - ``` +```cmake +psn00bsdk_target_incbin( + + + +) +``` - The fourth argument specifies the path to the binary file relative to the - source directory. This path can be prepended with `${PROJECT_BINARY_DIR}/` to - reference a file generated by the build script (such as an LZP archive): in - that case a file-level dependency will also be created, ensuring CMake does - not attempt to compile the executable or library before the file is built. +Embeds the contents of a binary file into an executable or a library. - **IMPORTANT**: in order for this command to work, assembly language support - must be enabled by specifying `LANGUAGES C ASM` (or `LANGUAGES C CXX ASM` if - C++ is also used) when invoking `project()`. +A new symbol/object will be created with the given name, escaped by replacing +non-alphanumeric characters with underscores. The contents of the file will be +aligned to 4 bytes and placed in the `.data` section. An unsigned 32-bit +integer named `_size` will also be defined and set to the length +of the file in bytes (without taking alignment/padding into account). -- `psn00bsdk_target_incbin_a( )` +Once added the file and its size can be accessed by C/C++ code by declaring the +respective symbols as an extern array and as an integer, like this: - Advanced variant of `psn00bsdk_target_incbin()` that allows specifying a - custom name for the size symbol and changing the default alignment setting. - Note that the size integer is always aligned to a multiple of 4 bytes as the - MIPS architecture doesn't support unaligned reads. +```c +extern const uint8_t my_file[]; +extern const size_t my_file_size; +``` -## Definitions +The fourth argument specifies the path to the binary file relative to the +source directory. This path can be prepended with `${PROJECT_BINARY_DIR}/` to +reference a file generated by the build script (such as an LZP archive): in +that case a file-level dependency will also be created, ensuring CMake does not +attempt to compile the executable or library before the file is built. + +**IMPORTANT**: in order for this command to work, assembly language support +must be enabled by specifying `LANGUAGES C ASM` (or `LANGUAGES C CXX ASM` to +enable C++ support as well) when invoking `project()`. + +### `psn00bsdk_target_incbin_a` + +```cmake +psn00bsdk_target_incbin_a( + + + + +
+ +) +``` -When compiling executables and libraries using the above commands the following -preprocessor macros are automatically `#define`'d: +Advanced variant of `psn00bsdk_target_incbin()` that allows specifying a custom +name for the size symbol and changing the default alignment setting. The value +of the size integer is always rounded up to a multiple of 4 bytes. -- `PLAYSTATION` +See `psn00bsdk_target_incbin()` above for more details. - Always set to 1. Can be used to implement different options or code paths for - libraries, so they can target both the host and PS1 (as it won't be defined - when compiling outside of the SDK). +## Target properties -- `DEBUG` +Each of the following properties can be set individually for each executable or +library using CMake's `set_property()` and `set_target_properties()` commands. - Defined and set to 1 in a debug configuration, i.e. when the - `CMAKE_BUILD_TYPE` variable is set to `Debug`. This value is used by the - PSn00bSDK libraries, and should be used in executables, to enable additional - debug logging. +### `PSN00BSDK_TARGET_TYPE` - Note that the default CMake configuration is usually debug, so it's - recommended to specify `-DCMAKE_BUILD_TYPE=Release` to get rid of the logging - overhead in release builds and reduce executable size. +Determines which SDK libraries are linked to and which compiler flags are added +to the target. Must be set to `EXECUTABLE_GPREL`, `EXECUTABLE_NOGPREL` or +`SHARED_LIBRARY`. -## Cached settings +This property is initialized automatically on executables and DLLs created via +`psn00bsdk_add_executable()` or `psn00bsdk_add_library()`, but *not* on static +libraries as CMake has no way to know about their intended usage (i.e. whether +they are going to be linked to an executable with or without $gp-relative +addressing, or to a DLL). Thus, `PSN00BSDK_TARGET_TYPE` must be set manually on +all static libraries and must match the value set on any executable or DLL the +static library is going to be linked to. + +There is no way to build a "hybrid" static library that can be linked to +multiple target types, short of building multiple copies of it. A workaround +(used internally by PSn00bSDK) is to create a virtual target and use CMake +generator expressions to link to one of the copies depending on the value of +`PSN00BSDK_TARGET_TYPE`. -These variables are stored in CMake's cache and can be edited by the project's -build script, from the CMake command line when configuring the project -(`-Dname=value`) or using an editor such as the CMake GUI. +## Preprocessor definitions -- `PSN00BSDK_TARGET` (`STRING`) +When compiling executables and libraries using the commands listed above the +following C/C++ preprocessor macros are automatically `#define`d: - The GCC toolchain's target triplet. PSn00bSDK assumes the toolchain targets - `mipsel-none-elf` by default, however this can be changed to e.g. use a MIPS - toolchain that was compiled for a slightly-different-but-equivalent target. +### `PSN00BSDK` - The following GCC target triplets have been confirmed to work with PSn00bSDK: +Always set to 1. Can be used to implement different options or code paths for +projects that target both PSn00bSDK and other platforms. - - `mipsel-none-elf` - - `mipsel-unknown-elf` - - ~~`mipsel-linux-gnu`~~ (has issues with linking) +### `NDEBUG` -- `PSN00BSDK_TC` (`PATH`) +Defined and set to 1 in a release configuration, i.e. when `CMAKE_BUILD_TYPE` +is set to `Release` or when a multi-configuration generator is building the +project in release mode; not defined if the project is being built in debug +mode. This value is used by the PSn00bSDK libraries, and should be used in +projects, to enable assertions and additional debug logging (the `assert()` +macro already resolves to a no-op in release mode). - Path to the GCC toolchain's installation prefix/directory. If not set, CMake - will attempt to find the toolchain in the `PATH` environment variable and - store its path in the project's variable cache (so the search does not have - to be repeated). It is recommended to add the toolchain's `bin` subfolder to - `PATH` rather than setting this variable. +Note that the default CMake configuration is usually debug. It is recommended +to build a project in release mode whenever appropriate (by specifying +`-DCMAKE_BUILD_TYPE=Release` or using the Ninja multi-configuration generator) +to get rid of logging overhead. - **IMPORTANT**: if the toolchain's target is not `mipsel-none-elf`, - `PSN00BSDK_TARGET` must be set regardless of whether or not `PSN00BSDK_TC` is - also set. +## Cached settings + +These variables are stored in CMake's cache and are meant to be set by the end +user when building the project (rather than by the project itself). They can be +modified by the build script after invoking `project()`, from the CMake command +line when configuring (`-Dname=value`) or using an IDE or other editor such as +the CMake GUI. + +### `PSN00BSDK_TARGET` (`STRING`) + +The GCC toolchain's target triplet. PSn00bSDK assumes the toolchain targets +`mipsel-none-elf` by default, however this can be changed to e.g. use a MIPS +toolchain that was compiled for `mipsel-unknown-elf` (as used by previous +versions of PSn00bSDK). + +Toolchains that target `mipsel-linux-gnu` are not supported by PSn00bSDK. + +### `PSN00BSDK_TC` (`PATH`) -- `PSN00BSDK_LIBGCC` (`FILEPATH`) +Path to the GCC toolchain's installation prefix/directory. If not set, CMake +will attempt to find the toolchain in the `PATH` environment variable and store +its path in the project's variable cache (so the search does not have to be +repeated). It is recommended to add the toolchain's `bin` subfolder to `PATH` +rather than setting this variable. - Path to the `libgcc.a` library bundled with the GCC toolchain. The contents - of this library are merged into `libc` when building the SDK, so this - variable is only actually needed when compiling `libpsn00b`. Setting this - variable manually usually isn't necessary as CMake will locate `libgcc.a` - automatically after finding the toolchain. +**IMPORTANT**: if the toolchain's target triplet is not `mipsel-none-elf`, +`PSN00BSDK_TARGET` must be set regardless of whether or not `PSN00BSDK_TC` is +also set. + +### `PSN00BSDK_LIBGCC` (`FILEPATH`) + +Path to the `libgcc` library bundled with the GCC toolchain. As required by GCC +this library is always linked to all targets, regardless of whether any SDK +libraries are linked or not. CMake will attempt to locate `libgcc` +automatically after finding the toolchain, so setting this variable manually is +not required in most cases. ## Internal settings These settings are not stored in CMake's cache and can only be set from within -the build script. +the build script after invoking `project()`. + +### `PSN00BSDK_EXECUTABLE_LINK_LIBRARIES`, `PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES` (list of `STRING`) -- `PSN00BSDK_LIBRARIES` +Lists of SDK libraries to be linked automatically to all new executables and +DLLs, respectively. By default `PSN00BSDK_EXECUTABLE_LINK_LIBRARIES` includes +all libraries that ship with PSn00bSDK while +`PSN00BSDK_SHARED_LIBRARY_LINK_LIBRARIES` is empty. - List of libraries to link all created targets against. By default this - includes all PSn00bSDK libraries. +These variables can be modified before invoking `psn00bsdk_add_executable()` or +`psn00bsdk_add_library()` to only link a subset of the SDK. Static libraries +are *not* automatically linked to any SDK libraries. -- `PSN00BSDK_EXECUTABLE_SUFFIX`, `PSN00BSDK_SHARED_LIBRARY_SUFFIX`, - `PSN00BSDK_SYMBOL_MAP_SUFFIX` +### `PSN00BSDK_EXECUTABLE_SUFFIX`, `PSN00BSDK_SHARED_LIBRARY_SUFFIX`, `PSN00BSDK_SYMBOL_MAP_SUFFIX` (`STRING`) - File extensions to use for generated PS1 files. The default values are - `.exe`, `.dll` and `.map` respectively. Note that file names and extensions - can be changed anyway when building a CD image. +File extensions to use for generated PS1 files. The default values are `.exe`, +`.dll` and `.map` respectively. These extensions do not have to match the ones +used in the CD image (if any). ## Read-only variables -- `PSN00BSDK_VERSION`, `PSN00BSDK_BUILD_DATE`, `PSN00BSDK_GIT_TAG`, - `PSN00BSDK_GIT_COMMIT` +### `PSN00BSDK_VERSION`, `PSN00BSDK_BUILD_DATE`, `PSN00BSDK_GIT_TAG`, `PSN00BSDK_GIT_COMMIT` (`STRING`) + +These variables are loaded from `lib/libpsn00b/build.json` and contain +information about the SDK's version. `PSN00BSDK_GIT_TAG` and +`PSN00BSDK_GIT_COMMIT` might be empty strings as they are only populated in CI +builds of PSn00bSDK. + +### `PSN00BSDK_LIBRARIES` (list of `STRING`) - These variables are loaded from `lib/libpsn00b/build.json` and contain - information about the SDK's version. Note that `PSN00BSDK_GIT_TAG` and - `PSN00BSDK_GIT_COMMIT` are not populated by default when building PSn00bSDK - manually from source, so they might be empty strings. +List of all libraries that ship with PSn00bSDK, excluding `libgcc`. Each +library in this list is also defined as a target. See the targets section for +more details. -- `PSN00BSDK_TOOLS`, `PSN00BSDK_INCLUDE`, `PSN00BSDK_LDSCRIPTS` +### `PSN00BSDK_TOOLS`, `PSN00BSDK_INCLUDE`, `PSN00BSDK_LDSCRIPTS` (list of `PATH`) - Lists of paths used internally. Should not be set, manipulated or overridden - by scripts. +Lists of paths used internally. Should not be set, manipulated or overridden by +scripts. -- `TOOLCHAIN_NM` +### `TOOLCHAIN_NM` (`FILEPATH`) - Path to the `nm` executable used to generate symbol maps. Although not used - internally by CMake, this program is part of the GCC toolchain. +Path to the `nm` executable used to generate symbol maps. Although not used +internally by CMake, this program is part of the GCC toolchain. -- `ELF2X`, `ELF2CPE`, `MKPSXISO`, `LZPACK`, `SMXLINK` +### `ELF2X`, `ELF2CPE`, `MKPSXISO`, `LZPACK`, `SMXLINK` (`FILEPATH`) - Paths to the PSn00bSDK tools' executables. As no functions are currently - provided for building assets, `LZPACK` and `SMXLINK` can be used with - `add_custom_command()`/`add_custom_target()` to convert models and generate - LZP archives as part of the build pipeline. +Paths to the PSn00bSDK tools' executables. As no functions are currently +provided for building assets, `LZPACK` and `SMXLINK` can be used manually with +CMake's `add_custom_command()` and `add_custom_target()` to convert models and +generate LZP archives as part of the build pipeline. ----------------------------------------- -_Last updated on 2022-02-26 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/doc/installation.md b/doc/installation.md index 382c721..70b7f3e 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -5,7 +5,7 @@ 1. Install prerequisites. Currently CMake is the only external dependency; you can install it from [here](https://cmake.org/download) or using MSys2 or - your distro's package manager. Make sure you have at least CMake 3.20. + your distro's package manager. Make sure you have at least CMake 3.21. 2. Head over to the releases page, download the latest release's ZIP for your operating system and extract its contents to a directory of your choice, @@ -44,7 +44,7 @@ being built without support for ripping CD audio tracks to FLAC, however the - `git` - `build-essential`, `base-devel` or similar - `make` or `ninja-build` - - `cmake` (3.20+ is required, download it from + - `cmake` (3.21 or later is required, download it from [here](https://cmake.org/download) if your package manager only provides older versions) @@ -185,4 +185,4 @@ The toolchain script defines a few CMake macros to create PS1 executables, DLLs and CD images. See the [reference](cmake_reference.md) for details. ----------------------------------------- -_Last updated on 2022-09-21 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/doc/known_bugs.md b/doc/known_bugs.md index 3fbfdc2..9e4785c 100644 --- a/doc/known_bugs.md +++ b/doc/known_bugs.md @@ -7,14 +7,15 @@ fixed. ## Toolchain -- It is currently not possible to link static libraries (including the SDK - libraries themselves) with DLLs, since the build scripts currently assume that - static library object files are always going to be linked into executables. - This can be worked around by linking all static libraries as part of the main - executable rather than the DLLs: the dynamic linker will automatically search - the executable for undefined symbols used by a DLL and patch the code to use - them. It might be necessary to list such symbols in a dummy array to prevent - the compiler from stripping them away from the executable. +- ~~It is currently not possible to link static libraries (including the SDK~~ + ~~libraries themselves) with DLLs, since the build scripts currently assume~~ + ~~that static library object files are always going to be linked into~~ + ~~executables. This can be worked around by linking all static libraries as~~ + ~~part of the main executable rather than the DLLs: the dynamic linker will~~ + ~~automatically search the executable for undefined symbols used by a DLL~~ + ~~and patch the code to use them.~~ Static libraries are now fully supported, + and SDK libraries can be linked to both executables and DLLs. See the CMake + reference for more details. - Link-time optimization is broken due to GCC not supporting it when linking weak functions written in assembly. @@ -28,7 +29,7 @@ fixed. the length of the data *must* be a multiple of 32 bytes. Attempting to transfer any data whose length isn't a multiple of 32 bytes will result in `DrawSync()` hanging and never returning, however a warning will be printed - on the debug console. + on the debug console if the executable is built in debug mode. `psxspu`: @@ -36,6 +37,11 @@ fixed. due to the SPU status register being emulated incorrectly. They work as expected on other emulators as well as on real hardware. +`psxcd`: + +- Custom callbacks registered using `CdReadyCallback()` seem to be unstable on + DuckStation (and possibly on real hardware), occasionally dropping sectors. + `psxetc`: - `DL_LoadSymbolMapFromFile()`, `DL_LoadDLLFromFile()` and `dlopen()` have been @@ -48,4 +54,4 @@ fixed. See [README.md in the examples directory](../examples/README.md#examples-summary). ----------------------------------------- -_Last updated on 2022-08-21 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/examples/README.md b/examples/README.md index 82d7698..b63b2a9 100644 --- a/examples/README.md +++ b/examples/README.md @@ -48,7 +48,7 @@ Notes: ## Building the examples -The instructions below assume that PSn00bSDK, CMake 3.20+ and a GCC toolchain +The instructions below assume that PSn00bSDK, CMake 3.21+ and a GCC toolchain are already installed. Refer to the [installation guide](../doc/installation.md) for details. @@ -84,4 +84,4 @@ are for rebuilding the examples *after* the SDK has been installed. CD images for each example. ----------------------------------------- -_Last updated on 2022-08-11 by spicyjpeg_ +_Last updated on 2022-10-11 by spicyjpeg_ diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index 6fecb9f..e78355f 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -173,7 +173,6 @@ function(psn00bsdk_add_executable name type) #$<${_repl},${PSN00BSDK_SYMBOL_MAP_SUFFIX}> ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_EXECUTABLE_SUFFIX} ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX} - VERBATIM ) endfunction() @@ -201,7 +200,6 @@ function(psn00bsdk_add_library name type) $ #BYPRODUCTS $<${_repl},${PSN00BSDK_SHARED_LIBRARY_SUFFIX}> BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/${name}${PSN00BSDK_SHARED_LIBRARY_SUFFIX} - VERBATIM ) else() message(FATAL_ERROR "Invalid library type: ${type} (must be STATIC, OBJECT, SHARED or MODULE)") diff --git a/template/CMakePresets.json b/template/CMakePresets.json index d08b334..97d8428 100644 --- a/template/CMakePresets.json +++ b/template/CMakePresets.json @@ -1,22 +1,25 @@ { - "version": 2, + "version": 3, "cmakeMinimumRequired": { "major": 3, - "minor": 20, + "minor": 21, "patch": 0 }, "configurePresets": [ { - "name": "default", - "displayName": "Default configuration", - "description": "Use this preset to build the project using PSn00bSDK.", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build", + "name": "default", + "displayName": "Default configuration", + "description": "Use this preset to build the project using PSn00bSDK.", + "generator": "Ninja", + "toolchainFile": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", + "binaryDir": "${sourceDir}/build", "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_TOOLCHAIN_FILE": "$env{PSN00BSDK_LIBS}/cmake/sdk.cmake", - "PSN00BSDK_TC": "", - "PSN00BSDK_TARGET": "mipsel-none-elf" + "CMAKE_BUILD_TYPE": "Debug", + "PSN00BSDK_TC": "", + "PSN00BSDK_TARGET": "mipsel-none-elf" + }, + "warnings": { + "dev": false } } ] -- cgit v1.2.3 From 6eabb5aa549254c2272cedee26d4245f31f2dc7a Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sat, 15 Oct 2022 10:02:35 +0200 Subject: Update sound/spustream, clean up other examples --- examples/cdrom/cdbrowse/iso.xml | 1 - examples/cdrom/cdxa/iso.xml | 1 - examples/graphics/tilesasm/iso.xml | 34 ----------- examples/graphics/tilesasm/system.cnf | 4 -- examples/io/pads/main.c | 22 +++---- examples/io/system573/iso.xml | 2 - examples/io/system573/main.c | 22 +++---- examples/sound/spustream/iso.xml | 1 - examples/sound/spustream/main.c | 91 +++++++++++++++++----------- examples/system/dynlink/library/balls.c | 27 +++++---- examples/system/dynlink/library/cube.c | 14 +++-- examples/system/dynlink/library/dll_common.h | 11 ++-- examples/system/dynlink/main.c | 17 +++--- template/iso.xml | 2 +- 14 files changed, 114 insertions(+), 135 deletions(-) delete mode 100644 examples/graphics/tilesasm/iso.xml delete mode 100644 examples/graphics/tilesasm/system.cnf (limited to 'template') diff --git a/examples/cdrom/cdbrowse/iso.xml b/examples/cdrom/cdbrowse/iso.xml index 5ffca18..771b0e9 100644 --- a/examples/cdrom/cdbrowse/iso.xml +++ b/examples/cdrom/cdbrowse/iso.xml @@ -17,7 +17,6 @@ - diff --git a/examples/cdrom/cdxa/iso.xml b/examples/cdrom/cdxa/iso.xml index b98a16f..6715f94 100644 --- a/examples/cdrom/cdxa/iso.xml +++ b/examples/cdrom/cdxa/iso.xml @@ -17,7 +17,6 @@ - diff --git a/examples/graphics/tilesasm/iso.xml b/examples/graphics/tilesasm/iso.xml deleted file mode 100644 index 477c636..0000000 --- a/examples/graphics/tilesasm/iso.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/examples/graphics/tilesasm/system.cnf b/examples/graphics/tilesasm/system.cnf deleted file mode 100644 index e221726..0000000 --- a/examples/graphics/tilesasm/system.cnf +++ /dev/null @@ -1,4 +0,0 @@ -BOOT=cdrom:\template.exe;1 -TCB=4 -EVENT=10 -STACK=801FFFF0 diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index 17bf331..29bb527 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -62,17 +62,17 @@ static const char *const PAD_TYPEIDS[] = { #define BGCOLOR_B 0 typedef struct { - DISPENV disp; - DRAWENV draw; -} DB; + DISPENV disp; + DRAWENV draw; +} Framebuffer; typedef struct { - DB db[2]; - uint32_t db_active; -} CONTEXT; + Framebuffer db[2]; + int db_active; +} RenderContext; -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); ctx->db_active = 0; @@ -99,8 +99,8 @@ void init_context(CONTEXT *ctx) { FntOpen(8, 16, 304, 208, 2, 512); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -227,7 +227,7 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { /* Main */ -static CONTEXT ctx; +static RenderContext ctx; int main(int argc, const char* argv[]) { init_context(&ctx); diff --git a/examples/io/system573/iso.xml b/examples/io/system573/iso.xml index 0bb84d5..2226089 100644 --- a/examples/io/system573/iso.xml +++ b/examples/io/system573/iso.xml @@ -30,8 +30,6 @@ --> - - diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c index 3404ee4..39ddb64 100644 --- a/examples/io/system573/main.c +++ b/examples/io/system573/main.c @@ -83,17 +83,17 @@ const char *const IO_BOARD_TYPES[] = { #define BGCOLOR_B 0 typedef struct { - DISPENV disp; - DRAWENV draw; -} DB; + DISPENV disp; + DRAWENV draw; +} Framebuffer; typedef struct { - DB db[2]; - uint32_t db_active; -} CONTEXT; + Framebuffer db[2]; + int db_active; +} RenderContext; -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); ctx->db_active = 0; @@ -120,8 +120,8 @@ void init_context(CONTEXT *ctx) { FntOpen(8, 16, 304, 208, 2, 512); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -135,7 +135,7 @@ void display(CONTEXT *ctx) { /* Main */ -static CONTEXT ctx; +static RenderContext ctx; #define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); } #define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); } diff --git a/examples/sound/spustream/iso.xml b/examples/sound/spustream/iso.xml index 3807046..050d673 100644 --- a/examples/sound/spustream/iso.xml +++ b/examples/sound/spustream/iso.xml @@ -17,7 +17,6 @@ - diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index 6179179..acd4f60 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -117,17 +117,17 @@ #define BGCOLOR_B 0 typedef struct { - DISPENV disp; - DRAWENV draw; -} DB; + DISPENV disp; + DRAWENV draw; +} Framebuffer; typedef struct { - DB db[2]; - int db_active; -} CONTEXT; + Framebuffer db[2]; + int db_active; +} RenderContext; -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); ctx->db_active = 0; @@ -154,8 +154,8 @@ void init_context(CONTEXT *ctx) { FntOpen(8, 16, 304, 208, 2, 512); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -181,13 +181,9 @@ void display(CONTEXT *ctx) { #define CHUNK_SIZE (BUFFER_SIZE * NUM_CHANNELS) typedef struct { - uint32_t lba; - uint32_t length; - uint32_t pos; - - uint32_t spu_addr; - uint32_t spu_pos; - uint32_t db_active; + int lba, length, pos; + int spu_addr, spu_pos; + int db_active; } StreamContext; static volatile StreamContext str_ctx; @@ -316,10 +312,10 @@ void init_stream(CdlFILE *file) { } void start_stream(void) { - SPU_KEY_OFF = CHANNEL_MASK; + uint32_t addr = BUFFER_START_ADDR + CHUNK_SIZE * str_ctx.db_active; for (int i = 0; i < NUM_CHANNELS; i++) { - SPU_CH_ADDR(i) = SPU_RAM_ADDR(BUFFER_START_ADDR + BUFFER_SIZE * i); + SPU_CH_ADDR(i) = SPU_RAM_ADDR(addr + BUFFER_SIZE * i); SPU_CH_FREQ(i) = SAMPLE_RATE; SPU_CH_ADSR(i) = 0x1fee80ff; } @@ -332,13 +328,25 @@ void start_stream(void) { SPU_CH_VOL_L(1) = 0x0000; SPU_CH_VOL_R(1) = 0x3fff; - SPU_KEY_ON = CHANNEL_MASK; spu_irq_handler(); + SPU_KEY_ON = CHANNEL_MASK; +} + +// This is basically a variant of reset_spu_channels() that only resets the +// channels used to play the stream, to (again) prevent them from triggering +// the SPU IRQ while the stream is paused. +void stop_stream(void) { + SPU_KEY_OFF = CHANNEL_MASK; + + for (int i = 0; i < NUM_CHANNELS; i++) + SPU_CH_ADDR(i) = SPU_RAM_ADDR(DUMMY_BLOCK_ADDR); + + SPU_KEY_ON = CHANNEL_MASK; } /* Main */ -static CONTEXT ctx; +static RenderContext ctx; #define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); } #define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); } @@ -351,7 +359,13 @@ int main(int argc, const char* argv[]) { CdInit(); reset_spu_channels(); - SHOW_STATUS("LOCATING STREAM FILE\n"); + // Set up controller polling. + uint8_t pad_buff[2][34]; + InitPAD(pad_buff[0], 34, pad_buff[1], 34); + StartPAD(); + ChangeClearPAD(0); + + SHOW_STATUS("OPENING STREAM FILE\n"); CdlFILE file; if (!CdSearchFile(&file, "\\STREAM.BIN")) @@ -361,28 +375,27 @@ int main(int argc, const char* argv[]) { init_stream(&file); start_stream(); - // Set up controller polling. - uint8_t pad_buff[2][34]; - InitPAD(pad_buff[0], 34, pad_buff[1], 34); - StartPAD(); - ChangeClearPAD(0); + int paused = 0; uint16_t sample_rate = SAMPLE_RATE; uint16_t last_buttons = 0xffff; while (1) { - FntPrint(-1, "PLAYING SPU STREAM\n"); + FntPrint(-1, "PLAYING SPU STREAM\n\n"); + + FntPrint(-1, "BUFFER: %d\nSTATUS: ", str_ctx.db_active); if (str_ctx.spu_pos >= CHUNK_SIZE) - FntPrint(-1, "STATUS: IDLE\n\n"); - else if (!str_ctx.spu_pos) - FntPrint(-1, "STATUS: SEEKING\n\n"); + FntPrint(-1, "IDLE\n\n"); + else if (str_ctx.spu_pos) + FntPrint(-1, "BUFFERING\n\n"); else - FntPrint(-1, "STATUS: BUFFERING\n\n"); + FntPrint(-1, "SEEKING\n\n"); - FntPrint(-1, "POSITION=%5d/%5d\n", str_ctx.pos, str_ctx.length); - FntPrint(-1, "BUFFERED=%5d/%5d\n", str_ctx.spu_pos, CHUNK_SIZE); - FntPrint(-1, "SMP RATE=%5d HZ\n\n", (sample_rate * 44100) >> 12); + FntPrint(-1, "POSITION: %5d/%5d\n", str_ctx.pos, str_ctx.length); + FntPrint(-1, "BUFFERED: %5d/%5d\n", str_ctx.spu_pos, CHUNK_SIZE); + FntPrint(-1, "SMP RATE: %5d HZ\n\n", (sample_rate * 44100) >> 12); + FntPrint(-1, "[START] %s\n", paused ? "RESUME" : "PAUSE"); FntPrint(-1, "[LEFT/RIGHT] SEEK\n"); FntPrint(-1, "[O] RESET POSITION\n"); FntPrint(-1, "[UP/DOWN] CHANGE SAMPLE RATE\n"); @@ -399,6 +412,14 @@ int main(int argc, const char* argv[]) { if ((pad->type != 4) && (pad->type != 5) && (pad->type != 7)) continue; + if ((last_buttons & PAD_START) && !(pad->btn & PAD_START)) { + paused ^= 1; + if (paused) + stop_stream(); + else + start_stream(); + } + // Seeking by an arbitrary number of sectors isn't a problem as // spu_irq_handler() always realigns the counter. if (!(pad->btn & PAD_LEFT)) diff --git a/examples/system/dynlink/library/balls.c b/examples/system/dynlink/library/balls.c index c537167..457ec4e 100644 --- a/examples/system/dynlink/library/balls.c +++ b/examples/system/dynlink/library/balls.c @@ -21,7 +21,7 @@ typedef struct { int16_t x, y; int16_t xdir, ydir; uint8_t r, g, b, p; -} BALL_TYPE; +} Ball; #define MAX_BALLS 512 @@ -35,12 +35,13 @@ typedef struct { // initialize variables or hardware. static uint32_t frame = 0; -static BALL_TYPE balls[MAX_BALLS]; +static Ball balls[MAX_BALLS]; static TIM_IMAGE ball_tim; -void init(CONTEXT *ctx) { - GetTimInfo(ball16c, &ball_tim); +void init(RenderContext *ctx) { + Framebuffer *db = &(ctx->db[ctx->db_active]); + GetTimInfo(ball16c, &ball_tim); LoadImage(ball_tim.prect, ball_tim.paddr); if (ball_tim.mode & 8) LoadImage(ball_tim.crect, ball_tim.caddr); @@ -48,10 +49,10 @@ void init(CONTEXT *ctx) { // Initialize the balls by giving them a random initial position, velocity // and color. for (uint32_t i = 0; i < MAX_BALLS; i++) { - BALL_TYPE *b = &(balls[i]); + Ball *b = &(balls[i]); - b->x = rand() % (ctx->xres - 16); - b->y = rand() % (ctx->yres - 16); + b->x = rand() % (db->draw.clip.w - 16); + b->y = rand() % (db->draw.clip.h - 16); b->xdir = ((rand() & 1) ? 1 : -1) * ((rand() % 3) + 1); b->ydir = ((rand() & 1) ? 1 : -1) * ((rand() % 3) + 1); b->r = rand() & 0xff; @@ -60,12 +61,12 @@ void init(CONTEXT *ctx) { } } -void render(CONTEXT *ctx, uint16_t buttons) { - DB *db = &(ctx->db[ctx->db_active]); - SPRT_16 *sprt = (SPRT_16 *) ctx->db_nextpri; +void render(RenderContext *ctx, uint16_t buttons) { + Framebuffer *db = &(ctx->db[ctx->db_active]); + SPRT_16 *sprt = (SPRT_16 *) ctx->db_nextpri; for (uint32_t i = 0; i < MAX_BALLS; i++) { - BALL_TYPE *b = &(balls[i]); + Ball *b = &(balls[i]); setSprt16(sprt); @@ -85,12 +86,12 @@ void render(CONTEXT *ctx, uint16_t buttons) { if ( (b->x < 0) || - ((b->x + 16) > ctx->xres) + ((b->x + 16) > db->draw.clip.w) ) b->xdir *= -1; if ( (b->y < 0) || - ((b->y + 16) > ctx->yres) + ((b->y + 16) > db->draw.clip.h) ) b->ydir *= -1; } diff --git a/examples/system/dynlink/library/cube.c b/examples/system/dynlink/library/cube.c index 84fe552..22a805f 100644 --- a/examples/system/dynlink/library/cube.c +++ b/examples/system/dynlink/library/cube.c @@ -81,16 +81,18 @@ static SVECTOR rot = { 0 }; static VECTOR pos = { 0, 0, 400 }; static MATRIX mtx, lmtx; -void init(CONTEXT *ctx) { +void init(RenderContext *ctx) { + Framebuffer *db = &(ctx->db[ctx->db_active]); + InitGeom(); - gte_SetGeomOffset(ctx->xres / 2, ctx->yres / 2); - gte_SetGeomScreen(ctx->xres / 2); + gte_SetGeomOffset(db->draw.clip.w / 2, db->draw.clip.h / 2); + gte_SetGeomScreen(db->draw.clip.w / 2); gte_SetBackColor(63, 63, 63); gte_SetColorMatrix(&color_mtx); } -void render(CONTEXT *ctx, uint16_t buttons) { +void render(RenderContext *ctx, uint16_t buttons) { RotMatrix(&rot, &mtx); TransMatrix(&mtx, &pos); MulMatrix0(&light_mtx, &mtx, &lmtx); @@ -104,8 +106,8 @@ void render(CONTEXT *ctx, uint16_t buttons) { rot.vx += step; rot.vz += step; - DB *db = &(ctx->db[ctx->db_active]); - POLY_F4 *pol4 = (POLY_F4 *) ctx->db_nextpri; + Framebuffer *db = &(ctx->db[ctx->db_active]); + POLY_F4 *pol4 = (POLY_F4 *) ctx->db_nextpri; for (uint32_t i = 0; i < CUBE_FACES; i++) { int32_t p; diff --git a/examples/system/dynlink/library/dll_common.h b/examples/system/dynlink/library/dll_common.h index 315a993..6606bda 100644 --- a/examples/system/dynlink/library/dll_common.h +++ b/examples/system/dynlink/library/dll_common.h @@ -19,13 +19,12 @@ typedef struct { DRAWENV draw; uint32_t ot[OT_LEN]; uint8_t p[PACKET_LEN]; -} DB; +} Framebuffer; typedef struct { - uint16_t xres, yres; - DB db[2]; - uint32_t db_active; - uint8_t *db_nextpri; -} CONTEXT; + Framebuffer db[2]; + int db_active; + uint8_t *db_nextpri; +} RenderContext; #endif diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c index fff7aa5..fcce5b1 100644 --- a/examples/system/dynlink/main.c +++ b/examples/system/dynlink/main.c @@ -83,12 +83,10 @@ static const char *const DLL_FILENAMES[] = { #define BGCOLOR_G 24 #define BGCOLOR_B 0 -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); - ctx->xres = SCREEN_XRES; - ctx->yres = SCREEN_YRES; ctx->db_active = 0; db = &(ctx->db[0]); @@ -121,8 +119,8 @@ void init_context(CONTEXT *ctx) { FntOpen(4, 12, 312, 32, 2, 256); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -185,13 +183,14 @@ void *custom_resolver(DLL *dll, const char *name) { // and the pointers returned by DL_GetDLLSymbol() should be saved and reused as // much as possible. typedef struct { - void (*init)(CONTEXT *); - void (*render)(CONTEXT *, uint16_t buttons); + void (*init)(RenderContext *); + void (*render)(RenderContext *, uint16_t buttons); } DLL_API; static DLL *dll = 0; static DLL_API dll_api; -static CONTEXT ctx; + +static RenderContext ctx; /* Main */ diff --git a/template/iso.xml b/template/iso.xml index 477c636..87162b2 100644 --- a/template/iso.xml +++ b/template/iso.xml @@ -24,7 +24,7 @@ - + -- cgit v1.2.3 From 8770122c970eeedb145ee903e2243b7d4a18605b Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sun, 16 Oct 2022 23:58:05 +0200 Subject: Fix sound/spustream, update README and changelog --- CHANGELOG.md | 23 +++++++++++++++++- examples/README.md | 11 +++++---- examples/io/pads/spi.c | 6 ++--- examples/sound/spustream/main.c | 12 +++++---- template/iso.xml | 54 ++++++++++++++++++++++++++++++++++++++++- 5 files changed, 91 insertions(+), 15 deletions(-) (limited to 'template') diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f04108..461d2b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,28 @@ to ensure the changelog can be parsed correctly. ------------------------------------------------------------------------------- -## 2022-10-11: 0.21 +## 2022-10-16: 0.21 + +spicyjpeg: + +- psxetc: Fixed (another) critical bug in the IRQ callback dispatcher. This + also fixed some examples that were broken ever since the library was + rewritten in C. Made the dynamic linker less verbose, improving DLL loading + speed in debug mode. + +- psxcd: Added `CdDataSync()`. Renamed `CdlModeSize0` and `CdlModeSize1` to + `CdlModeIgnore` and `CdlModeSize` respectively. + +- psxpress: Fixed a bug in the Huffman decompression API that would make it + crash if the bitstream header didn't contain a valid decompressed length, + even if the bitstream was properly encoded. This fix makes the API fully + usable for video playback (as demonstrated by the new example). + +- examples: Added `mdec/strvideo` FMV playback example. Fixed + `system/childexec` not properly uninstalling BIOS callbacks before launching + the child executable. Added pause/resume code to `sound/spustream`. + +## 2022-10-11 spicyjpeg: diff --git a/examples/README.md b/examples/README.md index b63b2a9..ade94b0 100644 --- a/examples/README.md +++ b/examples/README.md @@ -24,7 +24,8 @@ Additional information may be found in the source code of each example. | [`io/pads`](./io/pads) | Demonstrates reading controllers via low-level access | EXE | 3 | | [`io/system573`](./io/system573) | Konami System 573 (PS1-based arcade board) example | CD | | | [`lowlevel/cartrom`](./lowlevel/cartrom) | ROM firmware for cheat devices written using GNU GAS | ROM | 4 | -| [`mdec/mdecimage`](./mdec/mdecimage) | Displays a (raw) MDEC format image using libpsxpress | EXE | | +| [`mdec/mdecimage`](./mdec/mdecimage) | Displays a (raw) MDEC format image | EXE | | +| [`mdec/strvideo`](./mdec/strvideo) | Plays a .STR video file using the MDEC | CD | 1 | | [`sound/spustream`](./sound/spustream) | Custom (non XA) CD-ROM audio streaming using the SPU | CD | | | [`sound/vagsample`](./sound/vagsample) | Demonstrates playing VAG sound files using the SPU | EXE | | | [`system/childexec`](./system/childexec) | Loading a child program and returning to parent | EXE | | @@ -35,9 +36,9 @@ Additional information may be found in the source code of each example. Notes: -1. `cdrom/cdxa` does not come with an example XA audio file. In order to run - this example you'll have to provide your own file and build the CD image - manually. +1. `cdrom/cdxa` and `mdec/strvideo` do not come with example files. In order + to run these examples you'll have to provide your own files and build the CD + image manually. 2. `demos/n00bdemo` suffers from flickering on real hardware, especially when masking/stencil buffering is used. 3. `io/pads` seems to work on real hardware, but fails to automatically enable @@ -84,4 +85,4 @@ are for rebuilding the examples *after* the SDK has been installed. CD images for each example. ----------------------------------------- -_Last updated on 2022-10-11 by spicyjpeg_ +_Last updated on 2022-10-16 by spicyjpeg_ diff --git a/examples/io/pads/spi.c b/examples/io/pads/spi.c index 133782c..292e682 100644 --- a/examples/io/pads/spi.c +++ b/examples/io/pads/spi.c @@ -46,9 +46,9 @@ typedef struct _SPI_Context { SPI_Callback callback; } SPI_Context; -static volatile SPI_Context _context; -static volatile SPI_Request volatile *_current_req; -static volatile SPI_Callback _default_cb; +static volatile SPI_Context _context; +static volatile SPI_Request *_current_req; +static volatile SPI_Callback _default_cb; /* Request queue management */ diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index acd4f60..1fee883 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -181,12 +181,14 @@ void display(RenderContext *ctx) { #define CHUNK_SIZE (BUFFER_SIZE * NUM_CHANNELS) typedef struct { - int lba, length, pos; - int spu_addr, spu_pos; - int db_active; + int lba, length; + + volatile int pos; + volatile int spu_addr, spu_pos; + volatile int db_active; } StreamContext; -static volatile StreamContext str_ctx; +static StreamContext str_ctx; // This buffer is used by cd_event_handler() as a temporary area for sectors // read from the CD and uploaded to SPU RAM. Due to DMA limitations it can't be @@ -328,8 +330,8 @@ void start_stream(void) { SPU_CH_VOL_L(1) = 0x0000; SPU_CH_VOL_R(1) = 0x3fff; - spu_irq_handler(); SPU_KEY_ON = CHANNEL_MASK; + spu_irq_handler(); } // This is basically a variant of reset_spu_channels() that only resets the diff --git a/template/iso.xml b/template/iso.xml index 87162b2..29fbd2d 100644 --- a/template/iso.xml +++ b/template/iso.xml @@ -11,6 +11,21 @@ cue_sheet="${CD_IMAGE_NAME}.cue" > + + + + + + - + + -- cgit v1.2.3