From a21e949c9aea98cb4b3feee48bb98579bbdfba70 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sun, 22 Jan 2023 15:40:14 +0100 Subject: Fix VSync(), assert(), warnings and some examples --- libpsn00b/include/assert.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'libpsn00b/include/assert.h') diff --git a/libpsn00b/include/assert.h b/libpsn00b/include/assert.h index 1b2bda2..d18a56f 100644 --- a/libpsn00b/include/assert.h +++ b/libpsn00b/include/assert.h @@ -1,6 +1,6 @@ /* * 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. @@ -32,9 +32,11 @@ 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 -- cgit v1.2.3 From 870f4dca9d7b5e86544216d0e36863d17aefef62 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Tue, 4 Apr 2023 15:09:38 +0200 Subject: Add argument validation to most libpsn00b functions --- libpsn00b/include/assert.h | 19 +++++++++++++++++++ libpsn00b/psxcd/cdread.c | 2 ++ libpsn00b/psxcd/common.c | 10 ++++++++-- libpsn00b/psxcd/isofs.c | 13 +++++++++++++ libpsn00b/psxcd/misc.c | 8 ++++++++ libpsn00b/psxetc/dl.c | 13 +++++++++++-- libpsn00b/psxetc/interrupts.c | 19 +++++++------------ libpsn00b/psxgpu/common.c | 16 +++++++++++++++- libpsn00b/psxgpu/env.c | 15 +++++++++++++++ libpsn00b/psxgpu/font.c | 14 ++++++++++---- libpsn00b/psxgpu/image.c | 16 ++++++++++++++++ libpsn00b/psxpress/mdec.c | 6 ++++++ libpsn00b/psxspu/common.c | 10 +++++++++- 13 files changed, 139 insertions(+), 22 deletions(-) (limited to 'libpsn00b/include/assert.h') diff --git a/libpsn00b/include/assert.h b/libpsn00b/include/assert.h index d18a56f..26b2023 100644 --- a/libpsn00b/include/assert.h +++ b/libpsn00b/include/assert.h @@ -25,6 +25,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 @@ -39,6 +42,22 @@ void _assert_abort(const char *file, int line, const char *expr); printf(fmt __VA_OPT__(,) __VA_ARGS__) #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 #endif diff --git a/libpsn00b/psxcd/cdread.c b/libpsn00b/psxcd/cdread.c index d211a01..1adc255 100644 --- a/libpsn00b/psxcd/cdread.c +++ b/libpsn00b/psxcd/cdread.c @@ -89,6 +89,8 @@ static int _poll_retry(void) { /* Public API */ int CdReadRetry(int sectors, uint32_t *buf, int mode, int attempts) { + _sdk_validate_args((sectors > 0) && buf && (attempts > 0), -1); + if (CdReadSync(1, 0) > 0) { _sdk_log("CdRead() failed, another read in progress (%d sectors pending)\n", _pending_sectors); return 0; diff --git a/libpsn00b/psxcd/common.c b/libpsn00b/psxcd/common.c index c8f01d1..461ab91 100644 --- a/libpsn00b/psxcd/common.c +++ b/libpsn00b/psxcd/common.c @@ -244,6 +244,8 @@ int CdInit(void) { /* Low-level command API */ int CdCommandF(CdlCommand cmd, const void *param, int length) { + _sdk_validate_args(param || (length <= 0), -1); + const uint8_t *_param = (const uint8_t *) param; _last_command = (uint8_t) cmd; @@ -283,7 +285,7 @@ int CdCommandF(CdlCommand cmd, const void *param, int length) { __asm__ volatile(""); CD_REG(0) = 0; - for (; length; length--) + for (; length > 0; length--) CD_REG(2) = *(_param++); CD_REG(0) = 0; @@ -292,6 +294,8 @@ int CdCommandF(CdlCommand cmd, const void *param, int length) { } int CdCommand(CdlCommand cmd, const void *param, int length, uint8_t *result) { + _sdk_validate_args(param || (length <= 0), -1); + /*if (_ack_pending) { _sdk_log("CdCommand(0x%02x) failed, drive busy\n", cmd); return 0; @@ -329,8 +333,10 @@ int CdControlF(CdlCommand cmd, const void *param) { } else { // The command takes a mandatory parameter or no parameter. length = flags & 3; - if (length && !param) + if (length && !param) { + _sdk_log("CdControl() param is required for command 0x%02x\n", cmd); return -1; + } } return CdCommandF(cmd, param, length); diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 0ac782b..5fd0536 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -450,6 +450,8 @@ static char* get_filename(char *name, const char *filename) CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) { + _sdk_validate_args(fp && filename, NULL); + int i,j,found_dir,num_dirs; int dir_len; char tpath_rbuff[128]; @@ -553,6 +555,8 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) CdlDIR *CdOpenDir(const char* path) { + _sdk_validate_args(path, NULL); + CdlDIR_INT* dir; int num_dirs; int i,found_dir; @@ -631,6 +635,8 @@ CdlDIR *CdOpenDir(const char* path) int CdReadDir(CdlDIR *dir, CdlFILE* file) { + _sdk_validate_args(dir && file, 0); + CdlDIR_INT* d_dir; ISO_DIR_ENTRY* dir_entry; @@ -683,6 +689,9 @@ int CdReadDir(CdlDIR *dir, CdlFILE* file) void CdCloseDir(CdlDIR *dir) { + if (!dir) + return; + CdlDIR_INT* d_dir; d_dir = (CdlDIR_INT*)dir; @@ -698,6 +707,8 @@ int CdIsoError() int CdGetVolumeLabel(char *label) { + _sdk_validate_args(label, -1); + int i, length = 31; ISO_DESCRIPTOR* descriptor; @@ -761,6 +772,8 @@ static void _scan_callback(CdlIntrResult status, unsigned char *result) int CdLoadSession(int session) { + _sdk_validate_args(session >= 0, -1); + CdlLOC *loc; CdlCB ready_oldcb; char scanbuff[2048]; diff --git a/libpsn00b/psxcd/misc.c b/libpsn00b/psxcd/misc.c index 851fea6..2f04821 100644 --- a/libpsn00b/psxcd/misc.c +++ b/libpsn00b/psxcd/misc.c @@ -33,6 +33,8 @@ static const char *const _unlock_regions[] = { /* Sector DMA transfer functions */ int CdGetSector(void *madr, int size) { + _sdk_validate_args(madr && (size > 0), 0); + //while (!(CD_REG(0) & (1 << 6))) //__asm__ volatile(""); @@ -47,6 +49,8 @@ int CdGetSector(void *madr, int size) { } int CdGetSector2(void *madr, int size) { + _sdk_validate_args(madr && (size > 0), 0); + //while (!(CD_REG(0) & (1 << 6))) //__asm__ volatile(""); @@ -170,6 +174,8 @@ int CdUnlock(CdlRegionCode region) { /* Misc. functions */ int CdGetToc(CdlLOC *toc) { + _sdk_validate_args(toc, 0); + uint8_t result[4]; if (!CdCommand(CdlGetTN, 0, 0, result)) @@ -199,6 +205,8 @@ int CdGetToc(CdlLOC *toc) { } int CdMix(const CdlATV *vol) { + _sdk_validate_args(vol, 0); + CD_REG(0) = 2; CD_REG(2) = vol->val0; CD_REG(3) = vol->val1; diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c index ff712eb..06302e2 100644 --- a/libpsn00b/psxetc/dl.c +++ b/libpsn00b/psxetc/dl.c @@ -112,6 +112,8 @@ static uint32_t _elf_hash(const char *str) { /* Symbol map loading/introspection API */ int DL_InitSymbolMap(int num_entries) { + _sdk_validate_args(num_entries, -1); + if (_symbol_map.entries) DL_UnloadSymbolMap(); @@ -151,6 +153,8 @@ void DL_UnloadSymbolMap(void) { } void DL_AddMapSymbol(const char *name, void *ptr) { + _sdk_validate_args_void(name); + uint32_t hash = _elf_hash(name); int index = _symbol_map.index; _symbol_map.index = index + 1; @@ -168,6 +172,8 @@ void DL_AddMapSymbol(const char *name, void *ptr) { } int DL_ParseSymbolMap(const char *ptr, size_t size) { + _sdk_validate_args(ptr && size, 0); + int entries = 0; // Perform a quick scan over the entire map text and count the number of @@ -232,6 +238,8 @@ int DL_ParseSymbolMap(const char *ptr, size_t size) { } void *DL_GetMapSymbol(const char *name) { + _sdk_validate_args(name, 0); + if (!_symbol_map.entries) { _sdk_log("DL_GetMapSymbol() with no map loaded\n"); return 0; @@ -275,8 +283,7 @@ void *DL_SetResolveCallback(void *(*callback)(DLL *, const char *)) { /* Library loading and linking API */ DLL *DL_CreateDLL(DLL *dll, void *ptr, size_t size, DL_ResolveMode mode) { - if (!dll || !ptr) - return 0; + _sdk_validate_args(dll && ptr && size, 0); dll->ptr = ptr; dll->malloc_ptr = (mode & DL_FREE_ON_DESTROY) ? ptr : 0; @@ -463,6 +470,8 @@ void DL_DestroyDLL(DLL *dll) { } void *DL_GetDLLSymbol(const DLL *dll, const char *name) { + _sdk_validate_args(name, 0); + if (!dll) return DL_GetMapSymbol(name); //return _dl_resolve_callback(0, name); diff --git a/libpsn00b/psxetc/interrupts.c b/libpsn00b/psxetc/interrupts.c index 7c8b206..b7bbd07 100644 --- a/libpsn00b/psxetc/interrupts.c +++ b/libpsn00b/psxetc/interrupts.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -99,8 +100,7 @@ static void _global_dma_handler(void) { /* IRQ and DMA handler API */ void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) { - if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) - return 0; + _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0); void *old_callback = _irq_handlers[irq]; _irq_handlers[irq] = func; @@ -116,15 +116,13 @@ void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) { } void *GetInterruptCallback(IRQ_Channel irq) { - if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) - return 0; + _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0); return _irq_handlers[irq]; } void *DMACallback(DMA_Channel dma, void (*func)(void)) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return 0; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0); void *old_callback = _dma_handlers[dma]; _dma_handlers[dma] = func; @@ -151,8 +149,7 @@ void *DMACallback(DMA_Channel dma, void (*func)(void)) { } void *GetDMACallback(DMA_Channel dma) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return 0; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0); return _dma_handlers[dma]; } @@ -160,8 +157,7 @@ void *GetDMACallback(DMA_Channel dma) { /* DMA channel priority API */ int SetDMAPriority(DMA_Channel dma, int priority) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return -1; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1); uint32_t dpcr = DMA_DPCR; uint32_t channel = dpcr >> (dma * 4); @@ -175,8 +171,7 @@ int SetDMAPriority(DMA_Channel dma, int priority) { } int GetDMAPriority(DMA_Channel dma) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return -1; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1); uint32_t channel = DMA_DPCR >> (dma * 4); return (channel & 8) ? (channel & 7) : -1; diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c index e354261..46f87bc 100644 --- a/libpsn00b/psxgpu/common.c +++ b/libpsn00b/psxgpu/common.c @@ -187,6 +187,8 @@ int EnqueueDrawOp( uint32_t arg2, uint32_t arg3 ) { + _sdk_validate_args(func, -1); + // If GPU DMA is currently busy, append the command to the queue instead of // executing it immediately. Note that interrupts must be disabled *prior* // to checking if DMA is busy; disabling them afterwards would create a @@ -263,6 +265,8 @@ void *DrawSyncCallback(void (*func)(void)) { /* OT and primitive drawing API */ void ClearOTagR(uint32_t *ot, size_t length) { + _sdk_validate_args_void(ot && length); + DMA_MADR(DMA_OTC) = (uint32_t) &ot[length - 1]; DMA_BCR(DMA_OTC) = length & 0xffff; DMA_CHCR(DMA_OTC) = 0x11000002; @@ -272,6 +276,8 @@ void ClearOTagR(uint32_t *ot, size_t length) { } void ClearOTag(uint32_t *ot, size_t length) { + _sdk_validate_args_void(ot && length); + // DMA6 only supports writing to RAM in reverse order (last to first), so // the OT has to be cleared in software here. This function is thus much // slower than ClearOTagR(). @@ -285,10 +291,14 @@ void ClearOTag(uint32_t *ot, size_t length) { } void AddPrim(uint32_t *ot, const void *pri) { + _sdk_validate_args_void(ot && pri); + addPrim(ot, pri); } -void DrawPrim(const uint32_t *pri) { +void DrawPrim(const uint32_t *pri) { + _sdk_validate_args_void(pri); + size_t length = getlen(pri); DrawSync(0); @@ -308,10 +318,14 @@ void DrawPrim(const uint32_t *pri) { } int DrawOTag(const uint32_t *ot) { + _sdk_validate_args(ot, -1); + return EnqueueDrawOp((void *) &DrawOTag2, (uint32_t) ot, 0, 0); } void DrawOTag2(const uint32_t *ot) { + _sdk_validate_args_void(ot); + GPU_GP1 = 0x04000002; // Enable DMA request, route to GP0 while (DMA_CHCR(DMA_GPU) & (1 << 24)) diff --git a/libpsn00b/psxgpu/env.c b/libpsn00b/psxgpu/env.c index b90a431..cfe09c0 100644 --- a/libpsn00b/psxgpu/env.c +++ b/libpsn00b/psxgpu/env.c @@ -4,6 +4,7 @@ */ #include +#include #include #include @@ -36,6 +37,8 @@ static inline uint32_t _get_window_mask(int size) { /* Drawing API */ DRAWENV *SetDefDrawEnv(DRAWENV *env, int x, int y, int w, int h) { + _sdk_validate_args(env && (w > 0) && (h > 0), 0); + env->clip.x = x; env->clip.y = y; env->clip.w = w; @@ -60,6 +63,8 @@ DRAWENV *SetDefDrawEnv(DRAWENV *env, int x, int y, int w, int h) { } int DrawOTagEnv(const uint32_t *ot, DRAWENV *env) { + _sdk_validate_args(ot && env, -1); + // All commands are grouped into a single display list packet for // performance reasons using tagless primitives (the GPU does not care // about the grouping as the display list is parsed by the CPU). @@ -102,6 +107,8 @@ int DrawOTagEnv(const uint32_t *ot, DRAWENV *env) { } void PutDrawEnv(DRAWENV *env) { + _sdk_validate_args_void(env); + DrawOTagEnv((const uint32_t *) 0x00ffffff, env); } @@ -109,6 +116,8 @@ void PutDrawEnv(DRAWENV *env) { // useful if the DRAWENV structure is never modified (which is the case most of // the time). void PutDrawEnvFast(DRAWENV *env) { + _sdk_validate_args_void(env); + if (!(env->dr_env.tag)) DrawOTagEnv((const uint32_t *) 0x00ffffff, env); else @@ -118,6 +127,8 @@ void PutDrawEnvFast(DRAWENV *env) { /* Display API */ DISPENV *SetDefDispEnv(DISPENV *env, int x, int y, int w, int h) { + _sdk_validate_args(env && (w > 0) && (h > 0), 0); + env->disp.x = x; env->disp.y = y; env->disp.w = w; @@ -136,6 +147,8 @@ DISPENV *SetDefDispEnv(DISPENV *env, int x, int y, int w, int h) { } void PutDispEnv(const DISPENV *env) { + _sdk_validate_args_void(env); + uint32_t h_range, v_range, mode, fb_pos; mode = _gpu_video_mode << 3; @@ -204,6 +217,8 @@ void PutDispEnv(const DISPENV *env) { /* Deprecated "raw" display API */ void PutDispEnvRaw(const DISPENV_RAW *env) { + _sdk_validate_args_void(env); + uint32_t h_range, v_range, fb_pos; h_range = 608 + env->vid_xpos; diff --git a/libpsn00b/psxgpu/font.c b/libpsn00b/psxgpu/font.c index b1c3c7a..c9d60f1 100644 --- a/libpsn00b/psxgpu/font.c +++ b/libpsn00b/psxgpu/font.c @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -23,6 +24,7 @@ uint16_t _font_clut; extern uint8_t _gpu_debug_font[]; void FntLoad(int x, int y) { + _sdk_validate_args_void((x >= 0) && (y >= 0) && (x < 1024) && (y < 1024)); RECT pos; TIM_IMAGE tim; @@ -66,7 +68,8 @@ void FntLoad(int x, int y) { } int FntOpen(int x, int y, int w, int h, int isbg, int n) { - + _sdk_validate_args((w > 0) && (h > 0) && (n > 0), -1); + int i; // Initialize a text stream @@ -98,7 +101,8 @@ int FntOpen(int x, int y, int w, int h, int isbg, int n) { } int FntPrint(int id, const char *fmt, ...) { - + _sdk_validate_args((id < _nstreams) && fmt, -1); + int n; va_list ap; @@ -124,7 +128,8 @@ int FntPrint(int id, const char *fmt, ...) { } char *FntFlush(int id) { - + _sdk_validate_args(id < _nstreams, 0); + char *opri; SPRT_8 *sprt; DR_TPAGE *tpage; @@ -226,7 +231,8 @@ char *FntFlush(int id) { } char *FntSort(uint32_t *ot, char *pri, int x, int y, const char *text) { - + _sdk_validate_args(ot && pri, 0); + DR_TPAGE *tpage; SPRT_8 *sprt = (SPRT_8*)pri; int i; diff --git a/libpsn00b/psxgpu/image.c b/libpsn00b/psxgpu/image.c index ba5c445..63bceb6 100644 --- a/libpsn00b/psxgpu/image.c +++ b/libpsn00b/psxgpu/image.c @@ -69,6 +69,8 @@ static void _dma_transfer(const RECT *rect, uint32_t *data, int write) { /* VRAM transfer API */ int LoadImage(const RECT *rect, const uint32_t *data) { + _sdk_validate_args(rect && data, -1); + int index = _next_saved_rect; _saved_rects[index] = *rect; @@ -83,6 +85,8 @@ int LoadImage(const RECT *rect, const uint32_t *data) { } int StoreImage(const RECT *rect, uint32_t *data) { + _sdk_validate_args(rect && data, -1); + int index = _next_saved_rect; _saved_rects[index] = *rect; @@ -97,18 +101,26 @@ int StoreImage(const RECT *rect, uint32_t *data) { } int MoveImage(const RECT *rect, int x, int y) { + _sdk_validate_args(rect, -1); + return EnqueueDrawOp((void *) &MoveImage2, (uint32_t) rect, x, y); } void LoadImage2(const RECT *rect, const uint32_t *data) { + _sdk_validate_args_void(rect && data); + _dma_transfer(rect, (uint32_t *) data, 1); } void StoreImage2(const RECT *rect, uint32_t *data) { + _sdk_validate_args_void(rect && data); + _dma_transfer(rect, data, 0); } void MoveImage2(const RECT *rect, int x, int y) { + _sdk_validate_args_void(rect); + while (!(GPU_GP1 & (1 << 26))) __asm__ volatile(""); @@ -131,6 +143,8 @@ void MoveImage2(const RECT *rect, int x, int y) { // returning pointers to them, which become useless once the .TIM file is // unloaded from main RAM. int GsGetTimInfo(const uint32_t *tim, GsIMAGE *info) { + _sdk_validate_args(tim && info, 1); + if ((*(tim++) & 0xffff) != 0x0010) return 1; @@ -157,6 +171,8 @@ int GsGetTimInfo(const uint32_t *tim, GsIMAGE *info) { } int GetTimInfo(const uint32_t *tim, TIM_IMAGE *info) { + _sdk_validate_args(tim && info, 1); + if ((*(tim++) & 0xffff) != 0x0010) return 1; diff --git a/libpsn00b/psxpress/mdec.c b/libpsn00b/psxpress/mdec.c index 394a0ce..b3aa837 100644 --- a/libpsn00b/psxpress/mdec.c +++ b/libpsn00b/psxpress/mdec.c @@ -111,6 +111,8 @@ void DecDCTPutEnv(const DECDCTENV *env, int mono) { } void DecDCTin(const uint32_t *data, int mode) { + _sdk_validate_args_void(data); + uint32_t header = *data; DecDCTinSync(0); @@ -128,6 +130,8 @@ void DecDCTin(const uint32_t *data, int mode) { // data length as an argument rather than parsing it from the first 4 bytes of // the stream. void DecDCTinRaw(const uint32_t *data, size_t length) { + _sdk_validate_args_void(data && length); + if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) { _sdk_log("input data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH); length += DMA_CHUNK_LENGTH - 1; @@ -157,6 +161,8 @@ int DecDCTinSync(int mode) { } void DecDCTout(uint32_t *data, size_t length) { + _sdk_validate_args_void(data && length); + DecDCToutSync(0); if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) { diff --git a/libpsn00b/psxspu/common.c b/libpsn00b/psxspu/common.c index 1275621..efe1d9e 100644 --- a/libpsn00b/psxspu/common.c +++ b/libpsn00b/psxspu/common.c @@ -164,12 +164,18 @@ void SpuInit(void) { } size_t SpuRead(uint32_t *data, size_t size) { + _sdk_validate_args(data && size, 0); + return _dma_transfer(data, size, 0) * 4; } size_t SpuWrite(const uint32_t *data, size_t size) { - if (_transfer_addr < WRITABLE_AREA_ADDR) + _sdk_validate_args(data && size, 0); + + if (_transfer_addr < WRITABLE_AREA_ADDR) { + _sdk_log("ignoring attempt to write to capture buffers at 0x%05x\n", _transfer_addr); return 0; + } // I/O transfer mode is not that useful, but whatever. if (_transfer_mode) @@ -179,6 +185,8 @@ size_t SpuWrite(const uint32_t *data, size_t size) { } size_t SpuWritePartly(const uint32_t *data, size_t size) { + //_sdk_validate_args(data && size, 0); + size_t _size = SpuWrite(data, size); _transfer_addr += (_size + 1) / 2; -- cgit v1.2.3 From b4242acc35c522bd4d4a951a84933ba6f80d2015 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Wed, 5 Apr 2023 01:30:55 +0200 Subject: Clean up all headers, add and rename some BIOS APIs --- examples/system/childexec/parent.c | 2 +- examples/system/console/main.c | 2 +- libpsn00b/include/assert.h | 9 +-- libpsn00b/include/ctype.h | 5 +- libpsn00b/include/dlfcn.h | 5 +- libpsn00b/include/elf.h | 18 +----- libpsn00b/include/hwregs_c.h | 5 +- libpsn00b/include/inline_c.h | 5 +- libpsn00b/include/ioctl.h | 19 ------ libpsn00b/include/lzconfig.h | 68 ---------------------- libpsn00b/include/lzp/lzp.h | 34 ++++++----- libpsn00b/include/lzp/lzqlp.h | 32 +++++++++- libpsn00b/include/malloc.h | 8 --- libpsn00b/include/psxapi.h | 116 +++++++++++++++++++++++++------------ libpsn00b/include/psxcd.h | 5 +- libpsn00b/include/psxetc.h | 5 +- libpsn00b/include/psxgpu.h | 22 +++++-- libpsn00b/include/psxgte.h | 5 +- libpsn00b/include/psxkernel.h | 45 -------------- libpsn00b/include/psxpad.h | 5 +- libpsn00b/include/psxpress.h | 5 +- libpsn00b/include/psxsio.h | 5 +- libpsn00b/include/psxsn.h | 5 +- libpsn00b/include/psxspu.h | 27 +++++++-- libpsn00b/include/stdio.h | 41 +++++-------- libpsn00b/include/stdlib.h | 7 +-- libpsn00b/include/string.h | 7 +-- libpsn00b/include/strings.h | 5 +- libpsn00b/include/sys/fcntl.h | 12 ++-- libpsn00b/include/sys/ioctl.h | 13 +++++ libpsn00b/include/sys/types.h | 12 ++-- libpsn00b/lzp/bit.h | 7 +-- libpsn00b/lzp/compress.c | 16 ++--- libpsn00b/lzp/lzconfig.h | 42 ++++++++++++++ libpsn00b/lzp/lzp.h | 34 ++++++----- libpsn00b/lzp/lzqlp.h | 32 +++++++++- libpsn00b/psxapi/drivers.s | 32 +++++----- libpsn00b/psxapi/fs.s | 18 ++++-- libpsn00b/psxapi/stdio.s | 36 ++++++++++-- libpsn00b/psxapi/stubs.json | 62 ++++++++++++++++---- libpsn00b/psxapi/sys.s | 58 +++++++++++++------ libpsn00b/psxetc/interrupts.c | 4 +- libpsn00b/psxsio/tty.c | 10 ++-- tools/CMakeLists.txt | 6 +- tools/lzpack/lzp/lzconfig.h | 68 ---------------------- 45 files changed, 491 insertions(+), 488 deletions(-) delete mode 100644 libpsn00b/include/ioctl.h delete mode 100644 libpsn00b/include/lzconfig.h delete mode 100644 libpsn00b/include/malloc.h delete mode 100644 libpsn00b/include/psxkernel.h create mode 100644 libpsn00b/include/sys/ioctl.h create mode 100644 libpsn00b/lzp/lzconfig.h delete mode 100644 tools/lzpack/lzp/lzconfig.h (limited to 'libpsn00b/include/assert.h') diff --git a/examples/system/childexec/parent.c b/examples/system/childexec/parent.c index 79c81f1..cfed11c 100644 --- a/examples/system/childexec/parent.c +++ b/examples/system/childexec/parent.c @@ -273,7 +273,7 @@ extern char child_exe[]; void run_child(void) { // Arguments for the child program - char *args[] = + const char *args[] = { "SAMPLE=0", "SESSION=1", diff --git a/examples/system/console/main.c b/examples/system/console/main.c index b4f91b4..845ca95 100644 --- a/examples/system/console/main.c +++ b/examples/system/console/main.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/libpsn00b/include/assert.h b/libpsn00b/include/assert.h index 26b2023..8f8df74 100644 --- a/libpsn00b/include/assert.h +++ b/libpsn00b/include/assert.h @@ -2,12 +2,11 @@ * PSn00bSDK assert macro and internal logging * (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 @@ -59,5 +58,3 @@ void _assert_abort(const char *file, int line, const char *expr); } #endif - -#endif diff --git a/libpsn00b/include/ctype.h b/libpsn00b/include/ctype.h index ad78397..2fe0a42 100644 --- a/libpsn00b/include/ctype.h +++ b/libpsn00b/include/ctype.h @@ -3,8 +3,7 @@ * (C) 2019-2023 PSXSDK authors, Lameguy64, spicyjpeg - MPL licensed */ -#ifndef __CTYPE_H -#define __CTYPE_H +#pragma once #ifdef __cplusplus extern "C" { @@ -23,5 +22,3 @@ 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 #include @@ -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 @@ -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 = """""" -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..3fd5b2c 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 @@ -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 #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 #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 " is deprecated, include instead" - -#include - -#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 #include @@ -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 78c90db..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 @@ -1073,5 +1072,3 @@ int CdLoadSession(int session); #ifdef __cplusplus } #endif - -#endif diff --git a/libpsn00b/include/psxetc.h b/libpsn00b/include/psxetc.h index e45abf4..8dd1dd5 100644 --- a/libpsn00b/include/psxetc.h +++ b/libpsn00b/include/psxetc.h @@ -13,8 +13,7 @@ * separate header). */ -#ifndef __PSXETC_H -#define __PSXETC_H +#pragma once /* IRQ and DMA channel definitions */ @@ -239,5 +238,3 @@ void StopCallback(void); #ifdef __cplusplus } #endif - -#endif diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h index 78d8342..9b99fe9 100644 --- a/libpsn00b/include/psxgpu.h +++ b/libpsn00b/include/psxgpu.h @@ -3,8 +3,24 @@ * (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 #include @@ -603,5 +619,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 @@ -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 @@ -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 ea0c2ec..f26e030 100644 --- a/libpsn00b/include/psxpress.h +++ b/libpsn00b/include/psxpress.h @@ -22,8 +22,7 @@ * anyway. */ -#ifndef __PSXPRESS_H -#define __PSXPRESS_H +#pragma once #include #include @@ -512,5 +511,3 @@ 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 @@ -280,5 +279,3 @@ void DelSIO(void); #ifdef __cplusplus } #endif - -#endif diff --git a/libpsn00b/include/psxsn.h b/libpsn00b/include/psxsn.h index 53a3cd9..1acbc18 100644 --- a/libpsn00b/include/psxsn.h +++ b/libpsn00b/include/psxsn.h @@ -18,8 +18,7 @@ * in PSn00bSDK they are part of libpsxapi. */ -#ifndef __PSXSN_H -#define __PSXSN_H +#pragma once #include @@ -50,5 +49,3 @@ int PClseek(int fd, int offset, PCDRV_SeekMode mode); #ifdef __cplusplus } #endif - -#endif diff --git a/libpsn00b/include/psxspu.h b/libpsn00b/include/psxspu.h index cdc3ac7..d829821 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 #include @@ -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 */ @@ -143,5 +162,3 @@ 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 +#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 #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 49ae7b9..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 @@ -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 84afbae..6310b1a 100644 --- a/libpsn00b/include/string.h +++ b/libpsn00b/include/string.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 __STRING_H -#define __STRING_H +#pragma once #include @@ -39,5 +38,3 @@ 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 @@ -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 " and u_* types are deprecated, include instead" +#pragma once -//#include +//#warning " and u_* types are deprecated, use 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 diff --git a/libpsn00b/lzp/bit.h b/libpsn00b/lzp/bit.h index 321160a..5e7ed23 100644 --- a/libpsn00b/lzp/bit.h +++ b/libpsn00b/lzp/bit.h @@ -1,5 +1,5 @@ -#ifndef _LZP_BIT_H -#define _LZP_BIT_H + +#pragma once extern const unsigned char* inPtr; extern int inBytes; @@ -21,6 +21,3 @@ int get_bits(int n); #ifdef __cplusplus } #endif - - -#endif // _LZP_BIT_H diff --git a/libpsn00b/lzp/compress.c b/libpsn00b/lzp/compress.c index 9cfc64d..16cb606 100644 --- a/libpsn00b/lzp/compress.c +++ b/libpsn00b/lzp/compress.c @@ -1,7 +1,7 @@ // Based on ilia muraviev's CRUSH compressor program which falls under public domain #include -#if LZP_USE_MALLOC == TRUE +#ifdef LZP_USE_MALLOC #include #endif @@ -11,7 +11,7 @@ // Internal structure for hash table allocation sizes -#if LZP_NO_COMPRESS == FALSE +#ifndef LZP_NO_COMPRESS struct { short WindowSize; // Window size (17 - 23) @@ -67,7 +67,7 @@ struct { // LZ77 // -#if LZP_NO_COMPRESS == FALSE +#ifndef LZP_NO_COMPRESS int update_hash1(int h, int c) { @@ -108,13 +108,13 @@ int get_penalty(int a, int b) { int lzCompress(void* outBuff, const void* inBuff, int inSize, int level) { - #if LZP_USE_MALLOC == FALSE +#ifndef LZP_USE_MALLOC int head[HASH1_SIZE+HASH2_SIZE]; int prev[W_SIZE]; - #else +#else int* head = malloc(4*(HASH1_SIZE+HASH2_SIZE)); int* prev = malloc(4*W_SIZE); - #endif +#endif int max_chain[] = {4, 256, 1<<12}; @@ -319,10 +319,10 @@ int lzCompress(void* outBuff, const void* inBuff, int inSize, int level) { flush_bits(); - #if LZP_USE_MALLOC == TRUE +#ifdef LZP_USE_MALLOC free(head); free(prev); - #endif +#endif return(outBytes); diff --git a/libpsn00b/lzp/lzconfig.h b/libpsn00b/lzp/lzconfig.h new file mode 100644 index 0000000..83579a3 --- /dev/null +++ b/libpsn00b/lzp/lzconfig.h @@ -0,0 +1,42 @@ +/*! \file lzconfig.h + * \brief Library configuration header + * \details Define settings will only take effect when you recompile the library. + */ + +#pragma once + +/* Uncomment 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 + +/* 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 + + +#if defined(PSN00BSDK) && !defined(LZP_MAX_COMPRESS) + +// Minimal defaults +#define LZP_WINDOW_SIZE 17 +#define LZP_HASH1_SIZE 8 +#define LZP_HASH2_SIZE 10 + +#else + +#define LZP_USE_MALLOC + +// Maximum defaults +#define LZP_WINDOW_SIZE 17 +#define LZP_HASH1_SIZE 22 +#define LZP_HASH2_SIZE 24 + +#endif diff --git a/libpsn00b/lzp/lzp.h b/libpsn00b/lzp/lzp.h index 456de02..1aeea30 100644 --- a/libpsn00b/lzp/lzp.h +++ b/libpsn00b/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 #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/lzp/lzqlp.h b/libpsn00b/lzp/lzqlp.h index 32ce0d7..127f263 100644 --- a/libpsn00b/lzp/lzqlp.h +++ b/libpsn00b/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 #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/psxapi/drivers.s b/libpsn00b/psxapi/drivers.s index d991f90..c601201 100644 --- a/libpsn00b/psxapi/drivers.s +++ b/libpsn00b/psxapi/drivers.s @@ -32,10 +32,10 @@ _96_remove: jr $t2 li $t1, 0x72 -.section .text.AddDummyTty -.global AddDummyTty -.type AddDummyTty, @function -AddDummyTty: +.section .text.add_nullcon_driver +.global add_nullcon_driver +.type add_nullcon_driver, @function +add_nullcon_driver: li $t2, 0xa0 jr $t2 li $t1, 0x99 @@ -66,26 +66,26 @@ _card_clear: ## B0 table functions (12) -.section .text.AddDev -.global AddDev -.type AddDev, @function -AddDev: +.section .text.AddDrv +.global AddDrv +.type AddDrv, @function +AddDrv: li $t2, 0xb0 jr $t2 li $t1, 0x47 -.section .text.DelDev -.global DelDev -.type DelDev, @function -DelDev: +.section .text.DelDrv +.global DelDrv +.type DelDrv, @function +DelDrv: li $t2, 0xb0 jr $t2 li $t1, 0x48 -.section .text.ListDev -.global ListDev -.type ListDev, @function -ListDev: +.section .text.ListDrv +.global ListDrv +.type ListDrv, @function +ListDrv: li $t2, 0xb0 jr $t2 li $t1, 0x49 diff --git a/libpsn00b/psxapi/fs.s b/libpsn00b/psxapi/fs.s index f225d64..8b6d57a 100644 --- a/libpsn00b/psxapi/fs.s +++ b/libpsn00b/psxapi/fs.s @@ -6,12 +6,12 @@ .set noreorder -## B0 table functions (5) +## B0 table functions (6) -.section .text.chdir -.global chdir -.type chdir, @function -chdir: +.section .text.cd +.global cd +.type cd, @function +cd: li $t2, 0xb0 jr $t2 li $t1, 0x40 @@ -48,3 +48,11 @@ erase: jr $t2 li $t1, 0x45 +.section .text.undelete +.global undelete +.type undelete, @function +undelete: + li $t2, 0xb0 + jr $t2 + li $t1, 0x46 + diff --git a/libpsn00b/psxapi/stdio.s b/libpsn00b/psxapi/stdio.s index e65f871..14c6d03 100644 --- a/libpsn00b/psxapi/stdio.s +++ b/libpsn00b/psxapi/stdio.s @@ -6,7 +6,7 @@ .set noreorder -## A0 table functions (13) +## A0 table functions (14) .section .text.open .global open @@ -16,10 +16,10 @@ open: jr $t2 li $t1, 0x00 -.section .text.seek -.global seek -.type seek, @function -seek: +.section .text.lseek +.global lseek +.type lseek, @function +lseek: li $t2, 0xa0 jr $t2 li $t1, 0x01 @@ -56,6 +56,14 @@ ioctl: jr $t2 li $t1, 0x05 +.section .text.isatty +.global isatty +.type isatty, @function +isatty: + li $t2, 0xa0 + jr $t2 + li $t1, 0x07 + .section .text.getc .global getc .type getc, @function @@ -112,3 +120,21 @@ printf: jr $t2 li $t1, 0x3f +## B0 table functions (2) + +.section .text._get_errno +.global _get_errno +.type _get_errno, @function +_get_errno: + li $t2, 0xb0 + jr $t2 + li $t1, 0x54 + +.section .text._get_error +.global _get_error +.type _get_error, @function +_get_error: + li $t2, 0xb0 + jr $t2 + li $t1, 0x55 + diff --git a/libpsn00b/psxapi/stubs.json b/libpsn00b/psxapi/stubs.json index 50ffb55..afa83c6 100644 --- a/libpsn00b/psxapi/stubs.json +++ b/libpsn00b/psxapi/stubs.json @@ -8,7 +8,7 @@ { "type": "a", "id": 1, - "name": "seek", + "name": "lseek", "file": "stdio.s" }, { @@ -35,6 +35,12 @@ "name": "ioctl", "file": "stdio.s" }, + { + "type": "a", + "id": 7, + "name": "isatty", + "file": "stdio.s" + }, { "type": "a", "id": 8, @@ -107,6 +113,12 @@ "name": "FlushCache", "file": "sys.s" }, + { + "type": "a", + "id": 81, + "name": "LoadExec", + "file": "sys.s" + }, { "type": "a", "id": 85, @@ -128,7 +140,7 @@ { "type": "a", "id": 153, - "name": "AddDummyTty", + "name": "add_nullcon_driver", "file": "drivers.s" }, { @@ -137,6 +149,18 @@ "name": "SetConf", "file": "sys.s" }, + { + "type": "a", + "id": 157, + "name": "GetConf", + "file": "sys.s" + }, + { + "type": "a", + "id": 159, + "name": "SetMem", + "file": "sys.s" + }, { "type": "a", "id": 160, @@ -170,13 +194,13 @@ { "type": "b", "id": 0, - "name": "_kernel_malloc", + "name": "alloc_kernel_memory", "file": "sys.s" }, { "type": "b", "id": 1, - "name": "_kernel_free", + "name": "free_kernel_memory", "file": "sys.s" }, { @@ -296,13 +320,13 @@ { "type": "b", "id": 24, - "name": "SetDefaultExitFromException", + "name": "ResetEntryInt", "file": "sys.s" }, { "type": "b", "id": 25, - "name": "SetCustomExitFromException", + "name": "HookEntryInt", "file": "sys.s" }, { @@ -314,7 +338,7 @@ { "type": "b", "id": 64, - "name": "chdir", + "name": "cd", "file": "fs.s" }, { @@ -341,22 +365,28 @@ "name": "erase", "file": "fs.s" }, + { + "type": "b", + "id": 70, + "name": "undelete", + "file": "fs.s" + }, { "type": "b", "id": 71, - "name": "AddDev", + "name": "AddDrv", "file": "drivers.s" }, { "type": "b", "id": 72, - "name": "DelDev", + "name": "DelDrv", "file": "drivers.s" }, { "type": "b", "id": 73, - "name": "ListDev", + "name": "ListDrv", "file": "drivers.s" }, { @@ -395,6 +425,18 @@ "name": "_new_card", "file": "drivers.s" }, + { + "type": "b", + "id": 84, + "name": "_get_errno", + "file": "stdio.s" + }, + { + "type": "b", + "id": 85, + "name": "_get_error", + "file": "stdio.s" + }, { "type": "b", "id": 86, diff --git a/libpsn00b/psxapi/sys.s b/libpsn00b/psxapi/sys.s index e2505e1..40dcdff 100644 --- a/libpsn00b/psxapi/sys.s +++ b/libpsn00b/psxapi/sys.s @@ -6,7 +6,7 @@ .set noreorder -## A0 table functions (8) +## A0 table functions (11) .section .text.b_setjmp .global b_setjmp @@ -48,6 +48,14 @@ FlushCache: jr $t2 li $t1, 0x44 +.section .text.LoadExec +.global LoadExec +.type LoadExec, @function +LoadExec: + li $t2, 0xa0 + jr $t2 + li $t1, 0x51 + .section .text.SetConf .global SetConf .type SetConf, @function @@ -56,6 +64,22 @@ SetConf: jr $t2 li $t1, 0x9c +.section .text.GetConf +.global GetConf +.type GetConf, @function +GetConf: + li $t2, 0xa0 + jr $t2 + li $t1, 0x9d + +.section .text.SetMem +.global SetMem +.type SetMem, @function +SetMem: + li $t2, 0xa0 + jr $t2 + li $t1, 0x9f + .section .text._boot .global _boot .type _boot, @function @@ -74,18 +98,18 @@ GetSystemInfo: ## B0 table functions (27) -.section .text._kernel_malloc -.global _kernel_malloc -.type _kernel_malloc, @function -_kernel_malloc: +.section .text.alloc_kernel_memory +.global alloc_kernel_memory +.type alloc_kernel_memory, @function +alloc_kernel_memory: li $t2, 0xb0 jr $t2 li $t1, 0x00 -.section .text._kernel_free -.global _kernel_free -.type _kernel_free, @function -_kernel_free: +.section .text.free_kernel_memory +.global free_kernel_memory +.type free_kernel_memory, @function +free_kernel_memory: li $t2, 0xb0 jr $t2 li $t1, 0x01 @@ -242,18 +266,18 @@ ReturnFromException: jr $t2 li $t1, 0x17 -.section .text.SetDefaultExitFromException -.global SetDefaultExitFromException -.type SetDefaultExitFromException, @function -SetDefaultExitFromException: +.section .text.ResetEntryInt +.global ResetEntryInt +.type ResetEntryInt, @function +ResetEntryInt: li $t2, 0xb0 jr $t2 li $t1, 0x18 -.section .text.SetCustomExitFromException -.global SetCustomExitFromException -.type SetCustomExitFromException, @function -SetCustomExitFromException: +.section .text.HookEntryInt +.global HookEntryInt +.type HookEntryInt, @function +HookEntryInt: li $t2, 0xb0 jr $t2 li $t1, 0x19 diff --git a/libpsn00b/psxetc/interrupts.c b/libpsn00b/psxetc/interrupts.c index b7bbd07..8bd11fc 100644 --- a/libpsn00b/psxetc/interrupts.c +++ b/libpsn00b/psxetc/interrupts.c @@ -210,7 +210,7 @@ void RestartCallback(void) { // Install the ISR hook and prevent the kernel's internal handlers from // automatically acknowledging SPI and timer IRQs. - SetCustomExitFromException(&_isr_jmp_buf); + HookEntryInt(&_isr_jmp_buf); ChangeClearPAD(0); ChangeClearRCnt(0, 0); ChangeClearRCnt(1, 0); @@ -237,7 +237,7 @@ void StopCallback(void) { DMA_DPCR = _saved_dma_dpcr & 0x07777777; DMA_DICR = 0; - SetDefaultExitFromException(); + ResetEntryInt(); ChangeClearPAD(1); ChangeClearRCnt(0, 1); ChangeClearRCnt(1, 1); diff --git a/libpsn00b/psxsio/tty.c b/libpsn00b/psxsio/tty.c index a1b33c8..a88af85 100644 --- a/libpsn00b/psxsio/tty.c +++ b/libpsn00b/psxsio/tty.c @@ -8,7 +8,7 @@ * critical section or even from an interrupt handler. */ -#include +#include #include #include #include @@ -93,8 +93,8 @@ void AddSIO(int baud) { close(0); close(1); - DelDev(_sio_dcb.name); - AddDev(&_sio_dcb); + DelDrv(_sio_dcb.name); + AddDrv(&_sio_dcb); open(_sio_dcb.name, 2); open(_sio_dcb.name, 1); } @@ -102,6 +102,6 @@ void AddSIO(int baud) { void DelSIO(void) { SIO_Quit(); - DelDev(_sio_dcb.name); - AddDummyTty(); + DelDrv(_sio_dcb.name); + add_nullcon_driver(); } diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index c48bc10..9246e19 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -38,11 +38,7 @@ file( ) add_library(lzp STATIC ${_sources}) -target_include_directories( - lzp PUBLIC - lzpack/lzp - ${LIBPSN00B_PATH}/include/lzp -) +target_include_directories(lzp PUBLIC ${LIBPSN00B_PATH}/lzp) ## Executables diff --git a/tools/lzpack/lzp/lzconfig.h b/tools/lzpack/lzp/lzconfig.h deleted file mode 100644 index 65e623c..0000000 --- a/tools/lzpack/lzp/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 FALSE - - -/* 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 TRUE - - -/* 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 TRUE - - -/* 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 -- cgit v1.2.3