annotate minijss/jloadjss.c @ 1350:dcb5c16ecdb9

Silence warnings about unused function arguments.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Aug 2017 22:38:13 +0300
parents 5adf67d1dea4
children ca9fe688ab6b
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 JSGETBYTE(XV) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
21 if (!dmf_read_byte(inFile, XV)) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
22 return DMERR_OUT_OF_DATA
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
25 static int jssDoGetConvertedNote(DMResource *inFile, JSSNote *pnote, Uint8 note)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 Uint8 tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
29 if (note == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
30 pnote->note = jsetNoteOff;
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
31 else
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
32 if (note == 0)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
33 pnote->note = jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 else
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
35 pnote->note = note - 1;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
38 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
41 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
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->effect = (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->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp;
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 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 }
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
51
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
52
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
53 static inline int jssGetConvertedNote(DMResource *inFile, JSSNote *pnote)
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
54 {
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
55 Uint8 tmp;
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
56 JSGETBYTE(&tmp);
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
57 return jssDoGetConvertedNote(inFile, pnote, tmp);
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
58 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
61 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
62 static int jssGetCompressedNote(DMResource *inFile, JSSNote *pnote)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 Uint8 packb, tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 JSGETBYTE(&packb);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 if (packb & 0x80)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 {
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
69 if (packb & JM_COMP_NOTE)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
73 pnote->note = jsetNoteOff;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
75 pnote->note = tmp;
0
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
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
78 if (packb & JM_COMP_INSTRUMENT)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
81 pnote->instrument = tmp;
0
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
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
84 if (packb & JM_COMP_VOLUME)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
87 pnote->volume = tmp;
0
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
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
90 if (packb & JM_COMP_EFFECT)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
93 pnote->effect = tmp;
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
94 pnote->param = 0;
0
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
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
97 if (packb & JM_COMP_PARAM)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
100 pnote->param = tmp;
0
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 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 {
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
105 int ret;
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
106 if ((ret = jssDoGetConvertedNote(inFile, pnote, packb)) != DMERR_OK)
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
107 return ret;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
115 #ifdef JM_SUP_PATMODE_2
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
116 static int jssGetPatternCompHoriz(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 int row, channel;
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 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 assert(pattern != NULL);
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 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
126 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
127 int res = jssGetCompressedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
129 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
130 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 return DMERR_OK;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
138 #ifdef JM_SUP_PATMODE_4
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
139 static int jssGetPatternCompVert(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
149 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
150 int res = jssGetCompressedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
152 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
153 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 return DMERR_OK;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
161 #ifdef JM_SUP_PATMODE_1
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
162 static int jssGetPatternRawHoriz(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
172 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
173 int res = jssGetConvertedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
175 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
176 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 return DMERR_OK;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
184 #ifdef JM_SUP_PATMODE_3
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
185 static int jssGetPatternRawVert(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 int row, channel;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 for (channel = 0; channel < pattern->nchannels; channel++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 for (row = 0; row < pattern->nrows; row++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 {
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
195 JSSNote *pnote = &pattern->data[(pattern->nchannels * row) + channel];
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
196 int res = jssGetConvertedNote(inFile, pnote);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 if (res != DMERR_OK)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
198 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n",
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
199 row, channel);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 return DMERR_OK;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
207 #ifdef JM_SUP_PATMODE_5
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
208
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
209 #undef JSGETBYTE
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
210 #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
211
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
212 #define JSFOREACHNOTE1 \
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
213 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
214 for (row = 0; row < pattern->nrows; row++) { \
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
215 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
216
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
217 #define JSFOREACHNOTE2 }
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
218
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
219 static int jssGetPatternRawVertElem(DMResource *inFile, JSSPattern *pattern)
0
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 int row, channel;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
222 Uint8 tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 assert(buf != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 assert(pattern != NULL);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
227 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
228 JSGETBYTE(&tmp);
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
229 if (tmp == 0)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
230 pnote->note = jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
231 else if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
232 pnote->note = jsetNoteOff;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
233 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
234 pnote->note = tmp - 1;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
235 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
236
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
237 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
238 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
239 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
240 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
241
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
242 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
243 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
244 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
245 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
246
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
247 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
248 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
249 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
250 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
251
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
252 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
253 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
254 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
255 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
256
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 #ifdef JM_SUP_EXT_INSTR
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
263 static int jssMODLoadEnvelope(DMResource *inFile,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
264 JSSEnvelope *env, const char *name, const int ninst)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
266 JSSMODEnvelope jssEnv;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267
1350
dcb5c16ecdb9 Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1349
diff changeset
268 (void) name;
dcb5c16ecdb9 Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1349
diff changeset
269 (void) ninst;
dcb5c16ecdb9 Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1349
diff changeset
270
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
271 // Read envelope data
1250
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
272 if (!dmf_read_byte(inFile, &jssEnv.flags) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
273 !dmf_read_byte(inFile, &jssEnv.npoints) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
274 !dmf_read_byte(inFile, &jssEnv.sustain) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
275 !dmf_read_byte(inFile, &jssEnv.loopS) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
276 !dmf_read_byte(inFile, &jssEnv.loopE))
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
277 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
278 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
279 "Failed to read %s-envelope data for instrument #%d.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
280 name, ninst);
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
281 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
282
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
283 // Do some sanity checking
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
284 if (jssEnv.npoints > jsetMaxEnvPoints ||
1331
c0479e984242 Fix a envelope "sanity check" in jmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1316
diff changeset
285 jssEnv.loopS > jssEnv.loopE ||
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
286 jssEnv.loopS > jssEnv.npoints ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
287 jssEnv.loopE > jssEnv.npoints)
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
288 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
289 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
290 "Invalid values in %s-envelope for instrument #%d.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
291 name, ninst);
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
292 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
294 // Copy data
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
295 env->flags = jssEnv.flags;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
296 env->npoints = jssEnv.npoints;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
297 env->sustain = jssEnv.sustain;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
298 env->loopS = jssEnv.loopS;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
299 env->loopE = jssEnv.loopE;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
300
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
301 for (int i = 0; i < jssEnv.npoints; i++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
303 Uint16 frame, value;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
304 if (!dmf_read_le16(inFile, &frame) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
305 !dmf_read_le16(inFile, &value))
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
306 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
307 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
308 "Failed to read %s-envelope values (%d) for instrument #%d.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
309 name, i, ninst);
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
310 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
311
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
312 env->points[i].frame = frame;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
313 env->points[i].value = value;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
315
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
316 return DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320
1256
d88d5f88b77a Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1255
diff changeset
321 int jssLoadJSSMOD(DMResource *inFile, JSSModule **pmodule, BOOL probe)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 JSSModule *module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 JSSMODHeader jssH;
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
325 int index, ret = DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326
1256
d88d5f88b77a Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1255
diff changeset
327 *pmodule = NULL;
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 // Check the JSSMOD header
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
330 if (!dmf_read_str(inFile, &jssH.idMagic, sizeof(jssH.idMagic)) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
331 !dmf_read_byte(inFile, &jssH.idVersion))
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
332 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
333 "Failed to read JSSMOD header #1.\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335 if (memcmp(jssH.idMagic, "JM", 2) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 {
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
337 if (probe)
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
338 return DMERR_NOT_SUPPORTED;
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
339 else
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
340 {
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
341 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
342 "Not a JSSMOD file, header signature mismatch!\n");
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
343 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346 if (jssH.idVersion != JSSMOD_VERSION)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 {
1198
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
348 if (probe)
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
349 return DMERR_VERSION;
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
350 else
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
351 {
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
352 JSSERROR(DMERR_VERSION, DMERR_VERSION,
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
353 "Unsupported version of JSSMOD 0x%2x, this version only supports 0x%2x!\n",
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
354 jssH.idVersion, JSSMOD_VERSION);
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
355 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
356 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
357
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
358 // Read rest of the header
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
359 if (!dmf_read_le16(inFile, &jssH.defFlags) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
360 !dmf_read_le16(inFile, &jssH.intVersion) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
361 !dmf_read_le16(inFile, &jssH.norders) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
362 !dmf_read_le16(inFile, &jssH.npatterns) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
363 !dmf_read_le16(inFile, &jssH.nextInstruments) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
364 !dmf_read_le16(inFile, &jssH.ninstruments) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
365 !dmf_read_le16(inFile, &jssH.defRestartPos) ||
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
366
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
367 !dmf_read_byte(inFile, &jssH.nchannels) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
368 !dmf_read_byte(inFile, &jssH.defSpeed) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
369 !dmf_read_byte(inFile, &jssH.defTempo) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
370 !dmf_read_byte(inFile, &jssH.patMode))
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
371 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
372 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
373 "Failed to read JSSMOD header #2.\n");
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
374 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
375
1198
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
376 if (probe)
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
377 return DMERR_OK;
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
378
1218
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
379 // Check some of the things for sanity
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
380 if (jssH.nchannels > jsetMaxChannels ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
381 jssH.nchannels == 0 ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
382 jssH.norders > jsetMaxOrders ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
383 jssH.npatterns > jsetMaxPatterns ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
384 jssH.nextInstruments > jsetMaxInstruments ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
385 jssH.ninstruments > jsetMaxInstruments)
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
386 {
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
387 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
388 "Invalid values in JSSMOD header.\n");
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
389 }
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
390
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 // Allocate the module
1256
d88d5f88b77a Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1255
diff changeset
392 if ((*pmodule = module = jssAllocateModule()) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
393 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
394 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
395 "Could not allocate memory for module structure.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
396 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
397
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
398 // Copy header information
1216
f57dc769bd39 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
399 module->defFlags = jssH.defFlags;
f57dc769bd39 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
400 module->intVersion = jssH.intVersion;
f57dc769bd39 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
401
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 module->norders = jssH.norders;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 module->npatterns = jssH.npatterns;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
404 module->nchannels = jssH.nchannels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
405 module->nextInstruments = jssH.nextInstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
406 module->ninstruments = jssH.ninstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
407 module->defRestartPos = jssH.defRestartPos;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
408 module->defSpeed = jssH.defSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
409 module->defTempo = jssH.defTempo;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
410
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
411 // Get the orders list
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 for (index = 0; index < module->norders; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
413 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
414 Uint16 tmp;
1250
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
415 if (!dmf_read_le16(inFile, &tmp))
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
416 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
417 "Failed to read orders list entry #%d.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
418 index);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
419
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
420 if (tmp != 0xffff && tmp > jssH.npatterns)
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
421 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
422 "Invalid orders list entry #%d value %d > %d.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
423 index, tmp, jssH.npatterns);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
424
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
425 module->orderList[index] = (tmp == 0xffff) ? jsetNotSet : tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
426 }
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 // Parse the patterns
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
429 for (index = 0; index < module->npatterns; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
430 {
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
431 JSSPattern *pattern;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
432 JSSMODPattern jssP;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
433
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
434 // Read pattern header
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
435 if (!dmf_read_le32(inFile, &jssP.size) ||
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
436 !dmf_read_le16(inFile, &jssP.nrows))
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
437 JSSERROR(DMERR_FREAD, DMERR_FREAD,
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
438 "Failed to read JSSMOD pattern header #%d.\n",
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
439 index);
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
440
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
441 // Validate
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
442 if (jssP.nrows == 0 || jssP.nrows > jsetMaxRows)
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
443 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
444 "Invalid number of rows in pattern #%d: %d.\n",
1257
60dc14a2e4c5 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1256
diff changeset
445 index, jssP.nrows);
0
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 // Allocate pattern
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
448 pattern = module->patterns[index] = jssAllocatePattern(jssP.nrows, module->nchannels);
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
449 if (pattern == NULL)
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
450 {
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
1212
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
452 "Could not allocate memory for pattern #%d.\n",
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
453 index);
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
454 }
0
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 // Get pattern data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
457 switch (jssH.patMode)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 #ifdef JM_SUP_PATMODE_1
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 case PATMODE_RAW_HORIZ:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
461 ret = jssGetPatternRawHoriz(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 #ifdef JM_SUP_PATMODE_2
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 case PATMODE_COMP_HORIZ:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
466 ret = jssGetPatternCompHoriz(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 #ifdef JM_SUP_PATMODE_3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
470 case PATMODE_RAW_VERT:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
471 ret = jssGetPatternRawVert(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
472 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
473 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
474 #ifdef JM_SUP_PATMODE_4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 case PATMODE_COMP_VERT:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
476 ret = jssGetPatternCompVert(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
478 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 #ifdef JM_SUP_PATMODE_5
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
480 case PATMODE_RAW_ELEM:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
481 ret = jssGetPatternRawVertElem(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
484 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
485 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
1212
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
486 "Unsupported pattern mode %d. Check compilation options.",
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
487 jssH.patMode);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
490
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
491 if (ret != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
493 JSSERROR(ret, ret,
1212
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
494 "Error in unpacking pattern #%d data.\n",
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
495 index);
0
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 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
498
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 #ifdef JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
500 // Read extended instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
501 for (index = 0; index < module->nextInstruments; 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 JSSMODExtInstrument jssE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
504 JSSExtInstrument *einst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
507 // Read header data
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
508 if (!dmf_read_byte(inFile, &jssE.nsamples) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
509 !dmf_read_byte(inFile, &jssE.vibratoType) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
510 !dmf_read_le16(inFile, &jssE.vibratoSweep) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
511 !dmf_read_le16(inFile, &jssE.vibratoDepth) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
512 !dmf_read_le16(inFile, &jssE.vibratoRate) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
513 !dmf_read_le16(inFile, &jssE.fadeOut))
1271
197c9ccdb33c Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1257
diff changeset
514 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
515 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
516 "Failed to read ext.instrument #%d header.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
517 index);
1271
197c9ccdb33c Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1257
diff changeset
518 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
519
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
520 // Allocate instrument
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
521 einst = module->extInstruments[index] = jssAllocateExtInstrument();
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
522 if (einst == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
523 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
1214
1133dffe3713 s/%i/%d/g.
Matti Hamalainen <ccr@tnsp.org>
parents: 1213
diff changeset
525 "Could not allocate extended instrument structure #%d\n", index);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 }
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 einst->nsamples = jssE.nsamples;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529 einst->vibratoType = jssE.vibratoType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 einst->vibratoSweep = jssE.vibratoSweep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
531 einst->vibratoDepth = jssE.vibratoDepth;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
532 einst->vibratoRate = jssE.vibratoRate;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
533 einst->fadeOut = jssE.fadeOut;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
534
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
535 // Read and somewhat validate sNumForNotes
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 for (i = 0; i < jsetNNotes; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
538 int snum;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
539 Uint32 tmp;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
540
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
541 if (!dmf_read_le32(inFile, &tmp))
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
542 {
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
543 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
544 "Failed to read ext.instrument #%d sNumForNotes[%d].\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
545 index, i);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
546 }
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
547
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
548 einst->sNumForNotes[i] = snum = (tmp > 0) ? ((int) tmp - 1) : jsetNotSet;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
549
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
550 if (snum != jsetNotSet && snum > module->ninstruments)
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
551 {
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
552 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
553 "Ext.instrument #%d has invalid sNumForNotes[%d] = %d > %d max.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
554 index, i, snum, module->ninstruments);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
555 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
558 // Read and validate envelopes
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
559 if ((ret = jssMODLoadEnvelope(inFile, &einst->volumeEnv, "volume", index)) != DMERR_OK ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
560 (ret = jssMODLoadEnvelope(inFile, &einst->panningEnv, "panning", index)) != DMERR_OK)
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
561 return ret;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 #ifdef JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 // Read sample instrument headers
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 for (index = 0; index < module->ninstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 JSSMODInstrument jssI;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 JSSInstrument *inst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
571 // Read header data
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
572 if (!dmf_read_le32(inFile, &jssI.size) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
573 !dmf_read_le32(inFile, &jssI.loopS) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
574 !dmf_read_le32(inFile, &jssI.loopE) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
575 !dmf_read_le16(inFile, &jssI.flags) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
576 !dmf_read_le16(inFile, &jssI.C4BaseSpeed) ||
1349
5adf67d1dea4 Fix loading of instrument relative note, finetune and panning values, which should be signed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1331
diff changeset
577 !dmf_read_le16(inFile, (Uint16 *) &jssI.ERelNote) ||
5adf67d1dea4 Fix loading of instrument relative note, finetune and panning values, which should be signed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1331
diff changeset
578 !dmf_read_le16(inFile, (Uint16 *) &jssI.EFineTune) ||
5adf67d1dea4 Fix loading of instrument relative note, finetune and panning values, which should be signed.
Matti Hamalainen <ccr@tnsp.org>
parents: 1331
diff changeset
579 !dmf_read_le16(inFile, (Uint16 *) &jssI.EPanning) ||
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
580 !dmf_read_byte(inFile, &jssI.volume) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
581 !dmf_read_byte(inFile, &jssI.convFlags))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
583 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
584 "Failed to read sample instrument #%d header.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
585 index);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
588 // Validate what we can
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
589 if (jssI.loopS > jssI.size ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
590 jssI.loopE > jssI.size ||
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
591 jssI.loopS > jssI.loopE)
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
592 {
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
593 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
594 "Invalid or corrupted sample instrument #%d.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
595 index);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
596 }
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
597
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
598 // Allocate instrument
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
599 inst = module->instruments[index] = jssAllocateInstrument();
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
600 if (inst == NULL)
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
601 {
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
602 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
603 "Could not allocate sample instrument structure #%d\n",
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
604 index);
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
605 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606
1231
a275b7382ffa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1219
diff changeset
607 // Copy data
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 inst->size = jssI.size;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 inst->loopS = jssI.loopS;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 inst->loopE = jssI.loopE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 inst->flags = jssI.flags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 inst->C4BaseSpeed = jssI.C4BaseSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613 inst->ERelNote = jssI.ERelNote;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 inst->EFineTune = jssI.EFineTune;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 inst->EPanning = jssI.EPanning;
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
616 inst->volume = jssI.volume;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 inst->convFlags = jssI.convFlags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 #ifdef JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 // Read sample data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 for (index = 0; index < module->ninstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 JSSInstrument *inst = module->instruments[index];
1312
4eb394c9e682 Clearer flag check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1311
diff changeset
625 if (inst != NULL && (inst->convFlags & jsampHasData) != 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 {
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
627 int ret;
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
628 size_t bsize = (inst->flags & jsf16bit) ? sizeof(Uint16) : sizeof(Uint8);
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
629 bsize *= inst->size;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
630
1316
817a4d0c70b5 Comment clarifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 1314
diff changeset
631 // Allocate sample data memory
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
632 if ((inst->data = dmMalloc(bsize)) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
633 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
634 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
635 "Could not allocate %d bytes of sample data #%d\n",
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
636 bsize, index);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
637 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
638
1316
817a4d0c70b5 Comment clarifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 1314
diff changeset
639 // Read data
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
640 if (!dmf_read_str(inFile, inst->data, bsize))
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
641 {
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
642 JSSERROR(DMERR_FREAD, DMERR_FREAD,
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
643 "Could not read %d bytes of sample data for #%d\n",
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
644 bsize, index);
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
645 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 // Convert, if needed
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 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
649 ret = jssDecodeSample16(inst->data, inst->size, inst->convFlags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 else
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
651 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
652
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
653 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
654 {
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
655 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
656 "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
657 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
661 # warning Not including JSSMOD sample loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 #endif // JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
664 # warning Not including JSSMOD instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665 #endif // JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
667 # warning Not including JSSMOD ext.instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
668 #endif // JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
670 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 }