Skip to content

Commit

Permalink
[playsid] Detect Sidplayer files
Browse files Browse the repository at this point in the history
  • Loading branch information
mywave82 committed Jun 16, 2024
1 parent 9e0b501 commit 88730b1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion filesel/mdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static const struct mdbReadInfoAPI_t mdbReadInfoAPI =
};
int mdbReadInfo (struct moduleinfostruct *m, struct ocpfilehandle_t *f)
{
char mdbScanBuf[1084];
char mdbScanBuf[4096];
struct mdbreadinforegstruct *rinfos;
int maxl;

Expand Down
1 change: 1 addition & 0 deletions playsid/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ sidptype.o: \
../config.h \
../types.h \
../boot/plinkman.h \
../filesel/dirdb.h \
../filesel/filesystem.h \
../filesel/mdb.h \
../filesel/pfilesel.h \
Expand Down
50 changes: 50 additions & 0 deletions playsid/sidtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "types.h"
#include "boot/plinkman.h"
#include "cpiface/cpiface.h"
#include "filesel/dirdb.h"
#include "filesel/filesystem.h"
#include "filesel/mdb.h"
#include "filesel/pfilesel.h"
Expand Down Expand Up @@ -60,6 +61,8 @@ static int sidReadInfo(struct moduleinfostruct *m, struct ocpfilehandle_t *fp, c
{
int i;
struct psidHeader *ph;
const char *filename = 0;
unsigned int filenamelen;

if (len<sizeof(struct psidHeader)+2)
return 0;
Expand Down Expand Up @@ -116,6 +119,52 @@ static int sidReadInfo(struct moduleinfostruct *m, struct ocpfilehandle_t *fp, c
return 1;
}

API->dirdb->GetName_internalstr (fp->dirdb_ref, &filename);
filenamelen = strlen (filename);

if ((filenamelen > 4) && (
(!strcasecmp(filename + filenamelen - 4, ".mus")) ||
(!strcasecmp(filename + filenamelen - 4, ".sid"))) &&
(len >= 8))
{
uint_least32_t voice1Index, voice2Index, voice3Index;
const uint_least16_t SIDTUNE_MUS_HLT_CMD = 0x14F;
const unsigned char *buf2 = (const unsigned char *)buf;

// Skip load address and 3x length entry.
voice1Index = 2 + 3 * 2;
// Add length of voice 1 data.
voice1Index += buf2[2] | (buf2[3] << 8);
// Add length of voice 2 data.
voice2Index = voice1Index + (buf2[4] | (buf2[5] << 8));
// Add length of voice 3 data.
voice3Index = voice2Index + (buf2[6] | (buf2[7] << 8));

if (
/* only scan voice1Index if we have enough data available */
(((voice1Index <= len) &&
((buf2[voice1Index - 1] | (buf2[voice1Index - 2] << 8)) == SIDTUNE_MUS_HLT_CMD)) ||
((voice1Index > len) &&
(voice1Index <= fp->filesize(fp)))) &&
/* only scan voice2Index if we have enough data available */
(((voice2Index <= len) &&
((buf2[voice2Index - 1] | (buf2[voice2Index - 2] << 8)) == SIDTUNE_MUS_HLT_CMD)) ||
((voice2Index > len) &&
(voice2Index <= fp->filesize(fp)))) &&
/* only scan voice3Index if we have enough data available */
(((voice3Index <= len) &&
((buf2[voice3Index - 1] | (buf2[voice3Index - 2] << 8)) == SIDTUNE_MUS_HLT_CMD)) ||
((voice3Index > len) &&
(voice3Index <= fp->filesize(fp))))
)
{
m->modtype.integer.i=MODULETYPE("SID");
m->channels=1;
strcpy(m->comment, "Sidplayer MUS file");
return 1;
}
}

return 0;
}

Expand All @@ -134,6 +183,7 @@ OCP_INTERNAL int sid_type_init (struct PluginInitAPI_t *API)
{
struct moduletype mt;

API->fsRegisterExt("MUS");
API->fsRegisterExt("SID");
API->fsRegisterExt("RSID");
API->fsRegisterExt("PSID");
Expand Down

0 comments on commit 88730b1

Please sign in to comment.