diff options
| author | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-04-24 19:01:28 +0800 |
|---|---|---|
| committer | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-04-24 19:01:28 +0800 |
| commit | 1aa0e17df7c325a41de8cf8a57f52ed853f08bf3 (patch) | |
| tree | 5ec7f69ca0104f2b0a41e2ee7d3cb0cf0c9c54c5 /libpsn00b | |
| parent | e82da2abe4c264d4b48a48d79cf9b8e4c4fb8ab6 (diff) | |
| download | psn00bsdk-1aa0e17df7c325a41de8cf8a57f52ed853f08bf3.tar.gz | |
Refined toolchain instructions, organized examples, added automatic retry for CdRead(), added FIOCSCAN ioctl in psxsio TTY driver, added tty and console examples.
Diffstat (limited to 'libpsn00b')
| -rw-r--r-- | libpsn00b/include/stdlib.h | 3 | ||||
| -rw-r--r-- | libpsn00b/psxapi/stdio/atoi.s | 9 | ||||
| -rw-r--r-- | libpsn00b/psxapi/stdio/atol.s | 9 | ||||
| -rw-r--r-- | libpsn00b/psxcd/psxcd.c | 61 | ||||
| -rw-r--r-- | libpsn00b/psxsio/siocons.c | 16 |
5 files changed, 95 insertions, 3 deletions
diff --git a/libpsn00b/include/stdlib.h b/libpsn00b/include/stdlib.h index fb20207..845cbea 100644 --- a/libpsn00b/include/stdlib.h +++ b/libpsn00b/include/stdlib.h @@ -53,6 +53,9 @@ long labs(long i); long long strtoll(const char *nptr, char **endptr, int base); long strtol(const char *nptr, char **endptr, int base); long double strtold(const char *nptr, char **endptr); +// BIOS temporary +int atoi(const char *s); +long atol(const char *s); // Note: these use floats internally! double strtod(const char *nptr, char **endptr); diff --git a/libpsn00b/psxapi/stdio/atoi.s b/libpsn00b/psxapi/stdio/atoi.s new file mode 100644 index 0000000..74c4ae7 --- /dev/null +++ b/libpsn00b/psxapi/stdio/atoi.s @@ -0,0 +1,9 @@ +.set noreorder +.section .text + +.global atoi +.type atoi, @function +atoi: + addiu $t2, $0, 0xa0 + jr $t2 + addiu $t1, $0, 0x10 diff --git a/libpsn00b/psxapi/stdio/atol.s b/libpsn00b/psxapi/stdio/atol.s new file mode 100644 index 0000000..f0da653 --- /dev/null +++ b/libpsn00b/psxapi/stdio/atol.s @@ -0,0 +1,9 @@ +.set noreorder +.section .text + +.global atol +.type atol, @function +atol: + addiu $t2, $0, 0xa0 + jr $t2 + addiu $t1, $0, 0x11 diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 7b4aa20..76b6c08 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -1,13 +1,22 @@ #include <stdio.h> +#include <psxgpu.h> #include "psxcd.h" +#define READ_TIMEOUT 600 // 10 seconds for NTSC + extern volatile char _cd_ack_wait; extern volatile unsigned char _cd_last_int; extern volatile unsigned char _cd_last_mode; extern volatile unsigned char _cd_status; extern volatile CdlCB _cd_callback_int1_data; + volatile unsigned char *_cd_result_ptr; +// For read retry +volatile CdlLOC _cd_last_setloc; +volatile unsigned int *_cd_last_read_addr; +volatile int _cd_last_sector_count; + extern volatile char _cd_media_changed; void _cd_init(void); @@ -76,6 +85,7 @@ int CdControlF(unsigned char com, unsigned char *param) { case CdlSetloc: param_len = 3; + _cd_last_setloc = *((CdlLOC*)param); break; case CdlPlay: if( param ) @@ -105,6 +115,7 @@ int CdControlF(unsigned char com, unsigned char *param) if( param ) { _cd_control(CdlSetloc, param, 3); + _cd_last_setloc = *((CdlLOC*)param); } } @@ -220,11 +231,17 @@ volatile unsigned int *_cd_read_addr; volatile unsigned char _cd_read_result[8]; volatile unsigned int _cd_read_oldcb; volatile unsigned int _cd_read_sector_sz; +volatile unsigned int _cd_read_counter; + + + volatile CdlCB _cd_read_cb; // Sector callback static void _CdReadReadyCallback(int status, unsigned char *result) { + _cd_read_counter = VSync(-1); + if( status == CdlDataReady ) { // Fetch sector from CD controller @@ -259,6 +276,8 @@ int CdRead(int sectors, unsigned int *buf, int mode) { // Set sectors to read count _cd_sector_count = sectors; + _cd_last_sector_count = sectors; + _cd_last_read_addr = buf; _cd_read_addr = buf; // Determine sector based on mode flags @@ -275,7 +294,9 @@ int CdRead(int sectors, unsigned int *buf, int mode) _cd_read_sector_sz = 2048; } - // Set readt callback + _cd_read_counter = VSync(-1); + + // Set read callback _cd_read_oldcb = CdReadyCallback(_CdReadReadyCallback); // Set specified mode @@ -287,8 +308,37 @@ int CdRead(int sectors, unsigned int *buf, int mode) return 0; } +static void CdDoRetry() +{ + int cb; + + printf( "CdRead: Retrying...\n" ); + + // Stop reading + CdControl(CdlPause, 0, 0); + CdSync(0, 0); + + // Reset parameters for retrying read operation + _cd_sector_count = _cd_last_sector_count; + _cd_read_addr = _cd_last_read_addr; + + // Reset timeout + _cd_read_counter = VSync(-1); + + CdReadyCallback(_CdReadReadyCallback); + + // Retry read + CdControl(CdlSetloc, (void*)&_cd_last_setloc, 0); + CdControl(CdlReadN, 0, (unsigned char*)_cd_read_result); +} + int CdReadSync(int mode, unsigned char *result) { + if( (VSync(-1)-_cd_read_counter) > READ_TIMEOUT ) + { + CdDoRetry(); + } + if( mode ) { if( CdSync(1, 0) == CdlDiskError ) @@ -298,7 +348,14 @@ int CdReadSync(int mode, unsigned char *result) return _cd_sector_count; } - while(_cd_sector_count > 0); + while(_cd_sector_count > 0) + { + if( (VSync(-1)-_cd_read_counter) > READ_TIMEOUT ) + { + CdDoRetry(); + } + } + if( CdSync(0, result) != CdlComplete ) { return -1; diff --git a/libpsn00b/psxsio/siocons.c b/libpsn00b/psxsio/siocons.c index 76bf8be..703504f 100644 --- a/libpsn00b/psxsio/siocons.c +++ b/libpsn00b/psxsio/siocons.c @@ -1,5 +1,6 @@ #include <stdio.h> #include <string.h> +#include <ioctl.h> #include <psxapi.h> #include <psxgpu.h> #include <psxsio.h> @@ -74,6 +75,19 @@ static int _sio_inout(FCB *fcb, int cmd) { } +static int _sio_ioctl(FCB *fcb, int cmd, int arg) +{ + if( cmd == FIOCSCAN ) + { + if( _sio_key_pending ) + { + return 0; + } + } + + return -1; +} + static int _sio_close(int h) { return h; @@ -112,7 +126,7 @@ static DCB _sio_dcb = { (void*)_sio_open, // open (void*)_sio_inout, // inout _sio_close, // close - NULL, // ioctl + _sio_ioctl, // ioctl NULL, // read NULL, // write NULL, // erase |
