5 uint16_t short_byteswap(uint16_t in
) {
6 in
= (((in
>> 8) & 0xff) | ((in
<< 8) & 0xff));
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
; //???
43 uint8_t *orders
; //orders, in order ;). length is it_header.ord_num
46 int main(int argc
, char **argv
){
48 struct it_header it_header
;
51 printf("usage: slurp <.it file>");
55 file
= fopen(argv
[1], "rb");
58 printf("couldnt open file!\n");
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
]);
71 /* read in songname */
72 fread(it_header
.songname
, 1, 26, file
);
73 printf("%s\n", it_header
.songname
);
78 fseek(file
, 0x20, SEEK_SET
);
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);
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
);
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
);
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
);
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
);
127 fread(&it_header
.sep
, 1, 1, file
);
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
]);