annotate minijss/jloadjss.c @ 1198:5d20c80df290

Improve probing.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Mar 2015 16:14:40 +0200
parents 0ee6ba7b3e4a
children fa758951720f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * miniJSS - JSSMOD module loader
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
1163
aa3738b121d1 Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 1129
diff changeset
4 * (C) Copyright 2007-2015 Tecnic Software productions (TNSP)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include "jssmod.h"
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
1196
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
9 // If all pattern modes are required, enable them here
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #ifdef JM_SUP_PATMODE_ALL
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
11 # define JM_SUP_PATMODE_1 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
12 # define JM_SUP_PATMODE_2 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
13 # define JM_SUP_PATMODE_3 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
14 # define JM_SUP_PATMODE_4 1
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
15 # define JM_SUP_PATMODE_5 1
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
1196
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
19 // Short helper macros for reading data
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
20 #define JSGETBUF(XV, XT) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
21 if (!dmf_read_str(inFile, XV, sizeof(XT))) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
22 return DMERR_OUT_OF_DATA
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
23
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
24 #define JSGETBYTE(XV) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
25 if (!dmf_read_byte(inFile, XV)) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
26 return DMERR_OUT_OF_DATA
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
29 #if defined(JM_SUP_PATMODE_1) || defined(JM_SUP_PATMODE_3)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
30 static int jssGetConvertedNote(DMResource *inFile, JSSNote *pnote)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 Uint8 tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
37 pnote->note = jsetNoteOff;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 else if (tmp == 0)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
39 pnote->note = jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
41 pnote->note = tmp - 1;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
44 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
47 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
50 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
53 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
60 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
61 static int jssGetCompressedNote(DMResource *inFile, JSSNote *pnote)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 Uint8 packb, tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 JSGETBYTE(&packb);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 if (packb & 0x80)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 if (packb & COMP_NOTE)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
72 pnote->note = jsetNoteOff;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
74 pnote->note = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 if (packb & COMP_INSTRUMENT)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
80 pnote->instrument = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 if (packb & COMP_VOLUME)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
86 pnote->volume = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 if (packb & COMP_EFFECT)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
92 pnote->effect = tmp;
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
93 pnote->param = 0;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 if (packb & COMP_PARAM)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
99 pnote->param = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 tmp = packb;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
107 pnote->note = jsetNoteOff;
1196
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
108 else
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
109 if (tmp == 0)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
110 pnote->note = jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
112 pnote->note = tmp - 1;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
115 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
118 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
121 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
124 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
132 #ifdef JM_SUP_PATMODE_2
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
133 static int jssGetPatternCompHoriz(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
143 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
144 int res = jssGetCompressedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
146 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
147 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
155 #ifdef JM_SUP_PATMODE_4
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
156 static int jssGetPatternCompVert(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
166 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
167 int res = jssGetCompressedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
169 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
170 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
178 #ifdef JM_SUP_PATMODE_1
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
179 static int jssGetPatternRawHoriz(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
189 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
190 int res = jssGetConvertedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
192 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
193 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
201 #ifdef JM_SUP_PATMODE_3
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
202 static int jssGetPatternRawVert(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
212 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
213 int res = jssGetConvertedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
215 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
216 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
224 #ifdef JM_SUP_PATMODE_5
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
225
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
226 #undef JSGETBYTE
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
227 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
228
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
229 #define JSFOREACHNOTE1 \
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
230 for (channel = 0; channel < pattern->nchannels; channel++) \
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
231 for (row = 0; row < pattern->nrows; row++) { \
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
232 JSSNote *pnote = pattern->data + (pattern->nchannels * row) + channel;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
233
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
234 #define JSFOREACHNOTE2 }
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
235
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
236 static int jssGetPatternRawVertElem(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 int row, channel;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
239 Uint8 tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
244 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
245 JSGETBYTE(&tmp);
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
246 if (tmp == 0)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
247 pnote->note = jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
248 else if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
249 pnote->note = jsetNoteOff;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
250 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
251 pnote->note = tmp - 1;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
252 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
253
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
254 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
255 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
256 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
257 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
258
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
259 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
260 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
261 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
262 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
263
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
264 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
265 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
266 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
267 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
268
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
269 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
270 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
271 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
272 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
273
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279 #undef JSGETBUF
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 #undef JSGETBYTE
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 #define JSGETBUF(XV, XT) do { \
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
282 if (!dmf_read_str(inFile, XV, sizeof(XT))) \
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 JSSERROR(DMERR_OUT_OF_DATA, DMERR_OUT_OF_DATA, \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 "Out of data at getting " # XT " (%d bytes)\n", sizeof(XT)); \
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 } while (0)
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
286 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 #ifdef JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 static void jssCopyEnvelope(JSSEnvelope *e, JSSMODEnvelope *je)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 e->flags = je->flags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 e->npoints = je->npoints;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 e->sustain = je->sustain;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 e->loopS = je->loopS;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 e->loopE = je->loopE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 for (i = 0; i < je->npoints; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 e->points[i].frame = je->points[i].frame;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 e->points[i].value = je->points[i].value;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
309 int jssLoadJSSMOD(DMResource *inFile, JSSModule **ppModule, BOOL probe)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 JSSModule *module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 JSSMODHeader jssH;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 int index;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 *ppModule = NULL;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 // Check the JSSMOD header
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1163
diff changeset
318 dmMemset(&jssH, 0, sizeof(jssH));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 JSGETBUF(&jssH, JSSMODHeader);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 if (memcmp(jssH.idMagic, "JM", 2) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 {
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
323 if (probe)
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
324 return DMERR_NOT_SUPPORTED;
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
325 else
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
326 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
327 "Not a JSSMOD file, header signature mismatch!\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 if (jssH.idVersion != JSSMOD_VERSION)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 {
1198
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
332 if (probe)
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
333 return DMERR_VERSION;
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
334 else
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 JSSERROR(DMERR_VERSION, DMERR_VERSION,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 "Unsupported version of JSSMOD 0x%4x, this version only supports 0x%4x!\n",
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 jssH.idVersion, JSSMOD_VERSION);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339
1198
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
340 if (probe)
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
341 return DMERR_OK;
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
342
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 // Allocate the module
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 module = jssAllocateModule();
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345 if (module == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348 "Could not allocate memory for module structure.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 *ppModule = module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352 // Copy header information
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 module->norders = jssH.norders;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
354 module->npatterns = jssH.npatterns;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 module->nchannels = jssH.nchannels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 module->nextInstruments = jssH.nextInstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357 module->ninstruments = jssH.ninstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 module->defFlags = jssH.defFlags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
359 module->intVersion = jssH.intVersion;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
360 module->defRestartPos = jssH.defRestartPos;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
361 module->defSpeed = jssH.defSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 module->defTempo = jssH.defTempo;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
363
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
364 // Get the orders list
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
365 for (index = 0; index < module->norders; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
366 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
367 Sint16 order;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 JSGETBUF(&order, Sint16);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
369 module->orderList[index] = order;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
371
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
372 // Parse the patterns
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 for (index = 0; index < module->npatterns; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375 JSSMODPattern jssP;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376 int result = DMERR_INVALID_DATA;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
377
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 // Get header and check size
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1163
diff changeset
379 dmMemset(&jssP, 0, sizeof(jssP));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 JSGETBUF(&jssP, JSSMODPattern);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
381
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382 // Allocate pattern
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
383 module->patterns[index] = jssAllocatePattern(jssP.nrows, module->nchannels);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384 if (module->patterns[index] == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
386 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
387 "Could not allocate memory for pattern #%d.\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
388 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
389
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390 // Get pattern data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 switch (jssH.patMode)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 #ifdef JM_SUP_PATMODE_1
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 case PATMODE_RAW_HORIZ:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
395 result = jssGetPatternRawHoriz(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 #ifdef JM_SUP_PATMODE_2
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
399 case PATMODE_COMP_HORIZ:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
400 result = jssGetPatternCompHoriz(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 #ifdef JM_SUP_PATMODE_3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 case PATMODE_RAW_VERT:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
405 result = jssGetPatternRawVert(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 #ifdef JM_SUP_PATMODE_4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 case PATMODE_COMP_VERT:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
410 result = jssGetPatternCompVert(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 #ifdef JM_SUP_PATMODE_5
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
414 case PATMODE_RAW_ELEM:
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
415 result = jssGetPatternRawVertElem(inFile, module->patterns[index]);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
416 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
417 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
418 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
419 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
420 "Unsupported pattern mode %d. Check compilation options.", jssH.patMode);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
421 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
422 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
423
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
424 if (result != DMERR_OK)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
425 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 JSSERROR(result, result, "Error in unpacking pattern #%i data\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
427 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
428 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 #ifdef JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
431 // Read extended instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 for (index = 0; index < module->nextInstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
434 JSSMODExtInstrument jssE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
435 JSSExtInstrument *einst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
436 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
437
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1163
diff changeset
438 dmMemset(&jssE, 0, sizeof(jssE));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
439 JSGETBUF(&jssE, JSSMODExtInstrument);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
440
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
441 if ((einst = jssAllocateExtInstrument()) == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
442 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
443 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
444 "Could not allocate extended instrument structure #%i\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
445 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
446
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 module->extInstruments[index] = einst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
448
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 einst->nsamples = jssE.nsamples;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 einst->vibratoType = jssE.vibratoType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 einst->vibratoSweep = jssE.vibratoSweep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 einst->vibratoDepth = jssE.vibratoDepth;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453 einst->vibratoRate = jssE.vibratoRate;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 einst->fadeOut = jssE.fadeOut;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
455
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
456 for (i = 0; i < jsetNNotes; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 int snum = jssE.sNumForNotes[i];
1118
de25e0f2b856 Fix sNumForNotes conversion/handling in JSSMOD loader and xm2jss.
Matti Hamalainen <ccr@tnsp.org>
parents: 796
diff changeset
459 einst->sNumForNotes[i] = (snum > 0) ? snum - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 jssCopyEnvelope(&(einst->volumeEnv), &jssE.volumeEnv);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 jssCopyEnvelope(&(einst->panningEnv), &jssE.panningEnv);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466 #ifdef JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 // Read sample instrument headers
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 for (index = 0; index < module->ninstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 JSSMODInstrument jssI;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
471 JSSInstrument *inst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1163
diff changeset
473 dmMemset(&jssI, 0, sizeof(jssI));
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 JSGETBUF(&jssI, JSSMODInstrument);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
476 if ((inst = jssAllocateInstrument()) == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 "Could not allocate instrument structure #%i\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 module->instruments[index] = inst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 inst->size = jssI.size;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 inst->loopS = jssI.loopS;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
486 inst->loopE = jssI.loopE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 inst->volume = jssI.volume;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 inst->flags = jssI.flags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 inst->C4BaseSpeed = jssI.C4BaseSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490 inst->ERelNote = jssI.ERelNote;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 inst->EFineTune = jssI.EFineTune;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 inst->EPanning = jssI.EPanning;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 inst->hasData = jssI.hasData;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
494 inst->convFlags = jssI.convFlags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
497 #ifdef JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498 // Read sample data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 for (index = 0; index < module->ninstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 JSSInstrument *inst = module->instruments[index];
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
502
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 if (inst && inst->hasData)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 {
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
505 int ret;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 size_t sz;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 // Calculate data size
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 if (inst->flags & jsf16bit)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 sz = inst->size * sizeof(Uint16);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 sz = inst->size * sizeof(Uint8);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 // Allocate
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 if ((inst->data = dmMalloc(sz)) == NULL)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 "Could not allocate sample data #%d\n", index);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 // Copy data
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
522 if (!dmf_read_str(inFile, inst->data, sz))
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
523 {
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
524 JSSERROR(DMERR_FREAD, DMERR_FREAD,
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
525 "Could not read sample data for #%d\n", index);
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
526 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
527
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 // Convert, if needed
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 if (inst->flags & jsf16bit)
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
530 ret = jssDecodeSample16(inst->data, inst->size, inst->convFlags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 else
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
532 ret = jssDecodeSample8(inst->data, inst->size, inst->convFlags);
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
533
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
534 if (ret != DMERR_OK)
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
535 {
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
536 JSSERROR(ret, ret,
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
537 "Failed to decode sample data for #%d\n", index);
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
538 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
539 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
540 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
541 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
542 # warning Not including JSSMOD sample loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 #endif // JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
545 # warning Not including JSSMOD instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 #endif // JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
548 # warning Not including JSSMOD ext.instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 #endif // JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 }