aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b/psxcd
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2022-10-18 17:29:42 +0200
committerspicyjpeg <thatspicyjpeg@gmail.com>2022-10-18 17:29:42 +0200
commit9b2ffc6078a850b7d354855cca7622090b41f30c (patch)
tree33654513b0b184c27f8035dbc405640fcbeb44ab /libpsn00b/psxcd
parentb71a55bc489db6bc9beca5cee9cd584e82846ac8 (diff)
downloadpsn00bsdk-9b2ffc6078a850b7d354855cca7622090b41f30c.tar.gz
Add debug log buffering, fix GetHeapUsage()
Diffstat (limited to 'libpsn00b/psxcd')
-rw-r--r--libpsn00b/psxcd/getsector.c11
-rw-r--r--libpsn00b/psxcd/isofs.c112
-rw-r--r--libpsn00b/psxcd/psxcd.c14
3 files changed, 58 insertions, 79 deletions
diff --git a/libpsn00b/psxcd/getsector.c b/libpsn00b/psxcd/getsector.c
index ee5315a..31d0ac7 100644
--- a/libpsn00b/psxcd/getsector.c
+++ b/libpsn00b/psxcd/getsector.c
@@ -4,19 +4,12 @@
*/
#include <stdint.h>
+#include <psxetc.h>
#include <psxcd.h>
#include <hwregs_c.h>
#define DATA_SYNC_TIMEOUT 0x100000
-/* Private utilities */
-
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
-
/* DMA transfer functions */
int CdGetSector(void *madr, int size) {
@@ -53,6 +46,6 @@ int CdDataSync(int mode) {
return 0;
}
- _LOG("psxcd: CdDataSync() timeout\n");
+ _sdk_log("psxcd: CdDataSync() timeout\n");
return -1;
}
diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c
index 4ec701c..0425c0d 100644
--- a/libpsn00b/psxcd/isofs.c
+++ b/libpsn00b/psxcd/isofs.c
@@ -1,18 +1,12 @@
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <psxgpu.h>
#include <psxapi.h>
+#include <psxetc.h>
#include "psxcd.h"
#include "isofs.h"
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
-
#define DEFAULT_PATH_SEP '\\'
#define IS_PATH_SEP(ch) (((ch) == '/') || ((ch) == '\\'))
@@ -49,7 +43,7 @@ static int _CdReadIsoDescriptor(int session_offs)
CdControl(CdlNop, 0, 0);
if( (CdStatus()&0x10) )
{
- _LOG("psxcd: Lid is still open.\n");
+ _sdk_log("psxcd: Lid is still open.\n");
_cd_iso_error = CdlIsoLidOpen;
return -1;
@@ -64,45 +58,45 @@ static int _CdReadIsoDescriptor(int session_offs)
return 0;
}
- _LOG("psxcd: Parsing ISO file system.\n");
+ _sdk_log("psxcd: Parsing ISO file system.\n");
// Seek to volume descriptor
CdIntToPos(16+session_offs, &loc);
if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) )
{
- _LOG("psxcd: Could not set seek destination.\n");
+ _sdk_log("psxcd: Could not set seek destination.\n");
_cd_iso_error = CdlIsoSeekError;
return -1;
}
- _LOG("psxcd: Read sectors.\n");
+ _sdk_log("psxcd: Read sectors.\n");
// Read volume descriptor
CdRead(1, (uint32_t*)_cd_iso_descriptor_buff, CdlModeSpeed);
if( CdReadSync(0, 0) )
{
- _LOG("psxcd: Error reading ISO volume descriptor.\n");
+ _sdk_log("psxcd: Error reading ISO volume descriptor.\n");
_cd_iso_error = CdlIsoReadError;
return -1;
}
- _LOG("psxcd: Read complete.\n");
+ _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) )
{
- _LOG("psxcd: Disc does not contain a ISO9660 file system.\n");
+ _sdk_log("psxcd: Disc does not contain a ISO9660 file system.\n");
_cd_iso_error = CdlIsoInvalidFs;
return -1;
}
- _LOG("psxcd: Path table LBA = %d\n", descriptor->pathTable1Offs);
- _LOG("psxcd: Path table len = %d\n", descriptor->pathTableSize.lsb);
+ _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;
@@ -112,7 +106,7 @@ static int _CdReadIsoDescriptor(int session_offs)
}
_cd_iso_pathtable_buff = (uint8_t*)malloc(i);
- _LOG("psxcd: Allocated %d bytes for path table.\n", i);
+ _sdk_log("psxcd: Allocated %d bytes for path table.\n", i);
// Read path table
CdIntToPos(descriptor->pathTable1Offs, &loc);
@@ -120,7 +114,7 @@ static int _CdReadIsoDescriptor(int session_offs)
CdRead(i>>11, (uint32_t*)_cd_iso_pathtable_buff, CdlModeSpeed);
if( CdReadSync(0, 0) )
{
- _LOG("psxcd: Error reading ISO path table.\n");
+ _sdk_log("psxcd: Error reading ISO path table.\n");
_cd_iso_error = CdlIsoReadError;
return -1;
@@ -148,11 +142,11 @@ static int _CdReadIsoDirectory(int lba)
CdIntToPos(lba, &loc);
i = CdPosToInt(&loc);
- _LOG("psxcd: Seek to sector %d\n", i);
+ _sdk_log("psxcd: Seek to sector %d\n", i);
if( !CdControl(CdlSetloc, (uint8_t*)&loc, 0) )
{
- _LOG("psxcd: Could not set seek destination.\n");
+ _sdk_log("psxcd: Could not set seek destination.\n");
_cd_iso_error = CdlIsoSeekError;
return -1;
@@ -168,7 +162,7 @@ static int _CdReadIsoDirectory(int lba)
CdRead(1, (uint32_t*)_cd_iso_directory_buff, CdlModeSpeed);
if( CdReadSync(0, 0) )
{
- _LOG("psxcd: Error reading initial directory record.\n");
+ _sdk_log("psxcd: Error reading initial directory record.\n");
_cd_iso_error = CdlIsoReadError;
return -1;
@@ -177,14 +171,14 @@ static int _CdReadIsoDirectory(int lba)
direntry = (ISO_DIR_ENTRY*)_cd_iso_directory_buff;
_cd_iso_directory_len = direntry->entrySize.lsb;
- _LOG("psxcd: Location of directory record = %d\n", direntry->entryOffs.lsb);
- _LOG("psxcd: Size of directory record = %d\n", _cd_iso_directory_len);
+ _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) )
{
- _LOG("psxcd: Could not set seek destination.\n");
+ _sdk_log("psxcd: Could not set seek destination.\n");
_cd_iso_error = CdlIsoSeekError;
return -1;
@@ -194,12 +188,12 @@ static int _CdReadIsoDirectory(int lba)
i = ((2047+_cd_iso_directory_len)>>11)<<11;
_cd_iso_directory_buff = (uint8_t*)malloc(i);
- _LOG("psxcd: Allocated %d bytes for directory record.\n", i);
+ _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) )
{
- _LOG("psxcd: Error reading remaining directory record.\n");
+ _sdk_log("psxcd: Error reading remaining directory record.\n");
_cd_iso_error = CdlIsoReadError;
return -1;
@@ -221,7 +215,7 @@ static void dump_directory(void)
ISO_DIR_ENTRY *dir_entry;
char namebuff[16];
- _LOG("psxcd: Cached directory record contents:\n");
+ _sdk_log("psxcd: Cached directory record contents:\n");
i = 0;
dir_pos = 0;
@@ -232,7 +226,7 @@ static void dump_directory(void)
strncpy(namebuff,
_cd_iso_directory_buff+dir_pos+sizeof(ISO_DIR_ENTRY), dir_entry->identifierLen);
- _LOG("psxcd: 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++;
@@ -251,7 +245,7 @@ static void dump_directory(void)
}
}
- _LOG("psxcd: --\n");
+ _sdk_log("psxcd: --\n");
}
@@ -262,7 +256,7 @@ static void dump_pathtable(void)
ISO_DESCRIPTOR *descriptor;
char namebuff[16];
- _LOG("psxcd: Path table entries:\n");
+ _sdk_log("psxcd: Path table entries:\n");
descriptor = (ISO_DESCRIPTOR*)_cd_iso_descriptor_buff;
@@ -276,7 +270,7 @@ static void dump_pathtable(void)
tbl_pos+sizeof(ISO_PATHTABLE_ENTRY),
tbl_entry->nameLength);
- _LOG("psxcd: %s\n", namebuff);
+ _sdk_log("psxcd: %s\n", namebuff);
// Advance to next entry
tbl_pos += sizeof(ISO_PATHTABLE_ENTRY)
@@ -372,7 +366,7 @@ static int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent)
ISO_DIR_ENTRY *dir_entry;
char namebuff[16];
- _LOG("psxcd: Locating file %s.\n", name);
+ _sdk_log("psxcd: Locating file %s.\n", name);
i = 0;
dir_pos = 0;
@@ -465,11 +459,11 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename)
// Read ISO descriptor and path table
if( _CdReadIsoDescriptor(0) )
{
- _LOG("psxcd: Could not read ISO file system.\n");
+ _sdk_log("psxcd: Could not read ISO file system.\n");
return NULL;
}
- // _LOG("psxcd: ISO file system cache updated.\n");
+ // _sdk_log("psxcd: ISO file system cache updated.\n");
// _cd_media_changed = 0;
//}
@@ -477,23 +471,23 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename)
num_dirs = get_pathtable_entry(0, NULL, NULL);
#ifndef NDEBUG
- _LOG("psxcd: Directories in path table: %d\n", num_dirs);
+ _sdk_log("psxcd: Directories in path table: %d\n", num_dirs);
rbuff = resolve_pathtable_path(num_dirs-1, tpath_rbuff+127);
if( !rbuff )
{
- _LOG("psxcd: Could not resolve path.\n");
+ _sdk_log("psxcd: Could not resolve path.\n");
}
else
{
- _LOG("psxcd: Longest path: %s|\n", rbuff);
+ _sdk_log("psxcd: Longest path: %s|\n", rbuff);
}
#endif
if( get_pathname(search_path, filename) )
{
- _LOG("psxcd: Search path = %s|\n", search_path);
+ _sdk_log("psxcd: Search path = %s|\n", search_path);
}
// Search the pathtable for a matching path
@@ -501,7 +495,7 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename)
for(i=1; i<num_dirs; i++)
{
rbuff = resolve_pathtable_path(i, tpath_rbuff+127);
- _LOG("psxcd: Found = %s|\n", rbuff);
+ _sdk_log("psxcd: Found = %s|\n", rbuff);
if( rbuff )
{
@@ -515,14 +509,14 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename)
if( !found_dir )
{
- _LOG("psxcd: Directory path not found.\n");
+ _sdk_log("psxcd: Directory path not found.\n");
return NULL;
}
- _LOG("psxcd: Found directory at record %d!\n", found_dir);
+ _sdk_log("psxcd: Found directory at record %d!\n", found_dir);
get_pathtable_entry(found_dir, &tbl_entry, NULL);
- _LOG("psxcd: Directory LBA = %d\n", tbl_entry.dirOffs);
+ _sdk_log("psxcd: Directory LBA = %d\n", tbl_entry.dirOffs);
_CdReadIsoDirectory(tbl_entry.dirOffs);
get_filename(fp->name, filename);
@@ -539,12 +533,12 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename)
if( find_dir_entry(fp->name, &dir_entry) )
{
- _LOG("psxcd: Could not find file.\n");
+ _sdk_log("psxcd: Could not find file.\n");
return NULL;
}
- _LOG("psxcd: Located file at LBA %d.\n", dir_entry.entryOffs.lsb);
+ _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;
@@ -568,11 +562,11 @@ CdlDIR *CdOpenDir(const char* path)
// Read ISO descriptor and path table
if( _CdReadIsoDescriptor( 0 ) )
{
- _LOG( "psxcd: Could not read ISO file system.\n" );
+ _sdk_log( "psxcd: Could not read ISO file system.\n" );
return NULL;
}
-// _LOG( "psxcd: ISO file system cache updated.\n" );
+// _sdk_log( "psxcd: ISO file system cache updated.\n" );
// _cd_media_changed = 0;
// }
@@ -582,7 +576,7 @@ CdlDIR *CdOpenDir(const char* path)
for( i=1; i<num_dirs; i++ )
{
rbuff = resolve_pathtable_path( i, tpath_rbuff+127 );
- _LOG( "psxcd: Found = %s|\n", rbuff );
+ _sdk_log( "psxcd: Found = %s|\n", rbuff );
if( rbuff )
{
@@ -596,14 +590,14 @@ CdlDIR *CdOpenDir(const char* path)
if( !found_dir )
{
- _LOG( "psxcd: Directory path not found.\n" );
+ _sdk_log( "psxcd: Directory path not found.\n" );
return NULL;
}
- _LOG( "psxcd: Found directory at record %d!\n", found_dir );
+ _sdk_log( "psxcd: Found directory at record %d!\n", found_dir );
get_pathtable_entry( found_dir, &tbl_entry, NULL );
- _LOG( "psxcd: Directory LBA = %d\n", tbl_entry.dirOffs );
+ _sdk_log( "psxcd: Directory LBA = %d\n", tbl_entry.dirOffs );
_CdReadIsoDirectory( tbl_entry.dirOffs );
@@ -668,11 +662,11 @@ int CdReadDir(CdlDIR *dir, CdlFILE* file)
file->size = dir_entry->entrySize.lsb;
- _LOG("psxcd: dir_entry->entryLength = %d, ", dir_entry->entryLength);
+ _sdk_log("psxcd: dir_entry->entryLength = %d, ", dir_entry->entryLength);
d_dir->_pos += dir_entry->entryLength;
- _LOG("psxcd: d_dir->_pos = %d\n", d_dir->_pos);
+ _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 )
@@ -776,15 +770,13 @@ int CdLoadSession(int session)
int i;
// Seek to specified session
- _LOG("psxcd: CdLoadSession(): Seeking to session %d...\n", session);
+ _sdk_log("psxcd: CdLoadSession(): Seeking to session %d...\n", session);
CdControl(CdlSetsession, (unsigned char*)&session,
(unsigned char*)&resultbuff);
if( CdSync(0, 0) == CdlDiskError )
{
- _LOG("psxcd: CdLoadSession(): Session seek failed, "
- "session does not exist.\n");
- _LOG("psxcd: CdLoadSession(): Restarting CD-ROM...\n");
+ _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);
@@ -805,7 +797,7 @@ int CdLoadSession(int session)
_ses_scanbuff = scanbuff;
// Begin scan for an ISO volume descriptor
- _LOG("psxcd: CdLoadSession(): Scanning for ISO9660 volume descriptor.\n");
+ _sdk_log("psxcd: CdLoadSession(): Scanning for ISO9660 volume descriptor.\n");
i = CdlModeSpeed;
CdControl(CdlSetmode, (unsigned char*)&i, 0);
@@ -820,7 +812,7 @@ int CdLoadSession(int session)
if( !_ses_scanfound )
{
- _LOG("psxcd: CdLoadSession(): Did not find volume descriptor.\n");
+ _sdk_log("psxcd: CdLoadSession(): Did not find volume descriptor.\n");
_cd_iso_error = CdlIsoInvalidFs;
EnterCriticalSection();
@@ -849,11 +841,11 @@ int CdLoadSession(int session)
loc = (CdlLOC*)resultbuff;
- _LOG("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));
i = CdPosToInt(loc)-17;
- _LOG("psxcd: CdLoadSession(): Session starting at LBA=%d\n", i);
+ _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 6730531..b914b5e 100644
--- a/libpsn00b/psxcd/psxcd.c
+++ b/libpsn00b/psxcd/psxcd.c
@@ -1,6 +1,6 @@
#include <stdint.h>
-#include <stdio.h>
#include <psxgpu.h>
+#include <psxetc.h>
#include <psxapi.h>
#include "psxcd.h"
@@ -21,12 +21,6 @@ volatile int _cd_last_sector_count;
int _cd_media_changed;
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
-
void _cd_init(void);
void _cd_control(unsigned char com, const void *param, int plen);
void _cd_wait_ack(void);
@@ -45,9 +39,9 @@ int CdInit(void) {
if(CdSync(0, 0) != CdlDiskError) {
CdControl(CdlDemute, 0, 0);
- _LOG("psxcd: setup done\n");
+ _sdk_log("psxcd: setup done\n");
} else {
- _LOG("psxcd: setup error, bad disc/drive or no disc inserted\n");
+ _sdk_log("psxcd: setup error, bad disc/drive or no disc inserted\n");
}
return 1;
@@ -311,7 +305,7 @@ static void CdDoRetry()
{
int cb;
- _LOG("psxcd: retrying read...\n");
+ _sdk_log("psxcd: retrying read...\n");
// Stop reading
CdControl(CdlPause, 0, 0);