diff options
Diffstat (limited to 'src/hd24syx2bin.cpp')
-rw-r--r-- | src/hd24syx2bin.cpp | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/hd24syx2bin.cpp b/src/hd24syx2bin.cpp new file mode 100644 index 0000000..1ccc501 --- /dev/null +++ b/src/hd24syx2bin.cpp | |||
@@ -0,0 +1,113 @@ | |||
1 | //syx2bin.cpp | ||
2 | //converts an alesis hd24 .syx OS file to binary | ||
3 | using namespace std; | ||
4 | #include <iostream> | ||
5 | #define SKIPCHARS 9 | ||
6 | |||
7 | int main(int argc, char *argv[]) | ||
8 | { | ||
9 | |||
10 | FILE *pInfile; | ||
11 | FILE *pOutfile; | ||
12 | char *pInfilename, *pOutfilename; | ||
13 | int loop; | ||
14 | int msbits; | ||
15 | |||
16 | if(argc < 3) | ||
17 | { | ||
18 | fprintf(stderr, "Usage : %s infile outfile\n",argv[0]); | ||
19 | exit(1); | ||
20 | } | ||
21 | |||
22 | pInfilename = argv[1]; | ||
23 | pOutfilename = argv[2]; | ||
24 | |||
25 | pInfile = fopen(pInfilename, "rb"); | ||
26 | if(!pInfile) | ||
27 | { | ||
28 | fprintf(stderr, "ERROR : couldn't open %s for reading\n", pInfilename); | ||
29 | exit(1); | ||
30 | } | ||
31 | pOutfile = fopen(pOutfilename, "wb"); | ||
32 | if(!pOutfile) | ||
33 | { | ||
34 | fprintf(stderr, "ERROR : couldn't open %s for writing\n", pOutfilename); | ||
35 | fclose(pInfile); //close open infile | ||
36 | exit(1); | ||
37 | } | ||
38 | |||
39 | //skip F0 and 5 byte header | ||
40 | for(loop = 0; loop < SKIPCHARS; loop++) | ||
41 | { | ||
42 | fgetc(pInfile); | ||
43 | } | ||
44 | |||
45 | // msbits = fgetc(pInfile); | ||
46 | unsigned char b[8]; | ||
47 | unsigned char header[64]; | ||
48 | int whichbyte=3; | ||
49 | int headerbyte=0; | ||
50 | unsigned int checksum=0; | ||
51 | int filesize=0; | ||
52 | int written=0; | ||
53 | while((msbits != EOF) && (msbits != 0xF7)) //get most significant bits byte | ||
54 | { | ||
55 | int i; | ||
56 | int j; | ||
57 | j=10; | ||
58 | |||
59 | for (i=0;i<8;i++) { | ||
60 | b[i]=fgetc(pInfile); | ||
61 | if (b[i]==0xF7) { | ||
62 | msbits=0xF7; | ||
63 | j=i; | ||
64 | } | ||
65 | } | ||
66 | // convert 8->7 bytes | ||
67 | unsigned char bits=b[0]; | ||
68 | int max=8; | ||
69 | if (j<max) { max=j; } | ||
70 | for (i=1;i<max;i++) { | ||
71 | #ifdef LSB | ||
72 | int onebit=(bits & 1) <<7; | ||
73 | b[i]|=onebit; | ||
74 | bits = (bits>>1); | ||
75 | #else | ||
76 | int onebit=(bits << 1) & 0x80; | ||
77 | b[i]|=onebit; | ||
78 | bits = (bits << 1); | ||
79 | #endif | ||
80 | fputc((unsigned char) b[i], pOutfile); | ||
81 | written++; | ||
82 | if (headerbyte<64) { | ||
83 | header[headerbyte]=b[i]; | ||
84 | headerbyte++; | ||
85 | } | ||
86 | else | ||
87 | { | ||
88 | if (filesize==0) { | ||
89 | int x1=(int)((unsigned char)header[47]); | ||
90 | int x2=(int)((unsigned char)header[46]); | ||
91 | int x3=(int)((unsigned char)header[45]); | ||
92 | int x4=(int)((unsigned char)header[44]); | ||
93 | filesize=x1+(256*x2)+(256*256*x3)+(256*256*256*x4); | ||
94 | } | ||
95 | } | ||
96 | whichbyte=(whichbyte+1)%4; | ||
97 | checksum=(checksum+b[i] ) % 256; | ||
98 | //((unsigned char)(b[i]) << (8*(whichbyte))) ; | ||
99 | if (filesize!=0) { | ||
100 | if (written>=filesize) break; | ||
101 | } | ||
102 | } | ||
103 | if (filesize!=0) { | ||
104 | if (written>=filesize) break; | ||
105 | } | ||
106 | |||
107 | } | ||
108 | printf("Checksum=%x\n",checksum); | ||
109 | fclose(pInfile); | ||
110 | fclose(pOutfile); | ||
111 | return 0; | ||
112 | } | ||
113 | |||