Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Major API cleanup + .argv parameter support

  • Loading branch information...
commit 6ab30e5ec771d6d2401a2250f7f2eaef41be49b7 1 parent f305435
@fincs authored
View
9 README.md
@@ -9,10 +9,15 @@ This is a homebrew player of Nintendo's SSEQ sequence format, used in commercial
How to build
------------
-1. Place a sseq file, a sbnk file and a swar file in the fs folder
-2. Open arm9/source/template.c and edit the parameters to the PlaySeq call accordingly.
+1. Optionally place a sseq file, a sbnk file and swar files in the fs folder under the names
+ YourFile.sseq, YourFile.sbnk, YourFile.swar and YourFile2..4.swar.
3. Compile by using make.
+Running the SSEQ player
+-----------------------
+
+If the .nds file is run with no parameters, it attempts to play the hardcoded files inside its NitroFS. Alternatively you can pass the paths to the sseq file, the sbnk file and the swar files (in that order) through the ARGV mechanism. In order to do so, use HomebrewMenu .argv files.
+
To do
-----
View
2  arm7/source/sndbase.arm.c
@@ -314,7 +314,7 @@ void sndsysMsgHandler(int bytes, void* user_data)
case SNDSYS_PLAYSEQ:
{
- PlaySeq(&msg.seq, &msg.bnk, msg.war);
+ PlaySeq(msg.seq, msg.bnk, msg.war);
return;
}
View
12 arm7/source/sseq.arm.c
@@ -220,6 +220,7 @@ int _Note(void* bnk, void** war, int instr, int note, int prio, playinfo_t* play
for(reg = 0; reg < 8; reg ++)
if (note <= insdata[reg]) break;
if (reg == 8) return -1;
+
int offset = 8 + reg*(2+sizeof(notedef_t));
fRecord = insdata[offset];
insdata += offset + 2;
@@ -291,16 +292,13 @@ static inline void PrepareTrack(int i, int pos)
tracks[i].a = -1; tracks[i].d = -1; tracks[i].s = -1; tracks[i].r = -1;
}
-void PlaySeq(data_t* seq, data_t* bnk, data_t* war)
+void PlaySeq(void* sseqData, void* sbnkData, void* swarData[])
{
- seqBnk = bnk->data;
- seqWar[0] = war[0].data;
- seqWar[1] = war[1].data;
- seqWar[2] = war[2].data;
- seqWar[3] = war[3].data;
+ seqBnk = sbnkData;
+ memcpy(seqWar, swarData, 4*sizeof(void*));
// Load sequence data
- seqData = (u8*)seq->data + ((u32*)seq->data)[6];
+ seqData = (u8*)sseqData + ((u32*)sseqData)[6];
ntracks = 1;
int pos = 0;
View
32 arm9/source/sndbase.c
@@ -45,31 +45,35 @@ void StopSmp(int handle)
}
*/
-static bool LoadFile(data_t* pData, const char* fname)
+void* LoadFile(const char* fname, size_t* outSize)
{
+ size_t size; void* ptr;
+ if (outSize) *outSize = 0;
+
FILE* f = fopen(fname, "rb");
- if (!f) return false;
+ if (!f) return NULL;
fseek(f, 0, SEEK_END);
- pData->size = ftell(f);
+ size = ftell(f);
rewind(f);
- pData->data = malloc(pData->size);
- fread(pData->data, 1, pData->size, f);
+
+ ptr = malloc(size);
+ fread(ptr, 1, size, f);
fclose(f);
- DC_FlushRange(pData->data, pData->size);
- return true;
+
+ DC_FlushRange(ptr, size);
+
+ if (outSize) *outSize = size;
+ return ptr;
}
-void PlaySeq(const char* seqFile, const char* bnkFile, const char* war1, const char* war2, const char* war3, const char* war4)
+void PlaySeq(void* sseqData, void* sbnkData, void* swarData[])
{
sndsysMsg msg;
msg.msg = SNDSYS_PLAYSEQ;
- LoadFile(&msg.seq, seqFile);
- LoadFile(&msg.bnk, bnkFile);
- LoadFile(msg.war + 0, war1);
- LoadFile(msg.war + 1, war2);
- LoadFile(msg.war + 2, war3);
- LoadFile(msg.war + 3, war4);
+ msg.seq = sseqData;
+ msg.bnk = sbnkData;
+ memcpy(msg.war, swarData, 4*sizeof(void*));
fifoSendDatamsg(FIFO_SNDSYS, sizeof(msg), (u8*) &msg);
}
View
95 arm9/source/template.c
@@ -1,25 +1,97 @@
#include <nds.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
#include <sndcommon.h>
#include <filesystem.h>
-int main()
+int error(const char* txt)
{
- consoleDemoInit();
- InstallSoundSys();
+ printf("\nERROR: %s\n", txt);
+ return 1;
+}
+
+int defaultLoad(void** sseqData, void** sbnkData, void* swarData[])
+{
+ *sseqData = NULL;
+ *sbnkData = NULL;
+ memset(swarData, 0, 4*sizeof(void*));
+
+ *sseqData = LoadFile("YourFile.sseq", NULL);
+ if (!*sseqData) return error("Can't load SSEQ!");
+ *sbnkData = LoadFile("YourFile.sbnk", NULL);
+ if (!*sbnkData) { free(*sseqData); return error("Can't load SBNK!"); }
+ swarData[0] = LoadFile("YourFile.swar", NULL);
+ swarData[1] = LoadFile("YourFile2.swar", NULL);
+ swarData[2] = LoadFile("YourFile3.swar", NULL);
+ swarData[3] = LoadFile("YourFile4.swar", NULL);
+ return 0;
+}
+
+int argvLoad(int argc, char* argv[], void** sseqData, void** sbnkData, void* swarData[])
+{
+ *sseqData = NULL;
+ *sbnkData = NULL;
+ memset(swarData, 0, 4*sizeof(void*));
+
+ *sseqData = LoadFile(argv[0], NULL);
+ if (!*sseqData) return error("Can't load SSEQ!");
+ *sbnkData = LoadFile(argv[1], NULL);
+ if (!*sbnkData) { free(*sseqData); return error("Can't load SBNK!"); }
+ swarData[0] = LoadFile(argv[2], NULL);
+ if (argc >= 4) swarData[1] = LoadFile(argv[3], NULL);
+ if (argc >= 5) swarData[2] = LoadFile(argv[4], NULL);
+ if (argc >= 6) swarData[3] = LoadFile(argv[5], NULL);
+ return 0;
+}
+
+void *g_sseqData, *g_sbnkData;
+void* g_swarData[4];
- if (!nitroFSInit())
+void anykey()
+{
+ iprintf("Press any key to exit...\n");
+ for(;;)
{
- iprintf("Filesystem FAIL");
- for(;;) swiWaitForVBlank();
+ scanKeys();
+ if (keysDown())
+ break;
}
+}
+
+int main(int argc, char* argv[])
+{
+ consoleDemoInit();
+ InstallSoundSys();
iprintf("\n\n\tSSEQ player PoC v1\n");
iprintf("\tfincs.drunkencoders.com\n");
iprintf("\tgithub.com/fincs");
- // Change this line!
- PlaySeq("YourFile.sseq", "YourFile.sbnk", "YourFile.swar", "YourFile2.swar", "YourFile3.swar", "YourFile4.swar");
+ if (argc < 4)
+ {
+ if (!nitroFSInit())
+ {
+ error("Can't initialize NitroFS!");
+ anykey();
+ return 0;
+ }
+ if (defaultLoad(&g_sseqData, &g_sbnkData, g_swarData) != 0)
+ {
+ anykey();
+ return 0;
+ }
+ }else
+ {
+ if (argvLoad(argc-1, argv+1, &g_sseqData, &g_sbnkData, g_swarData) != 0)
+ {
+ anykey();
+ return 0;
+ }
+ }
+
+ PlaySeq(g_sseqData, g_sbnkData, g_swarData);
for(;;)
{
@@ -28,13 +100,6 @@ int main()
scanKeys();
if (keysDown() & KEY_START) break;
if (keysDown() & KEY_B) StopSeq();
-
- /*
- touchPosition touch;
- touchRead(&touch);
- iprintf("\x1b[10;0HTouch x = %04i, %04i\n", touch.rawx, touch.px);
- iprintf("Touch y = %04i, %04i\n", touch.rawy, touch.py);
- */
}
return 0;
View
11 common/sndcommon.h
@@ -38,9 +38,9 @@ typedef struct
*/
struct
{
- data_t seq;
- data_t bnk;
- data_t war[4];
+ void* seq;
+ void* bnk;
+ void* war[4];
};
};
} sndsysMsg;
@@ -89,7 +89,7 @@ volatile extern int ADSR_mastervolume;
void seq_tick();
-void PlaySeq(data_t* seq, data_t* bnk, data_t* war);
+void PlaySeq(void*, void*, void*[]);
void StopSeq();
int ds_freechn();
@@ -110,7 +110,8 @@ int GetSoundSine(int arg);
int PlaySmp(sndreg_t* smp, int a, int d, int s, int r, int vol, int vel, int pan);
void StopSmp(int handle);
*/
-void PlaySeq(const char*, const char*, const char*, const char*, const char*, const char*);
+void PlaySeq(void*, void*, void*[]);
void StopSeq();
+void* LoadFile(const char*, size_t*);
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.