diff options
| -rw-r--r-- | examples/sound/cdstream/main.c | 2 | ||||
| -rw-r--r-- | examples/system/childexec/child/child.c | 1 | ||||
| -rw-r--r-- | libpsn00b/include/psxsn.h | 54 | ||||
| -rw-r--r-- | libpsn00b/psxapi/_syscalls.s | 111 | ||||
| -rw-r--r-- | tools/util/elf2x.c | 9 |
5 files changed, 164 insertions, 13 deletions
diff --git a/examples/sound/cdstream/main.c b/examples/sound/cdstream/main.c index 324abb2..53b88e6 100644 --- a/examples/sound/cdstream/main.c +++ b/examples/sound/cdstream/main.c @@ -212,7 +212,7 @@ void spu_irq_handler(void) { // if str_ctx.state is set to STATE_DATA_NEEDED and fetch the next chunk. } -void cd_read_handler(int event, uint8_t *payload) { +void cd_read_handler(CdlIntrResult event, uint8_t *payload) { // Attempt to read the chunk again if an error has occurred, otherwise // start uploading it to SPU RAM. if (event == CdlDiskError) { diff --git a/examples/system/childexec/child/child.c b/examples/system/childexec/child/child.c index b52dd32..e5e16b9 100644 --- a/examples/system/childexec/child/child.c +++ b/examples/system/childexec/child/child.c @@ -1,5 +1,6 @@ #include <stdint.h> #include <stdio.h> +#include <psxetc.h> #include <psxapi.h> #include <psxgpu.h> #include <psxgte.h> diff --git a/libpsn00b/include/psxsn.h b/libpsn00b/include/psxsn.h new file mode 100644 index 0000000..53a3cd9 --- /dev/null +++ b/libpsn00b/include/psxsn.h @@ -0,0 +1,54 @@ +/* + * PSn00bSDK kernel API library (host file access) + * (C) 2023 spicyjpeg - MPL licensed + */ + +/** + * @file psxsn.h + * @brief Host file access API header + * + * @details This header provides stubs for the PCDRV API, which grants read and + * write access to a directory on the host's filesystem when the executable is + * running on an emulator or through a debugger that supports the PCDRV + * protocol, such as Unirom or pcsx-redux. These functions are completely + * separate and independent from the BIOS file API and do not register any + * device drivers. + * + * Note that in the official SDK these functions are provided by libsn, while + * in PSn00bSDK they are part of libpsxapi. + */ + +#ifndef __PSXSN_H +#define __PSXSN_H + +#include <stddef.h> + +typedef enum _PCDRV_OpenMode { + PCDRV_MODE_READ = 0, + PCDRV_MODE_WRITE = 1, + PCDRV_MODE_READ_WRITE = 2 +} PCDRV_OpenMode; + +typedef enum _PCDRV_SeekMode { + PCDRV_SEEK_SET = 0, + PCDRV_SEEK_CUR = 1, + PCDRV_SEEK_END = 2 +} PCDRV_SeekMode; + +#ifdef __cplusplus +extern "C" { +#endif + +int PCinit(void); +int PCcreat(const char *path); +int PCopen(const char *path, PCDRV_OpenMode mode); +int PCclose(int fd); +int PCread(int fd, void *data, size_t length); +int PCwrite(int fd, const void *data, size_t length); +int PClseek(int fd, int offset, PCDRV_SeekMode mode); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/libpsn00b/psxapi/_syscalls.s b/libpsn00b/psxapi/_syscalls.s index 6eaed72..5062b15 100644 --- a/libpsn00b/psxapi/_syscalls.s +++ b/libpsn00b/psxapi/_syscalls.s @@ -1,26 +1,28 @@ # PSn00bSDK syscall wrappers -# (C) 2022 spicyjpeg - MPL licensed +# (C) 2022-2023 spicyjpeg - MPL licensed .set noreorder +## Interrupt enable/disable + .section .text.EnterCriticalSection .global EnterCriticalSection .type EnterCriticalSection, @function EnterCriticalSection: - li $a0, 0x01 + li $a0, 0x01 syscall 0 - jr $ra + jr $ra nop .section .text.ExitCriticalSection .global ExitCriticalSection .type ExitCriticalSection, @function ExitCriticalSection: - li $a0, 0x02 + li $a0, 0x02 syscall 0 - jr $ra + jr $ra nop .section .text.SwEnterCriticalSection @@ -31,7 +33,7 @@ SwEnterCriticalSection: li $a1, -1026 and $a1, $a0 mtc0 $a1, $12 - andi $a0, 0x0401 # return ((cop0r12_prev & 0x401) == 0x401) + andi $a0, 0x0401 # return !((cop0r12_prev & 0x401) < 0x401) sltiu $v0, $a0, 0x0401 jr $ra @@ -49,3 +51,100 @@ SwExitCriticalSection: jr $ra nop + +## PCDRV (host file access) API + +.section .text.PCinit +.global PCinit +.type PCinit, @function +PCinit: + break 0, 0x101 # () -> error + + jr $ra + nop + +.section .text.PCcreat +.global PCcreat +.type PCcreat, @function +PCcreat: + li $a2, 0 + move $a1, $a0 + break 0, 0x102 # (path, path, 0) -> error, fd + + bgez $v0, .Lcreate_ok # if (error < 0) fd = error + nop + move $v1, $v0 +.Lcreate_ok: + jr $ra # return fd + move $v0, $v1 + +.section .text.PCopen +.global PCopen +.type PCopen, @function +PCopen: + move $a2, $a1 + move $a1, $a0 + break 0, 0x103 # (path, path, mode) -> error, fd + + bgez $v0, .Lopen_ok # if (error < 0) fd = error + nop + move $v1, $v0 +.Lopen_ok: + jr $ra # return fd + move $v0, $v1 + +.section .text.PCclose +.global PCclose +.type PCclose, @function +PCclose: + move $a1, $a0 + break 0, 0x104 # (fd, fd) -> error + + jr $ra + nop + +.section .text.PCread +.global PCread +.type PCread, @function +PCread: + move $a3, $a1 + move $a1, $a0 + break 0, 0x105 # (fd, fd, length, data) -> error, length + + bgez $v0, .Lread_ok # if (error < 0) length = error + nop + move $v1, $v0 +.Lread_ok: + jr $ra # return length + move $v0, $v1 + +.section .text.PCwrite +.global PCwrite +.type PCwrite, @function +PCwrite: + move $a3, $a1 + move $a1, $a0 + break 0, 0x106 # (fd, fd, length, data) -> error, length + + bgez $v0, .Lwrite_ok # if (error < 0) length = error + nop + move $v1, $v0 +.Lwrite_ok: + jr $ra # return length + move $v0, $v1 + +.section .text.PClseek +.global PClseek +.type PClseek, @function +PClseek: + move $a3, $a2 + move $a2, $a1 + move $a1, $a0 + break 0, 0x107 # (fd, fd, offset, mode) -> error, offset + + bgez $v0, .Lseek_ok # if (error < 0) offset = error + nop + move $v1, $v0 +.Lseek_ok: + jr $ra # return offset + move $v0, $v1 diff --git a/tools/util/elf2x.c b/tools/util/elf2x.c index 38ed60d..fc0ea9f 100644 --- a/tools/util/elf2x.c +++ b/tools/util/elf2x.c @@ -237,13 +237,10 @@ int main(int argc, char** argv) { exe.params.t_size = exe_tsize; exe.params.pc0 = head.prg_entry_addr; - // Some later PAL BIOS versions seem to actually verify the license string - // in the executable (despite what the nocash docs claim) and display the - // dreaded "insert PlayStation CD-ROM" screen if it's not valid. strncpy( exe.header, "PS-X EXE", 8 ); - strcpy( exe.license, - "Sony Computer Entertainment Inc. for Europe area" ); - strcpy( exe.pad2, "Built using GCC and PSn00bSDK libraries" ); + //strcpy( exe.license, + //"Sony Computer Entertainment Inc. for Europe area" ); + //strcpy( exe.pad2, "Built using GCC and PSn00bSDK libraries" ); // Write file |
