aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2020-02-28 11:41:30 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2020-02-28 11:41:30 +0800
commit84422eceb3ecaa325f814b306665e58b0c3be647 (patch)
tree40abe71be412ee2845a66d46fe1146a073c04c52 /libpsn00b
parente14a2a4cde7fa2518df2cb0ed7063962bd52a46e (diff)
downloadpsn00bsdk-84422eceb3ecaa325f814b306665e58b0c3be647.tar.gz
Added CdOpenDir(), CdReadDir() and CdCloseDir(). Fixed SpuKeyOn() bug and added cdbrowse example.
Diffstat (limited to 'libpsn00b')
-rw-r--r--libpsn00b/include/psxcd.h61
-rw-r--r--libpsn00b/include/psxgpu.h16
-rw-r--r--libpsn00b/psxcd/isofs.c (renamed from libpsn00b/psxcd/cdsearchfile.c)219
-rw-r--r--libpsn00b/psxcd/psxcd_asm.s11
-rw-r--r--libpsn00b/psxgpu/getode.s20
-rw-r--r--libpsn00b/psxspu/spukeyon.s3
6 files changed, 286 insertions, 44 deletions
diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h
index 5bb1b5f..1d045d9 100644
--- a/libpsn00b/include/psxcd.h
+++ b/libpsn00b/include/psxcd.h
@@ -65,13 +65,21 @@
#define CdlDataEnd 0x04
#define CdlDiskError 0x05
+/*
+ * CD-ROM file system error codes (original)
+ */
+#define CdlIsoOkay 0x00
+#define CdlIsoSeekError 0x01
+#define CdlIsoReadError 0x02
+#define CdlIsoInvalidFs 0x03
+
#define btoi(b) ((b)/16*10+(b)%16) /* Convert BCD value to integer */
#define itob(i) ((i)/10*16+(i)%10) /* Convert integer to BCD value */
/*
* CD-ROM disc location struct
*/
-typedef struct CdlLOC
+typedef struct _CdlLOC
{
u_char minute;
u_char second;
@@ -82,7 +90,7 @@ typedef struct CdlLOC
/*
* CD-ROM audio attenuation struct (volume)
*/
-typedef struct CdlATV
+typedef struct _CdlATV
{
u_char val0; /* L -> SPU L */
u_char val1; /* L -> SPU R */
@@ -93,20 +101,23 @@ typedef struct CdlATV
/*
* CD-ROM file information struct
*/
-typedef struct CdlFILE
+typedef struct _CdlFILE
{
CdlLOC loc;
u_int size;
char name[16];
} CdlFILE;
-typedef struct CdlFILTER
+typedef struct _CdlFILTER
{
u_char file;
u_char chan;
u_short pad;
} CdlFILTER;
+/* Directory query context */
+typedef void* CdlDIR;
+
/* Data callback */
typedef void (*CdlCB)(int, unsigned char *);
@@ -114,33 +125,41 @@ typedef void (*CdlCB)(int, unsigned char *);
extern "C" {
#endif
-int CdInit(int mode);
+int CdInit(int mode);
-CdlLOC *CdIntToPos(int i, CdlLOC *p);
-int CdPosToInt(CdlLOC *p);
-int CdGetToc(CdlLOC *toc);
+CdlLOC* CdIntToPos(int i, CdlLOC *p);
+int CdPosToInt(CdlLOC *p);
+int CdGetToc(CdlLOC *toc);
-int CdControl(unsigned char com, unsigned char *param, unsigned char *result);
-int CdControlB(unsigned char com, unsigned char *param, unsigned char *result);
-int CdControlF(unsigned char com, unsigned char *param);
-int CdSync(int mode, unsigned char *result);
+int CdControl(unsigned char com, unsigned char *param, unsigned char *result);
+int CdControlB(unsigned char com, unsigned char *param, unsigned char *result);
+int CdControlF(unsigned char com, unsigned char *param);
+int CdSync(int mode, unsigned char *result);
unsigned int CdSyncCallback(CdlCB func);
-long CdReadyCallback(CdlCB func);
-int CdGetSector(void *madr, int size);
+long CdReadyCallback(CdlCB func);
+int CdGetSector(void *madr, int size);
-CdlFILE *CdSearchFile(CdlFILE *loc, const char *filename);
-int CdRead(int sectors, unsigned int *buf, int mode);
-int CdReadSync(int mode, unsigned char *result);
+CdlFILE* CdSearchFile(CdlFILE *loc, const char *filename);
+
+int CdRead(int sectors, unsigned int *buf, int mode);
+int CdReadSync(int mode, unsigned char *result);
unsigned int CdReadCallback(CdlCB func);
-int CdStatus(void);
-int CdMode(void);
+int CdStatus(void);
+int CdMode(void);
-int CdMix(CdlATV *vol);
+int CdMix(CdlATV *vol);
/* ORIGINAL CODE */
-long *CdAutoPauseCallback(void(*func)());
+CdlDIR* CdOpenDir(const char* path);
+int CdReadDir(CdlDIR* dir, CdlFILE* file);
+void CdCloseDir(CdlDIR* dir);
+
+int CdGetVolumeLabel(char* label);
+
+long* CdAutoPauseCallback(void(*func)());
+int CdIsoError();
#ifdef __cplusplus
}
diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h
index 65d3f66..01b3280 100644
--- a/libpsn00b/include/psxgpu.h
+++ b/libpsn00b/include/psxgpu.h
@@ -540,9 +540,11 @@ extern "C" {
void ResetGraph(int mode);
-int GetVideoMode();
+int GetVideoMode(void);
void SetVideoMode(int mode);
+int GetODE(void);
+
void PutDispEnvRaw(DISPENV_RAW *disp);
void PutDispEnv(DISPENV *disp);
void PutDrawEnv(DRAWENV *draw);
@@ -551,16 +553,16 @@ void SetDispMask(int mask);
int VSync(int m);
int DrawSync(int m);
-void WaitGPUcmd();
-void WaitGPUdma();
+void WaitGPUcmd(void);
+void WaitGPUdma(void);
// Callback hook functions
-void *VSyncCallback(void (*func)());
-void *DrawSyncCallback(void (*func)());
+void *VSyncCallback(void (*func)(void));
+void *DrawSyncCallback(void (*func)(void));
// Interrupt callback functions
-void *DMACallback(int dma, void (*func)());
-void *InterruptCallback(int irq, void (*func)());
+void *DMACallback(int dma, void (*func)(void));
+void *InterruptCallback(int irq, void (*func)(void));
void *GetInterruptCallback(int irq); // Original
void RestartCallback();
diff --git a/libpsn00b/psxcd/cdsearchfile.c b/libpsn00b/psxcd/isofs.c
index 60e4377..7d48eea 100644
--- a/libpsn00b/psxcd/cdsearchfile.c
+++ b/libpsn00b/psxcd/isofs.c
@@ -150,18 +150,27 @@ typedef struct ISO_DESCRIPTOR
} ISO_DESCRIPTOR;
+typedef struct _CdlDIR_INT
+{
+ u_int _pos;
+ u_int _len;
+ u_char* _dir;
+} CdlDIR_INT;
+
// Leave non-aligned structure packing
#pragma pack(pop)
extern char _cd_media_changed;
-int _cd_iso_last_dir_lba;
-u_char _cd_iso_descriptor_buff[2048];
-u_char *_cd_iso_pathtable_buff=NULL;
-u_char *_cd_iso_directory_buff=NULL;
-int _cd_iso_directory_len;
-int _CdReadIsoDescriptor(int session_offs)
+static int _cd_iso_last_dir_lba;
+static u_char _cd_iso_descriptor_buff[2048];
+static u_char* _cd_iso_pathtable_buff=NULL;
+static u_char* _cd_iso_directory_buff=NULL;
+static int _cd_iso_directory_len;
+static int _cd_iso_error=0;
+
+static int _CdReadIsoDescriptor(int session_offs)
{
int i;
CdlLOC loc;
@@ -174,6 +183,7 @@ int _CdReadIsoDescriptor(int session_offs)
#ifdef DEBUG
printf("psxcd: Could not set seek destination.\n");
#endif
+ _cd_iso_error = CdlIsoSeekError;
return -1;
}
@@ -184,6 +194,7 @@ int _CdReadIsoDescriptor(int session_offs)
#ifdef DEBUG
printf("psxcd: Error reading ISO volume descriptor.\n");
#endif
+ _cd_iso_error = CdlIsoReadError;
return -1;
}
@@ -195,6 +206,7 @@ int _CdReadIsoDescriptor(int session_offs)
#ifdef DEBUG
printf("psxcd: Disc does not have a ISO9660 file system.\n");
#endif
+ _cd_iso_error = CdlIsoInvalidFs;
return -1;
}
@@ -224,15 +236,17 @@ int _CdReadIsoDescriptor(int session_offs)
#ifdef DEBUG
printf("psxcd: Error reading ISO path table.\n");
#endif
+ _cd_iso_error = CdlIsoReadError;
return -1;
}
_cd_iso_last_dir_lba = 0;
+ _cd_iso_error = CdlIsoOkay;
return 0;
}
-int _CdReadIsoDirectory(int lba)
+static int _CdReadIsoDirectory(int lba)
{
int i;
CdlLOC loc;
@@ -253,6 +267,7 @@ int _CdReadIsoDirectory(int lba)
#ifdef DEBUG
printf("psxcd: Could not set seek destination.\n");
#endif
+ _cd_iso_error = CdlIsoSeekError;
return -1;
}
@@ -269,6 +284,7 @@ int _CdReadIsoDirectory(int lba)
#ifdef DEBUG
printf("psxcd: Error reading initial directory record.\n");
#endif
+ _cd_iso_error = CdlIsoReadError;
return -1;
}
@@ -287,6 +303,7 @@ int _CdReadIsoDirectory(int lba)
#ifdef DEBUG
printf("psxcd: Could not set seek destination.\n");
#endif
+ _cd_iso_error = CdlIsoSeekError;
return -1;
}
@@ -301,20 +318,22 @@ int _CdReadIsoDirectory(int lba)
if( CdReadSync(0, 0) )
{
#ifdef DEBUG
- printf("psxcd: Error reading initial directory record.\n");
+ printf("psxcd: Error reading remaining directory record.\n");
#endif
+ _cd_iso_error = CdlIsoReadError;
return -1;
}
}
_cd_iso_last_dir_lba = lba;
+ _cd_iso_error = CdlIsoOkay;
return 0;
}
#ifdef DEBUG
-void dump_directory(void)
+static void dump_directory(void)
{
int i;
int dir_pos;
@@ -355,7 +374,7 @@ void dump_directory(void)
}
-void dump_pathtable(void)
+static void dump_pathtable(void)
{
u_char *tbl_pos;
ISO_PATHTABLE_ENTRY *tbl_entry;
@@ -389,7 +408,7 @@ void dump_pathtable(void)
#endif
-int get_pathtable_entry(int entry, ISO_PATHTABLE_ENTRY *tbl, char *namebuff)
+static int get_pathtable_entry(int entry, ISO_PATHTABLE_ENTRY *tbl, char *namebuff)
{
int i;
u_char *tbl_pos;
@@ -438,7 +457,7 @@ int get_pathtable_entry(int entry, ISO_PATHTABLE_ENTRY *tbl, char *namebuff)
return -1;
}
-char *resolve_pathtable_path(int entry, char *rbuff)
+static char* resolve_pathtable_path(int entry, char *rbuff)
{
char namebuff[16];
ISO_PATHTABLE_ENTRY tbl_entry;
@@ -465,7 +484,7 @@ char *resolve_pathtable_path(int entry, char *rbuff)
return rbuff;
}
-int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent)
+static int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent)
{
int i;
int dir_pos;
@@ -510,7 +529,7 @@ int find_dir_entry(const char *name, ISO_DIR_ENTRY *dirent)
return -1;
}
-char *get_pathname(char *path, const char *filename)
+static char* get_pathname(char *path, const char *filename)
{
char *c;
c = strrchr(filename, '\\');
@@ -526,7 +545,7 @@ char *get_pathname(char *path, const char *filename)
return path;
}
-char *get_filename(char *name, const char *filename)
+static char* get_filename(char *name, const char *filename)
{
char *c;
c = strrchr(filename, '\\');
@@ -661,3 +680,173 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename)
return fp;
}
+
+CdlDIR *CdOpenDir(const char* path)
+{
+ CdlDIR_INT* dir;
+ int num_dirs;
+ int i,found_dir;
+ char tpath_rbuff[128];
+ char* rbuff;
+
+ ISO_PATHTABLE_ENTRY tbl_entry;
+
+ // Read ISO descriptor if changed flag is set
+ if( _cd_media_changed )
+ {
+ // Read ISO descriptor and path table
+ if( _CdReadIsoDescriptor( 0 ) )
+ {
+#ifdef DEBUG
+ printf( "psxcd: Could not read ISO file system.\n" );
+#endif
+ return NULL;
+ }
+#ifdef DEBUG
+ printf( "psxcd: ISO file system cache updated.\n" );
+#endif
+ _cd_media_changed = 0;
+ }
+
+ num_dirs = get_pathtable_entry( 0, NULL, NULL );
+
+ found_dir = 0;
+ 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
+ if( rbuff )
+ {
+ if( strcmp( path, rbuff ) == 0 )
+ {
+ found_dir = i;
+ break;
+ }
+ }
+ }
+
+ if( !found_dir )
+ {
+#ifdef DEBUG
+ printf( "psxcd_dbg: Directory path not found.\n" );
+#endif
+ return NULL;
+ }
+
+#ifdef DEBUG
+ printf( "psxcd_dbg: Found directory at record %d!\n", found_dir );
+#endif
+
+ get_pathtable_entry( found_dir, &tbl_entry, NULL );
+
+#ifdef DEBUG
+ printf( "psxcd_dbg: Directory LBA = %d\n", tbl_entry.dirOffs );
+#endif
+
+ _CdReadIsoDirectory( tbl_entry.dirOffs );
+
+ dir = (CdlDIR_INT*)malloc( sizeof(CdlDIR_INT) );
+
+ dir->_len = _cd_iso_directory_len;
+ dir->_dir = malloc( _cd_iso_directory_len );
+
+ memcpy( dir->_dir, _cd_iso_directory_buff, _cd_iso_directory_len );
+
+ dir->_pos = 0;
+
+ if( found_dir == 1 )
+ {
+ ISO_DIR_ENTRY *dir_entry;
+
+ for( i=0; i<2; i++ )
+ {
+ dir_entry = (ISO_DIR_ENTRY*)(dir->_dir+dir->_pos);
+ dir->_pos += dir_entry->entryLength;
+ }
+ }
+
+ return (CdlDIR)dir;
+}
+
+int CdReadDir(CdlDIR *dir, CdlFILE* file)
+{
+ CdlDIR_INT* d_dir;
+ ISO_DIR_ENTRY* dir_entry;
+
+ d_dir = (CdlDIR_INT*)dir;
+
+ if( d_dir->_pos >= _cd_iso_directory_len )
+ return 0;
+
+ dir_entry = (ISO_DIR_ENTRY*)(d_dir->_dir+d_dir->_pos);
+
+ if( d_dir->_dir[d_dir->_pos+sizeof(ISO_DIR_ENTRY)] == 0 )
+ {
+ strcpy( file->name, "." );
+ }
+ else if( d_dir->_dir[d_dir->_pos+sizeof(ISO_DIR_ENTRY)] == 1 )
+ {
+ strcpy( file->name, ".." );
+ }
+ else
+ {
+ strncpy( file->name,
+ d_dir->_dir+d_dir->_pos+sizeof(ISO_DIR_ENTRY),
+ dir_entry->identifierLen );
+ }
+
+ CdIntToPos( dir_entry->entryOffs.lsb, &file->loc );
+
+ file->size = dir_entry->entrySize.lsb;
+
+ d_dir->_pos += dir_entry->entryLength;
+
+ // Check if padding is reached (end of record sector)
+ if( d_dir->_dir[d_dir->_pos] == 0 )
+ {
+ // Snap it to next sector
+ d_dir->_pos = ((d_dir->_pos+2047)>>11)<<11;
+ }
+
+ return 1;
+}
+
+void CdCloseDir(CdlDIR *dir)
+{
+ CdlDIR_INT* d_dir;
+
+ d_dir = (CdlDIR_INT*)dir;
+
+ free( d_dir->_dir );
+ free( d_dir );
+}
+
+int CdIsoError()
+{
+ return _cd_iso_error;
+}
+
+int CdGetVolumeLabel(char* label)
+{
+ int i;
+ ISO_DESCRIPTOR* descriptor;
+
+ if( _CdReadIsoDescriptor(0) )
+ {
+ return -1;
+ }
+
+ descriptor = (ISO_DESCRIPTOR*)_cd_iso_descriptor_buff;
+
+ i = 0;
+ for( i=0; (descriptor->volumeID[i]!=0x20)&&(i<32); i++ )
+ {
+ label[i] = descriptor->volumeID[i];
+ }
+
+ label[i] = 0x00;
+
+ return 0;
+} \ No newline at end of file
diff --git a/libpsn00b/psxcd/psxcd_asm.s b/libpsn00b/psxcd/psxcd_asm.s
index 7fe1c1d..0bfe5ca 100644
--- a/libpsn00b/psxcd/psxcd_asm.s
+++ b/libpsn00b/psxcd/psxcd_asm.s
@@ -371,6 +371,17 @@ _cd_fetch_result:
.Lwrite_status:
+ andi $v1, $v0, 0x10
+
+ beqz $v1, .Lno_disc_change
+ nop
+
+ la $v1, _cd_media_changed
+ addiu $a1, $0 , 1
+ sw $a1, 0($v1)
+
+.Lno_disc_change:
+
sb $v0, 0($a0)
.Lskip_status:
diff --git a/libpsn00b/psxgpu/getode.s b/libpsn00b/psxgpu/getode.s
new file mode 100644
index 0000000..5dc1e70
--- /dev/null
+++ b/libpsn00b/psxgpu/getode.s
@@ -0,0 +1,20 @@
+.set noreorder
+
+.include "hwregs_a.h"
+
+.section .text
+
+
+.global GetODE
+.type GetODE, @function
+GetODE:
+ addiu $sp, -4
+ sw $ra, 0($sp)
+ jal ReadGPUstat
+ nop
+ srl $v0, 31
+ andi $v0, 1
+ lw $ra, 0($sp)
+ addiu $sp, 4
+ jr $ra
+ nop
diff --git a/libpsn00b/psxspu/spukeyon.s b/libpsn00b/psxspu/spukeyon.s
index 556f976..33592c2 100644
--- a/libpsn00b/psxspu/spukeyon.s
+++ b/libpsn00b/psxspu/spukeyon.s
@@ -11,6 +11,7 @@ SpuKeyOn:
lui $v1, IOBASE
li $v0, 1
sll $v0, $a0
- sh $v0, SPU_KEY_ON($v1)
+ sw $v0, SPU_KEY_ON($v1)
+ sw $v0, SPU_KEY_ON($v1)
jr $ra
nop \ No newline at end of file