From 3f859332c8e345ef3a35e24ab8ee3617cb477df7 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Tue, 11 Oct 2022 11:22:30 +0200 Subject: Bump required CMake version to 3.21 --- examples/cdrom/cdbrowse/CMakeLists.txt | 4 ++-- examples/cdrom/cdxa/CMakeLists.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'examples/cdrom') diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt index c2e93fc..0cc091f 100644 --- a/examples/cdrom/cdbrowse/CMakeLists.txt +++ b/examples/cdrom/cdbrowse/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) project( cdbrowse @@ -12,7 +12,7 @@ project( ) file(GLOB _sources *.c) -psn00bsdk_add_executable(cdbrowse STATIC ${_sources}) +psn00bsdk_add_executable(cdbrowse GPREL ${_sources}) psn00bsdk_add_cd_image(cdbrowse_iso cdbrowse iso.xml DEPENDS cdbrowse) psn00bsdk_target_incbin(cdbrowse PRIVATE ball16c ball16c.tim) diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt index 70ef77c..fd2f653 100644 --- a/examples/cdrom/cdxa/CMakeLists.txt +++ b/examples/cdrom/cdxa/CMakeLists.txt @@ -1,7 +1,7 @@ # PSn00bSDK example CMake script # (C) 2021 spicyjpeg - MPL licensed -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.21) project( cdxa @@ -13,7 +13,7 @@ project( # TODO: add rules to actually generate a valid .XA file file(GLOB _sources *.c) -psn00bsdk_add_executable(cdxa STATIC ${_sources}) +psn00bsdk_add_executable(cdxa GPREL ${_sources}) #psn00bsdk_add_cd_image(cdxa_iso cdxa iso.xml DEPENDS cdxa) psn00bsdk_target_incbin(cdxa PRIVATE ball16c ball16c.tim) -- cgit v1.2.3 From 6eabb5aa549254c2272cedee26d4245f31f2dc7a Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Sat, 15 Oct 2022 10:02:35 +0200 Subject: Update sound/spustream, clean up other examples --- examples/cdrom/cdbrowse/iso.xml | 1 - examples/cdrom/cdxa/iso.xml | 1 - examples/graphics/tilesasm/iso.xml | 34 ----------- examples/graphics/tilesasm/system.cnf | 4 -- examples/io/pads/main.c | 22 +++---- examples/io/system573/iso.xml | 2 - examples/io/system573/main.c | 22 +++---- examples/sound/spustream/iso.xml | 1 - examples/sound/spustream/main.c | 91 +++++++++++++++++----------- examples/system/dynlink/library/balls.c | 27 +++++---- examples/system/dynlink/library/cube.c | 14 +++-- examples/system/dynlink/library/dll_common.h | 11 ++-- examples/system/dynlink/main.c | 17 +++--- template/iso.xml | 2 +- 14 files changed, 114 insertions(+), 135 deletions(-) delete mode 100644 examples/graphics/tilesasm/iso.xml delete mode 100644 examples/graphics/tilesasm/system.cnf (limited to 'examples/cdrom') diff --git a/examples/cdrom/cdbrowse/iso.xml b/examples/cdrom/cdbrowse/iso.xml index 5ffca18..771b0e9 100644 --- a/examples/cdrom/cdbrowse/iso.xml +++ b/examples/cdrom/cdbrowse/iso.xml @@ -17,7 +17,6 @@ - diff --git a/examples/cdrom/cdxa/iso.xml b/examples/cdrom/cdxa/iso.xml index b98a16f..6715f94 100644 --- a/examples/cdrom/cdxa/iso.xml +++ b/examples/cdrom/cdxa/iso.xml @@ -17,7 +17,6 @@ - diff --git a/examples/graphics/tilesasm/iso.xml b/examples/graphics/tilesasm/iso.xml deleted file mode 100644 index 477c636..0000000 --- a/examples/graphics/tilesasm/iso.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/examples/graphics/tilesasm/system.cnf b/examples/graphics/tilesasm/system.cnf deleted file mode 100644 index e221726..0000000 --- a/examples/graphics/tilesasm/system.cnf +++ /dev/null @@ -1,4 +0,0 @@ -BOOT=cdrom:\template.exe;1 -TCB=4 -EVENT=10 -STACK=801FFFF0 diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c index 17bf331..29bb527 100644 --- a/examples/io/pads/main.c +++ b/examples/io/pads/main.c @@ -62,17 +62,17 @@ static const char *const PAD_TYPEIDS[] = { #define BGCOLOR_B 0 typedef struct { - DISPENV disp; - DRAWENV draw; -} DB; + DISPENV disp; + DRAWENV draw; +} Framebuffer; typedef struct { - DB db[2]; - uint32_t db_active; -} CONTEXT; + Framebuffer db[2]; + int db_active; +} RenderContext; -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); ctx->db_active = 0; @@ -99,8 +99,8 @@ void init_context(CONTEXT *ctx) { FntOpen(8, 16, 304, 208, 2, 512); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -227,7 +227,7 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) { /* Main */ -static CONTEXT ctx; +static RenderContext ctx; int main(int argc, const char* argv[]) { init_context(&ctx); diff --git a/examples/io/system573/iso.xml b/examples/io/system573/iso.xml index 0bb84d5..2226089 100644 --- a/examples/io/system573/iso.xml +++ b/examples/io/system573/iso.xml @@ -30,8 +30,6 @@ --> - - diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c index 3404ee4..39ddb64 100644 --- a/examples/io/system573/main.c +++ b/examples/io/system573/main.c @@ -83,17 +83,17 @@ const char *const IO_BOARD_TYPES[] = { #define BGCOLOR_B 0 typedef struct { - DISPENV disp; - DRAWENV draw; -} DB; + DISPENV disp; + DRAWENV draw; +} Framebuffer; typedef struct { - DB db[2]; - uint32_t db_active; -} CONTEXT; + Framebuffer db[2]; + int db_active; +} RenderContext; -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); ctx->db_active = 0; @@ -120,8 +120,8 @@ void init_context(CONTEXT *ctx) { FntOpen(8, 16, 304, 208, 2, 512); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -135,7 +135,7 @@ void display(CONTEXT *ctx) { /* Main */ -static CONTEXT ctx; +static RenderContext ctx; #define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); } #define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); } diff --git a/examples/sound/spustream/iso.xml b/examples/sound/spustream/iso.xml index 3807046..050d673 100644 --- a/examples/sound/spustream/iso.xml +++ b/examples/sound/spustream/iso.xml @@ -17,7 +17,6 @@ - diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c index 6179179..acd4f60 100644 --- a/examples/sound/spustream/main.c +++ b/examples/sound/spustream/main.c @@ -117,17 +117,17 @@ #define BGCOLOR_B 0 typedef struct { - DISPENV disp; - DRAWENV draw; -} DB; + DISPENV disp; + DRAWENV draw; +} Framebuffer; typedef struct { - DB db[2]; - int db_active; -} CONTEXT; + Framebuffer db[2]; + int db_active; +} RenderContext; -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); ctx->db_active = 0; @@ -154,8 +154,8 @@ void init_context(CONTEXT *ctx) { FntOpen(8, 16, 304, 208, 2, 512); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -181,13 +181,9 @@ void display(CONTEXT *ctx) { #define CHUNK_SIZE (BUFFER_SIZE * NUM_CHANNELS) typedef struct { - uint32_t lba; - uint32_t length; - uint32_t pos; - - uint32_t spu_addr; - uint32_t spu_pos; - uint32_t db_active; + int lba, length, pos; + int spu_addr, spu_pos; + int db_active; } StreamContext; static volatile StreamContext str_ctx; @@ -316,10 +312,10 @@ void init_stream(CdlFILE *file) { } void start_stream(void) { - SPU_KEY_OFF = CHANNEL_MASK; + uint32_t addr = BUFFER_START_ADDR + CHUNK_SIZE * str_ctx.db_active; for (int i = 0; i < NUM_CHANNELS; i++) { - SPU_CH_ADDR(i) = SPU_RAM_ADDR(BUFFER_START_ADDR + BUFFER_SIZE * i); + SPU_CH_ADDR(i) = SPU_RAM_ADDR(addr + BUFFER_SIZE * i); SPU_CH_FREQ(i) = SAMPLE_RATE; SPU_CH_ADSR(i) = 0x1fee80ff; } @@ -332,13 +328,25 @@ void start_stream(void) { SPU_CH_VOL_L(1) = 0x0000; SPU_CH_VOL_R(1) = 0x3fff; - SPU_KEY_ON = CHANNEL_MASK; spu_irq_handler(); + SPU_KEY_ON = CHANNEL_MASK; +} + +// This is basically a variant of reset_spu_channels() that only resets the +// channels used to play the stream, to (again) prevent them from triggering +// the SPU IRQ while the stream is paused. +void stop_stream(void) { + SPU_KEY_OFF = CHANNEL_MASK; + + for (int i = 0; i < NUM_CHANNELS; i++) + SPU_CH_ADDR(i) = SPU_RAM_ADDR(DUMMY_BLOCK_ADDR); + + SPU_KEY_ON = CHANNEL_MASK; } /* Main */ -static CONTEXT ctx; +static RenderContext ctx; #define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); } #define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); } @@ -351,7 +359,13 @@ int main(int argc, const char* argv[]) { CdInit(); reset_spu_channels(); - SHOW_STATUS("LOCATING STREAM FILE\n"); + // Set up controller polling. + uint8_t pad_buff[2][34]; + InitPAD(pad_buff[0], 34, pad_buff[1], 34); + StartPAD(); + ChangeClearPAD(0); + + SHOW_STATUS("OPENING STREAM FILE\n"); CdlFILE file; if (!CdSearchFile(&file, "\\STREAM.BIN")) @@ -361,28 +375,27 @@ int main(int argc, const char* argv[]) { init_stream(&file); start_stream(); - // Set up controller polling. - uint8_t pad_buff[2][34]; - InitPAD(pad_buff[0], 34, pad_buff[1], 34); - StartPAD(); - ChangeClearPAD(0); + int paused = 0; uint16_t sample_rate = SAMPLE_RATE; uint16_t last_buttons = 0xffff; while (1) { - FntPrint(-1, "PLAYING SPU STREAM\n"); + FntPrint(-1, "PLAYING SPU STREAM\n\n"); + + FntPrint(-1, "BUFFER: %d\nSTATUS: ", str_ctx.db_active); if (str_ctx.spu_pos >= CHUNK_SIZE) - FntPrint(-1, "STATUS: IDLE\n\n"); - else if (!str_ctx.spu_pos) - FntPrint(-1, "STATUS: SEEKING\n\n"); + FntPrint(-1, "IDLE\n\n"); + else if (str_ctx.spu_pos) + FntPrint(-1, "BUFFERING\n\n"); else - FntPrint(-1, "STATUS: BUFFERING\n\n"); + FntPrint(-1, "SEEKING\n\n"); - FntPrint(-1, "POSITION=%5d/%5d\n", str_ctx.pos, str_ctx.length); - FntPrint(-1, "BUFFERED=%5d/%5d\n", str_ctx.spu_pos, CHUNK_SIZE); - FntPrint(-1, "SMP RATE=%5d HZ\n\n", (sample_rate * 44100) >> 12); + FntPrint(-1, "POSITION: %5d/%5d\n", str_ctx.pos, str_ctx.length); + FntPrint(-1, "BUFFERED: %5d/%5d\n", str_ctx.spu_pos, CHUNK_SIZE); + FntPrint(-1, "SMP RATE: %5d HZ\n\n", (sample_rate * 44100) >> 12); + FntPrint(-1, "[START] %s\n", paused ? "RESUME" : "PAUSE"); FntPrint(-1, "[LEFT/RIGHT] SEEK\n"); FntPrint(-1, "[O] RESET POSITION\n"); FntPrint(-1, "[UP/DOWN] CHANGE SAMPLE RATE\n"); @@ -399,6 +412,14 @@ int main(int argc, const char* argv[]) { if ((pad->type != 4) && (pad->type != 5) && (pad->type != 7)) continue; + if ((last_buttons & PAD_START) && !(pad->btn & PAD_START)) { + paused ^= 1; + if (paused) + stop_stream(); + else + start_stream(); + } + // Seeking by an arbitrary number of sectors isn't a problem as // spu_irq_handler() always realigns the counter. if (!(pad->btn & PAD_LEFT)) diff --git a/examples/system/dynlink/library/balls.c b/examples/system/dynlink/library/balls.c index c537167..457ec4e 100644 --- a/examples/system/dynlink/library/balls.c +++ b/examples/system/dynlink/library/balls.c @@ -21,7 +21,7 @@ typedef struct { int16_t x, y; int16_t xdir, ydir; uint8_t r, g, b, p; -} BALL_TYPE; +} Ball; #define MAX_BALLS 512 @@ -35,12 +35,13 @@ typedef struct { // initialize variables or hardware. static uint32_t frame = 0; -static BALL_TYPE balls[MAX_BALLS]; +static Ball balls[MAX_BALLS]; static TIM_IMAGE ball_tim; -void init(CONTEXT *ctx) { - GetTimInfo(ball16c, &ball_tim); +void init(RenderContext *ctx) { + Framebuffer *db = &(ctx->db[ctx->db_active]); + GetTimInfo(ball16c, &ball_tim); LoadImage(ball_tim.prect, ball_tim.paddr); if (ball_tim.mode & 8) LoadImage(ball_tim.crect, ball_tim.caddr); @@ -48,10 +49,10 @@ void init(CONTEXT *ctx) { // Initialize the balls by giving them a random initial position, velocity // and color. for (uint32_t i = 0; i < MAX_BALLS; i++) { - BALL_TYPE *b = &(balls[i]); + Ball *b = &(balls[i]); - b->x = rand() % (ctx->xres - 16); - b->y = rand() % (ctx->yres - 16); + b->x = rand() % (db->draw.clip.w - 16); + b->y = rand() % (db->draw.clip.h - 16); b->xdir = ((rand() & 1) ? 1 : -1) * ((rand() % 3) + 1); b->ydir = ((rand() & 1) ? 1 : -1) * ((rand() % 3) + 1); b->r = rand() & 0xff; @@ -60,12 +61,12 @@ void init(CONTEXT *ctx) { } } -void render(CONTEXT *ctx, uint16_t buttons) { - DB *db = &(ctx->db[ctx->db_active]); - SPRT_16 *sprt = (SPRT_16 *) ctx->db_nextpri; +void render(RenderContext *ctx, uint16_t buttons) { + Framebuffer *db = &(ctx->db[ctx->db_active]); + SPRT_16 *sprt = (SPRT_16 *) ctx->db_nextpri; for (uint32_t i = 0; i < MAX_BALLS; i++) { - BALL_TYPE *b = &(balls[i]); + Ball *b = &(balls[i]); setSprt16(sprt); @@ -85,12 +86,12 @@ void render(CONTEXT *ctx, uint16_t buttons) { if ( (b->x < 0) || - ((b->x + 16) > ctx->xres) + ((b->x + 16) > db->draw.clip.w) ) b->xdir *= -1; if ( (b->y < 0) || - ((b->y + 16) > ctx->yres) + ((b->y + 16) > db->draw.clip.h) ) b->ydir *= -1; } diff --git a/examples/system/dynlink/library/cube.c b/examples/system/dynlink/library/cube.c index 84fe552..22a805f 100644 --- a/examples/system/dynlink/library/cube.c +++ b/examples/system/dynlink/library/cube.c @@ -81,16 +81,18 @@ static SVECTOR rot = { 0 }; static VECTOR pos = { 0, 0, 400 }; static MATRIX mtx, lmtx; -void init(CONTEXT *ctx) { +void init(RenderContext *ctx) { + Framebuffer *db = &(ctx->db[ctx->db_active]); + InitGeom(); - gte_SetGeomOffset(ctx->xres / 2, ctx->yres / 2); - gte_SetGeomScreen(ctx->xres / 2); + gte_SetGeomOffset(db->draw.clip.w / 2, db->draw.clip.h / 2); + gte_SetGeomScreen(db->draw.clip.w / 2); gte_SetBackColor(63, 63, 63); gte_SetColorMatrix(&color_mtx); } -void render(CONTEXT *ctx, uint16_t buttons) { +void render(RenderContext *ctx, uint16_t buttons) { RotMatrix(&rot, &mtx); TransMatrix(&mtx, &pos); MulMatrix0(&light_mtx, &mtx, &lmtx); @@ -104,8 +106,8 @@ void render(CONTEXT *ctx, uint16_t buttons) { rot.vx += step; rot.vz += step; - DB *db = &(ctx->db[ctx->db_active]); - POLY_F4 *pol4 = (POLY_F4 *) ctx->db_nextpri; + Framebuffer *db = &(ctx->db[ctx->db_active]); + POLY_F4 *pol4 = (POLY_F4 *) ctx->db_nextpri; for (uint32_t i = 0; i < CUBE_FACES; i++) { int32_t p; diff --git a/examples/system/dynlink/library/dll_common.h b/examples/system/dynlink/library/dll_common.h index 315a993..6606bda 100644 --- a/examples/system/dynlink/library/dll_common.h +++ b/examples/system/dynlink/library/dll_common.h @@ -19,13 +19,12 @@ typedef struct { DRAWENV draw; uint32_t ot[OT_LEN]; uint8_t p[PACKET_LEN]; -} DB; +} Framebuffer; typedef struct { - uint16_t xres, yres; - DB db[2]; - uint32_t db_active; - uint8_t *db_nextpri; -} CONTEXT; + Framebuffer db[2]; + int db_active; + uint8_t *db_nextpri; +} RenderContext; #endif diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c index fff7aa5..fcce5b1 100644 --- a/examples/system/dynlink/main.c +++ b/examples/system/dynlink/main.c @@ -83,12 +83,10 @@ static const char *const DLL_FILENAMES[] = { #define BGCOLOR_G 24 #define BGCOLOR_B 0 -void init_context(CONTEXT *ctx) { - DB *db; +void init_context(RenderContext *ctx) { + Framebuffer *db; ResetGraph(0); - ctx->xres = SCREEN_XRES; - ctx->yres = SCREEN_YRES; ctx->db_active = 0; db = &(ctx->db[0]); @@ -121,8 +119,8 @@ void init_context(CONTEXT *ctx) { FntOpen(4, 12, 312, 32, 2, 256); } -void display(CONTEXT *ctx) { - DB *db; +void display(RenderContext *ctx) { + Framebuffer *db; DrawSync(0); VSync(0); @@ -185,13 +183,14 @@ void *custom_resolver(DLL *dll, const char *name) { // and the pointers returned by DL_GetDLLSymbol() should be saved and reused as // much as possible. typedef struct { - void (*init)(CONTEXT *); - void (*render)(CONTEXT *, uint16_t buttons); + void (*init)(RenderContext *); + void (*render)(RenderContext *, uint16_t buttons); } DLL_API; static DLL *dll = 0; static DLL_API dll_api; -static CONTEXT ctx; + +static RenderContext ctx; /* Main */ diff --git a/template/iso.xml b/template/iso.xml index 477c636..87162b2 100644 --- a/template/iso.xml +++ b/template/iso.xml @@ -24,7 +24,7 @@ - + -- cgit v1.2.3 From 2f100c78c0f12b56bcd73c203e6216d415d9f772 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Mon, 17 Oct 2022 22:42:00 +0200 Subject: Remove interrupt disabling calls in psxcd callback APIs --- examples/cdrom/cdxa/main.c | 2 ++ libpsn00b/include/psxcd.h | 4 ++-- libpsn00b/psxcd/isofs.c | 19 ++++++++++++++----- libpsn00b/psxcd/psxcd.c | 11 ++++++++--- libpsn00b/psxcd/psxcd_asm.s | 30 ++++++------------------------ 5 files changed, 32 insertions(+), 34 deletions(-) (limited to 'examples/cdrom') diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c index 4921658..93cf01a 100644 --- a/examples/cdrom/cdxa/main.c +++ b/examples/cdrom/cdxa/main.c @@ -349,7 +349,9 @@ int main(int argc, const char* argv[]) xa_loc = file.pos; /* Hook XA callback function to CdReadyCallback (for auto stop/loop */ + EnterCriticalSection(); CdReadyCallback(xa_callback); + ExitCriticalSection(); /* Set CD mode for XA streaming (2x speed, send XA to SPU, enable filter */ i = CdlModeSpeed|CdlModeRT|CdlModeSF; diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h index 429a439..0460f20 100644 --- a/libpsn00b/include/psxcd.h +++ b/libpsn00b/include/psxcd.h @@ -145,7 +145,7 @@ int CdControlF(uint8_t com, const void *param); int CdSync(int mode, uint8_t *result); uint32_t CdSyncCallback(CdlCB func); -long CdReadyCallback(CdlCB func); +int CdReadyCallback(CdlCB func); int CdGetSector(void *madr, int size); int CdGetSector2(void *madr, int size); int CdDataSync(int mode); @@ -168,7 +168,7 @@ void CdCloseDir(CdlDIR* dir); int CdGetVolumeLabel(char* label); -long* CdAutoPauseCallback(void(*func)()); +int* CdAutoPauseCallback(void(*func)()); int CdIsoError(); int CdLoadSession(int session); diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 16e64ef..4ec701c 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "psxcd.h" #include "isofs.h" @@ -795,8 +795,10 @@ int CdLoadSession(int session) } // Set search routine callback + EnterCriticalSection(); ready_oldcb = CdReadyCallback(_scan_callback); - + ExitCriticalSection(); + _ses_scanfound = 0; _ses_scancount = 0; _ses_scancomplete = 0; @@ -811,21 +813,28 @@ int CdLoadSession(int session) // Wait until scan complete while(!_ses_scancomplete); - + + EnterCriticalSection(); CdReadyCallback((void*)_ready_oldcb); - + ExitCriticalSection(); + if( !_ses_scanfound ) { _LOG("psxcd: CdLoadSession(): Did not find volume descriptor.\n"); _cd_iso_error = CdlIsoInvalidFs; + EnterCriticalSection(); CdReadyCallback((CdlCB)ready_oldcb); + ExitCriticalSection(); + return -1; } // Restore old callback if any + EnterCriticalSection(); CdReadyCallback((CdlCB)ready_oldcb); - + ExitCriticalSection(); + // Wait until CD-ROM has completely stopped reading, to get a consistent // fix of the CD-ROM pickup's current location do diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index f48542d..6730531 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "psxcd.h" #define READ_TIMEOUT 600 // 10 seconds for NTSC @@ -293,8 +294,10 @@ int CdRead(int sectors, uint32_t *buf, int mode) _cd_read_counter = VSync(-1); // Set read callback + EnterCriticalSection(); _cd_read_oldcb = CdReadyCallback(_CdReadReadyCallback); - + ExitCriticalSection(); + // Set specified mode CdControl(CdlSetmode, (uint8_t*)&mode, 0); @@ -320,9 +323,11 @@ static void CdDoRetry() // Reset timeout _cd_read_counter = VSync(-1); - + + EnterCriticalSection(); CdReadyCallback(_CdReadReadyCallback); - + ExitCriticalSection(); + // Retry read CdControl(CdlSetloc, (void*)&_cd_last_setloc, 0); CdControl(CdlReadN, 0, (uint8_t*)_cd_read_result); diff --git a/libpsn00b/psxcd/psxcd_asm.s b/libpsn00b/psxcd/psxcd_asm.s index 16e17d8..c0a5312 100644 --- a/libpsn00b/psxcd/psxcd_asm.s +++ b/libpsn00b/psxcd/psxcd_asm.s @@ -413,17 +413,11 @@ CdAutoPauseCallback: lw $v0, 0($v1) la $v1, _cd_callback_int4 - - jal EnterCriticalSection - nop - + lw $a0, 4($sp) nop sw $a0, 0($v1) - - jal ExitCriticalSection - nop - + lw $ra, 0($sp) addiu $sp, 8 jr $ra @@ -443,17 +437,11 @@ CdReadyCallback: la $v1, _cd_callback_int1_data sw $v0, 8($sp) - - jal EnterCriticalSection - nop - + lw $a0, 4($sp) nop sw $a0, 0($v1) - - jal ExitCriticalSection - nop - + lw $ra, 0($sp) lw $v0, 8($sp) jr $ra @@ -472,17 +460,11 @@ CdSyncCallback: la $v1, _cd_sync_cb sw $v0, 8($sp) - - jal EnterCriticalSection - nop - + lw $a0, 4($sp) nop sw $a0, 0($v1) - - jal ExitCriticalSection - nop - + lw $ra, 0($sp) lw $v0, 8($sp) jr $ra -- cgit v1.2.3