SPC music playback tools for real snes apu

Dependencies:   mbed

Revision:
3:b845c0cf715a
Parent:
2:62e6e22f8be2
--- a/apu2.cpp	Wed Jan 11 16:00:29 2017 +0000
+++ b/apu2.cpp	Fri Jan 13 06:13:53 2017 +0000
@@ -6,6 +6,18 @@
 extern int g_debug;
 extern int g_verbose;
 
+// code loaded at 0xf2
+static unsigned char dsploader[16] = {
+    0xc4, 0xf2,         // start: MOV f2, A
+    0x64, 0xf4,         // loop: CMP A, f4 
+    0xd0, 0xfc,         // BNE loop
+    0xfa, 0xf5, 0xf3,   // MOV f3 , f5
+    0xc4, 0xf4,         // MOV f4, A
+    0xbc,               // INC A
+    0x10, 0xf2,         // BPL start
+    0x2f, 0xb7          // BRA 0xb7 ; jump inside rom
+};
+
 static unsigned char bootcode[77] = {
     0x8f, 0x00, 0x00, 0x8f, 0x00, 0x01, 0x8f, 0xff, 
     0xfc, 0x8f, 0xff, 0xfb, 0x8f, 0x4f, 0xfa, 0x8f, 
@@ -19,18 +31,6 @@
     0x8d, 0x00, 0xcd, 0x00, 0x7f
 };
 
-// code loaded at 0xf2
-static unsigned char dsploader[16] = {
-    0xc4, 0xf2,         // start: MOV f2, A
-    0x64, 0xf4,         // loop: CMP A, f4 
-    0xd0, 0xfc,         // BNE loop
-    0xfa, 0xf5, 0xf3,   // MOV f3 , f5
-    0xc4, 0xf4,         // MOV f4, A
-    0xbc,               // INC A
-    0x10, 0xf2,         // BPL start
-    0x2f, 0xb7          // BRA 0xb7 ; jump inside rom
-};
-
 int LoadAPU_embedded(FILE *fp)
 {
     int i=0, j=0, count=0, val=0;
@@ -263,31 +263,31 @@
     // and look for an area with the same consecutive value repeated 77 times
     fseek(fp, OFFSET_SPCDATA+0x100, SEEK_SET);
     bootptr = -1;
-    for(i=0x100; i <= 65471; i+= 16)
+    for(i=0x100; i<=65471; i+=16)
     {
         fread(workbuf, 16, 1, fp);
         
         for(j=0; j<16; j++)
         {
             // push program counter and status ward on stack
-            if((i+j) == (0x100 +spc_sp - 0))
+            if((i+j) == (0x100 + spc_sp - 0))
             {
                 workbuf[j] = spc_pch;
             }
 
-            if((i+j) == (0x100 +spc_sp - 1))
+            if((i+j) == (0x100 + spc_sp - 1))
             {
                 workbuf[j] = spc_pcl;
             }
 
-            if((i+j) == (0x100 +spc_sp - 2))
+            if((i+j) == (0x100 + spc_sp - 2))
             {
                 workbuf[j] = spc_sw;
             }
             
             if((i > echoregion + echosize) || (i < echoregion))
             {
-                if(val==workbuf[j])
+                if(val == workbuf[j])
                 {
                     count++;
                     if(count >= 77)
@@ -332,7 +332,7 @@
         // at least 77 bytes...
         if(echosize < 77)
         {
-            fprintf(stderr, "This spc file does not have sufficient ram to be loaded");
+            fprintf(stderr, "This spc file does not have sufficient ram to be loaded\n");
             return -1;
         }
         else