diff options
Diffstat (limited to 'libpsn00b/psxcd')
| -rw-r--r-- | libpsn00b/psxcd/cdgetsector.s | 56 | ||||
| -rw-r--r-- | libpsn00b/psxcd/getsector.c | 51 | ||||
| -rw-r--r-- | libpsn00b/psxcd/isofs.c | 285 | ||||
| -rw-r--r-- | libpsn00b/psxcd/psxcd.c | 72 | ||||
| -rw-r--r-- | libpsn00b/psxcd/psxcd_asm.s | 38 |
5 files changed, 198 insertions, 304 deletions
diff --git a/libpsn00b/psxcd/cdgetsector.s b/libpsn00b/psxcd/cdgetsector.s deleted file mode 100644 index 6a29069..0000000 --- a/libpsn00b/psxcd/cdgetsector.s +++ /dev/null @@ -1,56 +0,0 @@ -.set noreorder - -.include "hwregs_a.inc" - -.section .text - -.global CdGetSector -.type CdGetSector, @function -CdGetSector: - - lui $a2, IOBASE - -#.Lwait_fifo: # Probably redundant as the BIOS CD-ROM -# lbu $v0, CD_REG0($a2) # routines do not not wait for this -# nop -# andi $v0, 0x40 -# beqz $v0, .Lwait_fifo -# nop - - lui $v0, 0x1 -# srl $a1, 2 # (the official implementation expects $a1/size - # to be in 32-bit words rather than bytes) - or $v0, $a1 - sw $a0, DMA3_MADR($a2) # Set DMA base address and transfer length - sw $v0, DMA3_BCR($a2) - - lui $v0, 0x1100 # Start DMA transfer - sw $v0, DMA3_CHCR($a2) - nop - nop - -.Ldma_wait: # Ensure DMA transfer has completed - lw $v0, DMA3_CHCR($a2) - nop - srl $v0, 24 - andi $v0, 0x1 - - bnez $v0, .Ldma_wait - nop - -# Not stable -# sb $0 , CD_REG0($a2) -#.Lflush_fifo: # Read out any remaining bytes in the buffer -# lbu $v1, CD_REG0($a2) -# li $v0, 0x40 -# and $v1, $v0 -# beqz $v1, .Lend_flush -# nop -# lbu $v0, CD_REG2($a2) -# b .Lflush_fifo -# nop -#.Lend_flush: - - jr $ra - li $v0, 1 - diff --git a/libpsn00b/psxcd/getsector.c b/libpsn00b/psxcd/getsector.c new file mode 100644 index 0000000..31d0ac7 --- /dev/null +++ b/libpsn00b/psxcd/getsector.c @@ -0,0 +1,51 @@ +/* + * PSn00bSDK CD drive library (sector DMA API) + * (C) 2022 spicyjpeg - MPL licensed + */ + +#include <stdint.h> +#include <psxetc.h> +#include <psxcd.h> +#include <hwregs_c.h> + +#define DATA_SYNC_TIMEOUT 0x100000 + +/* DMA transfer functions */ + +int CdGetSector(void *madr, int size) { + //while (!(CD_STAT & (1 << 6))) + //__asm__ volatile(""); + + DMA_MADR(3) = (uint32_t) madr; + DMA_BCR(3) = size | (1 << 16); + DMA_CHCR(3) = 0x11000000; + + while (DMA_CHCR(3) & (1 << 24)) + __asm__ volatile(""); + + return 1; +} + +int CdGetSector2(void *madr, int size) { + //while (!(CD_STAT & (1 << 6))) + //__asm__ volatile(""); + + DMA_MADR(3) = (uint32_t) madr; + DMA_BCR(3) = size | (1 << 16); + DMA_CHCR(3) = 0x11400100; // Transfer 1 word every 16 CPU cycles + + return 1; +} + +int CdDataSync(int mode) { + if (mode) + return (DMA_CHCR(3) >> 24) & 1; + + for (int i = DATA_SYNC_TIMEOUT; i; i--) { + if (!(DMA_CHCR(3) & (1 << 24))) + return 0; + } + + _sdk_log("psxcd: CdDataSync() timeout\n"); + return -1; +} diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 582b8d9..0425c0d 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -1,15 +1,12 @@ #include <stdint.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> #include <psxgpu.h> -#include <psxsio.h> +#include <psxapi.h> +#include <psxetc.h> #include "psxcd.h" #include "isofs.h" -// Uncommend to enable debug output -//#define DEBUG - #define DEFAULT_PATH_SEP '\\' #define IS_PATH_SEP(ch) (((ch) == '/') || ((ch) == '\\')) @@ -46,9 +43,8 @@ static int _CdReadIsoDescriptor(int session_offs) CdControl(CdlNop, 0, 0); if( (CdStatus()&0x10) ) { -#ifdef DEBUG - printf("psxcd: Lid is still open.\n"); -#endif + _sdk_log("psxcd: Lid is still open.\n"); + _cd_iso_error = CdlIsoLidOpen; return -1; } @@ -61,61 +57,47 @@ static int _CdReadIsoDescriptor(int session_offs) { return 0; } - -#ifdef DEBUG - printf("psxcd: Parsing ISO file system.\n"); -#endif + + _sdk_log("psxcd: Parsing ISO file system.\n"); // Seek to volume descriptor CdIntToPos(16+session_offs, &loc); if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) ) { -#ifdef DEBUG - printf("psxcd: Could not set seek destination.\n"); -#endif + _sdk_log("psxcd: Could not set seek destination.\n"); + _cd_iso_error = CdlIsoSeekError; return -1; } -#ifdef DEBUG - printf("psxcd: Set seek target.\n"); -#endif - -#ifdef DEBUG - printf("psxcd: Read sectors.\n"); -#endif + _sdk_log("psxcd: Read sectors.\n"); + // Read volume descriptor CdRead(1, (uint32_t*)_cd_iso_descriptor_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { -#ifdef DEBUG - printf("psxcd: Error reading ISO volume descriptor.\n"); -#endif + _sdk_log("psxcd: Error reading ISO volume descriptor.\n"); + _cd_iso_error = CdlIsoReadError; return -1; } - -#ifdef DEBUG - printf("psxcd: Read complete.\n"); -#endif - + + _sdk_log("psxcd: Read complete.\n"); + // Verify if volume descriptor is present descriptor = (ISO_DESCRIPTOR*)_cd_iso_descriptor_buff; if( strncmp("CD001", descriptor->header.id, 5) ) { -#ifdef DEBUG - printf("psxcd: Disc does not contain a ISO9660 file system.\n"); -#endif + _sdk_log("psxcd: Disc does not contain a ISO9660 file system.\n"); + _cd_iso_error = CdlIsoInvalidFs; return -1; } - -#ifdef DEBUG - printf("psxcd_dbg: Path table LBA = %d\n", descriptor->pathTable1Offs); - printf("psxcd_dbg: Path table len = %d\n", descriptor->pathTableSize.lsb); -#endif - + + _sdk_log("psxcd: Path table LBA = %d\n", descriptor->pathTable1Offs); + _sdk_log("psxcd: Path table len = %d\n", descriptor->pathTableSize.lsb); + // Allocate path table buffer i = ((2047+descriptor->pathTableSize.lsb)>>11)<<11; if( _cd_iso_pathtable_buff ) @@ -123,20 +105,17 @@ static int _CdReadIsoDescriptor(int session_offs) free(_cd_iso_pathtable_buff); } _cd_iso_pathtable_buff = (uint8_t*)malloc(i); - -#ifdef DEBUG - printf("psxcd_dbg: Allocated %d bytes for path table.\n", i); -#endif - + + _sdk_log("psxcd: Allocated %d bytes for path table.\n", i); + // Read path table CdIntToPos(descriptor->pathTable1Offs, &loc); CdControl(CdlSetloc, (uint8_t*)&loc, 0); CdRead(i>>11, (uint32_t*)_cd_iso_pathtable_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { -#ifdef DEBUG - printf("psxcd: Error reading ISO path table.\n"); -#endif + _sdk_log("psxcd: Error reading ISO path table.\n"); + _cd_iso_error = CdlIsoReadError; return -1; } @@ -162,14 +141,13 @@ static int _CdReadIsoDirectory(int lba) CdIntToPos(lba, &loc); i = CdPosToInt(&loc); -#ifdef DEBUG - printf("psxcd_dbg: Seek to sector %d\n", i); -#endif + + _sdk_log("psxcd: Seek to sector %d\n", i); + if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) ) { -#ifdef DEBUG - printf("psxcd: Could not set seek destination.\n"); -#endif + _sdk_log("psxcd: Could not set seek destination.\n"); + _cd_iso_error = CdlIsoSeekError; return -1; } @@ -184,28 +162,24 @@ static int _CdReadIsoDirectory(int lba) CdRead(1, (uint32_t*)_cd_iso_directory_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { -#ifdef DEBUG - printf("psxcd: Error reading initial directory record.\n"); -#endif + _sdk_log("psxcd: Error reading initial directory record.\n"); + _cd_iso_error = CdlIsoReadError; return -1; } direntry = (ISO_DIR_ENTRY*)_cd_iso_directory_buff; _cd_iso_directory_len = direntry->entrySize.lsb; - -#ifdef DEBUG - printf("psxcd_dbg: Location of directory record = %d\n", direntry->entryOffs.lsb); - printf("psxcd_dbg: Size of directory record = %d\n", _cd_iso_directory_len); -#endif + + _sdk_log("psxcd: Location of directory record = %d\n", direntry->entryOffs.lsb); + _sdk_log("psxcd: Size of directory record = %d\n", _cd_iso_directory_len); if( _cd_iso_directory_len > 2048 ) { if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) ) { -#ifdef DEBUG - printf("psxcd: Could not set seek destination.\n"); -#endif + _sdk_log("psxcd: Could not set seek destination.\n"); + _cd_iso_error = CdlIsoSeekError; return -1; } @@ -213,16 +187,14 @@ static int _CdReadIsoDirectory(int lba) free(_cd_iso_directory_buff); i = ((2047+_cd_iso_directory_len)>>11)<<11; _cd_iso_directory_buff = (uint8_t*)malloc(i); -#ifdef DEBUG - printf("psxcd_dbg: Allocated %d bytes for directory record.\n", i); -#endif + + _sdk_log("psxcd: Allocated %d bytes for directory record.\n", i); CdRead(i>>11, (uint32_t*)_cd_iso_directory_buff, CdlModeSpeed); if( CdReadSync(0, 0) ) { -#ifdef DEBUG - printf("psxcd: Error reading remaining directory record.\n"); -#endif + _sdk_log("psxcd: Error reading remaining directory record.\n"); + _cd_iso_error = CdlIsoReadError; return -1; } @@ -234,7 +206,7 @@ static int _CdReadIsoDirectory(int lba) return 0; } -#ifdef DEBUG +#ifndef NDEBUG static void dump_directory(void) { @@ -243,7 +215,7 @@ static void dump_directory(void) ISO_DIR_ENTRY *dir_entry; char namebuff[16]; - printf("psxcd_dbg: Cached directory record contents:\n"); + _sdk_log("psxcd: Cached directory record contents:\n"); i = 0; dir_pos = 0; @@ -254,7 +226,7 @@ static void dump_directory(void) strncpy(namebuff, _cd_iso_directory_buff+dir_pos+sizeof(ISO_DIR_ENTRY), dir_entry->identifierLen); - printf("P:%d L:%d %s\n", dir_pos, dir_entry->identifierLen, namebuff); + _sdk_log("psxcd: P:%d L:%d %s\n", dir_pos, dir_entry->identifierLen, namebuff); dir_pos += dir_entry->entryLength; i++; @@ -273,7 +245,7 @@ static void dump_directory(void) } } - printf("--\n"); + _sdk_log("psxcd: --\n"); } @@ -284,7 +256,7 @@ static void dump_pathtable(void) ISO_DESCRIPTOR *descriptor; char namebuff[16]; - printf("psxcd_dbg: Path table entries:\n"); + _sdk_log("psxcd: Path table entries:\n"); descriptor = (ISO_DESCRIPTOR*)_cd_iso_descriptor_buff; @@ -298,7 +270,7 @@ static void dump_pathtable(void) tbl_pos+sizeof(ISO_PATHTABLE_ENTRY), tbl_entry->nameLength); - printf("psxcd_dbg: %s\n", namebuff); + _sdk_log("psxcd: %s\n", namebuff); // Advance to next entry tbl_pos += sizeof(ISO_PATHTABLE_ENTRY) @@ -393,10 +365,8 @@ static int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent) int dir_pos; ISO_DIR_ENTRY *dir_entry; char namebuff[16]; - -#ifdef DEBUG - printf( "psxcd_dbg: Locating file %s.\n", name ); -#endif + + _sdk_log("psxcd: Locating file %s.\n", name); i = 0; dir_pos = 0; @@ -434,8 +404,8 @@ static int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent) static char* get_pathname(char *path, const char *filename) { - char *c = 0; - for (char *i = filename; *i; i++) { + const char *c = 0; + for (const char *i = filename; *i; i++) { if (IS_PATH_SEP(*i)) c = i; } @@ -453,8 +423,8 @@ static char* get_pathname(char *path, const char *filename) static char* get_filename(char *name, const char *filename) { - char *c = 0; - for (char *i = filename; *i; i++) { + const char *c = 0; + for (const char *i = filename; *i; i++) { if (IS_PATH_SEP(*i)) c = i; } @@ -489,40 +459,35 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) // Read ISO descriptor and path table if( _CdReadIsoDescriptor(0) ) { -#ifdef DEBUG - printf("psxcd: Could not read ISO file system.\n"); -#endif + _sdk_log("psxcd: Could not read ISO file system.\n"); return NULL; } -#ifdef DEBUG - // printf("psxcd: ISO file system cache updated.\n"); -#endif + + // _sdk_log("psxcd: ISO file system cache updated.\n"); // _cd_media_changed = 0; //} // Get number of directories in path table num_dirs = get_pathtable_entry(0, NULL, NULL); -#ifdef DEBUG - printf("psxcd_dbg: Directories in path table: %d\n", num_dirs); +#ifndef NDEBUG + _sdk_log("psxcd: Directories in path table: %d\n", num_dirs); rbuff = resolve_pathtable_path(num_dirs-1, tpath_rbuff+127); if( !rbuff ) { - printf("psxcd_dbg: Could not resolve path.\n"); + _sdk_log("psxcd: Could not resolve path.\n"); } else { - printf("psxcd_dbg: Longest path: %s|\n", rbuff); + _sdk_log("psxcd: Longest path: %s|\n", rbuff); } #endif if( get_pathname(search_path, filename) ) { -#ifdef DEBUG - printf("psxcd_dbg: Search path = %s|\n", search_path); -#endif + _sdk_log("psxcd: Search path = %s|\n", search_path); } // Search the pathtable for a matching path @@ -530,9 +495,8 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) for(i=1; i<num_dirs; i++) { rbuff = resolve_pathtable_path(i, tpath_rbuff+127); -#ifdef DEBUG - printf("psxcd_dbg: Found = %s|\n", rbuff); -#endif + _sdk_log("psxcd: Found = %s|\n", rbuff); + if( rbuff ) { if( strcmp(search_path, rbuff) == 0 ) @@ -545,24 +509,16 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) if( !found_dir ) { -#ifdef DEBUG - printf("psxcd_dbg: Directory path not found.\n"); -#endif + _sdk_log("psxcd: Directory path not found.\n"); return NULL; } - -#ifdef DEBUG - printf("psxcd_dbg: Found directory at record %d!\n", found_dir); -#endif - get_pathtable_entry(found_dir, &tbl_entry, NULL); + _sdk_log("psxcd: Found directory at record %d!\n", found_dir); -#ifdef DEBUG - printf("psxcd_dbg: Directory LBA = %d\n", tbl_entry.dirOffs); -#endif + get_pathtable_entry(found_dir, &tbl_entry, NULL); + _sdk_log("psxcd: Directory LBA = %d\n", tbl_entry.dirOffs); _CdReadIsoDirectory(tbl_entry.dirOffs); - get_filename(fp->name, filename); // Add version number if not specified @@ -571,21 +527,18 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) strcat(fp->name, ";1"); } -#ifdef DEBUG - dump_directory(); +#ifndef NDEBUG + //dump_directory(); #endif if( find_dir_entry(fp->name, &dir_entry) ) { -#ifdef DEBUG - printf("psxcd: Could not find file.\n"); -#endif + _sdk_log("psxcd: Could not find file.\n"); + return NULL; } - -#ifdef DEBUG - printf("psxcd_dbg: Located file at LBA %d.\n", dir_entry.entryOffs.lsb); -#endif + + _sdk_log("psxcd: Located file at LBA %d.\n", dir_entry.entryOffs.lsb); CdIntToPos(dir_entry.entryOffs.lsb, &fp->pos); fp->size = dir_entry.entrySize.lsb; @@ -609,14 +562,11 @@ CdlDIR *CdOpenDir(const char* path) // Read ISO descriptor and path table if( _CdReadIsoDescriptor( 0 ) ) { -#ifdef DEBUG - printf( "psxcd: Could not read ISO file system.\n" ); -#endif + _sdk_log( "psxcd: Could not read ISO file system.\n" ); return NULL; } -#ifdef DEBUG -// printf( "psxcd: ISO file system cache updated.\n" ); -#endif + +// _sdk_log( "psxcd: ISO file system cache updated.\n" ); // _cd_media_changed = 0; // } @@ -626,9 +576,8 @@ CdlDIR *CdOpenDir(const char* path) for( i=1; i<num_dirs; i++ ) { rbuff = resolve_pathtable_path( i, tpath_rbuff+127 ); -#ifdef DEBUG - printf( "psxcd_dbg: Found = %s|\n", rbuff ); -#endif + _sdk_log( "psxcd: Found = %s|\n", rbuff ); + if( rbuff ) { if( strcmp( path, rbuff ) == 0 ) @@ -641,21 +590,14 @@ CdlDIR *CdOpenDir(const char* path) if( !found_dir ) { -#ifdef DEBUG - printf( "psxcd_dbg: Directory path not found.\n" ); -#endif + _sdk_log( "psxcd: Directory path not found.\n" ); return NULL; } - -#ifdef DEBUG - printf( "psxcd_dbg: Found directory at record %d!\n", found_dir ); -#endif + + _sdk_log( "psxcd: Found directory at record %d!\n", found_dir ); get_pathtable_entry( found_dir, &tbl_entry, NULL ); - -#ifdef DEBUG - printf( "psxcd_dbg: Directory LBA = %d\n", tbl_entry.dirOffs ); -#endif + _sdk_log( "psxcd: Directory LBA = %d\n", tbl_entry.dirOffs ); _CdReadIsoDirectory( tbl_entry.dirOffs ); @@ -720,15 +662,11 @@ int CdReadDir(CdlDIR *dir, CdlFILE* file) file->size = dir_entry->entrySize.lsb; -#ifdef DEBUG - printf("dir_entry->entryLength = %d, ", dir_entry->entryLength); -#endif - + _sdk_log("psxcd: dir_entry->entryLength = %d, ", dir_entry->entryLength); + d_dir->_pos += dir_entry->entryLength; - -#ifdef DEBUG - printf("d_dir->_pos = %d\n", d_dir->_pos); -#endif + + _sdk_log("psxcd: d_dir->_pos = %d\n", d_dir->_pos); // Check if padding is reached (end of record sector) if( d_dir->_dir[d_dir->_pos] == 0 ) @@ -832,19 +770,13 @@ int CdLoadSession(int session) int i; // Seek to specified session -#ifdef DEBUG - printf("psxcd: CdLoadSession(): Seeking to session %d...\n", session); -#endif + _sdk_log("psxcd: CdLoadSession(): Seeking to session %d...\n", session); CdControl(CdlSetsession, (unsigned char*)&session, (unsigned char*)&resultbuff); if( CdSync(0, 0) == CdlDiskError ) { -#ifdef DEBUG - printf("psxcd: CdLoadSession(): Session seek failed, " - "session does not exist.\n"); - printf("psxcd: CdLoadSession(): Restarting CD-ROM...\n"); -#endif + _sdk_log("psxcd: CdLoadSession(): Session seek failed, session does not exist. Restarting CD-ROM...\n"); // Restart CD-ROM on session seek failure CdControl(CdlNop, 0, 0); @@ -855,39 +787,46 @@ int CdLoadSession(int session) } // Set search routine callback + EnterCriticalSection(); ready_oldcb = CdReadyCallback(_scan_callback); - + ExitCriticalSection(); + _ses_scanfound = 0; _ses_scancount = 0; _ses_scancomplete = 0; _ses_scanbuff = scanbuff; // Begin scan for an ISO volume descriptor -#ifdef DEBUG - printf("psxcd: CdLoadSession(): Scanning for ISO9660 volume descriptor.\n"); -#endif + _sdk_log("psxcd: CdLoadSession(): Scanning for ISO9660 volume descriptor.\n"); + i = CdlModeSpeed; CdControl(CdlSetmode, (unsigned char*)&i, 0); CdControl(CdlReadN, 0, (unsigned char*)resultbuff); // Wait until scan complete while(!_ses_scancomplete); - + + EnterCriticalSection(); CdReadyCallback((void*)_ready_oldcb); - + ExitCriticalSection(); + if( !_ses_scanfound ) { -#ifdef DEBUG - printf("psxcd: CdLoadSession(): Did not find volume descriptor.\n"); -#endif + _sdk_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 @@ -901,16 +840,12 @@ int CdLoadSession(int session) CdSync(0, 0); loc = (CdlLOC*)resultbuff; - -#ifdef DEBUG - printf("psxcd: CdLoadSession(): Session found in %02d:%02d:%02d (LBA=%d)\n", + + _sdk_log("psxcd: CdLoadSession(): Session found in %02d:%02d:%02d (LBA=%d)\n", btoi(loc->minute), btoi(loc->second), btoi(loc->sector), CdPosToInt(loc)); -#endif - + i = CdPosToInt(loc)-17; -#ifdef DEBUG - printf("psxcd: CdLoadSession(): Session starting at LBA=%d\n", i); -#endif + _sdk_log("psxcd: CdLoadSession(): Session starting at LBA=%d\n", i); _cd_media_changed = 1; diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 6340638..b914b5e 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -1,6 +1,7 @@ #include <stdint.h> -#include <stdio.h> #include <psxgpu.h> +#include <psxetc.h> +#include <psxapi.h> #include "psxcd.h" #define READ_TIMEOUT 600 // 10 seconds for NTSC @@ -25,8 +26,7 @@ void _cd_control(unsigned char com, const void *param, int plen); void _cd_wait_ack(void); void _cd_wait(void); -int CdInit(void) -{ +int CdInit(void) { // Sets up CD-ROM hardware and low-level subsystem _cd_init(); @@ -37,14 +37,11 @@ int CdInit(void) CdControl(CdlNop, 0, 0); CdControl(CdlInit, 0, 0); - if( CdSync(0, 0) != CdlDiskError ) - { + if(CdSync(0, 0) != CdlDiskError) { CdControl(CdlDemute, 0, 0); - printf("psxcd: Init Ok!\n"); - } - else - { - printf("psxcd: Error initializing. Bad disc/drive or no disc inserted.\n"); + _sdk_log("psxcd: setup done\n"); + } else { + _sdk_log("psxcd: setup error, bad disc/drive or no disc inserted\n"); } return 1; @@ -86,7 +83,7 @@ int CdControlB(unsigned char com, const void *param, unsigned char *result) int CdControlF(unsigned char com, const void *param) { int param_len=0; - + // Command specific parameters switch(com) { @@ -104,31 +101,26 @@ int CdControlF(unsigned char com, const void *param) param_len = 2; break; case CdlSetmode: - param_len = 1; - break; case CdlSetsession: - param_len = 1; - break; case CdlTest: - param_len = 1; - break; case CdlGetTD: param_len = 1; + break; + case CdlReadN: + case CdlReadS: + case CdlSeekL: + case CdlSeekP: + if( param ) + { + _cd_control(CdlSetloc, param, 3); + _cd_last_setloc = *((CdlLOC*)param); + } + break; } - - // Issue Setloc if parameters are specified on CdlReadN and CdlReadS - if( ( com == CdlReadN ) || ( com == CdlReadS ) ) - { - if( param ) - { - _cd_control(CdlSetloc, param, 3); - _cd_last_setloc = *((CdlLOC*)param); - } - } - + // Issue CD command _cd_control(com, param, param_len); - + return 1; } @@ -288,24 +280,18 @@ int CdRead(int sectors, uint32_t *buf, int mode) _cd_read_addr = buf; // Determine sector based on mode flags - if( mode & CdlModeSize0 ) - { - _cd_read_sector_sz = 2328 / 4; - } - else if( mode & CdlModeSize1 ) - { + if( mode & CdlModeSize ) _cd_read_sector_sz = 2340 / 4; - } else - { _cd_read_sector_sz = 2048 / 4; - } _cd_read_counter = VSync(-1); // Set read callback + EnterCriticalSection(); _cd_read_oldcb = CdReadyCallback(_CdReadReadyCallback); - + ExitCriticalSection(); + // Set specified mode CdControl(CdlSetmode, (uint8_t*)&mode, 0); @@ -319,7 +305,7 @@ static void CdDoRetry() { int cb; - printf( "CdRead: Retrying...\n" ); + _sdk_log("psxcd: retrying read...\n"); // Stop reading CdControl(CdlPause, 0, 0); @@ -331,9 +317,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 906ab32..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 @@ -490,13 +472,7 @@ CdSyncCallback: .section .data - -.global psxcd_credits -.type psxcd_credits, @object -psxgpu_credits: - .ascii "psxcd library programs by Lameguy64\n" - .asciiz "2020 PSn00bSDK Project / Meido-Tek Productions\n" - + .comm _cd_last_cmd, 1, 1 .comm _cd_last_mode, 1, 1 .comm _cd_ack_wait, 1, 1 |
