From c4c66b22ae607aa8dc5e6983f7ab030ead01faae Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 21 Dec 2014 00:36:00 +0200 Subject: spu: avoid NULL pSpuIrq CTR sets 0 irq address, and savestates mess up --- plugins/dfsound/freeze.c | 7 +++++-- plugins/dfsound/spu.c | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/dfsound/freeze.c b/plugins/dfsound/freeze.c index b865b84..d38faa6 100644 --- a/plugins/dfsound/freeze.c +++ b/plugins/dfsound/freeze.c @@ -307,6 +307,9 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode, SPUFreeze_t * pF, ClearWorkingState(); spu.cycles_played = cycles; + if (spu.spuCtrl & CTRL_IRQ) + schedule_next_irq(); + return 1; } @@ -318,7 +321,7 @@ void LoadStateV5(SPUFreeze_t * pF) pFO=(SPUOSSFreeze_t *)(pF+1); - if(pFO->pSpuIrq) spu.pSpuIrq = spu.spuMemC+((long)pFO->pSpuIrq&0x7fff0); else spu.pSpuIrq=NULL; + spu.pSpuIrq = spu.spuMemC + ((spu.regArea[(H_SPUirqAddr - 0x0c00) / 2] << 3) & ~0xf); if(pFO->spuAddr) { @@ -353,7 +356,7 @@ void LoadStateUnknown(SPUFreeze_t * pF, uint32_t cycles) spu.dwNewChannel=0; spu.dwChannelOn=0; spu.dwChannelDead=0; - spu.pSpuIrq=0; + spu.pSpuIrq=spu.spuMemC; for(i=0;i<0xc0;i++) { diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index ca362b7..2c13ca1 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -738,7 +738,7 @@ void do_samples(unsigned int cycles_to) // an IRQ. if (unlikely((spu.spuCtrl & CTRL_IRQ) - && spu.pSpuIrq && spu.pSpuIrq < spu.spuMemC+0x1000)) + && spu.pSpuIrq < spu.spuMemC+0x1000)) { int irq_pos = (spu.pSpuIrq - spu.spuMemC) / 2 & 0x1ff; int left = (irq_pos - spu.decode_pos) & 0x1ff; @@ -1027,7 +1027,7 @@ long CALLBACK SPUinit(void) spu.spuAddr = 0xffffffff; spu.decode_pos = 0; memset((void *)s_chan, 0, sizeof(s_chan)); - spu.pSpuIrq = 0; + spu.pSpuIrq = spu.spuMemC; SetupStreams(); // prepare streaming -- cgit v1.2.3 From bdd050c3ed792381df2e744fee5b7ee80b93fd68 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 21 Dec 2014 02:20:41 +0200 Subject: spu: fix first sample, don't play ahead --- plugins/dfsound/spu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/plugins/dfsound/spu.c b/plugins/dfsound/spu.c index 2c13ca1..835555d 100644 --- a/plugins/dfsound/spu.c +++ b/plugins/dfsound/spu.c @@ -5,7 +5,7 @@ copyright : (C) 2002 by Pete Bernert email : BlackDove@addcom.de - Portions (C) Gražvydas "notaz" Ignotas, 2010-2012 + Portions (C) Gražvydas "notaz" Ignotas, 2010-2012,2014 ***************************************************************************/ /*************************************************************************** @@ -253,14 +253,13 @@ INLINE void StartSound(int ch) s_chan[ch].SB[26]=0; // init mixing vars s_chan[ch].SB[27]=0; - s_chan[ch].iSBPos=28; + s_chan[ch].iSBPos=27; + s_chan[ch].SB[28]=0; s_chan[ch].SB[29]=0; // init our interpolation helpers s_chan[ch].SB[30]=0; - - if(spu_config.iUseInterpolation>=2) // gauss interpolation? - {s_chan[ch].spos=0x30000L;s_chan[ch].SB[28]=0;} // -> start with more decoding - else {s_chan[ch].spos=0x10000L;s_chan[ch].SB[31]=0;} // -> no/simple interpolation starts with one 44100 decoding + s_chan[ch].SB[31]=0; + s_chan[ch].spos=0; spu.dwNewChannel&=~(1<= 2) { - if (exename[i - 2] == ';') i-= 2; - c = 8; i--; - while (i >= 0 && c >= 0) { - if (isalnum(exename[i])) CdromId[c--] = exename[i]; - i--; - } + len = strlen(exename); + c = 0; + for (i = 0; i < len; ++i) { + if (exename[i] == ';' || c >= sizeof(CdromId) - 1) + break; + if (isalnum(exename[i])) + CdromId[c++] = exename[i]; } } @@ -388,6 +388,7 @@ int CheckCdrom() { } SysPrintf(_("CD-ROM Label: %.32s\n"), CdromLabel); SysPrintf(_("CD-ROM ID: %.9s\n"), CdromId); + SysPrintf(_("CD-ROM EXE Name: %.255s\n"), exename); BuildPPFCache(); -- cgit v1.2.3 From e7e1f57236744efe2e22ab1aa2f10f34787e431a Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 21 Dec 2014 20:31:42 +0200 Subject: psxbios: merge from pcsxr r90224-r90227 Author: weimingzhi psxbios: format() --- libpcsxcore/psxbios.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 04c959a..144a7b4 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -1025,6 +1025,26 @@ _start: pc0 = ra; } +void psxBios_format() { // 0x41 + if (strcmp(Ra0, "bu00:") == 0 && Config.Mcd1[0] != '\0') + { + CreateMcd(Config.Mcd1); + LoadMcd(1, Config.Mcd1); + v0 = 1; + } + else if (strcmp(Ra0, "bu10:") == 0 && Config.Mcd2[0] != '\0') + { + CreateMcd(Config.Mcd2); + LoadMcd(2, Config.Mcd2); + v0 = 1; + } + else + { + v0 = 0; + } + pc0 = ra; +} + /* * long Load(char *name, struct EXEC *header); */ @@ -2521,7 +2541,7 @@ void psxBiosInit() { biosB0[0x3c] = psxBios_getchar; //biosB0[0x3e] = psxBios_gets; //biosB0[0x40] = psxBios_cd; - //biosB0[0x41] = psxBios_format; + biosB0[0x41] = psxBios_format; biosB0[0x42] = psxBios_firstfile; biosB0[0x43] = psxBios_nextfile; biosB0[0x44] = psxBios_rename; -- cgit v1.2.3 From 9726a4aff95e362af3df014a02185031911bf784 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 21 Dec 2014 20:43:23 +0200 Subject: cdriso: merge from pcsxr r90558 Author: edgbla cdriso: cbn/cbin detection fix; --- libpcsxcore/cdriso.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index d6672f9..2c9e692 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -795,6 +795,8 @@ static int handlepbp(const char *isofile) { if (ext == NULL || (strcmp(ext, ".pbp") != 0 && strcmp(ext, ".PBP") != 0)) return -1; + fseek(cdHandle, 0, SEEK_SET); + numtracks = 0; ret = fread(&pbp_hdr, 1, sizeof(pbp_hdr), cdHandle); @@ -958,6 +960,8 @@ static int handlecbin(const char *isofile) { if (ext == NULL || (strcasecmp(ext + 1, ".cbn") != 0 && strcasecmp(ext, ".cbin") != 0)) return -1; + fseek(cdHandle, 0, SEEK_SET); + ret = fread(&ciso_hdr, 1, sizeof(ciso_hdr), cdHandle); if (ret != sizeof(ciso_hdr)) { SysPrintf("failed to read ciso header\n"); -- cgit v1.2.3 From 9a9bcd781195829a8bc63144d516bc6087bb6b52 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 21 Dec 2014 21:00:34 +0200 Subject: misc: merge from pcsxr r91261,r91276 Author: edgbla Small fixes. 11834, 11836 (Lioncash); --- libpcsxcore/cdriso.c | 4 ++-- libpcsxcore/misc.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libpcsxcore/cdriso.c b/libpcsxcore/cdriso.c index 2c9e692..b733f5b 100644 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@ -552,9 +552,9 @@ static int parsecue(const char *isofile) { pregapOffset = -1; // mark to fill track start_offset } else if (!strcmp(token, "FILE")) { - t = sscanf(linebuf, " FILE \"%256[^\"]\"", tmpb); + t = sscanf(linebuf, " FILE \"%255[^\"]\"", tmpb); if (t != 1) - sscanf(linebuf, " FILE %256s", tmpb); + sscanf(linebuf, " FILE %255s", tmpb); // absolute path? ti[numtracks + 1].handle = fopen(tmpb, "rb"); diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 14f68ec..3ee9876 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -208,9 +208,9 @@ int LoadCdrom() { // read the SYSTEM.CNF READTRACK(); - sscanf((char *)buf + 12, "BOOT = cdrom:\\%256s", exename); + sscanf((char *)buf + 12, "BOOT = cdrom:\\%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { - sscanf((char *)buf + 12, "BOOT = cdrom:%256s", exename); + sscanf((char *)buf + 12, "BOOT = cdrom:%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { char *ptr = strstr((char *)buf + 12, "cdrom:"); if (ptr != NULL) { @@ -268,7 +268,7 @@ int LoadCdromFile(const char *filename, EXE_HEADER *head) { u32 size, addr; void *mem; - sscanf(filename, "cdrom:\\%256s", exename); + sscanf(filename, "cdrom:\\%255s", exename); time[0] = itob(0); time[1] = itob(2); time[2] = itob(0x10); @@ -338,9 +338,9 @@ int CheckCdrom() { if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") != -1) { READTRACK(); - sscanf(buf + 12, "BOOT = cdrom:\\%256s", exename); + sscanf(buf + 12, "BOOT = cdrom:\\%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { - sscanf(buf + 12, "BOOT = cdrom:%256s", exename); + sscanf(buf + 12, "BOOT = cdrom:%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { char *ptr = strstr(buf + 12, "cdrom:"); // possibly the executable is in some subdir if (ptr != NULL) { -- cgit v1.2.3 From 5ec7acdfb1bc4c3da372f7f8e1a0a1022becce21 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 21 Dec 2014 21:27:02 +0200 Subject: psxbios: don't crash on negative length Contra Legacy of War does memset(..., -1) --- libpcsxcore/psxbios.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/libpcsxcore/psxbios.c b/libpcsxcore/psxbios.c index 144a7b4..292d80d 100644 --- a/libpcsxcore/psxbios.c +++ b/libpcsxcore/psxbios.c @@ -613,14 +613,14 @@ void psxBios_tolower() { // 0x26 void psxBios_bcopy() { // 0x27 char *p1 = (char *)Ra1, *p2 = (char *)Ra0; - while (a2-- > 0) *p1++ = *p2++; + while ((s32)a2-- > 0) *p1++ = *p2++; pc0 = ra; } void psxBios_bzero() { // 0x28 char *p = (char *)Ra0; - while (a1-- > 0) *p++ = '\0'; + while ((s32)a1-- > 0) *p++ = '\0'; pc0 = ra; } @@ -630,7 +630,7 @@ void psxBios_bcmp() { // 0x29 if (a0 == 0 || a1 == 0) { v0 = 0; pc0 = ra; return; } - while (a2-- > 0) { + while ((s32)a2-- > 0) { if (*p1++ != *p2++) { v0 = *p1 - *p2; // BUG: compare the NEXT byte pc0 = ra; @@ -643,15 +643,16 @@ void psxBios_bcmp() { // 0x29 void psxBios_memcpy() { // 0x2a char *p1 = (char *)Ra0, *p2 = (char *)Ra1; - while (a2-- > 0) *p1++ = *p2++; + while ((s32)a2-- > 0) *p1++ = *p2++; v0 = a0; pc0 = ra; } void psxBios_memset() { // 0x2b char *p = (char *)Ra0; - while (a2-- > 0) *p++ = (char)a1; + while ((s32)a2-- > 0) *p++ = (char)a1; + a2 = 0; v0 = a0; pc0 = ra; } @@ -662,9 +663,9 @@ void psxBios_memmove() { // 0x2c a2++; // BUG: copy one more byte here p1 += a2; p2 += a2; - while (a2-- > 0) *--p1 = *--p2; + while ((s32)a2-- > 0) *--p1 = *--p2; } else { - while (a2-- > 0) *p1++ = *p2++; + while ((s32)a2-- > 0) *p1++ = *p2++; } v0 = a0; pc0 = ra; @@ -677,7 +678,7 @@ void psxBios_memcmp() { // 0x2d void psxBios_memchr() { // 0x2e char *p = (char *)Ra0; - while (a2-- > 0) { + while ((s32)a2-- > 0) { if (*p++ != (s8)a1) continue; v0 = a0 + (p - (char *)Ra0 - 1); pc0 = ra; -- cgit v1.2.3