aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/include
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2023-05-11 23:42:43 +0200
committerGitHub <noreply@github.com>2023-05-11 23:42:43 +0200
commit04d7728350cbd04dd86cd894e906c98673e3f9a7 (patch)
tree08e8c7dd495d1c4c6fcf5f7ba6b4b10693dc42f6 /libpsn00b/include
parenteaec942f56ceec9c14de5c4185a02602abadd50a (diff)
parent58a8306d24fe29d965aa8b40ddc37c3163c0a2f9 (diff)
downloadpsn00bsdk-04d7728350cbd04dd86cd894e906c98673e3f9a7.tar.gz
Merge pull request #70 from Lameguy64/v0.23-wip
Header cleanups, PCDRV, more safety checks, libc and mkpsxiso fixes (v0.23)
Diffstat (limited to 'libpsn00b/include')
-rw-r--r--libpsn00b/include/assert.h34
-rw-r--r--libpsn00b/include/cassert8
-rw-r--r--libpsn00b/include/cctype22
-rw-r--r--libpsn00b/include/cstdint34
-rw-r--r--libpsn00b/include/cstdio32
-rw-r--r--libpsn00b/include/cstdlib59
-rw-r--r--libpsn00b/include/cstring38
-rw-r--r--libpsn00b/include/ctype.h18
-rw-r--r--libpsn00b/include/dlfcn.h5
-rw-r--r--libpsn00b/include/elf.h18
-rw-r--r--libpsn00b/include/hwregs_c.h43
-rw-r--r--libpsn00b/include/inline_c.h5
-rw-r--r--libpsn00b/include/ioctl.h19
-rw-r--r--libpsn00b/include/lzconfig.h68
-rw-r--r--libpsn00b/include/lzp/lzp.h34
-rw-r--r--libpsn00b/include/lzp/lzqlp.h32
-rw-r--r--libpsn00b/include/malloc.h8
-rw-r--r--libpsn00b/include/psxapi.h116
-rw-r--r--libpsn00b/include/psxcd.h62
-rw-r--r--libpsn00b/include/psxetc.h55
-rw-r--r--libpsn00b/include/psxgpu.h375
-rw-r--r--libpsn00b/include/psxgte.h5
-rw-r--r--libpsn00b/include/psxkernel.h45
-rw-r--r--libpsn00b/include/psxpad.h5
-rw-r--r--libpsn00b/include/psxpress.h136
-rw-r--r--libpsn00b/include/psxsio.h5
-rw-r--r--libpsn00b/include/psxsn.h51
-rw-r--r--libpsn00b/include/psxspu.h29
-rw-r--r--libpsn00b/include/stdio.h41
-rw-r--r--libpsn00b/include/stdlib.h17
-rw-r--r--libpsn00b/include/string.h51
-rw-r--r--libpsn00b/include/strings.h5
-rw-r--r--libpsn00b/include/sys/fcntl.h12
-rw-r--r--libpsn00b/include/sys/ioctl.h13
-rw-r--r--libpsn00b/include/sys/types.h12
35 files changed, 927 insertions, 585 deletions
diff --git a/libpsn00b/include/assert.h b/libpsn00b/include/assert.h
index 1b2bda2..8f8df74 100644
--- a/libpsn00b/include/assert.h
+++ b/libpsn00b/include/assert.h
@@ -1,13 +1,12 @@
/*
* PSn00bSDK assert macro and internal logging
- * (C) 2022 spicyjpeg - MPL licensed
+ * (C) 2022-2023 spicyjpeg - MPL licensed
*
- * Note that the _sdk_log() macro is used internally by PSn00bSDK to output
- * debug messages and warnings.
+ * The _sdk_*() macros are used internally by PSn00bSDK to output messages when
+ * building in debug mode.
*/
-#ifndef __ASSERT_H
-#define __ASSERT_H
+#pragma once
#include <stdio.h>
@@ -25,6 +24,9 @@ void _assert_abort(const char *file, int line, const char *expr);
#define assert(expr)
#define _sdk_log(fmt, ...)
+#define _sdk_assert(expr, fmt, ...)
+#define _sdk_validate_args_void(expr)
+#define _sdk_validate_args(expr, ret)
#else
@@ -32,11 +34,27 @@ void _assert_abort(const char *file, int line, const char *expr);
((expr) ? ((void) 0) : _assert_abort(__FILE__, __LINE__, #expr))
#ifdef SDK_LIBRARY_NAME
-#define _sdk_log(fmt, ...) printf(SDK_LIBRARY_NAME ": " fmt, ##__VA_ARGS__)
+#define _sdk_log(fmt, ...) \
+ printf(SDK_LIBRARY_NAME ": " fmt __VA_OPT__(,) __VA_ARGS__)
#else
-#define _sdk_log(fmt, ...) printf(fmt, ##__VA_ARGS__)
+#define _sdk_log(fmt, ...) \
+ printf(fmt __VA_OPT__(,) __VA_ARGS__)
#endif
-#endif
+#define _sdk_assert(expr, ret, fmt, ...) \
+ if (!(expr)) { \
+ _sdk_log(fmt, __VA_ARGS__); \
+ return ret; \
+ }
+#define _sdk_validate_args_void(expr) \
+ if (!(expr)) { \
+ _sdk_log("invalid args to %s() (%s)\n", __func__, #expr); \
+ return; \
+ }
+#define _sdk_validate_args(expr, ret) \
+ if (!(expr)) { \
+ _sdk_log("invalid args to %s() (%s)\n", __func__, #expr); \
+ return ret; \
+ }
#endif
diff --git a/libpsn00b/include/cassert b/libpsn00b/include/cassert
new file mode 100644
index 0000000..0923486
--- /dev/null
+++ b/libpsn00b/include/cassert
@@ -0,0 +1,8 @@
+/*
+ * PSn00bSDK assert macro and internal logging
+ * (C) 2022-2023 spicyjpeg - MPL licensed
+ */
+
+#pragma once
+
+#include <assert.h>
diff --git a/libpsn00b/include/cctype b/libpsn00b/include/cctype
new file mode 100644
index 0000000..b73ad34
--- /dev/null
+++ b/libpsn00b/include/cctype
@@ -0,0 +1,22 @@
+/*
+ * PSn00bSDK standard library
+ * (C) 2019-2023 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
+ */
+
+#pragma once
+
+namespace std {
+extern "C" {
+
+int isprint(int ch);
+int isgraph(int ch);
+int isspace(int ch);
+int isblank(int ch);
+int isalpha(int ch);
+int isdigit(int ch);
+
+int tolower(int ch);
+int toupper(int ch);
+
+}
+}
diff --git a/libpsn00b/include/cstdint b/libpsn00b/include/cstdint
new file mode 100644
index 0000000..3b1bc4a
--- /dev/null
+++ b/libpsn00b/include/cstdint
@@ -0,0 +1,34 @@
+/*
+ * PSn00bSDK standard library
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
+ *
+ * This is a replacement for the <cstdint> header included with GCC, which seems
+ * to be broken (at least in GCC 12.2.0) as it requires some macros to be set.
+ */
+
+#pragma once
+
+#include <stdint.h>
+
+namespace std {
+
+#define _DEF_TYPE(bits, prefix) \
+ using ::prefix##bits##_t; \
+ using ::prefix##_fast##bits##_t; \
+ using ::prefix##_least##bits##_t;
+
+_DEF_TYPE( 8, int)
+_DEF_TYPE( 8, uint)
+_DEF_TYPE(16, int)
+_DEF_TYPE(16, uint)
+_DEF_TYPE(32, int)
+_DEF_TYPE(32, uint)
+
+#undef _DEF_TYPE
+
+using ::intmax_t;
+using ::uintmax_t;
+using ::intptr_t;
+using ::uintptr_t;
+
+}
diff --git a/libpsn00b/include/cstdio b/libpsn00b/include/cstdio
new file mode 100644
index 0000000..800d1a2
--- /dev/null
+++ b/libpsn00b/include/cstdio
@@ -0,0 +1,32 @@
+/*
+ * PSn00bSDK standard library
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
+ */
+
+#pragma once
+
+#include <cstdarg>
+
+namespace std {
+extern "C" {
+
+/* String I/O API (provided by BIOS) */
+
+int printf(const char *fmt, ...);
+char *gets(char *str);
+void puts(const char *str);
+int getchar(void);
+void putchar(int ch);
+
+/* String formatting API (built-in) */
+
+int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap);
+int vsprintf(char *string, const char *fmt, va_list ap);
+int sprintf(char *string, const char *fmt, ...);
+int snprintf(char *string, unsigned int size, const char *fmt, ...);
+
+int vsscanf(const char *str, const char *format, va_list ap);
+int sscanf(const char *str, const char *fmt, ...);
+
+}
+}
diff --git a/libpsn00b/include/cstdlib b/libpsn00b/include/cstdlib
new file mode 100644
index 0000000..4fa859d
--- /dev/null
+++ b/libpsn00b/include/cstdlib
@@ -0,0 +1,59 @@
+/*
+ * PSn00bSDK standard library
+ * (C) 2019-2023 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
+ */
+
+#pragma once
+
+#include <cstddef>
+
+namespace std {
+
+/* Definitions */
+
+static constexpr int RAND_MAX = 0x7fff;
+
+/* Structure definitions */
+
+struct HeapUsage {
+ size_t total; // Total size of heap + stack
+ size_t heap; // Amount of memory currently reserved for heap
+ size_t stack; // Amount of memory currently reserved for stack
+ size_t alloc; // Amount of memory currently allocated
+ size_t alloc_max; // Maximum amount of memory ever allocated
+};
+
+/* API */
+
+extern "C" {
+
+extern int __argc;
+extern const char **__argv;
+
+void abort(void);
+
+int rand(void);
+void srand(int seed);
+
+int abs(int j);
+long labs(long i);
+
+long strtol(const char *str, char **str_end, int base);
+long long strtoll(const char *str, char **str_end, int base);
+//float strtof(const char *str, char **str_end);
+//double strtod(const char *str, char **str_end);
+//long double strtold(const char *str, char **str_end);
+
+void InitHeap(void *addr, size_t size);
+void *sbrk(ptrdiff_t incr);
+
+void TrackHeapUsage(ptrdiff_t alloc_incr);
+void GetHeapUsage(HeapUsage *usage);
+
+void *malloc(size_t size);
+void *calloc(size_t num, size_t size);
+void *realloc(void *ptr, size_t size);
+void free(void *ptr);
+
+}
+}
diff --git a/libpsn00b/include/cstring b/libpsn00b/include/cstring
new file mode 100644
index 0000000..1ce7246
--- /dev/null
+++ b/libpsn00b/include/cstring
@@ -0,0 +1,38 @@
+/*
+ * PSn00bSDK standard library
+ * (C) 2019-2023 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
+ */
+
+#pragma once
+
+#include <cstddef>
+
+namespace std {
+extern "C" {
+
+void *memset(void *dest, int ch, size_t count);
+void *memcpy(void *dest, const void *src, size_t count);
+void *memccpy(void *dest, const void *src, int ch, size_t count);
+void *memmove(void *dest, const void *src, size_t count);
+int memcmp(const void *lhs, const void *rhs, size_t count);
+void *memchr(const void *ptr, int ch, size_t count);
+
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, size_t count);
+int strcmp(const char *lhs, const char *rhs);
+int strncmp(const char *lhs, const char *rhs, size_t count);
+char *strchr(const char *str, int ch);
+char *strrchr(const char *str, int ch);
+char *strpbrk(const char *str, const char *breakset);
+char *strstr(const char *str, const char *substr);
+
+size_t strlen(const char *str);
+char *strcat(char *dest, const char *src);
+char *strncat(char *dest, const char *src, size_t count);
+char *strdup(const char *str);
+char *strndup(const char *str, size_t count);
+
+char *strtok(char *str, const char *delim);
+
+}
+}
diff --git a/libpsn00b/include/ctype.h b/libpsn00b/include/ctype.h
index 24ee9d9..2fe0a42 100644
--- a/libpsn00b/include/ctype.h
+++ b/libpsn00b/include/ctype.h
@@ -1,20 +1,24 @@
/*
* PSn00bSDK standard library
- * (C) 2019-2022 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
+ * (C) 2019-2023 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
*/
-#ifndef __CTYPE_H
-#define __CTYPE_H
+#pragma once
#ifdef __cplusplus
extern "C" {
#endif
-int tolower(int chr);
-int toupper(int chr);
+int isprint(int ch);
+int isgraph(int ch);
+int isspace(int ch);
+int isblank(int ch);
+int isalpha(int ch);
+int isdigit(int ch);
+
+int tolower(int ch);
+int toupper(int ch);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/dlfcn.h b/libpsn00b/include/dlfcn.h
index 6192430..5e1e3b6 100644
--- a/libpsn00b/include/dlfcn.h
+++ b/libpsn00b/include/dlfcn.h
@@ -3,8 +3,7 @@
* (C) 2021-2022 spicyjpeg - MPL licensed
*/
-#ifndef __DLFCN_H
-#define __DLFCN_H
+#pragma once
#include <stdint.h>
#include <stddef.h>
@@ -215,5 +214,3 @@ void *DL_GetDLLSymbol(const DLL *dll, const char *name);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/elf.h b/libpsn00b/include/elf.h
index abfb3d5..b0ddf71 100644
--- a/libpsn00b/include/elf.h
+++ b/libpsn00b/include/elf.h
@@ -9,8 +9,7 @@
* converted to enums.
*/
-#ifndef __ELF_H
-#define __ELF_H
+#pragma once
#include <stdint.h>
@@ -121,18 +120,3 @@ typedef enum {
STT_LOPROC = 13, /* Start of processor-specific */
STT_HIPROC = 15 /* End of processor-specific */
} Elf32_st_type;
-
-// If you need to add more constants, you may use the following Python snippet
-// to quickly convert #defines to enums:
-/*
-import re
-t = """<paste #defines here>"""
-t = re.sub(
- r"(0x[0-9a-f]+|0b[01]+|[0-9]+)",
- lambda m: f"= {m.group(1)},",
- t.replace("#define ", "\t").replace("#define\t", "\t")
-)
-print("typedef enum {\n" + t + "\n} NAME;")
-*/
-
-#endif
diff --git a/libpsn00b/include/hwregs_c.h b/libpsn00b/include/hwregs_c.h
index 7015101..2152986 100644
--- a/libpsn00b/include/hwregs_c.h
+++ b/libpsn00b/include/hwregs_c.h
@@ -3,8 +3,7 @@
* (C) 2022 spicyjpeg - MPL licensed
*/
-#ifndef __HWREGS_C_H
-#define __HWREGS_C_H
+#pragma once
#include <stdint.h>
@@ -35,7 +34,7 @@
#define CD_DATA _MMIO8(IOBASE | 0x1802)
#define CD_IRQ _MMIO8(IOBASE | 0x1803)
-#define CD_REG(N) _MMIO8(IOBASE | 0x1800 + (N))
+#define CD_REG(N) _MMIO8((IOBASE | 0x1800) + (N))
/* SPU */
@@ -74,13 +73,13 @@
// These are not named SPU_VOICE_* to avoid name clashes with SPU attribute
// flags defined in psxspu.h.
-#define SPU_CH_VOL_L(N) _MMIO16(IOBASE | 0x1c00 + 16 * (N))
-#define SPU_CH_VOL_R(N) _MMIO16(IOBASE | 0x1c02 + 16 * (N))
-#define SPU_CH_FREQ(N) _MMIO16(IOBASE | 0x1c04 + 16 * (N))
-#define SPU_CH_ADDR(N) _MMIO16(IOBASE | 0x1c06 + 16 * (N))
-#define SPU_CH_ADSR1(N) _MMIO16(IOBASE | 0x1c08 + 16 * (N))
-#define SPU_CH_ADSR2(N) _MMIO16(IOBASE | 0x1c0a + 16 * (N))
-#define SPU_CH_LOOP_ADDR(N) _MMIO16(IOBASE | 0x1c0e + 16 * (N))
+#define SPU_CH_VOL_L(N) _MMIO16((IOBASE | 0x1c00) + (16 * (N)))
+#define SPU_CH_VOL_R(N) _MMIO16((IOBASE | 0x1c02) + (16 * (N)))
+#define SPU_CH_FREQ(N) _MMIO16((IOBASE | 0x1c04) + (16 * (N)))
+#define SPU_CH_ADDR(N) _MMIO16((IOBASE | 0x1c06) + (16 * (N)))
+#define SPU_CH_ADSR1(N) _MMIO16((IOBASE | 0x1c08) + (16 * (N)))
+#define SPU_CH_ADSR2(N) _MMIO16((IOBASE | 0x1c0a) + (16 * (N)))
+#define SPU_CH_LOOP_ADDR(N) _MMIO16((IOBASE | 0x1c0e) + (16 * (N)))
/* MDEC */
@@ -92,11 +91,11 @@
// IMPORTANT: even though SIO_DATA is a 32-bit register, it should only be
// accessed as 8-bit. Reading it as 16 or 32-bit works fine on real hardware,
// but leads to problems in some emulators.
-#define SIO_DATA(N) _MMIO8 (IOBASE | 0x1040 + 16 * (N))
-#define SIO_STAT(N) _MMIO16(IOBASE | 0x1044 + 16 * (N))
-#define SIO_MODE(N) _MMIO16(IOBASE | 0x1048 + 16 * (N))
-#define SIO_CTRL(N) _MMIO16(IOBASE | 0x104a + 16 * (N))
-#define SIO_BAUD(N) _MMIO16(IOBASE | 0x104e + 16 * (N))
+#define SIO_DATA(N) _MMIO8 ((IOBASE | 0x1040) + (16 * (N)))
+#define SIO_STAT(N) _MMIO16((IOBASE | 0x1044) + (16 * (N)))
+#define SIO_MODE(N) _MMIO16((IOBASE | 0x1048) + (16 * (N)))
+#define SIO_CTRL(N) _MMIO16((IOBASE | 0x104a) + (16 * (N)))
+#define SIO_BAUD(N) _MMIO16((IOBASE | 0x104e) + (16 * (N)))
/* IRQ controller */
@@ -108,15 +107,15 @@
#define DMA_DPCR _MMIO32(IOBASE | 0x10f0)
#define DMA_DICR _MMIO32(IOBASE | 0x10f4)
-#define DMA_MADR(N) _MMIO32(IOBASE | 0x1080 + 16 * (N))
-#define DMA_BCR(N) _MMIO32(IOBASE | 0x1084 + 16 * (N))
-#define DMA_CHCR(N) _MMIO32(IOBASE | 0x1088 + 16 * (N))
+#define DMA_MADR(N) _MMIO32((IOBASE | 0x1080) + (16 * (N)))
+#define DMA_BCR(N) _MMIO32((IOBASE | 0x1084) + (16 * (N)))
+#define DMA_CHCR(N) _MMIO32((IOBASE | 0x1088) + (16 * (N)))
/* Timers */
-#define TIMER_VALUE(N) _MMIO32(IOBASE | 0x1100 + 16 * (N))
-#define TIMER_CTRL(N) _MMIO32(IOBASE | 0x1104 + 16 * (N))
-#define TIMER_RELOAD(N) _MMIO32(IOBASE | 0x1108 + 16 * (N))
+#define TIMER_VALUE(N) _MMIO32((IOBASE | 0x1100) + (16 * (N)))
+#define TIMER_CTRL(N) _MMIO32((IOBASE | 0x1104) + (16 * (N)))
+#define TIMER_RELOAD(N) _MMIO32((IOBASE | 0x1108) + (16 * (N)))
/* Memory/bus control */
@@ -130,5 +129,3 @@
#define BUS_EXP2_CFG _MMIO32(IOBASE | 0x101c)
#define BUS_COM_DELAY _MMIO32(IOBASE | 0x1020)
#define BUS_RAM_SIZE _MMIO32(IOBASE | 0x1060)
-
-#endif
diff --git a/libpsn00b/include/inline_c.h b/libpsn00b/include/inline_c.h
index 5facc1c..cb550b9 100644
--- a/libpsn00b/include/inline_c.h
+++ b/libpsn00b/include/inline_c.h
@@ -16,8 +16,7 @@
* compiled object files.
*/
-#ifndef _INLINE_C_H
-#define _INLINE_C_H
+#pragma once
/* GTE load macros */
@@ -1612,5 +1611,3 @@
: "g"( r0 ) )
#define gte_mvmva_b(sf, mx, v, cv, lm) gte_mvmva_core_b( 0x0400012 | \
((sf)<<19) | ((mx)<<17) | ((v)<<15) | ((cv)<<13) | ((lm)<<10) )
-
-#endif // _INLINE_C_H
diff --git a/libpsn00b/include/ioctl.h b/libpsn00b/include/ioctl.h
deleted file mode 100644
index 5c56422..0000000
--- a/libpsn00b/include/ioctl.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef _IOCTL_H
-#define _IOCTL_H
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-#ifndef EOF
-#define EOF -1
-#endif
-
-// General
-#define FIONBLOCK (('f'<<8)|1)
-#define FIOCSCAN (('f'<<8)|2)
-
-// disk
-#define DIO_FORMAT (('d'<<8)|1)
-
-#endif \ No newline at end of file
diff --git a/libpsn00b/include/lzconfig.h b/libpsn00b/include/lzconfig.h
deleted file mode 100644
index cb8a830..0000000
--- a/libpsn00b/include/lzconfig.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*! \file lzconfig.h
- * \brief Library configuration header
- * \details Define settings will only take effect when you recompile the library.
- */
-
-#ifndef _LZP_CONFIG_H
-#define _LZP_CONFIG_H
-
-
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
-
-
-/* Set to TRUE to compile without data compression routines useful if you
- * plan to use this library on a program that does not require said routines
- * especially on a platform with limited memory (such as the PlayStation).
- *
- * This define will rule out lzCompress(), lzSetHashSizes() and
- * lzResetHashSizes() functions and their associated functions.
- */
-#define LZP_NO_COMPRESS TRUE
-
-
-/* Set to TRUE to make default compression table sizes to maximum and works best
- * when compressing large amounts of data. LZP_USE_MALLOC must be set to TRUE to
- * prevent stack overflow errors.
- *
- * Do not enable this if you plan to compile for a platform with limited memory
- * otherwise, the library will consume all memory and crash the system.
- *
- * This define only affects lzCompress().
- */
-#define LZP_MAX_COMPRESS FALSE
-
-
-/* Uncomment to make the library use malloc() instead of array initializers to
- * allocate hash tables. Enabling this is a must if you plan to use large hash
- * and window table sizes.
- */
-#define LZP_USE_MALLOC FALSE
-
-
-/* Hash table sizes (in power-of-two multiple units)
- *
- * These define only affect lzCompress().
- */
-#if LZP_MAX_COMPRESS == TRUE
-
-// Minimal defaults
-#define LZP_WINDOW_SIZE 17
-#define LZP_HASH1_SIZE 8
-#define LZP_HASH2_SIZE 10
-
-#else
-
-// Maximum defaults
-#define LZP_WINDOW_SIZE 17
-#define LZP_HASH1_SIZE 22
-#define LZP_HASH2_SIZE 24
-
-#endif
-
-
-#endif // _LZP_CONFIG_H
diff --git a/libpsn00b/include/lzp/lzp.h b/libpsn00b/include/lzp/lzp.h
index 456de02..1aeea30 100644
--- a/libpsn00b/include/lzp/lzp.h
+++ b/libpsn00b/include/lzp/lzp.h
@@ -1,20 +1,29 @@
-/*! \file lzp.h
- * \brief Main library header
+/*
+ * liblzp data compression library
+ * (C) 2019 Lameguy64 - MPL licensed
*/
-/*! \mainpage
- * \version 0.20b
- * \author John Wilbert 'Lameguy64' Villamor
+/**
+ * @file lzp.h
+ * @brief Utility library for file bundling and compression
*
- * \section creditsSection Credits
- * - LZ77 data compression/decompression routines based from Ilya Muravyov's
- * crush.cpp released under public domain. Refined and ported to C by Lameguy64.
- * - CRC calculation routines based from Lammert Bies' lib_crc routines.
+ * @details This library implements a simple in-memory archive format which
+ * can be used to package and compress assets for faster loading, as well as a
+ * generic LZ77 compressor and matching decompressor. Two archive formats are
+ * supported, one uncompressed (.QLP) and one with individually compressed
+ * entries (.LZP).
*
+ * This header provides the LZ77 compression API and functions to parse and
+ * decompress .LZP archives after they have been loaded into memory.
+ *
+ * @section creditsSection Credits
+ * - LZ77 data compression/decompression routines based from Ilya Muravyov's
+ * crush.cpp released under public domain. Refined and ported to C by
+ * Lameguy64.
+ * - CRC calculation routines based from Lammert Bies' lib_crc routines.
*/
-#ifndef _LZPACK_H
-#define _LZPACK_H
+#pragma once
#include <stdint.h>
#ifdef _WIN32
@@ -218,6 +227,3 @@ int lzpUnpackFile(void* buff, const LZP_HEAD* lzpack, int fileNum);
#ifdef __cplusplus
}
#endif
-
-
-#endif // _LZPACK_H
diff --git a/libpsn00b/include/lzp/lzqlp.h b/libpsn00b/include/lzp/lzqlp.h
index 32ce0d7..127f263 100644
--- a/libpsn00b/include/lzp/lzqlp.h
+++ b/libpsn00b/include/lzp/lzqlp.h
@@ -1,5 +1,23 @@
-#ifndef _QLP_H
-#define _QLP_H
+/*
+ * liblzp data compression library
+ * (C) 2019 Lameguy64 - MPL licensed
+ */
+
+/**
+ * @file lzqlp.h
+ * @brief Utility library for file bundling
+ *
+ * @details This library implements a simple in-memory archive format which
+ * can be used to package and compress assets for faster loading, as well as a
+ * generic LZ77 compressor and matching decompressor. Two archive formats are
+ * supported, one uncompressed (.QLP) and one with individually compressed
+ * entries (.LZP).
+ *
+ * This header provides functions to parse .QLP archives and retrieve pointers
+ * to their contents after they have been loaded into memory.
+ */
+
+#pragma once
#include <stdint.h>
#ifdef _WIN32
@@ -23,9 +41,17 @@ typedef struct {
uint32_t offs;
} QLP_FILE;
+
+// Function prototypes
+#ifdef __cplusplus
+extern "C" {
+#endif
+
int qlpFileCount(const QLP_HEAD* qlpfile);
const QLP_FILE* qlpFileEntry(int index, const QLP_HEAD* qlpfile);
const void* qlpFileAddr(int index, const QLP_HEAD* qlpfile);
int qlpFindFile(char* fileName, const QLP_HEAD* qlpfile);
-#endif // _QLP_H \ No newline at end of file
+#ifdef __cplusplus
+}
+#endif
diff --git a/libpsn00b/include/malloc.h b/libpsn00b/include/malloc.h
deleted file mode 100644
index 75c3711..0000000
--- a/libpsn00b/include/malloc.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef _MALLOC_H
-#define _MALLOC_H
-
-#warning "<malloc.h> is deprecated, include <stdlib.h> instead"
-
-#include <stdlib.h>
-
-#endif // _MALLOC_H \ No newline at end of file
diff --git a/libpsn00b/include/psxapi.h b/libpsn00b/include/psxapi.h
index 7353ed2..35ee040 100644
--- a/libpsn00b/include/psxapi.h
+++ b/libpsn00b/include/psxapi.h
@@ -1,10 +1,21 @@
/*
* PSn00bSDK kernel API library
- * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
*/
-#ifndef __PSXAPI_H
-#define __PSXAPI_H
+/**
+ * @file psxapi.h
+ * @brief Kernel API library header
+ *
+ * @details This header provides access to most of the APIs made available by
+ * the system's BIOS, including basic file I/O, TTY output, controller and
+ * memory card drivers, threads, events as well as kernel memory allocation.
+ *
+ * For more information and up-to-date documentation on kernel APIs, see:
+ * https://psx-spx.consoledev.net/kernelbios/
+ */
+
+#pragma once
#include <stdint.h>
#include <stddef.h>
@@ -12,13 +23,38 @@
/* Definitions */
-#define DescHW 0xf0000000
-#define DescSW 0xf4000000
-
-#define HwCARD (DescHW|0x11)
-#define HwCARD_1 (DescHW|0x12)
-#define HwCARD_0 (DescHW|0x13)
-#define SwCARD (DescHW|0x02)
+// TODO: these desperately need to be cleaned up
+
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
+
+#define DescMask 0xff000000 // Event descriptor mask
+#define DescTH DescMask
+#define DescHW 0xf0000000 // Hardware event (IRQ)
+#define DescEV 0xf1000000 // Event event
+#define DescRC 0xf2000000 // Root counter event
+#define DescUEV 0xf3000000 // User event
+#define DescSW 0xf4000000 // BIOS event
+
+#define HwVBLANK (DescHW|0x01) // VBlank
+#define HwGPU (DescHW|0x02) // GPU
+#define HwCdRom (DescHW|0x03) // CDROM
+#define HwDMAC (DescHW|0x04) // DMA
+#define HwRTC0 (DescHW|0x05) // Timer 0
+#define HwRTC1 (DescHW|0x06) // Timer 1
+#define HwRTC2 (DescHW|0x07) // Timer 2
+#define HwCNTL (DescHW|0x08) // Controller
+#define HwSPU (DescHW|0x09) // SPU
+#define HwPIO (DescHW|0x0a) // PIO & lightgun
+#define HwSIO (DescHW|0x0b) // Serial
+
+#define HwCPU (DescHW|0x10) // Processor exception
+#define HwCARD (DescHW|0x11) // Memory card (lower level BIOS functions)
+#define HwCard_0 (DescHW|0x12)
+#define HwCard_1 (DescHW|0x13)
+#define SwCARD (DescSW|0x01) // Memory card (higher level BIOS functions)
+#define SwMATH (DescSW|0x02)
#define EvSpIOE 0x0004
#define EvSpERROR 0x8000
@@ -135,8 +171,6 @@ struct JMP_BUF {
uint32_t gp;
};
-// Not recommended to use these functions to install IRQ handlers
-
typedef struct {
uint32_t *next;
uint32_t *func2;
@@ -158,7 +192,8 @@ typedef struct {
#define FastExitCriticalSection() \
(IRQ_MASK = __saved_irq_mask)
-/*#define FastEnterCriticalSection() { \
+#if 0
+#define FastEnterCriticalSection() { \
uint32_t r0, r1; \
__asm__ volatile( \
"mfc0 %0, $12;" \
@@ -179,9 +214,10 @@ typedef struct {
"nop;" \
: "=r"(r0) :: \
); \
-}*/
+}
+#endif
-/* API */
+/* BIOS API */
#ifdef __cplusplus
extern "C" {
@@ -199,23 +235,28 @@ int DisableEvent(int event);
void DeliverEvent(uint32_t cl, uint32_t spec);
void UnDeliverEvent(uint32_t cl, uint32_t spec);
-int open(const char *name, int mode);
+int open(const char *path, int mode);
int close(int fd);
-int seek(int fd, uint32_t offset, int mode);
-int read(int fd, uint8_t *buff, size_t len);
-int write(int fd, const uint8_t *buff, size_t len);
+int lseek(int fd, uint32_t offset, int mode);
+int read(int fd, void *buff, size_t len);
+int write(int fd, const void *buff, size_t len);
+int getc(int fd);
+int putc(int ch, int fd);
int ioctl(int fd, int cmd, int arg);
+int isatty(int fd);
struct DIRENTRY *firstfile(const char *wildcard, struct DIRENTRY *entry);
struct DIRENTRY *nextfile(struct DIRENTRY *entry);
-int erase(const char *name);
-int chdir(const char *path);
+int erase(const char *path);
+int undelete(const char *path);
+int cd(const char *path);
-//#define cd(p) chdir(p)
+int _get_errno(void);
+int _get_error(int fd);
-int AddDev(DCB *dcb);
-int DelDev(const char *name);
-void ListDev(void);
-void AddDummyTty(void);
+int AddDrv(DCB *dcb);
+int DelDrv(const char *name);
+void ListDrv(void);
+void add_nullcon_driver(void);
int EnterCriticalSection(void);
void ExitCriticalSection(void);
@@ -254,30 +295,33 @@ int ResetRCnt(int spec);
void ChangeClearPAD(int mode);
void ChangeClearRCnt(int t, int m);
-uint32_t OpenTh(uint32_t (*func)(), uint32_t sp, uint32_t gp);
-int CloseTh(uint32_t thread);
-int ChangeTh(uint32_t thread);
+int OpenTh(uint32_t (*func)(), uint32_t sp, uint32_t gp);
+int CloseTh(int thread);
+int ChangeTh(int thread);
-int Exec(struct EXEC *exec, int argc, char **argv);
+int Exec(struct EXEC *exec, int argc, const char **argv);
+int LoadExec(const char *path, int argc, const char **argv);
void FlushCache(void);
void b_setjmp(struct JMP_BUF *buf);
void b_longjmp(const struct JMP_BUF *buf, int param);
-void SetDefaultExitFromException(void);
-void SetCustomExitFromException(const struct JMP_BUF *buf);
+void ResetEntryInt(void);
+void HookEntryInt(const struct JMP_BUF *buf);
void ReturnFromException(void);
+int SetConf(int evcb, int tcb, uint32_t sp);
+void GetConf(int *evcb, int *tcb, uint32_t *sp);
+void SetMem(int size);
+
int GetSystemInfo(int index);
void *GetB0Table(void);
void *GetC0Table(void);
-void *_kernel_malloc(int size);
-void _kernel_free(void *ptr);
+void *alloc_kernel_memory(int size);
+void free_kernel_memory(void *ptr);
void _boot(void);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h
index 503bc83..fc9c391 100644
--- a/libpsn00b/include/psxcd.h
+++ b/libpsn00b/include/psxcd.h
@@ -21,8 +21,7 @@
* library extension is considered for future development.
*/
-#ifndef __PSXCD_H
-#define __PSXCD_H
+#pragma once
#include <stdint.h>
@@ -811,6 +810,48 @@ int CdMode(void);
int CdStatus(void);
/**
+ * @brief Returns the CD-ROM controller's region code.
+ *
+ * @details Reads region information from the drive using a CdlTest command.
+ * This can be used to reliably determine the system's region without having to
+ * resort to workarounds like probing the BIOS ROM.
+ *
+ * This function may return incorrect results and trigger error callbacks on
+ * emulators or consoles equipped with CD-ROM drive emulation devices such as
+ * the PSIO. It is not affected by modchips.
+ *
+ * @return Region code or 0 if the region cannot be determined
+ */
+CdlRegionCode CdGetRegion(void);
+
+/**
+ * @brief Attempts to disable the CD-ROM controller's region check.
+ *
+ * @details Sends undocumented commands to the drive in an attempt to disable
+ * the region string check, in order to allow reading data from non-PS1 discs
+ * as well as CD-Rs without needing a modchip. As unlocking commands are region
+ * specific, the drive's region must be obtained beforehand using CdGetRegion()
+ * and passed to this function. The unlock persists even if the lid is opened,
+ * but not if a CdlReset command is issued.
+ *
+ * Unlocking is only supported on US, European and Net Yaroze consoles (not on
+ * Japanese models, devkits and most emulators). This function will return 1
+ * without doing anything if CdlRegionDebug is passed as region, as debug
+ * consoles can already read unlicensed discs.
+ *
+ * NOTE: if any callbacks were set using CdReadyCallback() or CdSyncCallback()
+ * prior to calling CdUnlock(), they will be called with an error code as part
+ * of the unlocking sequence, even if the unlock was successful. It is thus
+ * recommended to call this function before setting any callbacks.
+ *
+ * @param region
+ * @return 1 if the drive was successfully unlocked, 0 otherwise
+ *
+ * @see CdGetRegion()
+ */
+int CdUnlock(CdlRegionCode region);
+
+/**
* @brief Retrieves the disc's table of contents.
*
* @details Retrieves the track entries from a CD's table of contents (TOC). The
@@ -832,21 +873,6 @@ int CdStatus(void);
int CdGetToc(CdlLOC *toc);
/**
- * @brief Returns the CD-ROM controller's region code.
- *
- * @details Attempts to fetch region information from the drive using a CdlTest
- * command. This can be used to reliably determine the system's region without
- * having to resort to workarounds like probing the BIOS ROM.
- *
- * This function may return incorrect results on emulators or consoles equipped
- * with CD-ROM drive emulation devices such as the PSIO. It is not affected by
- * modchips.
- *
- * @return Region code or 0 if the region cannot be determined
- */
-CdlRegionCode CdGetRegion(void);
-
-/**
* @brief Sets the CD-ROM volume mixing matrix.
*
* @details Sets the volume levels of the CD-ROM drive's audio output (used for
@@ -1046,5 +1072,3 @@ int CdLoadSession(int session);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/psxetc.h b/libpsn00b/include/psxetc.h
index ae4611e..8dd1dd5 100644
--- a/libpsn00b/include/psxetc.h
+++ b/libpsn00b/include/psxetc.h
@@ -1,6 +1,6 @@
/*
* PSn00bSDK interrupt management library
- * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
*/
/**
@@ -13,8 +13,7 @@
* separate header).
*/
-#ifndef __PSXETC_H
-#define __PSXETC_H
+#pragma once
/* IRQ and DMA channel definitions */
@@ -68,7 +67,7 @@ extern "C" {
* | ID | Channel | Used by |
* | --: | :--------------- | :-------------------------------------- |
* | 0 | IRQ_VBLANK | psxgpu (use VSyncCallback() instead) |
- * | 1 | IRQ_GPU | |
+ * | 1 | IRQ_GPU | psxgpu (use DrawSyncCallback() instead) |
* | 2 | IRQ_CD | psxcd (use CdReadyCallback() instead) |
* | 3 | IRQ_DMA | psxetc (use DMACallback() instead) |
* | 4 | IRQ_TIMER0 | |
@@ -156,19 +155,50 @@ void *DMACallback(DMA_Channel dma, void (*func)(void));
void *GetDMACallback(DMA_Channel dma);
/**
- * @brief Initializes the interrupt dispatcher.
+ * @brief Enables, disables or sets the priority of a DMA channel.
+ *
+ * @details Enables the specified DMA channel and configures its priority (if
+ * priority >= 0) or disables it (if priority = -1). The priority value must be
+ * in 0-7 range, with 0 being the highest priority and 7 the lowest.
+ *
+ * All channels are disabled upon calling ResetCallback(); most libraries will
+ * re-enable them as needed. By default the priority is set to 3 for all
+ * channels.
+ *
+ * @param dma
+ * @param priority Priority in 0-7 range or -1 to disable the channel
+ * @return Previously set priority in 0-7 range, -1 if the channel was disabled
+ */
+int SetDMAPriority(DMA_Channel dma, int priority);
+
+/**
+ * @brief Gets the priority of a DMA channel.
+ *
+ * @details Returns the currently set priority value for the specified DMA
+ * channel in 0-7 range, with 0 being the highest priority and 7 the lowest.
+ * Returns -1 if the channel is not enabled.
+ *
+ * @param dma
+ * @return Priority in 0-7 range, -1 if the channel is disabled
+ *
+ * @see SetDMAPriority()
+ */
+int GetDMAPriority(DMA_Channel dma);
+
+/**
+ * @brief Initializes the interrupt dispatcher and DMA controller.
*
* @details Sets up the interrupt handling system, hooks the BIOS to dispatch
- * interrupts to the library and clears all registered callbacks. This function
- * must be called once at the beginning of the program, prior to registering
- * any IRQ or DMA callbacks.
+ * interrupts to the library, clears all registered callbacks and disables all
+ * DMA channels. This function must be called once at the beginning of the
+ * program, prior to registering any IRQ or DMA callbacks.
*
* ResetCallback() is called by psxgpu's ResetGraph(), so invoking it manually
* is usually not required. Calling ResetCallback() after ResetGraph() will
* actually result in improper initialization, as ResetGraph() registers
* several callbacks used internally by psxgpu.
*
- * @return 0 or -1 if the was already initialized
+ * @return 0 or -1 if the dispatcher was already initialized
*/
int ResetCallback(void);
@@ -196,6 +226,11 @@ void RestartCallback(void);
* Note that interrupts are (obviously) disabled until RestartCallback() is
* called.
*
+ * WARNING: any ongoing background processing or DMA transfer must be stopped
+ * before calling StopCallback(), otherwise crashes may occur. This includes
+ * flushing psxgpu's command queue using DrawSync(), stopping CD-ROM reading
+ * and calling StopPAD() to disable the BIOS controller driver if used.
+ *
* @see RestartCallback()
*/
void StopCallback(void);
@@ -203,5 +238,3 @@ void StopCallback(void);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h
index 26e560f..d7f1ad5 100644
--- a/libpsn00b/include/psxgpu.h
+++ b/libpsn00b/include/psxgpu.h
@@ -1,10 +1,26 @@
/*
* PSn00bSDK GPU library
- * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
*/
-#ifndef __PSXGPU_H
-#define __PSXGPU_H
+/**
+ * @file psxgpu.h
+ * @brief GPU library header
+ *
+ * @details This library provides access to the PS1's GPU through a fully
+ * asynchronous command queue, which allows GPU commands to be batched and sent
+ * efficiently in the background without stalling the CPU. Helper structures
+ * and macros to initialize, generate and link GPU display lists in memory are
+ * also provided, in addition to support for asynchronous VRAM data transfers
+ * and a debug font API that can be used to easily draw text overlays for
+ * debugging purposes.
+ *
+ * This library is for the most part a drop-in replacement for the official
+ * SDK's GPU library and is only missing a handful of functions, mainly related
+ * to Kanji debug fonts and command queue pausing.
+ */
+
+#pragma once
#include <stdint.h>
#include <stddef.h>
@@ -28,6 +44,11 @@ typedef enum _GPU_VideoMode {
MODE_PAL = 1
} GPU_VideoMode;
+typedef enum _GPU_DrawOpType {
+ DRAWOP_TYPE_DMA = 1,
+ DRAWOP_TYPE_GPU_IRQ = 2
+} GPU_DrawOpType;
+
/* Structure macros */
#define setVector(v, _x, _y, _z) \
@@ -83,7 +104,7 @@ typedef enum _GPU_VideoMode {
(p)->u0 = (_u0), (p)->v0 = (_v0), \
(p)->u1 = (_u1), (p)->v1 = (_v1), \
(p)->u2 = (_u2), (p)->v2 = (_v2)
-
+
#define setUV4(p, _u0, _v0, _u1, _v1, _u2, _v2, _u3, _v3) \
(p)->u0 = (_u0), (p)->v0 = (_v0), \
(p)->u1 = (_u1), (p)->v1 = (_v1), \
@@ -101,9 +122,12 @@ typedef enum _GPU_VideoMode {
#define setlen(p, _len) (((P_TAG *) (p))->len = (uint8_t) (_len))
#define setaddr(p, _addr) (((P_TAG *) (p))->addr = (uint32_t) (_addr))
#define setcode(p, _code) (((P_TAG *) (p))->code = (uint8_t) (_code))
+#define setcode_T(p, _code) (((P_TAG_T *) (p))->code = (uint8_t) (_code))
+
#define getlen(p) (((P_TAG *) (p))->len)
#define getaddr(p) (((P_TAG *) (p))->addr)
#define getcode(p) (((P_TAG *) (p))->code)
+#define getcode_T(p) (((P_TAG_T *) (p))->code)
#define nextPrim(p) (void *) (0x80000000 | (((P_TAG *) (p))->addr))
#define isendprim(p) ((((P_TAG *) (p))->addr) == 0xffffff)
@@ -114,16 +138,20 @@ typedef enum _GPU_VideoMode {
#define setSemiTrans(p, abe) \
((abe) ? (getcode(p) |= 2) : (getcode(p) &= ~2))
+#define setSemiTrans_T(p, abe) \
+ ((abe) ? (getcode_T(p) |= 2) : (getcode_T(p) &= ~2))
#define setShadeTex(p, tge) \
((tge) ? (getcode(p) |= 1) : (getcode(p) &= ~1))
+#define setShadeTex_T(p, tge) \
+ ((tge) ? (getcode_T(p) |= 1) : (getcode_T(p) &= ~1))
#define getTPage(tp, abr, x, y) ( \
- (((x) / 64) & 15) | \
- ((((y) / 256) & 1) << 4) | \
- (((abr) & 3) << 5) | \
- (((tp) & 3) << 7) | \
- ((((y) / 512) & 1) << 11) \
+ (((x) & 0x3c0) >> 6) | \
+ (((y) & 0x100) >> 4) | \
+ (((y) & 0x200) << 2) | \
+ (((abr) & 3) << 5) | \
+ (((tp) & 3) << 7) \
)
#define getClut(x, y) (((y) << 6) | (((x) >> 4) & 0x3f))
@@ -147,59 +175,109 @@ typedef enum _GPU_VideoMode {
#define setTile(p) setlen(p, 3), setcode(p, 0x60)
#define setLineF2(p) setlen(p, 3), setcode(p, 0x40)
#define setLineG2(p) setlen(p, 4), setcode(p, 0x50)
-#define setLineF3(p) setlen(p, 5), setcode(p, 0x48), \
- (p)->pad = 0x55555555
-#define setLineG3(p) setlen(p, 7), setcode(p, 0x58), \
- (p)->pad = 0x55555555, (p)->p1 = 0, (p)->p2 = 0
-#define setLineF4(p) setlen(p, 6), setcode(p, 0x4c), \
- (p)->pad = 0x55555555
-#define setLineG4(p) setlen(p, 9), setcode(p, 0x5c), \
- (p)->pad = 0x55555555, (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0
-#define setFill(p) setlen(p, 3), setcode(p, 0x02)
-#define setVram2Vram(p) setlen(p, 8), setcode(p, 0x80), \
+#define setLineF3(p) setlen(p, 5), setcode(p, 0x48), (p)->pad = 0x55555555
+#define setLineG3(p) setlen(p, 7), setcode(p, 0x58), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0
+#define setLineF4(p) setlen(p, 6), setcode(p, 0x4c), (p)->pad = 0x55555555
+#define setLineG4(p) setlen(p, 9), setcode(p, 0x5c), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0
+#define setFill(p) setlen(p, 3), setcode(p, 0x02)
+#define setBlit(p) setlen(p, 8), setcode(p, 0x80), \
(p)->pad[0] = 0, (p)->pad[1] = 0, (p)->pad[2] = 0, (p)->pad[3] = 0
-#define setDrawTPage(p, dfe, dtd, tpage) \
- setlen(p, 1), \
+#define setPolyF3_T(p) setcode_T(p, 0x20)
+#define setPolyFT3_T(p) setcode_T(p, 0x24)
+#define setPolyG3_T(p) setcode_T(p, 0x30)
+#define setPolyGT3_T(p) setcode_T(p, 0x34)
+#define setPolyF4_T(p) setcode_T(p, 0x28)
+#define setPolyFT4_T(p) setcode_T(p, 0x2c)
+#define setPolyG4_T(p) setcode_T(p, 0x38)
+#define setPolyGT4_T(p) setcode_T(p, 0x3c)
+#define setSprt8_T(p) setcode_T(p, 0x74)
+#define setSprt16_T(p) setcode_T(p, 0x7c)
+#define setSprt_T(p) setcode_T(p, 0x64)
+#define setTile1_T(p) setcode_T(p, 0x68)
+#define setTile8_T(p) setcode_T(p, 0x70)
+#define setTile16_T(p) setcode_T(p, 0x78)
+#define setTile_T(p) setcode_T(p, 0x60)
+#define setLineF2_T(p) setcode_T(p, 0x40)
+#define setLineG2_T(p) setcode_T(p, 0x50)
+#define setLineF3_T(p) setcode_T(p, 0x48), (p)->pad = 0x55555555
+#define setLineG3_T(p) setcode_T(p, 0x58), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0
+#define setLineF4_T(p) setcode_T(p, 0x4c), (p)->pad = 0x55555555
+#define setLineG4_T(p) setcode_T(p, 0x5c), (p)->pad = 0x55555555, \
+ (p)->p1 = 0, (p)->p2 = 0, (p)->p3 = 0
+#define setFill_T(p) setcode_T(p, 0x02)
+#define setBlit_T(p) setcode_T(p, 0x80), \
+ (p)->pad[0] = 0, (p)->pad[1] = 0, (p)->pad[2] = 0, (p)->pad[3] = 0
+
+#define setDrawTPage_T(p, dfe, dtd, tpage) \
(p)->code[0] = (0xe1000000 | \
(tpage) | \
- ((dtd) << 9) | \
- ((dfe) << 10) \
+ (((dtd) & 1) << 9) | \
+ (((dfe) & 1) << 10) \
)
+#define setDrawTPage(p, dfe, dtd, tpage) \
+ setlen(p, 1), setDrawTPage_T(p, dfe, dtd, tpage)
-#define setDrawOffset(p, _x, _y) \
- setlen(p, 1), \
- (p)->code[0] = (0xe5000000 | \
- ((_x) % 1024) | \
- (((_y) % 1024) << 11) \
+#define setTexWindow_T(p, r) \
+ (p)->code[0] = (0xe2000000 | \
+ ((r)->w & 0x1f) | \
+ (((r)->h & 0x1f) << 5) | \
+ (((r)->x & 0x1f) << 10) | \
+ (((r)->y & 0x1f) << 15) \
)
+#define setTexWindow(p, r) \
+ setlen(p, 1), setTexWindow_T(p, r)
-#define setDrawMask(p, sb, mt) \
- setlen(p, 1), \
- (p)->code[0] = (0xe6000000 | (sb) | ((mt) << 1))
-
-#define setDrawArea(p, r) \
- setlen(p, 2), \
+#define setDrawAreaXY_T(p, _x0, _y0, _x1, _y1) \
(p)->code[0] = (0xe3000000 | \
- ((r)->x % 1024) | \
- (((r)->y % 1024) << 10) \
+ ((_x0) & 0x3ff) | \
+ (((_y0) & 0x3ff) << 10) \
), \
(p)->code[1] = (0xe4000000 | \
- (((r)->x + (r)->w - 1) % 1024) | \
- ((((r)->y + (r)->h - 1) % 1024) << 10) \
+ ((_x1) & 0x3ff) | \
+ (((_y1) & 0x3ff) << 10) \
)
+#define setDrawAreaXY(p, _x0, _y0, _x1, _y1) \
+ setlen(p, 2), setDrawAreaXY_T(p, _x0, _y0, _x1, _y1)
+
+#define setDrawArea_T(p, r) \
+ setDrawAreaXY_T(p, \
+ (r)->x, \
+ (r)->y, \
+ (r)->x + (r)->w - 1, \
+ (r)->y + (r)->h - 1 \
+ )
+#define setDrawArea(p, r) \
+ setlen(p, 2), setDrawArea_T(p, r)
-#define setTexWindow(p, r) \
- setlen(p, 1), \
- (p)->code[0] = (0xe2000000 | \
- ((r)->w % 32) | \
- (((r)->h % 32) << 5) | \
- (((r)->x % 32) << 10) | \
- (((r)->y % 32) << 15) \
+#define setDrawOffset_T(p, _x, _y) \
+ (p)->code[0] = (0xe5000000 | \
+ ((_x) & 0x7ff) | \
+ (((_y) & 0x7ff) << 11) \
)
+#define setDrawOffset(p, _x, _y) \
+ setlen(p, 1), setDrawOffset_T(p, _x, _y)
+
+#define setDrawStp_T(p, pbw, mt) \
+ (p)->code[0] = (0xe6000000 | (pbw) | ((mt) << 1))
+#define setDrawStp(p, pbw, mt) \
+ setlen(p, 1), setDrawStp_T(p, pbw, mt)
+
+#define setDrawIRQ_T(p) \
+ (p)->code[0] = 0x1f000000
+#define setDrawIRQ(p) \
+ setlen(p, 1), setDrawIRQ_T(p)
/* Primitive structure definitions */
+typedef struct _P_TAG_T {
+ uint32_t color:24;
+ uint32_t code:8;
+} P_TAG_T;
+
typedef struct _P_TAG {
uint32_t addr:24;
uint32_t len:8;
@@ -212,25 +290,31 @@ typedef struct _P_COLOR {
uint32_t pad:8;
} P_COLOR;
-typedef struct _POLY_F3 {
- uint32_t tag;
+// These macros are used to define two variants of each primitive, a regular one
+// and a "tagless" one (_T suffix) without the OT/display list header.
+#define _DEF_PRIM(name, ...) \
+ typedef struct _##name##_T { __VA_ARGS__ } name##_T; \
+ typedef struct _##name { uint32_t tag; __VA_ARGS__ } name;
+#define _DEF_ALIAS(name, target) \
+ typedef struct _##target##_T name##_T; \
+ typedef struct _##target name;
+
+_DEF_PRIM(POLY_F3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
-} POLY_F3;
+)
-typedef struct _POLY_F4 {
- uint32_t tag;
+_DEF_PRIM(POLY_F4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
int16_t x3, y3;
-} POLY_F4;
+)
-typedef struct _POLY_FT3 {
- uint32_t tag;
+_DEF_PRIM(POLY_FT3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
@@ -241,10 +325,9 @@ typedef struct _POLY_FT3 {
int16_t x2, y2;
uint8_t u2, v2;
uint16_t pad;
-} POLY_FT3;
+)
-typedef struct _POLY_FT4 {
- uint32_t tag;
+_DEF_PRIM(POLY_FT4,
uint8_t r0, g0, b0, code;
uint16_t x0, y0;
uint8_t u0, v0;
@@ -258,20 +341,18 @@ typedef struct _POLY_FT4 {
int16_t x3, y3;
uint8_t u3, v3;
uint16_t pad1;
-} POLY_FT4;
+)
-typedef struct _POLY_G3 {
- uint32_t tag;
+_DEF_PRIM(POLY_G3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, pad0;
int16_t x1, y1;
uint8_t r2, g2, b2, pad1;
int16_t x2, y2;
-} POLY_G3;
+)
-typedef struct _POLY_G4 {
- uint32_t tag;
+_DEF_PRIM(POLY_G4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, pad0;
@@ -280,10 +361,9 @@ typedef struct _POLY_G4 {
int16_t x2, y2;
uint8_t r3, g3, b3, pad2;
int16_t x3, y3;
-} POLY_G4;
+)
-typedef struct _POLY_GT3 {
- uint32_t tag;
+_DEF_PRIM(POLY_GT3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
@@ -296,10 +376,9 @@ typedef struct _POLY_GT3 {
int16_t x2, y2;
uint8_t u2, v2;
uint16_t pad2;
-} POLY_GT3;
+)
-typedef struct _POLY_GT4 {
- uint32_t tag;
+_DEF_PRIM(POLY_GT4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
@@ -316,34 +395,30 @@ typedef struct _POLY_GT4 {
int16_t x3, y3;
uint8_t u3, v3;
uint16_t pad4;
-} POLY_GT4;
+)
-typedef struct _LINE_F2 {
- uint32_t tag;
+_DEF_PRIM(LINE_F2,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
-} LINE_F2;
+)
-typedef struct _LINE_G2 {
- uint32_t tag;
+_DEF_PRIM(LINE_G2,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, p1;
int16_t x1, y1;
-} LINE_G2;
+)
-typedef struct _LINE_F3 {
- uint32_t tag;
+_DEF_PRIM(LINE_F3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
uint32_t pad;
-} LINE_F3;
+)
-typedef struct _LINE_G3 {
- uint32_t tag;
+_DEF_PRIM(LINE_G3,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, p1;
@@ -351,20 +426,18 @@ typedef struct _LINE_G3 {
uint8_t r2, g2, b2, p2;
int16_t x2, y2;
uint32_t pad;
-} LINE_G3;
+)
-typedef struct _LINE_F4 {
- uint32_t tag;
+_DEF_PRIM(LINE_F4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t x1, y1;
int16_t x2, y2;
int16_t x3, y3;
uint32_t pad;
-} LINE_F4;
+)
-typedef struct _LINE_G4 {
- uint32_t tag;
+_DEF_PRIM(LINE_G4,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t r1, g1, b1, p1;
@@ -374,88 +447,80 @@ typedef struct _LINE_G4 {
uint8_t r3, g3, b3, p3;
int16_t x3, y3;
uint32_t pad;
-} LINE_G4;
+)
-typedef struct _TILE {
- uint32_t tag;
+_DEF_PRIM(TILE,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
int16_t w, h;
-} TILE;
+)
-struct _TILE_FIXED {
- uint32_t tag;
+_DEF_PRIM(TILE_1,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
-};
-typedef struct _TILE_FIXED TILE_1;
-typedef struct _TILE_FIXED TILE_8;
-typedef struct _TILE_FIXED TILE_16;
+)
+_DEF_ALIAS(TILE_8, TILE_1)
+_DEF_ALIAS(TILE_16, TILE_1)
-typedef struct _SPRT {
- uint32_t tag;
+_DEF_PRIM(SPRT,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
uint16_t clut;
uint16_t w, h;
-} SPRT;
+)
-struct _SPRT_FIXED {
- uint32_t tag;
+_DEF_PRIM(SPRT_1,
uint8_t r0, g0, b0, code;
int16_t x0, y0;
uint8_t u0, v0;
uint16_t clut;
-};
-typedef struct _SPRT_FIXED SPRT_8;
-typedef struct _SPRT_FIXED SPRT_16;
-
-typedef struct _DR_ENV {
- uint32_t tag;
- uint32_t code[8];
-} DR_ENV;
-
-typedef struct _DR_AREA {
- uint32_t tag;
- uint32_t code[2];
-} DR_AREA;
-
-typedef struct _DR_OFFSET {
- uint32_t tag;
- uint32_t code[1];
-} DR_OFFSET;
-
-typedef struct _DR_TWIN {
- uint32_t tag;
- uint32_t code[2];
-} DR_TWIN;
-
-typedef struct _DR_TPAGE {
- uint32_t tag;
- uint32_t code[1];
-} DR_TPAGE;
-
-typedef struct _DR_MASK {
- uint32_t tag;
- uint32_t code[1];
-} DR_MASK;
+)
+_DEF_ALIAS(SPRT_8, SPRT_1)
+_DEF_ALIAS(SPRT_16, SPRT_1)
-typedef struct _FILL {
- uint32_t tag;
+_DEF_PRIM(FILL,
uint8_t r0, g0, b0, code;
- uint16_t x0, y0; // Note: coordinates must be in 16 pixel steps
+ uint16_t x0, y0;
uint16_t w, h;
-} FILL;
+)
-typedef struct _VRAM2VRAM {
- uint32_t tag;
+_DEF_PRIM(DR_MOVE,
uint8_t p0, p1, p2, code;
uint16_t x0, y0;
uint16_t x1, y1;
uint16_t w, h;
- uint32_t pad[4];
-} VRAM2VRAM;
+)
+
+_DEF_PRIM(DR_AREA,
+ uint32_t code[2];
+)
+_DEF_PRIM(DR_OFFSET,
+ uint32_t code[1];
+)
+_DEF_PRIM(DR_TWIN,
+ uint32_t code[1];
+)
+_DEF_PRIM(DR_TPAGE,
+ uint32_t code[1];
+)
+_DEF_PRIM(DR_STP,
+ uint32_t code[1];
+)
+_DEF_PRIM(DR_IRQ,
+ uint32_t code[1];
+)
+
+_DEF_PRIM(DR_ENV,
+ DR_TPAGE_T tpage;
+ DR_TWIN_T twin;
+ DR_AREA_T area;
+ DR_OFFSET_T offset;
+ FILL_T fill;
+)
+
+#undef _DEF_PRIM
+#undef _DEF_ALIAS
/* Structure definitions */
@@ -478,13 +543,13 @@ typedef struct _DISPENV {
typedef struct _DRAWENV {
RECT clip; // Drawing area
int16_t ofs[2]; // GPU draw offset (relative to draw area)
- RECT tw; // Texture window (doesn't do anything atm)
+ RECT tw; // Texture window
uint16_t tpage; // Initial tpage value
uint8_t dtd; // Dither processing flag (simply OR'ed to tpage)
uint8_t dfe; // Drawing to display area blocked/allowed (simply OR'ed to tpage)
uint8_t isbg; // Clear draw area if non-zero
uint8_t r0, g0, b0; // Draw area clear color (if isbg iz nonzero)
- DR_ENV dr_env; // Draw mode packet area (used by PutDrawEnv)
+ DR_ENV dr_env; // GPU primitive cache area (used internally)
} DRAWENV;
typedef struct _TIM_IMAGE {
@@ -521,31 +586,35 @@ void PutDrawEnv(DRAWENV *env);
void PutDrawEnvFast(DRAWENV *env);
int GetODE(void);
+int IsIdleGPU(int timeout);
int VSync(int mode);
void *VSyncHaltFunction(void (*func)(void));
void *VSyncCallback(void (*func)(void));
-int EnqueueDrawOp(
- void (*func)(uint32_t, uint32_t, uint32_t),
- uint32_t arg1,
- uint32_t arg2,
- uint32_t arg3
-);
+void SetDrawOpType(GPU_DrawOpType type);
+int EnqueueDrawOp(void (*func)(), uint32_t arg1, uint32_t arg2, uint32_t arg3);
int DrawSync(int mode);
void *DrawSyncCallback(void (*func)(void));
int LoadImage(const RECT *rect, const uint32_t *data);
int StoreImage(const RECT *rect, uint32_t *data);
-//int MoveImage(const RECT *rect, int x, int y);
+int MoveImage(const RECT *rect, int x, int y);
void LoadImage2(const RECT *rect, const uint32_t *data);
void StoreImage2(const RECT *rect, uint32_t *data);
-//void MoveImage2(const RECT *rect, int x, int y);
+void MoveImage2(const RECT *rect, int x, int y);
void ClearOTagR(uint32_t *ot, size_t length);
void ClearOTag(uint32_t *ot, size_t length);
int DrawOTag(const uint32_t *ot);
+int DrawOTagIRQ(const uint32_t *ot);
int DrawOTagEnv(const uint32_t *ot, DRAWENV *env);
+int DrawOTagEnvIRQ(const uint32_t *ot, DRAWENV *env);
void DrawOTag2(const uint32_t *ot);
+void DrawOTagIRQ2(const uint32_t *ot);
+int DrawBuffer(const uint32_t *buf, size_t length);
+int DrawBufferIRQ(const uint32_t *buf, size_t length);
+void DrawBuffer2(const uint32_t *buf, size_t length);
+void DrawBufferIRQ2(const uint32_t *buf, size_t length);
void DrawPrim(const uint32_t *pri);
void AddPrim(uint32_t *ot, const void *pri);
@@ -565,5 +634,3 @@ char *FntFlush(int id);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/psxgte.h b/libpsn00b/include/psxgte.h
index 91dfd6a..2200a55 100644
--- a/libpsn00b/include/psxgte.h
+++ b/libpsn00b/include/psxgte.h
@@ -14,8 +14,7 @@
* registers and issue commands to the GTE.
*/
-#ifndef __PSXGTE_H
-#define __PSXGTE_H
+#pragma once
#include <stdint.h>
@@ -259,5 +258,3 @@ void Square0(VECTOR *v0, VECTOR *v1);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/psxkernel.h b/libpsn00b/include/psxkernel.h
deleted file mode 100644
index 0c55bcb..0000000
--- a/libpsn00b/include/psxkernel.h
+++ /dev/null
@@ -1,45 +0,0 @@
-#ifndef _PSXKERNEL_H
-#define _PSXKERNEL_H
-
-// Event descriptors
-#define DescMask 0xff000000 // Event descriptor mask
-#define DescTH DescMask
-#define DescHW 0xf0000000 // Hardware event (IRQ)
-#define DescEV 0xf1000000 // Event event
-#define DescRC 0xf2000000 // Root counter event
-#define DescUEV 0xf3000000 // User event
-#define DescSW 0xf4000000 // BIOS event
-
-// Hardware events
-#define HwVBLANK (DescHW|0x01) // VBlank
-#define HwGPU (DescHW|0x02) // GPU
-#define HwCdRom (DescHW|0x03) // CDROM
-#define HwDMAC (DescHW|0x04) // DMA
-#define HwRTC0 (DescHW|0x05) // Timer 0
-#define HwRTC1 (DescHW|0x06) // Timer 1
-#define HwRTC2 (DescHW|0x07) // Timer 2
-#define HwCNTL (DescHW|0x08) // Controller
-#define HwSPU (DescHW|0x09) // SPU
-#define HwPIO (DescHW|0x0a) // PIO & lightgun
-#define HwSIO (DescHW|0x0b) // Serial
-
-#define HwCPU (DescHW|0x10) // Processor exception
-#define HwCARD (DescHW|0x11) // Memory card (lower level BIOS functions)
-#define HwCard_0 (DescHW|0x12) // Memory card (unused)
-#define HwCard_1 (DescHW|0x13) // Memory card (unused)
-#define SwCARD (DescSW|0x01) // Memory card (higher level BIOS functions)
-#define SwMATH (DescSW|0x02) // Libmath related apparently, unknown purpose
-
-#define RCntCNT0 (DescRC|0x00) // Root counter 0 (dot clock)
-#define RCntCNT1 (DescRC|0x01) // Horizontal sync
-#define RCntCNT2 (DescRC|0x02) // 1/8 of system clock
-#define RCntCNT3 (DescRC|0x03) // Vertical blank
-
-#define RCntMdINTR 0x1000 // General interrupt
-#define RCntMdNOINTR 0x2000 // New device
-#define RCntMdSC 0x0001 // Counter becomes zero
-#define RCntMdSP 0x0000 // Unknown purpose
-#define RCntMdFR 0x0000
-#define RCntMdGATE 0x0010 // Command acknowledged
-
-#endif // _PSXKERNEL_H \ No newline at end of file
diff --git a/libpsn00b/include/psxpad.h b/libpsn00b/include/psxpad.h
index 32f7f8a..09f28c4 100644
--- a/libpsn00b/include/psxpad.h
+++ b/libpsn00b/include/psxpad.h
@@ -11,8 +11,7 @@
* Reference: https://gist.github.com/scanlime/5042071
*/
-#ifndef _PSXPAD_H
-#define _PSXPAD_H
+#pragma once
#include <stdint.h>
@@ -234,5 +233,3 @@ typedef struct __attribute__((packed)) _MemCardRequest {
uint8_t checksum; // = lba_h ^ lba_l ^ data (CMD_WRITE only)
uint8_t dummy2[3];
} MemCardRequest;
-
-#endif \ No newline at end of file
diff --git a/libpsn00b/include/psxpress.h b/libpsn00b/include/psxpress.h
index dc1d52c..f26e030 100644
--- a/libpsn00b/include/psxpress.h
+++ b/libpsn00b/include/psxpress.h
@@ -1,6 +1,6 @@
/*
* PSn00bSDK MDEC library
- * (C) 2022 spicyjpeg - MPL licensed
+ * (C) 2022-2023 spicyjpeg - MPL licensed
*/
/**
@@ -17,11 +17,12 @@
* FMV playback is not part of this library per se, but can implemented using
* the APIs defined here alongside some code to stream data from the CD drive.
*
- * Currently only version 1 and 2 .BS files are supported.
+ * Currently bitstream versions 1, 2 and 3 are supported. Version 0 and .IKI
+ * bitstreams are not supported, but no encoder is publicly available for those
+ * anyway.
*/
-#ifndef __PSXPRESS_H
-#define __PSXPRESS_H
+#pragma once
#include <stdint.h>
#include <stddef.h>
@@ -34,28 +35,26 @@ typedef struct _DECDCTENV {
int16_t dct[64]; // Inverse DCT matrix (2.14 fixed-point)
} DECDCTENV;
-// This is the "small" lookup table used by DecDCTvlc(). It can be copied to
-// the scratchpad.
+typedef struct _VLC_TableV2 {
+ uint16_t ac0[2];
+ uint32_t ac2[8], ac3[64];
+ uint16_t ac4[8], ac5[8], ac7[16], ac8[32];
+ uint16_t ac9[32], ac10[32], ac11[32], ac12[32];
+} VLC_TableV2;
+
+typedef struct _VLC_TableV3 {
+ uint16_t ac0[2];
+ uint32_t ac2[8], ac3[64];
+ uint16_t ac4[8], ac5[8], ac7[16], ac8[32];
+ uint16_t ac9[32], ac10[32], ac11[32], ac12[32];
+ uint8_t dc[128], dc_len[9];
+ uint8_t _reserved[3];
+} VLC_TableV3;
+
typedef struct _DECDCTTAB {
- uint16_t lut0[2];
- uint32_t lut2[8];
- uint32_t lut3[64];
- uint16_t lut4[8];
- uint16_t lut5[8];
- uint16_t lut7[16];
- uint16_t lut8[32];
- uint16_t lut9[32];
- uint16_t lut10[32];
- uint16_t lut11[32];
- uint16_t lut12[32];
+ uint32_t ac[8192], ac00[512];
} DECDCTTAB;
-// This is the "large" table used by DecDCTvlc2().
-typedef struct _DECDCTTAB2 {
- uint32_t lut[8192];
- uint32_t lut00[512];
-} DECDCTTAB2;
-
typedef enum _DECDCTMODE {
DECDCT_MODE_24BPP = 1,
DECDCT_MODE_16BPP = 0,
@@ -66,8 +65,9 @@ typedef enum _DECDCTMODE {
typedef struct _VLC_Context {
const uint32_t *input;
uint32_t window, next_window, remaining;
- uint16_t quant_scale;
int8_t is_v3, bit_offset, block_index, coeff_index;
+ uint16_t quant_scale;
+ int16_t last_y, last_cr, last_cb;
} VLC_Context;
// Despite what some docs claim, the "number of 32-byte blocks" and "always
@@ -233,8 +233,9 @@ int DecDCToutSync(int mode);
* frame) into a buffer that can be passed to DecDCTin(). This function uses a
* small (<1 KB) lookup table combined with the GTE to accelerate the process;
* performance is roughly on par with DecDCTvlcStart2() if the lookup table
- * is copied to the scratchpad beforehand by calling DecDCTvlcCopyTable(). The
- * contents of the GTE's LZCR register, if any, will be destroyed.
+ * is copied to the scratchpad beforehand by calling DecDCTvlcCopyTableV2() or
+ * DecDCTvlcCopyTableV3(). The contents of the GTE's LZCS and LZCR registers,
+ * if any, will be destroyed.
*
* A VLC_Context object must be created and passed to this function, which will
* then proceed to initialize its fields. The max_size argument sets the
@@ -244,8 +245,6 @@ int DecDCToutSync(int mode);
* can be different). If max_size = 0, the entire frame will always be decoded
* in one shot.
*
- * Only bitstream version 2 is currently supported.
- *
* WARNING: InitGeom() must be called prior to using DecDCTvlcStart() for the
* first time. Attempting to call this function with the GTE disabled will
* result in a crash.
@@ -256,7 +255,7 @@ int DecDCToutSync(int mode);
* @param bs
* @return 0, 1 if more data needs to be output or -1 in case of failure
*
- * @see DecDCTvlcContinue(), DecDCTvlcCopyTable()
+ * @see DecDCTvlcContinue(), DecDCTvlcCopyTableV2(), DecDCTvlcCopyTableV3()
*/
int DecDCTvlcStart(VLC_Context *ctx, uint32_t *buf, size_t max_size, const uint32_t *bs);
@@ -275,7 +274,8 @@ int DecDCTvlcStart(VLC_Context *ctx, uint32_t *buf, size_t max_size, const uint3
* context returned 0; in that case the context shall be discarded or reused to
* decode another bitstream.
*
- * The contents of the GTE's LZCR register, if any, will be destroyed.
+ * The contents of the GTE's LZCS and LZCR registers, if any, will be
+ * destroyed.
*
* See DecDCTvlcStart() for more details.
*
@@ -309,7 +309,7 @@ int DecDCTvlcContinue(VLC_Context *ctx, uint32_t *buf, size_t max_size);
* @param buf
* @return 0, 1 if more data needs to be output or -1 in case of failure
*
- * @see DecDCTvlcSize(), DecDCTvlcCopyTable()
+ * @see DecDCTvlcSize(), DecDCTvlcCopyTableV2(), DecDCTvlcCopyTableV3()
*/
int DecDCTvlc(const uint32_t *bs, uint32_t *buf);
@@ -332,23 +332,60 @@ int DecDCTvlc(const uint32_t *bs, uint32_t *buf);
size_t DecDCTvlcSize(size_t size);
/**
- * @brief Moves the lookup table used by the .BS decompressor to the scratchpad
- * region.
+ * @brief Copies the lookup tables used by the .BS decompressor (v1/v2) to the
+ * scratchpad region.
*
- * @details Copies the small (<1 KB) lookup table used by DecDCTvlcContinue(),
- * DecDCTvlcStart() and DecDCTvlc() (a DECDCTTAB structure) to the specified
- * address. A copy of this table is always present in main RAM, however this
- * function can be used to copy it to the scratchpad region to boost
- * decompression performance.
+ * @details Copies the lookup table used by DecDCTvlcContinue(),
+ * DecDCTvlcStart() and DecDCTvlc() to the specified address. A copy of this
+ * table is always present in main RAM, however this function can be used to
+ * copy it to the scratchpad region to boost decompression performance.
+ *
+ * This function copies a 676-byte table (VLC_TableV2 structure) containing
+ * only the data necessary for decoding version 1 and 2 bitstreams, to help
+ * save scratchpad space. If support for version 3 is required,
+ * DecDCTvlcCopyTableV3() can be used instead to copy the full 816-byte table.
*
* The address passed to this function is saved. Calls to DecDCTvlcStart(),
* DecDCTvlcContinue() and DecDCTvlc() will automatically use the last table
- * copied. Call DecDCTvlcCopyTable(0) to revert to using the library's internal
- * table in main RAM.
+ * copied. Call DecDCTvlcCopyTableV2(0) or DecDCTvlcCopyTableV3(0) to revert to
+ * using the library's internal table in main RAM.
+ *
+ * WARNING: attempting to decode a version 3 .BS file or .STR frame after
+ * calling this function will result in undefined behavior and potentially a
+ * crash. To re-enable version 3 decoding, use DecDCTvlcCopyTableV3() to copy
+ * the full table to the scratchpad or revert to using the built-in table in
+ * main RAM.
+ *
+ * @param addr Pointer to free 676-byte area in scratchpad region or 0 to reset
*
- * @param addr Pointer to free area in scratchpad region or 0 to reset
+ * @see DecDCTvlcCopyTableV3()
*/
-void DecDCTvlcCopyTable(DECDCTTAB *addr);
+void DecDCTvlcCopyTableV2(VLC_TableV2 *addr);
+
+/**
+ * @brief Copies the lookup tables used by the .BS decompressor (v1/v2/v3) to
+ * the scratchpad region.
+ *
+ * @details Copies the lookup table used by DecDCTvlcContinue(),
+ * DecDCTvlcStart() and DecDCTvlc() to the specified address. A copy of this
+ * table is always present in main RAM, however this function can be used to
+ * copy it to the scratchpad region to boost decompression performance.
+ *
+ * This function copies the full 816-byte table (VLC_TableV3 structure),
+ * including the data used to decode version 3 bitstreams. If support for
+ * version 3 is not required, DecDCTvlcCopyTableV2() can be used instead to
+ * save scratchpad space by only copying the first 676 bytes of the table.
+ *
+ * The address passed to this function is saved. Calls to DecDCTvlcStart(),
+ * DecDCTvlcContinue() and DecDCTvlc() will automatically use the last table
+ * copied. Call DecDCTvlcCopyTableV2(0) or DecDCTvlcCopyTableV3(0) to revert to
+ * using the library's internal table in main RAM.
+ *
+ * @param addr Pointer to free 816-byte area in scratchpad region or 0 to reset
+ *
+ * @see DecDCTvlcCopyTableV2()
+ */
+void DecDCTvlcCopyTableV3(VLC_TableV3 *addr);
/**
* @brief Decompresses or begins decompressing a .BS file into MDEC codes
@@ -360,8 +397,8 @@ void DecDCTvlcCopyTable(DECDCTTAB *addr);
* calling DecDCTvlcBuild(), but does not use the GTE nor the scratchpad.
* Depending on the specific bitstream being decoded DecDCTvlcStart2() might be
* slightly faster or slower than DecDCTvlcStart() with its lookup table copied
- * to the scratchpad (see DecDCTvlcCopyTable()). DecDCTvlcStart() with the
- * table in main RAM tends to be much slower.
+ * to the scratchpad (see DecDCTvlcCopyTableV2() and DecDCTvlcCopyTableV3()).
+ * DecDCTvlcStart() with the table in main RAM tends to be much slower.
*
* A VLC_Context object must be created and passed to this function, which will
* then proceed to initialize its fields. The max_size argument sets the
@@ -371,7 +408,8 @@ void DecDCTvlcCopyTable(DECDCTTAB *addr);
* buffer can be different). If max_size = 0, the entire frame will always be
* decoded in one shot.
*
- * Only bitstream version 2 is currently supported.
+ * This function only supports decoding version 1 and 2 bitstreams. Use
+ * DecDCTvlcStart() to decode a version 3 bitstream.
*
* @param ctx Pointer to VLC_Context structure (which will be initialized)
* @param buf
@@ -432,7 +470,7 @@ int DecDCTvlcContinue2(VLC_Context *ctx, uint32_t *buf, size_t max_size);
*
* @see DecDCTvlcSize2(), DecDCTvlcBuild()
*/
-int DecDCTvlc2(const uint32_t *bs, uint32_t *buf, DECDCTTAB2 *table);
+int DecDCTvlc2(const uint32_t *bs, uint32_t *buf, DECDCTTAB *table);
/**
* @brief Sets the maximum amount of data to be decompressed (alternate
@@ -458,7 +496,7 @@ size_t DecDCTvlcSize2(size_t size);
* the .BS decompressor.
*
* @details Generates the lookup table required by DecDCTvlcStart2(),
- * DecDCTvlcContinue2() and DecDCTvlc2() (a DECDCTTAB2 structure) into the
+ * DecDCTvlcContinue2() and DecDCTvlc2() (a DECDCTTAB structure) into the
* specified buffer. Since the table is relatively large (34 KB), it is
* recommended to only generate it in a dynamically-allocated buffer when
* needed and deallocate the buffer afterwards.
@@ -468,10 +506,8 @@ size_t DecDCTvlcSize2(size_t size);
*
* @param table
*/
-void DecDCTvlcBuild(DECDCTTAB2 *table);
+void DecDCTvlcBuild(DECDCTTAB *table);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/psxsio.h b/libpsn00b/include/psxsio.h
index 449e43a..8932830 100644
--- a/libpsn00b/include/psxsio.h
+++ b/libpsn00b/include/psxsio.h
@@ -18,8 +18,7 @@
* debugging purposes.
*/
-#ifndef __PSXSIO_H
-#define __PSXSIO_H
+#pragma once
#include <stdint.h>
@@ -280,5 +279,3 @@ void DelSIO(void);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/psxsn.h b/libpsn00b/include/psxsn.h
new file mode 100644
index 0000000..1acbc18
--- /dev/null
+++ b/libpsn00b/include/psxsn.h
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#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
diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h
index cdc3ac7..b544952 100644
--- a/libpsn00b/include/psxspu.h
+++ b/libpsn00b/include/psxspu.h
@@ -1,10 +1,25 @@
/*
* PSn00bSDK SPU library
- * (C) 2019-2022 Lameguy64, spicyjpeg - MPL licensed
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
*/
-#ifndef __PSXSPU_H
-#define __PSXSPU_H
+/**
+ * @file psxspu.h
+ * @brief SPU library header
+ *
+ * @details The PSn00bSDK SPU library allows for SPU initialization, DMA
+ * transfers (both sample data uploads and capture buffer reads) and provides
+ * helper macros for accessing SPU control registers, which can be used to
+ * control sample playback on each channel, configure reverb and enable more
+ * advanced features such as interrupts.
+ *
+ * This library currently has fewer functions than its Sony SDK counterpart, in
+ * part because it is not yet complete but also since the vast majority of the
+ * Sony library's functions are redundant, inefficient and can be replaced with
+ * simple SPU register writes.
+ */
+
+#pragma once
#include <stdint.h>
#include <stddef.h>
@@ -12,6 +27,7 @@
/* Definitions */
+#if 0
typedef enum _SPU_AttrMask {
SPU_VOICE_VOLL = 1 << 0, // Left volume
SPU_VOICE_VOLR = 1 << 1, // Right volume
@@ -33,6 +49,7 @@ typedef enum _SPU_AttrMask {
SPU_VOICE_ADSR_ADSR1 = 1 << 17,
SPU_VOICE_ADSR_ADSR2 = 1 << 18
} SPU_AttrMask;
+#endif
typedef enum _SPU_TransferMode {
SPU_TRANSFER_BY_DMA = 0,
@@ -46,6 +63,7 @@ typedef enum _SPU_WaitMode {
/* Structure definitions */
+#if 0
typedef struct _SpuVolume {
int16_t left, right;
} SpuVolume;
@@ -72,6 +90,7 @@ typedef struct _SpuCommonAttr {
SpuVolume mvol, mvolmode, mvolx;
SpuExtAttr cd, ext;
} SpuCommonAttr;
+#endif
/* Macros */
@@ -137,11 +156,11 @@ size_t SpuRead(uint32_t *data, size_t size);
size_t SpuWrite(const uint32_t *data, size_t size);
size_t SpuWritePartly(const uint32_t *data, size_t size);
SPU_TransferMode SpuSetTransferMode(SPU_TransferMode mode);
+SPU_TransferMode SpuGetTransferMode(void);
uint32_t SpuSetTransferStartAddr(uint32_t addr);
+uint32_t SpuGetTransferStartAddr(void);
int SpuIsTransferCompleted(int mode);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/stdio.h b/libpsn00b/include/stdio.h
index 8aaf4c7..1bb5b74 100644
--- a/libpsn00b/include/stdio.h
+++ b/libpsn00b/include/stdio.h
@@ -1,39 +1,26 @@
-#ifndef _STDIO_H
-#define _STDIO_H
+/*
+ * PSn00bSDK standard library
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
+ */
-#include <stdarg.h>
+#pragma once
-// BIOS seek modes
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#endif
-#ifndef SEEK_CUR
-#define SEEK_CUR 1
-#endif
-#ifndef SEEK_END
-#define SEEK_END 2 /* warning: reportedly buggy */
-#endif
+#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
-// The following functions use the BIOS
-extern void printf (const char *__format, ...);
-
-extern int getc(int __fd);
-extern int putc(int __char, int __fd);
+/* String I/O API (provided by BIOS) */
-#define fputc(__char, __fd) putc(__char, __fd)
-#define fgetc(__char, __fd) getc(__char, __fd)
+int printf(const char *fmt, ...);
+char *gets(char *str);
+void puts(const char *str);
+int getchar(void);
+void putchar(int ch);
-// Console TTY
-extern void gets(char *__s);
-extern void puts(const char *__s);
-extern int getchar(void);
-extern void putchar(int __c);
+/* String formatting API (built-in) */
-// The following functions do not use the BIOS
int vsnprintf(char *string, unsigned int size, const char *fmt, va_list ap);
int vsprintf(char *string, const char *fmt, va_list ap);
int sprintf(char *string, const char *fmt, ...);
@@ -45,5 +32,3 @@ int sscanf(const char *str, const char *fmt, ...);
#ifdef __cplusplus
}
#endif
-
-#endif // _STDIO_H \ No newline at end of file
diff --git a/libpsn00b/include/stdlib.h b/libpsn00b/include/stdlib.h
index 049d067..19761df 100644
--- a/libpsn00b/include/stdlib.h
+++ b/libpsn00b/include/stdlib.h
@@ -1,10 +1,9 @@
/*
* PSn00bSDK standard library
- * (C) 2019-2022 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
+ * (C) 2019-2023 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
*/
-#ifndef __STDLIB_H
-#define __STDLIB_H
+#pragma once
#include <stddef.h>
@@ -39,11 +38,11 @@ void srand(int seed);
int abs(int j);
long labs(long i);
-long strtol(const char *nptr, char **endptr, int base);
-long long strtoll(const char *nptr, char **endptr, int base);
-float strtof(const char *nptr, char **endptr);
-double strtod(const char *nptr, char **endptr);
-long double strtold(const char *nptr, char **endptr);
+long strtol(const char *str, char **str_end, int base);
+long long strtoll(const char *str, char **str_end, int base);
+//float strtof(const char *str, char **str_end);
+//double strtod(const char *str, char **str_end);
+//long double strtold(const char *str, char **str_end);
void InitHeap(void *addr, size_t size);
void *sbrk(ptrdiff_t incr);
@@ -59,5 +58,3 @@ void free(void *ptr);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/string.h b/libpsn00b/include/string.h
index ceee066..6310b1a 100644
--- a/libpsn00b/include/string.h
+++ b/libpsn00b/include/string.h
@@ -1,37 +1,40 @@
/*
* PSn00bSDK standard library
- * (C) 2019-2022 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
+ * (C) 2019-2023 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
*/
-#ifndef __STRING_H
-#define __STRING_H
+#pragma once
+
+#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
-int strcmp(const char *dst , const char *src);
-int strncmp(const char *dst , const char *src , int len);
-char *strpbrk(const char *dst , const char *src);
-char *strtok(char *s , char *set);
-char *strstr(const char *big , const char *little);
-
-char *strcat(char *s , const char *append);
-char *strncat(char *s , const char *append, int n);
-char *strcpy(char *dst , const char *src);
-char *strncpy(char *dst , const char *src , int n);
-int strlen(const char *s);
-char *strchr(const char *s , int c);
-char *strrchr(const char *s , int c);
-
-void *memmove(void *dst , const void *src , int n);
-void *memchr(void *s , int c , int n);
-void *memcpy(void *dst , const void *src , int n);
-void *memset(void *dst , char c , int n);
-int memcmp(const void *b1 , const void *b2 , int n);
+void *memset(void *dest, int ch, size_t count);
+void *memcpy(void *dest, const void *src, size_t count);
+void *memccpy(void *dest, const void *src, int ch, size_t count);
+void *memmove(void *dest, const void *src, size_t count);
+int memcmp(const void *lhs, const void *rhs, size_t count);
+void *memchr(const void *ptr, int ch, size_t count);
+
+char *strcpy(char *dest, const char *src);
+char *strncpy(char *dest, const char *src, size_t count);
+int strcmp(const char *lhs, const char *rhs);
+int strncmp(const char *lhs, const char *rhs, size_t count);
+char *strchr(const char *str, int ch);
+char *strrchr(const char *str, int ch);
+char *strpbrk(const char *str, const char *breakset);
+char *strstr(const char *str, const char *substr);
+
+size_t strlen(const char *str);
+char *strcat(char *dest, const char *src);
+char *strncat(char *dest, const char *src, size_t count);
+char *strdup(const char *str);
+char *strndup(const char *str, size_t count);
+
+char *strtok(char *str, const char *delim);
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/libpsn00b/include/strings.h b/libpsn00b/include/strings.h
index 7223ab9..0595637 100644
--- a/libpsn00b/include/strings.h
+++ b/libpsn00b/include/strings.h
@@ -3,8 +3,7 @@
* (C) 2019-2022 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed
*/
-#ifndef __STRINGS_H
-#define __STRINGS_H
+#pragma once
#include <string.h>
@@ -15,5 +14,3 @@
#define bcmp(b1, b2, len) memcmp(b1, b2, len)
#define index(s, c) strchr(s, c)
#define rindex(s, c) strrchr(s, c)
-
-#endif
diff --git a/libpsn00b/include/sys/fcntl.h b/libpsn00b/include/sys/fcntl.h
index dfbf5b2..54c2d05 100644
--- a/libpsn00b/include/sys/fcntl.h
+++ b/libpsn00b/include/sys/fcntl.h
@@ -1,8 +1,10 @@
-#ifndef _SYS_FCNTL_H
-#define _SYS_FCNTL_H
+/*
+ * PSn00bSDK kernel API library
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
+ */
+
+#pragma once
-// File control mode flags for BIOS file functions
-// (many weren't documented in nocash docs)
#define FREAD 0x1 // Read
#define FWRITE 0x2 // Write
#define FNBLOCK 0x4 // Non-blocking read access
@@ -16,5 +18,3 @@
#define FNBUF 0x4000 // No ring buffer and terminal interrupt
#define FASYNC 0x8000 // Asynchronous I/O
#define FNBLOCKS(a) (a<<16) // Number of blocks? (from nocash docs)
-
-#endif \ No newline at end of file
diff --git a/libpsn00b/include/sys/ioctl.h b/libpsn00b/include/sys/ioctl.h
new file mode 100644
index 0000000..af65e5d
--- /dev/null
+++ b/libpsn00b/include/sys/ioctl.h
@@ -0,0 +1,13 @@
+/*
+ * PSn00bSDK kernel API library
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
+ */
+
+#pragma once
+
+#define EOF -1
+
+#define FIONBLOCK (('f'<<8)|1)
+#define FIOCSCAN (('f'<<8)|2)
+
+#define DIOFORMAT (('d'<<8)|1)
diff --git a/libpsn00b/include/sys/types.h b/libpsn00b/include/sys/types.h
index da43590..9075b5e 100644
--- a/libpsn00b/include/sys/types.h
+++ b/libpsn00b/include/sys/types.h
@@ -1,13 +1,13 @@
-#ifndef _TYPES_H
-#define _TYPES_H
+/*
+ * PSn00bSDK standard library
+ * (C) 2019-2023 Lameguy64, spicyjpeg - MPL licensed
+ */
-//#warning "<sys/types.h> and u_* types are deprecated, include <stdint.h> instead"
+#pragma once
-//#include <stdint.h>
+//#warning "<sys/types.h> and u_* types are deprecated, use <stdint.h> instead"
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
-
-#endif // _TYPES_H \ No newline at end of file