aboutsummaryrefslogtreecommitdiff
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
parentb71a55bc489db6bc9beca5cee9cd584e82846ac8 (diff)
downloadpsn00bsdk-9b2ffc6078a850b7d354855cca7622090b41f30c.tar.gz
Add debug log buffering, fix GetHeapUsage()
-rw-r--r--libpsn00b/include/psxetc.h15
-rw-r--r--libpsn00b/libc/abort.c16
-rw-r--r--libpsn00b/libc/malloc.c22
-rw-r--r--libpsn00b/psxcd/getsector.c11
-rw-r--r--libpsn00b/psxcd/isofs.c112
-rw-r--r--libpsn00b/psxcd/psxcd.c14
-rw-r--r--libpsn00b/psxetc/dl.c91
-rw-r--r--libpsn00b/psxetc/logging.c50
-rw-r--r--libpsn00b/psxgpu/common.c31
-rw-r--r--libpsn00b/psxgpu/env.c2
-rw-r--r--libpsn00b/psxgpu/image.c22
-rw-r--r--libpsn00b/psxpress/mdec.c20
-rw-r--r--libpsn00b/psxspu/common.c14
13 files changed, 216 insertions, 204 deletions
diff --git a/libpsn00b/include/psxetc.h b/libpsn00b/include/psxetc.h
index 24485d9..fcfec06 100644
--- a/libpsn00b/include/psxetc.h
+++ b/libpsn00b/include/psxetc.h
@@ -6,12 +6,27 @@
#ifndef __PSXETC_H
#define __PSXETC_H
+/* Macros */
+
+// This macro is used internally by PSn00bSDK to log debug messages to a buffer
+// which is then printed to stdout when calling VSync().
+#ifdef NDEBUG
+#define _sdk_log(...)
+#define _sdk_dump_log()
+#else
+#define _sdk_log(...) _sdk_log_inner(__VA_ARGS__)
+#define _sdk_dump_log() _sdk_dump_log_inner()
+#endif
+
/* Public API */
#ifdef __cplusplus
extern "C" {
#endif
+void _sdk_log_inner(const char *fmt, ...);
+void _sdk_dump_log_inner(void);
+
void *InterruptCallback(int irq, void (*func)(void));
void *GetInterruptCallback(int irq);
void *DMACallback(int dma, void (*func)(void));
diff --git a/libpsn00b/libc/abort.c b/libpsn00b/libc/abort.c
index 1108160..2db5016 100644
--- a/libpsn00b/libc/abort.c
+++ b/libpsn00b/libc/abort.c
@@ -1,16 +1,10 @@
-#include <stdio.h>
-
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
+#include <psxetc.h>
/* Standard abort */
-void abort() {
- _LOG("abort()\n");
+void abort(void) {
+ _sdk_log("abort()\n");
for (;;)
__asm__ volatile("");
@@ -19,7 +13,7 @@ void abort() {
/* Internal function used by assert() macro */
void _assert_abort(const char *file, int line, const char *expr) {
- _LOG("%s:%d: assert(%s)\n", file, line, expr);
+ _sdk_log("%s:%d: assert(%s)\n", file, line, expr);
for (;;)
__asm__ volatile("");
@@ -28,7 +22,7 @@ void _assert_abort(const char *file, int line, const char *expr) {
/* Pure virtual function call (C++) */
void __cxa_pure_virtual(void) {
- _LOG("__cxa_pure_virtual()\n");
+ _sdk_log("__cxa_pure_virtual()\n");
for (;;)
__asm__ volatile("");
diff --git a/libpsn00b/libc/malloc.c b/libpsn00b/libc/malloc.c
index acac753..e9fd6f4 100644
--- a/libpsn00b/libc/malloc.c
+++ b/libpsn00b/libc/malloc.c
@@ -120,7 +120,7 @@ __attribute__((weak)) void *malloc(size_t size) {
_alloc_head = new;
_alloc_tail = new;
- TrackHeapUsage(_size);
+ TrackHeapUsage(size);
return ptr;
}
@@ -139,7 +139,7 @@ __attribute__((weak)) void *malloc(size_t size) {
_alloc_head->prev = new;
_alloc_head = new;
- TrackHeapUsage(_size);
+ TrackHeapUsage(size);
return ptr;
}
@@ -157,7 +157,7 @@ __attribute__((weak)) void *malloc(size_t size) {
(new->next)->prev = new;
prev->next = new;
- TrackHeapUsage(_size);
+ TrackHeapUsage(size);
return ptr;
}
@@ -175,7 +175,7 @@ __attribute__((weak)) void *malloc(size_t size) {
_alloc_tail->next = new;
_alloc_tail = new;
- TrackHeapUsage(_size);
+ TrackHeapUsage(size);
return ptr;
}
@@ -196,7 +196,7 @@ __attribute__((weak)) void *realloc(void *ptr, size_t size) {
// New memory block shorter?
if (prev->size >= _size) {
- TrackHeapUsage(_size - prev->size);
+ TrackHeapUsage(size - prev->size);
prev->size = _size;
if (!prev->next)
@@ -211,14 +211,14 @@ __attribute__((weak)) void *realloc(void *ptr, size_t size) {
if (!new)
return 0;
- TrackHeapUsage(_size - prev->size);
+ TrackHeapUsage(size - prev->size);
prev->size = _size;
return ptr;
}
// Do we have free memory after it?
if (((prev->next)->ptr - ptr) > _size) {
- TrackHeapUsage(_size - prev->size);
+ TrackHeapUsage(size - prev->size);
prev->size = _size;
return ptr;
}
@@ -250,7 +250,7 @@ __attribute__((weak)) void free(void *ptr) {
sbrk(-size);
}
- TrackHeapUsage(-size);
+ TrackHeapUsage(-(_alloc_head->size));
return;
}
@@ -265,17 +265,15 @@ __attribute__((weak)) void free(void *ptr) {
if (cur->next) {
// In the middle, just unlink it
(cur->next)->prev = cur->prev;
- TrackHeapUsage(-(cur->size + sizeof(BlockHeader)));
} else {
// At the end, shrink heap
- _alloc_tail = cur->prev;
-
void *top = sbrk(0);
size_t size = (top - (cur->prev)->ptr) - (cur->prev)->size;
+ _alloc_tail = cur->prev;
sbrk(-size);
- TrackHeapUsage(-size);
}
+ TrackHeapUsage(-(cur->size));
(cur->prev)->next = cur->next;
}
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);
diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c
index cf4e466..b85a7df 100644
--- a/libpsn00b/psxetc/dl.c
+++ b/libpsn00b/psxetc/dl.c
@@ -30,6 +30,7 @@
#include <elf.h>
#include <dlfcn.h>
#include <string.h>
+#include <psxetc.h>
#include <psxapi.h>
/* Compile options */
@@ -66,12 +67,6 @@ void *(*_dl_resolve_callback)(DLL *, const char *) = 0;
/* Private utilities */
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
-
#define _ERROR(code, ret) { \
_error_code = code; \
return ret; \
@@ -92,7 +87,7 @@ void *_dl_resolve_helper(DLL *dll, uint32_t index) {
address = DL_GetSymbolByName(_name);
if (!address) {
- _LOG("psxetc: FATAL! can't resolve %s, locking up\n", _name);
+ _sdk_log("psxetc: FATAL! can't resolve %s, locking up\n", _name);
while (1)
__asm__ volatile("nop");
}
@@ -133,7 +128,7 @@ static uint32_t _elf_hash(const char *str) {
static uint8_t *_dl_load_file(const char *filename, size_t *size_output) {
int32_t fd = open(filename, 1);
if (fd < 0) {
- _LOG("psxetc: can't open %s, error = %d\n", filename, fd);
+ _sdk_log("psxetc: can't open %s, error = %d\n", filename, fd);
_ERROR(RTLD_E_FILE_OPEN, 0);
}
@@ -144,11 +139,11 @@ static uint8_t *_dl_load_file(const char *filename, size_t *size_output) {
uint8_t *buffer = malloc(size);
if (!buffer) {
- _LOG("psxetc: unable to allocate %d bytes for %s\n", size, filename);
+ _sdk_log("psxetc: unable to allocate %d bytes for %s\n", size, filename);
_ERROR(RTLD_E_FILE_ALLOC, 0);
}
- //_LOG("psxetc: loading %s (%d bytes)..", filename, size);
+ //_sdk_log("psxetc: loading %s (%d bytes)..", filename, size);
for (uint32_t offset = 0; offset < size; ) {
int32_t length = read(fd, &(buffer[offset]), 0x800);
@@ -157,16 +152,16 @@ static uint8_t *_dl_load_file(const char *filename, size_t *size_output) {
close(fd);
free(buffer);
- _LOG("failed, error = %d\n", length);
+ _sdk_log("failed, error = %d\n", length);
_ERROR(RTLD_E_FILE_READ, 0);
}
- //_LOG(".");
+ //_sdk_log(".");
offset += length;
}
close(fd);
- _LOG(" done\n");
+ _sdk_log(" done\n");
if (size_output)
*size_output = size;
@@ -192,7 +187,7 @@ int32_t DL_ParseSymbolMap(const char *ptr, size_t size) {
// in order to minimize hash table size
_symbol_map.nbucket = entries;
_symbol_map.nchain = entries;
- _LOG(
+ _sdk_log(
"psxetc: allocating nbucket = %d, nchain = %d\n",
_symbol_map.nbucket,
entries
@@ -205,7 +200,7 @@ int32_t DL_ParseSymbolMap(const char *ptr, size_t size) {
_symbol_map.chain = malloc(sizeof(uint32_t) * entries);
if (!_symbol_map.entries || !_symbol_map.bucket || !_symbol_map.chain) {
- _LOG("psxetc: unable to allocate symbol map table\n");
+ _sdk_log("psxetc: unable to allocate symbol map table\n");
_ERROR(RTLD_E_MAP_ALLOC, -1);
}
@@ -248,7 +243,7 @@ int32_t DL_ParseSymbolMap(const char *ptr, size_t size) {
(_type == 'D') || // .data
(_type == 'B') // .bss
)) {
- //_LOG(
+ //_sdk_log(
//"psxetc: map sym: %08x,%08x [%c %s]\n",
//address, _size, _type, name
//);
@@ -274,7 +269,7 @@ int32_t DL_ParseSymbolMap(const char *ptr, size_t size) {
pos++;
}
- _LOG("psxetc: parsed %d symbols\n", entries);
+ _sdk_log("psxetc: parsed %d symbols\n", entries);
if (!entries)
_ERROR(RTLD_E_NO_SYMBOLS, -1);
@@ -307,7 +302,7 @@ void DL_UnloadSymbolMap(void) {
void *DL_GetSymbolByName(const char *name) {
if (!_symbol_map.entries) {
- _LOG("psxetc: attempted lookup with no map loaded\n");
+ _sdk_log("psxetc: attempted lookup with no map loaded\n");
_ERROR(RTLD_E_NO_MAP, 0);
}
@@ -319,7 +314,7 @@ void *DL_GetSymbolByName(const char *name) {
// calculated.
for (uint32_t i = _symbol_map.bucket[hash_mod]; i != 0xffffffff;) {
if (i >= _symbol_map.nchain) {
- _LOG(
+ _sdk_log(
"psxetc: GetSymbolByName() index out of bounds (%d >= %d)\n",
i, _symbol_map.nchain
);
@@ -329,14 +324,14 @@ void *DL_GetSymbolByName(const char *name) {
MapEntry *entry = &(_symbol_map.entries[i]);
if (hash == entry->hash) {
- //_LOG("psxetc: map lookup [%s = %08x]\n", name, entry->ptr);
+ //_sdk_log("psxetc: map lookup [%s = %08x]\n", name, entry->ptr);
return entry->ptr;
}
i = _symbol_map.chain[i];
}
- _LOG("psxetc: map lookup [%s not found]\n", name);
+ _sdk_log("psxetc: map lookup [%s not found]\n", name);
_ERROR(RTLD_E_MAP_SYMBOL, 0);
}
@@ -352,14 +347,14 @@ DLL *DL_CreateDLL(void *ptr, size_t size, DL_ResolveMode mode) {
DLL *dll = malloc(sizeof(DLL));
if (!dll) {
- _LOG("psxetc: unable to allocate DLL struct\n");
+ _sdk_log("psxetc: unable to allocate DLL struct\n");
_ERROR(RTLD_E_DLL_ALLOC, 0);
}
dll->ptr = ptr;
dll->malloc_ptr = (mode & RTLD_FREE_ON_DESTROY) ? ptr : 0;
dll->size = size;
- _LOG("psxetc: initializing DLL at %08x\n", ptr);
+ _sdk_log("psxetc: initializing DLL at %08x\n", ptr);
// Interpret the key-value pairs in the .dynamic section to obtain info
// about all the other sections. The pairs are null-terminated, which makes
@@ -368,128 +363,128 @@ DLL *DL_CreateDLL(void *ptr, size_t size, DL_ResolveMode mode) {
uint32_t first_got_sym = 0;
for (Elf32_Dyn *dyn = (Elf32_Dyn *) ptr; dyn->d_tag; dyn++) {
- //_LOG("psxetc: .dynamic %08x=%08x ", dyn->d_tag, dyn->d_un.d_val);
+ //_sdk_log("psxetc: .dynamic %08x=%08x ", dyn->d_tag, dyn->d_un.d_val);
switch (dyn->d_tag) {
// Offset of .got section
case DT_PLTGOT:
- //_LOG("[PLTGOT]\n");
+ //_sdk_log("[PLTGOT]\n");
dll->got = (void *) (ptr + dyn->d_un.d_val);
break;
// Offset of .hash section
case DT_HASH:
- //_LOG("[HASH]\n");
+ //_sdk_log("[HASH]\n");
dll->hash = (void *) (ptr + dyn->d_un.d_val);
break;
// Offset of .dynstr (NOT .strtab) section
case DT_STRTAB:
- //_LOG("[STRTAB]\n");
+ //_sdk_log("[STRTAB]\n");
dll->strtab = (void *) (ptr + dyn->d_un.d_val);
break;
// Offset of .dynsym (NOT .symtab) section
case DT_SYMTAB:
- //_LOG("[SYMTAB]\n");
+ //_sdk_log("[SYMTAB]\n");
dll->symtab = (void *) (ptr + dyn->d_un.d_val);
break;
// Length of .dynstr section
//case DT_STRSZ:
- //_LOG("[STRSZ]\n");
+ //_sdk_log("[STRSZ]\n");
//break;
// Length of each .dynsym entry
case DT_SYMENT:
- //_LOG("[SYMENT]\n");
+ //_sdk_log("[SYMENT]\n");
// Only 16-byte symbol table entries are supported.
if (dyn->d_un.d_val != sizeof(Elf32_Sym)) {
free(dll);
- _LOG("psxetc: invalid DLL symtab entry size %d\n", dyn->d_un.d_val);
+ _sdk_log("psxetc: invalid DLL symtab entry size %d\n", dyn->d_un.d_val);
_ERROR(RTLD_E_DLL_FORMAT, 0);
}
break;
// MIPS ABI (?) version
case DT_MIPS_RLD_VERSION:
- //_LOG("[MIPS_RLD_VERSION]\n");
+ //_sdk_log("[MIPS_RLD_VERSION]\n");
// Versions other than 1 are unsupported (do they even exist?).
if (dyn->d_un.d_val != 1) {
free(dll);
- _LOG("psxetc: invalid DLL version %d\n", dyn->d_un.d_val);
+ _sdk_log("psxetc: invalid DLL version %d\n", dyn->d_un.d_val);
_ERROR(RTLD_E_DLL_FORMAT, 0);
}
break;
// DLL/ABI flags
case DT_MIPS_FLAGS:
- //_LOG("[MIPS_FLAGS]\n");
+ //_sdk_log("[MIPS_FLAGS]\n");
// Shortcut pointers (whatever they are) are not supported.
if (dyn->d_un.d_val & RHF_QUICKSTART) {
free(dll);
- _LOG("psxetc: invalid DLL flags\n");
+ _sdk_log("psxetc: invalid DLL flags\n");
_ERROR(RTLD_E_DLL_FORMAT, 0);
}
break;
// Number of local (not to resolve) GOT entries
case DT_MIPS_LOCAL_GOTNO:
- //_LOG("[MIPS_LOCAL_GOTNO]\n");
+ //_sdk_log("[MIPS_LOCAL_GOTNO]\n");
local_got_len = dyn->d_un.d_val;
break;
// Base address DLL was compiled for
case DT_MIPS_BASE_ADDRESS:
- //_LOG("[MIPS_BASE_ADDRESS]\n");
+ //_sdk_log("[MIPS_BASE_ADDRESS]\n");
// Base addresses other than zero are not supported. It would
// be easy enough to support them, but why?
if (dyn->d_un.d_val) {
free(dll);
- _LOG("psxetc: invalid DLL base address %08x\n", dyn->d_un.d_val);
+ _sdk_log("psxetc: invalid DLL base address %08x\n", dyn->d_un.d_val);
_ERROR(RTLD_E_DLL_FORMAT, 0);
}
break;
// Number of symbol table entries
case DT_MIPS_SYMTABNO:
- //_LOG("[MIPS_SYMTABNO]\n");
+ //_sdk_log("[MIPS_SYMTABNO]\n");
dll->symbol_count = dyn->d_un.d_val;
break;
// Index of first unresolved symbol table entry
//case DT_MIPS_UNREFEXTNO:
- //_LOG("[MIPS_UNREFEXTNO]\n");
+ //_sdk_log("[MIPS_UNREFEXTNO]\n");
//break;
// Index of first symbol table entry which has a matching GOT entry
case DT_MIPS_GOTSYM:
- //_LOG("[MIPS_GOTSYM]\n");
+ //_sdk_log("[MIPS_GOTSYM]\n");
first_got_sym = dyn->d_un.d_val;
break;
// Number of pages the GOT is split into (does not apply to PS1)
//case DT_MIPS_HIPAGENO:
- //_LOG("[MIPS_HIPAGENO]\n");
+ //_sdk_log("[MIPS_HIPAGENO]\n");
//break;
//default:
- //_LOG("[ignored]\n");
+ //_sdk_log("[ignored]\n");
}
}
@@ -501,7 +496,7 @@ DLL *DL_CreateDLL(void *ptr, size_t size, DL_ResolveMode mode) {
((uint32_t) ptr + size - (uint32_t) dll->got) / sizeof(uint32_t) - 2;
dll->got_length = local_got_len + (dll->symbol_count - first_got_sym) - 2;
- _LOG(
+ _sdk_log(
"psxetc: %d symbols, %d GOT entries\n",
dll->symbol_count, dll->got_length
);
@@ -530,7 +525,7 @@ DLL *DL_CreateDLL(void *ptr, size_t size, DL_ResolveMode mode) {
continue;
sym->st_value += (uint32_t) ptr;
- //_LOG(
+ //_sdk_log(
//"psxetc: DLL sym: %08x,%08x [%s]\n",
//sym->st_value, sym->st_size, _name
//);
@@ -641,7 +636,7 @@ void *DL_GetDLLSymbol(const DLL *dll, const char *name) {
// provided.
for (uint32_t i = bucket[hash_mod]; i != 0xffffffff;) {
if (i >= nchain) {
- _LOG("psxetc: DL_GetDLLSymbol() index out of bounds (%d >= %d)\n", i, nchain);
+ _sdk_log("psxetc: DL_GetDLLSymbol() index out of bounds (%d >= %d)\n", i, nchain);
_ERROR(RTLD_E_HASH_LOOKUP, 0);
}
@@ -649,14 +644,14 @@ void *DL_GetDLLSymbol(const DLL *dll, const char *name) {
const char *_name = &(dll->strtab[sym->st_name]);
if (!strcmp(name, _name)) {
- //_LOG("psxetc: DLL lookup [%s = %08x]\n", name, sym->st_value);
+ //_sdk_log("psxetc: DLL lookup [%s = %08x]\n", name, sym->st_value);
return sym->st_value;
}
i = chain[i];
}
- _LOG("psxetc: DLL lookup [%s not found]\n", name);
+ _sdk_log("psxetc: DLL lookup [%s not found]\n", name);
_ERROR(RTLD_E_DLL_SYMBOL, 0);
}
diff --git a/libpsn00b/psxetc/logging.c b/libpsn00b/psxetc/logging.c
new file mode 100644
index 0000000..5199190
--- /dev/null
+++ b/libpsn00b/psxetc/logging.c
@@ -0,0 +1,50 @@
+/*
+ * PSn00bSDK internal debug logger
+ * (C) 2022 spicyjpeg - MPL licensed
+ *
+ * This file provides the (admittedly minimal) logging system used by all
+ * PSn00bSDK libraries. Log messages and warnings are issued using the
+ * _sdk_log() macro and collected into a buffer, whose contents can be flushed
+ * by calling _sdk_dump_log() (by default this is done by VSync()). Logging is
+ * only enabled in debug builds of libpsn00b.
+ */
+
+#include <stddef.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <psxapi.h>
+#include <psxetc.h>
+
+#define LOG_BUFFER_SIZE 256
+
+#ifndef NDEBUG
+
+/* Internal globals */
+
+static char _log_buffer[LOG_BUFFER_SIZE];
+static size_t _log_buffer_length = 0;
+
+/* Internal logging API */
+
+void _sdk_log_inner(const char *fmt, ...) {
+ va_list ap;
+
+ va_start(ap, fmt);
+ _log_buffer_length += vsnprintf(
+ &_log_buffer[_log_buffer_length],
+ LOG_BUFFER_SIZE - _log_buffer_length,
+ fmt,
+ ap
+ );
+ va_end(ap);
+}
+
+void _sdk_dump_log_inner(void) {
+ if (!_log_buffer_length)
+ return;
+
+ write(1, _log_buffer, _log_buffer_length);
+ _log_buffer_length = 0;
+}
+
+#endif
diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c
index bf70b72..a262472 100644
--- a/libpsn00b/psxgpu/common.c
+++ b/libpsn00b/psxgpu/common.c
@@ -4,7 +4,6 @@
*/
#include <stdint.h>
-#include <stdio.h>
#include <psxetc.h>
#include <psxapi.h>
#include <psxgpu.h>
@@ -36,13 +35,7 @@ static volatile uint8_t _queue_head, _queue_tail, _queue_length;
static volatile uint32_t _vblank_counter;
static volatile uint16_t _last_hblank;
-/* Private utilities and interrupt handlers */
-
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
+/* Private interrupt handlers */
static void _vblank_handler(void) {
_vblank_counter++;
@@ -57,8 +50,8 @@ static void _gpu_dma_handler(void) {
__asm__ volatile("");
if (--_queue_length) {
- QueueEntry *entry = &_draw_queue[_queue_head++];
- _queue_head %= QUEUE_LENGTH;
+ volatile QueueEntry *entry = &_draw_queue[_queue_head++];
+ _queue_head %= QUEUE_LENGTH;
entry->func(entry->arg1, entry->arg2, entry->arg3);
} else {
@@ -82,7 +75,7 @@ void ResetGraph(int mode) {
_gpu_video_mode = (GPU_GP1 >> 20) & 1;
ExitCriticalSection();
- _LOG("psxgpu: setup done, default mode is %s\n", _gpu_video_mode ? "PAL" : "NTSC");
+ _sdk_log("psxgpu: setup done, default mode is %s\n", _gpu_video_mode ? "PAL" : "NTSC");
}
if (mode == 3) {
@@ -115,13 +108,13 @@ void ResetGraph(int mode) {
// TODO: add support for no$psx's "halt" register
static void _default_vsync_halt(void) {
int counter = _vblank_counter;
-
for (int i = VSYNC_TIMEOUT; i; i--) {
if (counter != _vblank_counter)
return;
}
- _LOG("psxgpu: VSync() timeout\n");
+ _sdk_log("psxgpu: VSync() timeout\n");
+ _sdk_dump_log();
ChangeClearPAD(0);
ChangeClearRCnt(3, 0);
}
@@ -137,6 +130,7 @@ int VSync(int mode) {
// Wait for at least one vertical blank event to occur.
do {
+ _sdk_dump_log();
_vsync_halt_func();
// If interlaced mode is enabled, wait until the GPU starts displaying
@@ -190,15 +184,15 @@ int EnqueueDrawOp(
if (_queue_length) {
if (_queue_length >= QUEUE_LENGTH) {
IRQ_MASK = mask;
- _LOG("psxgpu: draw queue overflow, dropping commands\n");
+ _sdk_log("psxgpu: draw queue overflow, dropping commands\n");
return -1;
}
int length = _queue_length;
_queue_length = length + 1;
- QueueEntry *entry = &_draw_queue[_queue_tail++];
- _queue_tail %= QUEUE_LENGTH;
+ volatile QueueEntry *entry = &_draw_queue[_queue_tail++];
+ _queue_tail %= QUEUE_LENGTH;
entry->func = func;
entry->arg1 = arg1;
@@ -236,7 +230,8 @@ int DrawSync(int mode) {
while (!(GPU_GP1 & (1 << 26)))
__asm__ volatile("");
} else {
- printf("psxgpu: DrawSync() timeout\n");
+ _sdk_log("psxgpu: DrawSync() timeout\n");
+ _sdk_dump_log();
}
return _queue_length;
@@ -297,7 +292,7 @@ void DrawPrim(const uint32_t *pri) {
}
int DrawOTag(const uint32_t *ot) {
- return EnqueueDrawOp(&DrawOTag2, (uint32_t) ot, 0, 0);
+ return EnqueueDrawOp((void *) &DrawOTag2, (uint32_t) ot, 0, 0);
}
void DrawOTag2(const uint32_t *ot) {
diff --git a/libpsn00b/psxgpu/env.c b/libpsn00b/psxgpu/env.c
index 1b97026..f513727 100644
--- a/libpsn00b/psxgpu/env.c
+++ b/libpsn00b/psxgpu/env.c
@@ -85,7 +85,7 @@ int DrawOTagEnv(const uint32_t *ot, DRAWENV *env) {
//while (!(GPU_GP1 & (1 << 26)))
//__asm__ volatile("");
- return EnqueueDrawOp(&DrawOTag2, (uint32_t) prim, 0, 0);
+ return EnqueueDrawOp((void *) &DrawOTag2, (uint32_t) prim, 0, 0);
}
void PutDrawEnv(DRAWENV *env) {
diff --git a/libpsn00b/psxgpu/image.c b/libpsn00b/psxgpu/image.c
index c09a59d..968dde5 100644
--- a/libpsn00b/psxgpu/image.c
+++ b/libpsn00b/psxgpu/image.c
@@ -4,7 +4,7 @@
*/
#include <stdint.h>
-#include <stdio.h>
+#include <psxetc.h>
#include <psxgpu.h>
#include <hwregs_c.h>
@@ -12,20 +12,14 @@
/* Private utilities */
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
-
static void _dma_transfer(const RECT *rect, uint32_t *data, int write) {
size_t length = rect->w * rect->h;
if (length % 2)
- _LOG("psxgpu: can't transfer an odd number of pixels\n");
+ _sdk_log("psxgpu: can't transfer an odd number of pixels\n");
length /= 2;
if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) {
- _LOG("psxgpu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
+ _sdk_log("psxgpu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
length += DMA_CHUNK_LENGTH - 1;
}
@@ -53,15 +47,19 @@ static void _dma_transfer(const RECT *rect, uint32_t *data, int write) {
/* VRAM transfer API */
int LoadImage(const RECT *rect, const uint32_t *data) {
- return EnqueueDrawOp(&_dma_transfer, (uint32_t) rect, (uint32_t) data, 1);
+ return EnqueueDrawOp(
+ (void *) &_dma_transfer, (uint32_t) rect, (uint32_t) data, 1
+ );
}
int StoreImage(const RECT *rect, uint32_t *data) {
- return EnqueueDrawOp(&_dma_transfer, (uint32_t) rect, (uint32_t) data, 0);
+ return EnqueueDrawOp(
+ (void *) &_dma_transfer, (uint32_t) rect, (uint32_t) data, 0
+ );
}
int MoveImage(const RECT *rect, int x, int y) {
- return EnqueueDrawOp(&MoveImage2, (uint32_t) rect, x, y);
+ return EnqueueDrawOp((void *) &MoveImage2, (uint32_t) rect, x, y);
}
void LoadImage2(const RECT *rect, const uint32_t *data) {
diff --git a/libpsn00b/psxpress/mdec.c b/libpsn00b/psxpress/mdec.c
index 06510cb..d43436f 100644
--- a/libpsn00b/psxpress/mdec.c
+++ b/libpsn00b/psxpress/mdec.c
@@ -4,7 +4,7 @@
*/
#include <stdint.h>
-#include <stdio.h>
+#include <psxetc.h>
#include <psxapi.h>
#include <psxpress.h>
#include <hwregs_c.h>
@@ -81,14 +81,6 @@ static const DECDCTENV _default_mdec_env = {
}
};
-/* Private utilities */
-
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
-
/* Public API */
void DecDCTReset(int mode) {
@@ -135,7 +127,7 @@ void DecDCTin(const uint32_t *data, int mode) {
// the stream.
void DecDCTinRaw(const uint32_t *data, size_t length) {
if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) {
- _LOG("psxpress: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
+ _sdk_log("psxpress: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
length += DMA_CHUNK_LENGTH - 1;
}
@@ -157,7 +149,8 @@ int DecDCTinSync(int mode) {
return 0;
}
- _LOG("psxpress: DecDCTinSync() timeout\n");
+ _sdk_log("psxpress: DecDCTinSync() timeout\n");
+ _sdk_dump_log();
return -1;
}
@@ -165,7 +158,7 @@ void DecDCTout(uint32_t *data, size_t length) {
DecDCToutSync(0);
if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) {
- _LOG("psxpress: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
+ _sdk_log("psxpress: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
length += DMA_CHUNK_LENGTH - 1;
}
@@ -187,6 +180,7 @@ int DecDCToutSync(int mode) {
return 0;
}
- _LOG("psxpress: DecDCToutSync() timeout\n");
+ _sdk_log("psxpress: DecDCToutSync() timeout\n");
+ _sdk_dump_log();
return -1;
}
diff --git a/libpsn00b/psxspu/common.c b/libpsn00b/psxspu/common.c
index 380bd3d..7d90858 100644
--- a/libpsn00b/psxspu/common.c
+++ b/libpsn00b/psxspu/common.c
@@ -4,7 +4,7 @@
*/
#include <stdint.h>
-#include <stdio.h>
+#include <psxetc.h>
#include <psxspu.h>
#include <hwregs_c.h>
@@ -19,28 +19,22 @@ static uint16_t _transfer_addr = WRITABLE_AREA_ADDR;
/* Private utilities */
-#ifdef NDEBUG
-#define _LOG(...)
-#else
-#define _LOG(...) printf(__VA_ARGS__)
-#endif
-
static void _wait_status(uint16_t mask, uint16_t value) {
for (int i = STATUS_TIMEOUT; i; i--) {
if ((SPU_STAT & mask) == value)
return;
}
- _LOG("psxspu: status register timeout (0x%04x)\n", SPU_STAT);
+ _sdk_log("psxspu: status register timeout (0x%04x)\n", SPU_STAT);
}
static void _dma_transfer(uint32_t *data, size_t length, int write) {
if (length % 4)
- _LOG("psxspu: can't transfer a number of bytes that isn't multiple of 4\n");
+ _sdk_log("psxspu: can't transfer a number of bytes that isn't multiple of 4\n");
length /= 4;
if ((length >= DMA_CHUNK_LENGTH) && (length % DMA_CHUNK_LENGTH)) {
- _LOG("psxspu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
+ _sdk_log("psxspu: transfer data length (%d) is not a multiple of %d, rounding\n", length, DMA_CHUNK_LENGTH);
length += DMA_CHUNK_LENGTH - 1;
}