Mixer is functional now. More signed/unsigned confusion was causing most of the probl...
[pineappletracker.git] / mod / it_loader.c
blob5d5938a651256e0b07f365703c17613223f4e8e5
1 #include <stdio.h>
2 #include <stdint.h>
3 #include <stdlib.h>
5 uint16_t short_byteswap(uint16_t in) {
6 in = (((in >> 8) & 0xff) | ((in << 8) & 0xff));
7 /*char tmp;
8 tmp = in[2];
9 in[2] = in[1];
10 in[1] = tmp;
12 return in;
16 struct it_header {
17 char sig[4];
18 char songname[26];
19 //0x20
20 uint16_t ord_num;
21 uint16_t ins_num;
22 uint16_t smp_num;
23 uint16_t pat_num;
24 uint16_t cwt;
25 uint16_t cmwt;
26 uint16_t flags;
27 uint16_t special;
28 //0x30
29 uint8_t gv; //global volume
30 uint8_t mv; //mix volume
31 uint8_t is; //initial speed
32 uint8_t it; //initial tempo
33 uint8_t sep; //panning separation between channels
34 uint8_t pwd; //pitch wheel depth for midi controllers
35 uint16_t msg_length; //length of song message
36 uint32_t msg_offset; //message offset
37 uint32_t reserved; //???
38 //0x40
39 uint8_t chnl_pan[64];
40 //0x80
41 uint8_t chnl_vol[64];
42 //0xc0
43 uint8_t *orders; //orders, in order ;). length is it_header.ord_num
46 int main(int argc, char **argv){
47 FILE *file;
48 struct it_header it_header;
50 if(argc < 2){
51 printf("usage: slurp <.it file>");
52 return 1;
55 file = fopen(argv[1], "rb");
57 if(!file){
58 printf("couldnt open file!\n");
59 return 1;
62 fseek(file, 0, SEEK_SET);
64 /* read in IMPM sig */
65 fread(it_header.sig, 1, 4, file);
67 for(int i = 0; i < 4; i++)
68 printf("%c", it_header.sig[i]);
69 printf("\n");
71 /* read in songname */
72 fread(it_header.songname, 1, 26, file);
73 printf("%s\n", it_header.songname);
75 /* read in PHiligt */
77 /* read in OrdNum */
78 fseek(file, 0x20, SEEK_SET);
79 //swap bytes
80 fread(&it_header.ord_num, 1, 2, file);
81 printf("Ordnum: %04x\n", it_header.ord_num);
82 //it_header.ord_num = short_byteswap(it_header.ord_num);
83 //printf("Ordnum: %04x\n", it_header.ord_num);
85 /*read in insnum*/
86 fread(&it_header.ins_num, 1, 2, file);
87 //it_header.ins_num = short_byteswap(it_header.ins_num);
88 printf("insnum: %d\n", it_header.ins_num);
90 /* read in sampnum */
91 fread(&it_header.smp_num, 1, 2, file);
92 //it_header.smp_num = short_byteswap(it_header.smp_num);
93 printf("smpnum: %d\n", it_header.smp_num);
95 /* read in patnum */
96 fread(&it_header.pat_num, 1, 2, file);
97 printf("patnum: %d\n", it_header.pat_num);
99 /* read in created with tracker version */
100 fread(&it_header.cwt, 1, 2, file);
101 printf("created with tracker version: %04x\n", it_header.cwt);
103 /* read in compatabile with tracker version greater than */
104 fread(&it_header.cmwt, 1, 2, file);
105 printf("compatibile with tracker version >: %04x\n", it_header.cmwt);
107 /* read in flags */
108 fread(&it_header.flags, 1, 2, file);
110 /* read in special */
111 fread(&it_header.special, 1, 2, file);
113 /* read in global vol. */
114 fread(&it_header.gv, 1, 1, file);
115 printf("global vol:%d\n", it_header.gv);
117 /* read in mix vol. */
118 fread(&it_header.mv, 1, 1, file);
119 printf("mix vol:%d\n", it_header.mv);
121 /* read in initial tempo and speed */
122 fread(&it_header.is, 1, 1, file);
123 fread(&it_header.it, 1, 1, file);
124 printf("initial speed: %d, initial tempo: %d\n", it_header.is, it_header.it);
126 /* read in sep */
127 fread(&it_header.sep, 1, 1, file);
128 /* read in pwd*/
129 fread(&it_header.pwd, 1, 1, file);
130 /* read in msg length */
131 fread(&it_header.msg_length, 1, 2, file);
132 /* read in msg offset */
133 fread(&it_header.msg_offset, 1, 4, file);
134 /* read in 4 reserved bytes */
135 fread(&it_header.reserved, 1, 4, file);
137 /* read in channel pans, 0x40 */
138 for(int i = 0; i < 64; i++)
139 fread(&it_header.chnl_pan[i], 1, 1, file);
140 printf("chnlpans:\n");
141 /* read in channel volumes, 0x80 */
142 for(int i = 0; i < 64; i++)
143 fread(&it_header.chnl_vol[i], 1, 1, file);
144 printf("chnlvols:\n");
146 /* read in order of orders , 0xc0*/
147 it_header.orders = malloc(sizeof(it_header.ord_num));
148 fread(it_header.orders, 1, it_header.ord_num, file);
149 for(int i = 0; i < it_header.ord_num; i++)
150 printf("%02x | ", it_header.orders[i]);
151 printf("\n");
153 return 0;