From 7186b911cc461dbdad9307afd8901be118e20893 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Sun, 28 Nov 2021 18:46:06 +0100 Subject: CMake fixes, psxcd and printf/scanf improvements --- libpsn00b/psxcd/isofs.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'libpsn00b/psxcd') diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 40a40af..29bbb76 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -10,6 +10,9 @@ // Uncommend to enable debug output //#define DEBUG +#define DEFAULT_PATH_SEP '\\' +#define IS_PATH_SEP(ch) (((ch) == '/') || ((ch) == '\\')) + typedef struct _CdlDIR_INT { u_long _pos; @@ -374,7 +377,7 @@ static char* resolve_pathtable_path(int entry, char *rbuff) rbuff -= tbl_entry.nameLength; memcpy(rbuff, namebuff, tbl_entry.nameLength); rbuff--; - *rbuff = '\\'; + *rbuff = DEFAULT_PATH_SEP; // Parse to the parent entry = tbl_entry.dirLevel; @@ -431,12 +434,15 @@ static int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent) static char* get_pathname(char *path, const char *filename) { - char *c; - c = strrchr(filename, '\\'); + char *c = 0; + for (char *i = filename; *i; i++) { + if (IS_PATH_SEP(*i)) + c = i; + } if(( c == filename ) || ( !c )) { - path[0] = '\\'; + path[0] = DEFAULT_PATH_SEP; path[1] = 0; return NULL; } @@ -447,11 +453,17 @@ static char* get_pathname(char *path, const char *filename) static char* get_filename(char *name, const char *filename) { - char *c; - c = strrchr(filename, '\\'); + char *c = 0; + for (char *i = filename; *i; i++) { + if (IS_PATH_SEP(*i)) + c = i; + } - if(( c == filename ) || ( !c )) - { + if (!c) { + strcpy(name, filename); + return name; + } + if (c == filename) { strcpy(name, filename+1); return name; } -- cgit v1.2.3 From 2e6625481cd006d0a9d68285ce557f195030718e Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 23 Dec 2021 22:09:06 +0100 Subject: Fix CdGetSector size inconsistency, update changelog --- .github/scripts/generate_release_notes.py | 46 ++++++++++--------------------- CHANGELOG.md | 29 +++++++++++++------ examples/cdrom/cdxa/main.c | 2 +- examples/io/system573/main.c | 2 +- libpsn00b/psxcd/cdgetsector.s | 3 +- libpsn00b/psxcd/isofs.c | 2 +- libpsn00b/psxcd/psxcd.c | 8 +++--- 7 files changed, 44 insertions(+), 48 deletions(-) (limited to 'libpsn00b/psxcd') diff --git a/.github/scripts/generate_release_notes.py b/.github/scripts/generate_release_notes.py index f3e4870..e3fbc7f 100644 --- a/.github/scripts/generate_release_notes.py +++ b/.github/scripts/generate_release_notes.py @@ -3,7 +3,7 @@ # (C) 2021 spicyjpeg - MPL licensed import sys, re -from time import gmtime, strptime +from time import gmtime, strptime, struct_time from argparse import ArgumentParser, FileType ## Helpers @@ -11,14 +11,13 @@ from argparse import ArgumentParser, FileType VERSION_REGEX = re.compile(r"^(?:refs\/tags\/)?(?:v|ver|version|release)? *(.*)") def parse_date(date): + if isinstance(date, struct_time): + return date + return strptime(date.strip(), "%Y-%m-%d") def normalize_version(version): - match = VERSION_REGEX.match(version.lower()) - if not match: - raise ValueError(f"invalid version string: {version}") - - return match.group(1) + return VERSION_REGEX.match(version.lower()).group(1) ## Changelog parser @@ -50,9 +49,6 @@ def parse_blocks(changelog): # [ _crap, date, version, body, date, version, body, ... ] items = BLOCK_REGEX.split(changelog.strip()) - #if items[0].strip(): - #raise RuntimeError("the changelog doesn't start with a valid block") - # Iterate over all blocks from bottom to top (i.e. oldest first). last_version = FIRST_VERSION @@ -110,51 +106,39 @@ def generate_notes(versions): def get_args(): parser = ArgumentParser( - description = "Generates and outputs release notes from a Markdown changelog file.", - add_help = False + description = "Generates and outputs release notes from a Markdown changelog file." ) - - tools_group = parser.add_argument_group("Tools") - tools_group.add_argument( - "-h", "--help", - action = "help", - help = "Show this help message and exits" - ) - - files_group = parser.add_argument_group("Files") - files_group.add_argument( + parser.add_argument( "changelog", type = FileType("rt"), help = "Markdown changelog file to parse" ) - files_group.add_argument( + parser.add_argument( "-o", "--output", type = FileType("wt"), default = sys.stdout, - help = "Where to output release notes (stdout by default)", + help = "where to output release notes (stdout by default)", metavar = "file" ) - - filter_group = parser.add_argument_group("Filters") - filter_group.add_argument( + parser.add_argument( "-v", "--version", action = "append", type = str, - help = "Ignore all changes not belonging to a version (can be specified multiple times)", + help = "ignore all changes not belonging to a version (can be specified multiple times)", metavar = "name" ) - filter_group.add_argument( + parser.add_argument( "-f", "--from-date", type = parse_date, default = parse_date("2000-01-01"), - help = "Ignore all changes before date", + help = "ignore all changes before date", metavar = "yyyy-mm-dd" ) - filter_group.add_argument( + parser.add_argument( "-t", "--to-date", type = parse_date, default = gmtime(), - help = "Ignore all changes after date", + help = "ignore all changes after date", metavar = "yyyy-mm-dd" ) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9463b83..ea4f4d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ contributing to PSn00bSDK, add a new block at the top following this template: ``` -## --: +## --: [optional new version] : @@ -19,6 +19,17 @@ to ensure the changelog can be parsed correctly. ------------------------------------------------------------------------------- +## 2021-12-23 + +spicyjpeg: + +- psxcd: `CdGetSector()` now expects the sector size to be in 32-bit word units + (rather than bytes) for consistency with the official CD-ROM library. The + library's ISO9660 parser and helper functions have been updated accordingly. + **This is a breaking change**. + +- examples: Added `spustream` audio streaming example. + ## 2021-11-28: 0.18 spicyjpeg: @@ -453,7 +464,7 @@ Lameguy64: - psxgpu: Fixed typos in `setUVWH()` macro. -- Added `_boot()` BIOS function (A(A0h) aka Warmboot, useful for CD based +- Added `_boot()` BIOS function (`A(A0h)` aka Warmboot, useful for CD based serial loaders). ## 2019-08-17: 0.13b @@ -505,9 +516,9 @@ Lameguy64: executable to return to a parent executable, return logic automatically calls `EnterCriticalSection()`. -- libc: Updated build method which takes libgcc from the compiler and adds +- libc: Updated build method which takes `libgcc` from the compiler and adds its own object files into it, eliminating linker problems caused by having - to order libc and libgcc libraries in a specific manner. + to order `libc` and `libgcc` libraries in a specific manner. - psxgpu: Added `RestartCallback()`. @@ -526,7 +537,7 @@ Lameguy64: performance, as the R3000 does not support 64-bit arithmetic natively so its emulated like floats. `int64` still used for processing floats and doubles and old `vsprintf.c` file is still included for those who really - want int64 support for whatever reason. + want `int64` support for whatever reason. - libc: Removed `stdarg.h` which is part of GCC and not license compatible with MPL. The toolchain compiled with libgcc provides `stdarg.h` and other @@ -540,7 +551,7 @@ Lameguy64: - psxgpu: Fixed bug in DMACallback where the internal DMA handler would fail to install due to `GetInterruptCallback()` retrieving the callback value - immediately in the branch delay slot of a jr instruction, which resuls to + immediately in the branch delay slot of a `jr` instruction, which resuls to an inconsistent return value. This also broke `DrawSyncCallback()`. - psxsio: Done fixes on `_sio_control()` from the aformentioned issues with @@ -619,7 +630,7 @@ Lameguy64: ready instead of simply waiting for GPU transfer ready which is the likely cause of subtle GPU related timing issues, it also sets GPU DMA transfer mode to off afterwards. It can also read number of words remaining in DMA - transfer if a0 is non-zero but it likely only returns the correct value on + transfer if `a0` is non-zero but it likely only returns the correct value on VRAM transfers. Exact way how `DrawSync()` returns the count in the official SDK is currently unknown. @@ -645,10 +656,10 @@ Lameguy64: - Added `rgb24` example. - Got custom exit handler set using `SetCustomExitFromException()` (BIOS - function B(19h)) working. Currently used to acknowledge VSync IRQ but + function `B(19h)`) working. Currently used to acknowledge VSync IRQ but actual VSync handling is still done with events and needs to be transferred to the custom exit handler. At least it lets BIOS - controller functions to work now. See doc/dev `notes.txt` for details + controller functions to work now. See `doc/dev notes.txt` for details on how this handler behaves. - Made stack usage in `ResetGraph()` less wasteful. You only need to diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c index 5f11d8d..284b92f 100644 --- a/examples/cdrom/cdxa/main.c +++ b/examples/cdrom/cdxa/main.c @@ -199,7 +199,7 @@ void xa_callback(int intr, unsigned char *result) if (intr == CdlDataReady) { /* Fetch data sector */ - CdGetSector((u_long*)&xa_sector_buff, 2048); + CdGetSector((u_long*)&xa_sector_buff, 512); /* Quirk: This CdGetSector() implementation must fetch 2048 bytes */ /* or more otherwise the following sectors will be read in an */ diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c index 67a98da..95c3155 100644 --- a/examples/io/system573/main.c +++ b/examples/io/system573/main.c @@ -306,7 +306,7 @@ int main(int argc, const char* argv[]) { FntPrint(-1, " P1 BUTTONS =%07@\n", inputs.p1_btn); FntPrint(-1, " P2 JOYSTICK =%04@\n", inputs.p2_joy); FntPrint(-1, " P2 BUTTONS =%07@\n", inputs.p2_btn); - FntPrint(-1, " COIN/SERVICE=%04@\n", inputs.coin); + FntPrint(-1, " COIN/SERVICE=%04@\n", inputs.coin & 0xf); FntPrint(-1, " DIP SWITCHES=%04@\n", inputs.dip_sw); FntPrint(-1, "\nCABINET LIGHTS:\n"); diff --git a/libpsn00b/psxcd/cdgetsector.s b/libpsn00b/psxcd/cdgetsector.s index 9af3543..dbe95cb 100644 --- a/libpsn00b/psxcd/cdgetsector.s +++ b/libpsn00b/psxcd/cdgetsector.s @@ -18,7 +18,8 @@ CdGetSector: # nop lui $v0, 0x1 - srl $a1, 2 +# srl $a1, 2 # (the official implementation expects $a1/size + # to be in 32-bit words rather than bytes) or $v0, $a1 sw $a0, D3_MADR($a2) # Set DMA base address and transfer length sw $v0, D3_BCR($a2) diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 29bbb76..d1c1b18 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -795,7 +795,7 @@ static void _scan_callback(int status, unsigned char *result) { if( status == CdlDataReady ) { - CdGetSector((void*)_ses_scanbuff, 2048); + CdGetSector((void*)_ses_scanbuff, 512); if( _ses_scanbuff[0] == 0x1 ) { diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 74c6c1c..76415f9 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -255,7 +255,7 @@ static void _CdReadReadyCallback(int status, unsigned char *result) CdGetSector((void*)_cd_read_addr, _cd_read_sector_sz); // Increment destination address - _cd_read_addr += _cd_read_sector_sz>>2; + _cd_read_addr += _cd_read_sector_sz; // Subtract sector count _cd_sector_count--; @@ -290,15 +290,15 @@ int CdRead(int sectors, u_long *buf, int mode) // Determine sector based on mode flags if( mode & CdlModeSize0 ) { - _cd_read_sector_sz = 2328; + _cd_read_sector_sz = 2328 / 4; } else if( mode & CdlModeSize1 ) { - _cd_read_sector_sz = 2340; + _cd_read_sector_sz = 2340 / 4; } else { - _cd_read_sector_sz = 2048; + _cd_read_sector_sz = 2048 / 4; } _cd_read_counter = VSync(-1); -- cgit v1.2.3 From de9047f568f2f3509b56a2b566d7353cae616eb7 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Thu, 30 Dec 2021 14:58:14 +0100 Subject: Add known_bugs.md, fix sound/vagsample and declarations --- CMakeLists.txt | 6 ++++ doc/known_bugs.md | 52 ++++++++++++++++++++++++++++++ examples/sound/vagsample/0proyt.h | 2 +- examples/sound/vagsample/threedeeffeggzz.h | 2 +- libpsn00b/include/psxcd.h | 6 ++-- libpsn00b/include/psxspu.h | 4 +-- libpsn00b/psxcd/psxcd.c | 8 ++--- 7 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 doc/known_bugs.md (limited to 'libpsn00b/psxcd') diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a20a0e..2079fd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,6 +78,12 @@ set( -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/examples ) +# Ensure PSn00bSDK isn't being built using the toolchain file from PSn00bSDK +# itself (or from another version of it). +if(CMAKE_TOOLCHAIN_FILE MATCHES ".*libpsn00b[/\\]cmake[/\\]sdk\.cmake$") + message(FATAL_ERROR "CMAKE_TOOLCHAIN_FILE is set to the toolchain file of an existing PSn00bSDK installation. It must be unset or overridden by passing '-DCMAKE_TOOLCHAIN_FILE=\"\"' to CMake.") +endif() + ## Subprojects if(NOT EXISTS ${PROJECT_SOURCE_DIR}/tools/mkpsxiso/CMakeLists.txt) diff --git a/doc/known_bugs.md b/doc/known_bugs.md new file mode 100644 index 0000000..2af9e3f --- /dev/null +++ b/doc/known_bugs.md @@ -0,0 +1,52 @@ + +# Known PSn00bSDK bugs + +This is an incomplete list of things that are currently broken (or not behaving +as they should, or untested on real hardware) and haven't yet been fixed. + +## Libraries + +`psxspu`: + +- Calls to `SpuSetTransferMode()` are ignored. SPU transfers are always + performed using DMA, which imposes limitations such as the data length having + to be a multiple of 64 bytes. + +`psxetc`: + +- `DL_LoadSymbolMapFromFile()`, `DL_LoadDLLFromFile()` and `dlopen()` have been + disabled due to bugs in the BIOS file APIs. The dynamic linker can still be + used by loading DLL binaries into RAM manually and calling `DL_CreateDLL()` + on them (see the `system/dynlink` example). + +## Tools + +- The `mkpsxiso` submodule is temporarily set to point to a fork of `mkpsxiso` + with bugfixed CMake scripts (the main repo is broken to the point it fails to + build). There is [another fork](https://github.com/CookiePLMonster/mkpsxiso) + which is currently work-in-progress and includes more fixes as well as a tool + to dump existing CD images: PSn00bSDK will switch back to the main `mkpsxiso` + repo once the changes get upstreamed. + +## Examples + +- `cdrom/cdxa` and `sound/spustream` demonstrate how to stream an audio file + from CD-ROM. Such a file isn't provided however, as PSn00bSDK does not yet + come with the tooling required for transcoding audio from a source file. In + order to run these examples you'll have to provide your own audio files, + convert them and build the CD image manually. + +- `demos/n00bdemo` suffers from flickering on real hardware, especially when + masking/stencil buffering is used. + +- `graphics/render2tex` gets stuck after initialization on real hardware. + +- `io/pads` seems to work on real hardware, but fails to automatically enable + analog mode on DualShock controllers. This example needs more testing with + official and unofficial controllers. + +- `io/system573` hasn't been tested on a real Konami System 573. It runs on + MAME, however MAME's System 573 emulation is *very* inaccurate. + +----------------------------------------- +_Last updated on 2021-12-30 by spicyjpeg_ diff --git a/examples/sound/vagsample/0proyt.h b/examples/sound/vagsample/0proyt.h index 4402b9a..73629f9 100644 --- a/examples/sound/vagsample/0proyt.h +++ b/examples/sound/vagsample/0proyt.h @@ -12616,6 +12616,6 @@ unsigned char proyt[] = { 0xf2,0xf0,0xf2,0x15,0xc2,0x1b,0x00,0x00,0x01,0xe3,0x31,0x13,0xf3,0x1f,0xe2, 0x2f,0x13,0xd6,0x20,0x6e,0x2d,0x1b,0x00,0x03,0x42,0xc3,0x14,0x30,0x20,0x21, 0x21,0x32,0x0e,0x32,0x12,0x42,0xf0,0x39,0x01,0x13,0x12,0x04,0xb3,0x06,0x1f, -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x00,0x77,0x77,0x77,0x77,0x77, +0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x05,0x77,0x77,0x77,0x77,0x77, 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77 }; diff --git a/examples/sound/vagsample/threedeeffeggzz.h b/examples/sound/vagsample/threedeeffeggzz.h index ed0e098..f0815aa 100644 --- a/examples/sound/vagsample/threedeeffeggzz.h +++ b/examples/sound/vagsample/threedeeffeggzz.h @@ -15194,6 +15194,6 @@ unsigned char tdfx[] = { 0x0b,0x1e,0x21,0xa0,0x4f,0xe2,0x2d,0x17,0x00,0xd2,0x02,0x1d,0xd1,0xf0,0x21, 0xfa,0x2e,0xc4,0x1e,0xfe,0xf2,0x2f,0x24,0x17,0x00,0xef,0xee,0x1f,0xf2,0xce, 0x0d,0x25,0x01,0x3e,0xcb,0xe1,0x30,0xeb,0xc4,0x17,0x01,0x1f,0x1f,0xaf,0x22, -0xfd,0xe0,0xf3,0x0b,0x2e,0xdd,0xc3,0xde,0x12,0x2d,0x07,0x00,0x77,0x77,0x77, +0xfd,0xe0,0xf3,0x0b,0x2e,0xdd,0xc3,0xde,0x12,0x2d,0x07,0x05,0x77,0x77,0x77, 0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77,0x77 }; diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h index ffbe86b..3336963 100644 --- a/libpsn00b/include/psxcd.h +++ b/libpsn00b/include/psxcd.h @@ -132,9 +132,9 @@ CdlLOC* CdIntToPos(int i, CdlLOC *p); int CdPosToInt(CdlLOC *p); int CdGetToc(CdlLOC *toc); -int CdControl(u_char com, u_char *param, u_char *result); -int CdControlB(u_char com, u_char *param, u_char *result); -int CdControlF(u_char com, u_char *param); +int CdControl(u_char com, const void *param, u_char *result); +int CdControlB(u_char com, const void *param, u_char *result); +int CdControlF(u_char com, const void *param); int CdSync(int mode, u_char *result); u_long CdSyncCallback(CdlCB func); diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index a87e347..da000e3 100644 --- a/libpsn00b/include/psxspu.h +++ b/libpsn00b/include/psxspu.h @@ -115,7 +115,7 @@ extern "C" { void SpuInit(); -void SpuSetVoiceRaw( int voice, SpuVoiceRaw* param ); +void SpuSetVoiceRaw( int voice, const SpuVoiceRaw* param ); void SpuReverbOn( int voice ); void SpuSetReverb(); @@ -128,7 +128,7 @@ void SpuSetKey(int on_off, u_int voice_bit); // SPU transfer functions int SpuSetTransferMode(int mode); int SpuSetTransferStartAddr(int addr); -int SpuWrite(unsigned char* addr, int size); +int SpuWrite(const unsigned char* addr, int size); void SpuWait(); #ifdef __cplusplus diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 76415f9..8f19c8d 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -21,7 +21,7 @@ volatile int _cd_last_sector_count; int _cd_media_changed; void _cd_init(void); -void _cd_control(unsigned char com, unsigned char *param, int plen); +void _cd_control(unsigned char com, const void *param, int plen); void _cd_wait_ack(void); void _cd_wait(void); @@ -50,7 +50,7 @@ int CdInit(void) return 1; } -int CdControl(unsigned char com, unsigned char *param, unsigned char *result) +int CdControl(unsigned char com, const void *param, unsigned char *result) { // Don't issue command if ack is not received yet if( _cd_ack_wait ) @@ -72,7 +72,7 @@ int CdControl(unsigned char com, unsigned char *param, unsigned char *result) return 1; } -int CdControlB(unsigned char com, unsigned char *param, unsigned char *result) +int CdControlB(unsigned char com, const void *param, unsigned char *result) { if( !CdControl(com, param, result) ) { @@ -83,7 +83,7 @@ int CdControlB(unsigned char com, unsigned char *param, unsigned char *result) return 1; } -int CdControlF(unsigned char com, unsigned char *param) +int CdControlF(unsigned char com, const void *param) { int param_len=0; -- cgit v1.2.3