X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libpcsxcore%2Fpsxbios.c;h=67a01e5aafd84e13499a195e60ecc316df641dbc;hb=fcf7ec6c12723009e4ad683841b46d0346c73934;hp=9341b0d6ced8f427832e51dd75a89b3f8245fa8a;hpb=b29f3be0ac3fb01453eae2dabf8471b262881b30;p=pcsx_rearmed.git diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 9341b0d6..67a01e5a 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -610,7 +610,13 @@ void psxBios_strlen() { // 0x1b void psxBios_index() { // 0x1c char *p = (char *)Ra0; - + if (a0 == 0) + { + v0 = 0; + pc0 = ra; + return; + } + do { if (*p == a1) { v0 = a0 + (p - (char *)Ra0); @@ -626,7 +632,11 @@ void psxBios_rindex() { // 0x1d char *p = (char *)Ra0; v0 = 0; - + if (a0 == 0) + { + pc0 = ra; + return; + } do { if (*p == a1) v0 = a0 + (p - (char *)Ra0); @@ -1667,8 +1677,20 @@ void psxBios_OpenTh() { // 0e int th; for (th=1; th<8; th++) + { if (Thread[th].status == 0) break; + } + if (th == 8) { + // Feb 2019 - Added out-of-bounds fix caught by cppcheck: + // When no free TCB is found, return 0xffffffff according to Nocash doc. +#ifdef PSXBIOS_LOG + PSXBIOS_LOG("\t%s() WARNING! No Free TCBs found!\n", __func__); +#endif + v0 = 0xffffffff; + pc0 = ra; + return; + } #ifdef PSXBIOS_LOG PSXBIOS_LOG("psxBios_%s: %x\n", biosB0n[0x0e], th); #endif @@ -1760,9 +1782,10 @@ void psxBios_StopPAD() { // 14 #ifdef PSXBIOS_LOG PSXBIOS_LOG("psxBios_%s\n", biosB0n[0x14]); #endif - + if (pad_buf == 0){ pad_buf1 = NULL; pad_buf2 = NULL; + } pc0 = ra; } @@ -2097,15 +2120,16 @@ void psxBios_firstfile() { // 42 pfile = ffile+5; nfile = 1; if (!strncmp(pa0, "bu00", 4)) { + // firstfile() calls _card_read() internally, so deliver it's event + DeliverEvent(0x11, 0x2); bufile(1); } else if (!strncmp(pa0, "bu10", 4)) { + // firstfile() calls _card_read() internally, so deliver it's event + DeliverEvent(0x11, 0x2); bufile(2); } } - // firstfile() calls _card_read() internally, so deliver it's event - DeliverEvent(0x11, 0x2); - pc0 = ra; }