annotate minijss/jloadjss.c @ 2472:fd02e78f6fdc

Allocate empty pattern for JSSMOD as well.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 Apr 2020 03:15:19 +0300
parents dcf1016f3d27
children 9807ae37ad69
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
2279
fc58f62f100c Bump copyright years.
Matti Hamalainen <ccr@tnsp.org>
parents: 2278
diff changeset
4 * (C) Copyright 2007-2019 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
2303
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
16 # define JM_SUP_PATMODE_6 1
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
20 static inline JSSNote * jssGetNotePtr(JSSPattern *pattern, const int channel, const int row)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
21 {
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
22 return pattern->data + (pattern->nchannels * row) + pattern->map[channel];
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
23 }
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
24
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
25
1196
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
26 // Short helper macros for reading data
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
27 #define JSGETBYTE(XV) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
28 if (!dmf_read_byte(inFile, XV)) \
aa6c3af36008 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
29 return DMERR_OUT_OF_DATA
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
32 static int jssDoGetConvertedNote(DMResource *inFile, JSSNote *pnote, const Uint8 note)
0
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 Uint8 tmp;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
36 if (note == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
37 pnote->note = jsetNoteOff;
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
38 else
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
39 if (note == 0)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
40 pnote->note = jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 else
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
42 pnote->note = note - 1;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
45 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
48 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
51 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
54 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
58
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
59
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
60 static inline int jssGetConvertedNote(DMResource *inFile,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
61 JSSPattern *pattern, const int channel, const int row)
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
62 {
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
63 Uint8 tmp;
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
64 int res;
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
65
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
66 JSGETBYTE(&tmp);
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
67 if ((res = jssDoGetConvertedNote(inFile,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
68 jssGetNotePtr(pattern, channel, row), tmp)) != DMERR_OK)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
69 JSSERROR(res, res, "Error converting note on row=%d, chn=%d\n",
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
70 row, channel);
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
71
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
72 return res;
1208
fa758951720f Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 1198
diff changeset
73 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
76 #if defined(JM_SUP_PATMODE_2) || defined(JM_SUP_PATMODE_4)
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
77 static int jssGetCompressedNoteDo(DMResource *inFile,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
78 JSSPattern *pattern, const int channel, const int row)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
80 JSSNote *pnote = jssGetNotePtr(pattern, channel, row);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 Uint8 packb, tmp;
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
82 int res = DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 JSGETBYTE(&packb);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 if (packb & 0x80)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 {
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
87 if (packb & JM_COMP_NOTE)
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 JSGETBYTE(&tmp);
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
91 pnote->note = jsetNoteOff;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
93 pnote->note = tmp;
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
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
96 if (packb & JM_COMP_INSTRUMENT)
0
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->instrument = 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
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
102 if (packb & JM_COMP_VOLUME)
0
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 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
105 pnote->volume = tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
108 if (packb & JM_COMP_EFFECT)
0
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 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
111 pnote->effect = tmp;
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
112 pnote->param = 0;
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
1210
6b48bad13399 Rename pattern note packing flag COMP_* constants to JM_COMP_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1208
diff changeset
115 if (packb & JM_COMP_PARAM)
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->param = tmp;
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 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 else
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
123 res = jssDoGetConvertedNote(inFile, pnote, packb);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
126 return res;
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
127 }
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
128
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
129
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
130 static int jssGetCompressedNote(DMResource *inFile,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
131 JSSPattern *pattern, const int channel, const int row)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
132 {
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
133 int res = jssGetCompressedNoteDo(inFile, pattern, channel, row);
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
134
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
135 if (res != DMERR_OK)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
136 JSSERROR(res, res, "Error uncompressing note on row=%d, chn=%d\n",
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
137 row, channel);
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
138
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
139 return res;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
144 #ifdef JM_SUP_PATMODE_2
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
145 static int jssGetPatternCompHoriz(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
147 for (int row = 0; row < pattern->nrows; row++)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
148 for (int channel = 0; channel < pattern->nmap; channel++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
150 int res = jssGetCompressedNote(inFile, pattern, channel, row);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 if (res != DMERR_OK)
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
152 return res;
0
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
160 #ifdef JM_SUP_PATMODE_4
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
161 static int jssGetPatternCompVert(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
163 for (int channel = 0; channel < pattern->nmap; channel++)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
164 for (int row = 0; row < pattern->nrows; row++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
166 int res = jssGetCompressedNote(inFile, pattern, channel, row);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 if (res != DMERR_OK)
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
168 return res;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 return DMERR_OK;
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 #endif
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
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
176 #ifdef JM_SUP_PATMODE_1
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
177 static int jssGetPatternRawHoriz(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
179 for (int row = 0; row < pattern->nrows; row++)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
180 for (int channel = 0; channel < pattern->nmap; channel++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
182 int res = jssGetConvertedNote(inFile, pattern, channel, row);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 if (res != DMERR_OK)
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
184 return res;
0
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 return DMERR_OK;
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 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
192 #ifdef JM_SUP_PATMODE_3
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
193 static int jssGetPatternRawVert(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
195 for (int channel = 0; channel < pattern->nmap; channel++)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
196 for (int row = 0; row < pattern->nrows; row++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 {
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
198 int res = jssGetConvertedNote(inFile, pattern, channel, row);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 if (res != DMERR_OK)
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
200 return res;
0
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
208 #ifdef JM_SUP_PATMODE_5
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
209
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
210 #undef JSGETBYTE
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
211 #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
212
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
213 #define JSFOREACHNOTE1 \
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
214 for (int channel = 0; channel < pattern->nmap; channel++) \
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
215 for (int row = 0; row < pattern->nrows; row++) { \
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
216 JSSNote *pnote = pattern->data + (pattern->nchannels * row) + pattern->map[channel];
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
217
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
218 #define JSFOREACHNOTE2 }
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
219
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
220
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
221 static int jssGetPatternRawVertElem(DMResource *inFile, JSSPattern *pattern)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 {
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
223 Uint8 tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
225 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
226 JSGETBYTE(&tmp);
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
227 if (tmp == 0)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
228 pnote->note = jsetNotSet;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
229 else if (tmp == 127)
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
230 pnote->note = jsetNoteOff;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
231 else
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
232 pnote->note = tmp - 1;
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
233 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
234
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
235 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
236 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
237 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
238 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
239
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
240 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
241 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
242 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
243 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
244
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
245 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
246 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
247 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
248 JSFOREACHNOTE2
1127
e22d4ceb6414 Cosmetics pass, remove excess and trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1118
diff changeset
249
204
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
250 JSFOREACHNOTE1
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
251 JSGETBYTE(&tmp);
1197
0ee6ba7b3e4a Rename variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 1196
diff changeset
252 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
253 JSFOREACHNOTE2
d3a9a3804079 Implement pattern mode 5 in the JMOD jloader.
Matti Hamalainen <ccr@tnsp.org>
parents: 96
diff changeset
254
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 }
2303
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
257
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
258 #undef JSFOREACHNOTE1
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
259 #undef JSFOREACHNOTE2
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
260 #endif
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
261
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
262
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
263 #ifdef JM_SUP_PATMODE_6
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
264
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
265 #undef JSGETBYTE
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
266 #define JSGETBYTE(XV) if (!dmf_read_byte(inFile, XV)) return DMERR_OUT_OF_DATA
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
267
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
268 #define JSFOREACHNOTE1 \
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
269 for (int row = 0; row < pattern->nrows; row++) \
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
270 for (int channel = 0; channel < pattern->nmap; channel++) { \
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
271 JSSNote *pnote = pattern->data + (pattern->nchannels * row) + pattern->map[channel];
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
272
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
273 #define JSFOREACHNOTE2 }
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
274
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
275
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
276 static int jssGetPatternRawHorizElem(DMResource *inFile, JSSPattern *pattern)
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
277 {
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
278 Uint8 tmp;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
279
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
280 JSFOREACHNOTE1
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
281 JSGETBYTE(&tmp);
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
282 if (tmp == 0)
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
283 pnote->note = jsetNotSet;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
284 else if (tmp == 127)
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
285 pnote->note = jsetNoteOff;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
286 else
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
287 pnote->note = tmp - 1;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
288 JSFOREACHNOTE2
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
289
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
290 JSFOREACHNOTE1
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
291 JSGETBYTE(&tmp);
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
292 pnote->instrument = (tmp > 0) ? tmp - 1 : jsetNotSet;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
293 JSFOREACHNOTE2
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
294
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
295 JSFOREACHNOTE1
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
296 JSGETBYTE(&tmp);
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
297 pnote->volume = (tmp > 0) ? tmp - 1 : jsetNotSet;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
298 JSFOREACHNOTE2
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
299
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
300 JSFOREACHNOTE1
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
301 JSGETBYTE(&tmp);
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
302 pnote->effect = (tmp > 0) ? tmp - 1 : jsetNotSet;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
303 JSFOREACHNOTE2
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
304
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
305 JSFOREACHNOTE1
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
306 JSGETBYTE(&tmp);
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
307 pnote->param = (tmp == 0 && pnote->effect == jsetNotSet) ? jsetNotSet : tmp;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
308 JSFOREACHNOTE2
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
309
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
310 return DMERR_OK;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
311 }
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
312
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
313 #undef JSFOREACHNOTE1
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
314 #undef JSFOREACHNOTE2
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 #endif
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
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 #ifdef JM_SUP_EXT_INSTR
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
319 static int jssMODLoadEnvelope(DMResource *inFile,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
320 JSSEnvelope *env, const char *name, const int ninst)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
322 JSSMODEnvelope jssEnv;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323
1350
dcb5c16ecdb9 Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1349
diff changeset
324 (void) name;
dcb5c16ecdb9 Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1349
diff changeset
325 (void) ninst;
dcb5c16ecdb9 Silence warnings about unused function arguments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1349
diff changeset
326
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
327 // Read envelope data
1250
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
328 if (!dmf_read_byte(inFile, &jssEnv.flags) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
329 !dmf_read_byte(inFile, &jssEnv.npoints) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
330 !dmf_read_byte(inFile, &jssEnv.sustain) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
331 !dmf_read_byte(inFile, &jssEnv.loopS) ||
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
332 !dmf_read_byte(inFile, &jssEnv.loopE))
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
333 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
334 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
335 "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
336 name, ninst);
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
337 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
338
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
339 // Do some sanity checking
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
340 if (jssEnv.npoints > jsetMaxEnvPoints ||
1331
c0479e984242 Fix a envelope "sanity check" in jmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1316
diff changeset
341 jssEnv.loopS > jssEnv.loopE ||
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
342 jssEnv.loopS > jssEnv.npoints ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
343 jssEnv.loopE > jssEnv.npoints)
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
344 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
345 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
346 "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
347 name, ninst);
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
348 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
350 // Copy data
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
351 env->flags = jssEnv.flags;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
352 env->npoints = jssEnv.npoints;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
353 env->sustain = jssEnv.sustain;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
354 env->loopS = jssEnv.loopS;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
355 env->loopE = jssEnv.loopE;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
356
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
357 for (int i = 0; i < jssEnv.npoints; i++)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
358 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
359 Uint16 frame, value;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
360 if (!dmf_read_le16(inFile, &frame) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
361 !dmf_read_le16(inFile, &value))
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
362 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
363 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
364 "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
365 name, i, ninst);
1314
4670907412e7 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1312
diff changeset
366 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
367
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
368 env->points[i].frame = frame;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
369 env->points[i].value = value;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
370 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
371
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
372 return DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
373 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
374 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
375
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
376
1256
d88d5f88b77a Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1255
diff changeset
377 int jssLoadJSSMOD(DMResource *inFile, JSSModule **pmodule, BOOL probe)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
378 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
379 JSSModule *module;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
380 JSSMODHeader jssH;
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
381 int index, ret = DMERR_OK;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
382
1256
d88d5f88b77a Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1255
diff changeset
383 *pmodule = NULL;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
384
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
385 // Check the JSSMOD header
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
386 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
387 !dmf_read_byte(inFile, &jssH.idVersion))
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
388 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
389 "Failed to read JSSMOD header #1.\n");
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
390
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
391 if (memcmp(jssH.idMagic, "JM", 2) != 0)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
392 {
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
393 if (probe)
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
394 return DMERR_NOT_SUPPORTED;
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
395 else
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
396 {
796
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
397 JSSERROR(DMERR_NOT_SUPPORTED, DMERR_NOT_SUPPORTED,
97ecc0a9c21f Silence some "probing".
Matti Hamalainen <ccr@tnsp.org>
parents: 777
diff changeset
398 "Not a JSSMOD file, header signature mismatch!\n");
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
399 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
400 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
401
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
402 if (jssH.idVersion != JSSMOD_VERSION)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
403 {
1198
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
404 if (probe)
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
405 return DMERR_VERSION;
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
406 else
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
407 {
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
408 JSSERROR(DMERR_VERSION, DMERR_VERSION,
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
409 "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
410 jssH.idVersion, JSSMOD_VERSION);
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
411 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
412 }
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 // Read rest of the header
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
415 if (!dmf_read_le16(inFile, &jssH.defFlags) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
416 !dmf_read_le16(inFile, &jssH.intVersion) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
417 !dmf_read_le16(inFile, &jssH.norders) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
418 !dmf_read_le16(inFile, &jssH.npatterns) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
419 !dmf_read_le16(inFile, &jssH.nextInstruments) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
420 !dmf_read_le16(inFile, &jssH.ninstruments) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
421 !dmf_read_le16(inFile, &jssH.defRestartPos) ||
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
422
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
423 !dmf_read_byte(inFile, &jssH.nchannels) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
424 !dmf_read_byte(inFile, &jssH.defSpeed) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
425 !dmf_read_byte(inFile, &jssH.defTempo) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
426 !dmf_read_byte(inFile, &jssH.patMode))
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
427 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
428 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
429 "Failed to read JSSMOD header #2.\n");
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
430 }
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
431
1198
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
432 if (probe)
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
433 return DMERR_OK;
5d20c80df290 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1197
diff changeset
434
1218
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
435 // 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
436 if (jssH.nchannels > jsetMaxChannels ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
437 jssH.nchannels == 0 ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
438 jssH.norders > jsetMaxOrders ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
439 jssH.npatterns > jsetMaxPatterns ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
440 jssH.nextInstruments > jsetMaxInstruments ||
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
441 jssH.ninstruments > jsetMaxInstruments)
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
442 {
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
443 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
444 "Invalid values in JSSMOD header.\n");
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
445 }
30c2dbf05841 Add a sanity check for JSSMOD header values.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
446
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
447 // Allocate the module
1256
d88d5f88b77a Rename variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1255
diff changeset
448 if ((*pmodule = module = jssAllocateModule()) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
449 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
450 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
451 "Could not allocate memory for module structure.\n");
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
452 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
453
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
454 // Copy header information
1216
f57dc769bd39 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
455 module->defFlags = jssH.defFlags;
f57dc769bd39 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
456 module->intVersion = jssH.intVersion;
f57dc769bd39 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1214
diff changeset
457
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
458 module->norders = jssH.norders;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
459 module->npatterns = jssH.npatterns;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
460 module->nchannels = jssH.nchannels;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
461 module->nextInstruments = jssH.nextInstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
462 module->ninstruments = jssH.ninstruments;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
463 module->defRestartPos = jssH.defRestartPos;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
464 module->defSpeed = jssH.defSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
465 module->defTempo = jssH.defTempo;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
466
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
467 // Get the orders list
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
468 for (index = 0; index < module->norders; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
469 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
470 Uint16 tmp;
1250
99852310dc02 Some more work on the loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1247
diff changeset
471 if (!dmf_read_le16(inFile, &tmp))
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
472 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
473 "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
474 index);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
475
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
476 if (tmp != 0xffff && tmp > jssH.npatterns)
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
477 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
478 "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
479 index, tmp, jssH.npatterns);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
480
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
481 module->orderList[index] = (tmp == 0xffff) ? jsetNotSet : tmp;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
482 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483
2472
fd02e78f6fdc Allocate empty pattern for JSSMOD as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 2303
diff changeset
484 // Allocate the empty pattern
fd02e78f6fdc Allocate empty pattern for JSSMOD as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 2303
diff changeset
485 module->patterns[jsetMaxPatterns] = jssAllocatePattern(64, module->nchannels);
fd02e78f6fdc Allocate empty pattern for JSSMOD as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 2303
diff changeset
486
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
487 // Parse the patterns
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 for (index = 0; index < module->npatterns; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
489 {
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
490 JSSPattern *pattern;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
491 JSSMODPattern jssP;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
493 // Read pattern header
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
494 if (!dmf_read_le32(inFile, &jssP.size) ||
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
495 !dmf_read_le16(inFile, &jssP.nrows) ||
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
496 !dmf_read_le16(inFile, &jssP.nchannels))
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
497 JSSERROR(DMERR_FREAD, DMERR_FREAD,
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
498 "Failed to read JSSMOD pattern header #%d.\n",
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
499 index);
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
500
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
501 // Validate
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
502 if (jssP.nrows == 0 || jssP.nrows > jsetMaxRows)
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
503 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
504 "Invalid number of rows in pattern #%d: %d.\n",
1257
60dc14a2e4c5 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1256
diff changeset
505 index, jssP.nrows);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
507 if (jssP.nchannels == 0 || jssP.nchannels > module->nchannels)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
508 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
509 "Invalid number of channels in pattern #%d: %d.\n",
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
510 index, jssP.nchannels);
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
511
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 // Allocate pattern
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
513 pattern = module->patterns[index] = jssAllocatePattern(jssP.nrows, module->nchannels);
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
514 if (pattern == NULL)
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
515 {
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
1212
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
517 "Could not allocate memory for pattern #%d.\n",
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
518 index);
1310
dce4730372c7 Add some blocks, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1271
diff changeset
519 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520
2278
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
521 // Read channel mappings, if any
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
522 pattern->nmap = jssP.nchannels;
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
523 if (jssP.nchannels != module->nchannels)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
524 {
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
525 if (!dmf_read_str(inFile, pattern->map,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
526 sizeof(pattern->map[0]) * jssP.nchannels))
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
527 JSSERROR(DMERR_FREAD, DMERR_FREAD,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
528 "Failed to read JSSMOD channel mapping data for pattern #%d.\n",
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
529 index);
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
530
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
531 // Check mapping
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
532 for (int nch = 0; nch < jssP.nchannels; nch++)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
533 {
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
534 if (pattern->map[nch] >= module->nchannels)
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
535 {
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
536 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
537 "Invalid channel mapping in pattern #%d: chn %d -> %d.\n",
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
538 index, nch, pattern->map[nch]);
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
539 }
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
540 }
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
541 }
40ccc09f09be Implement empty channel removal in xm2jss and make JSSMOD format support
Matti Hamalainen <ccr@tnsp.org>
parents: 1817
diff changeset
542
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
543 // Get pattern data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
544 switch (jssH.patMode)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
546 #ifdef JM_SUP_PATMODE_1
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
547 case PATMODE_RAW_HORIZ:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
548 ret = jssGetPatternRawHoriz(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
549 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
550 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
551 #ifdef JM_SUP_PATMODE_2
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 case PATMODE_COMP_HORIZ:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
553 ret = jssGetPatternCompHoriz(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 #ifdef JM_SUP_PATMODE_3
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
557 case PATMODE_RAW_VERT:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
558 ret = jssGetPatternRawVert(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
561 #ifdef JM_SUP_PATMODE_4
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 case PATMODE_COMP_VERT:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
563 ret = jssGetPatternCompVert(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 #endif
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 #ifdef JM_SUP_PATMODE_5
2303
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
567 case PATMODE_RAW_ELEM_VERT:
1255
f9bf71071f0b Some work on JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1250
diff changeset
568 ret = jssGetPatternRawVertElem(inFile, pattern);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 #endif
2303
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
571 #ifdef JM_SUP_PATMODE_6
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
572 case PATMODE_RAW_ELEM_HORIZ:
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
573 ret = jssGetPatternRawHorizElem(inFile, pattern);
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
574 break;
dcf1016f3d27 Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
Matti Hamalainen <ccr@tnsp.org>
parents: 2279
diff changeset
575 #endif
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 default:
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
1212
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
578 "Unsupported pattern mode %d. Check compilation options.",
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
579 jssH.patMode);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 break;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 }
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 if (ret != DMERR_OK)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
585 JSSERROR(ret, ret,
1212
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
586 "Error in unpacking pattern #%d data.\n",
1483b6af6065 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1210
diff changeset
587 index);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 #ifdef JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 // Read extended instruments
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 for (index = 0; index < module->nextInstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 JSSMODExtInstrument jssE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 JSSExtInstrument *einst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 int i;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
598
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
599 // Read header data
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
600 if (!dmf_read_byte(inFile, &jssE.nsamples) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
601 !dmf_read_byte(inFile, &jssE.vibratoType) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
602 !dmf_read_le16(inFile, &jssE.vibratoSweep) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
603 !dmf_read_le16(inFile, &jssE.vibratoDepth) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
604 !dmf_read_le16(inFile, &jssE.vibratoRate) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
605 !dmf_read_le16(inFile, &jssE.fadeOut))
1271
197c9ccdb33c Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1257
diff changeset
606 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
607 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
608 "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
609 index);
1271
197c9ccdb33c Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1257
diff changeset
610 }
1817
ca9fe688ab6b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1350
diff changeset
611
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
612 // Allocate instrument
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
613 einst = module->extInstruments[index] = jssAllocateExtInstrument();
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
614 if (einst == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
616 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
1214
1133dffe3713 s/%i/%d/g.
Matti Hamalainen <ccr@tnsp.org>
parents: 1213
diff changeset
617 "Could not allocate extended instrument structure #%d\n", index);
0
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 einst->nsamples = jssE.nsamples;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 einst->vibratoType = jssE.vibratoType;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 einst->vibratoSweep = jssE.vibratoSweep;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 einst->vibratoDepth = jssE.vibratoDepth;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
624 einst->vibratoRate = jssE.vibratoRate;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625 einst->fadeOut = jssE.fadeOut;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
627 // Read and somewhat validate sNumForNotes
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
628 for (i = 0; i < jsetNNotes; i++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
629 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
630 int snum;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
631 Uint32 tmp;
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
632
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
633 if (!dmf_read_le32(inFile, &tmp))
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
634 {
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
635 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
636 "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
637 index, i);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
638 }
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
639
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
640 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
641
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
642 if (snum != jsetNotSet && snum > module->ninstruments)
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
643 {
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
644 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
645 "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
646 index, i, snum, module->ninstruments);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
647 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
650 // Read and validate envelopes
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
651 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
652 (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
653 return ret;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
655
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
656 #ifdef JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 // Read sample instrument headers
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 for (index = 0; index < module->ninstruments; index++)
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 JSSMODInstrument jssI;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 JSSInstrument *inst;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
663 // Read header data
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
664 if (!dmf_read_le32(inFile, &jssI.size) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
665 !dmf_read_le32(inFile, &jssI.loopS) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
666 !dmf_read_le32(inFile, &jssI.loopE) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
667 !dmf_read_le16(inFile, &jssI.flags) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
668 !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
669 !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
670 !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
671 !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
672 !dmf_read_byte(inFile, &jssI.volume) ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
673 !dmf_read_byte(inFile, &jssI.convFlags))
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
674 {
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
675 JSSERROR(DMERR_FREAD, DMERR_FREAD,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
676 "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
677 index);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
678 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
679
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
680 // Validate what we can
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
681 if (jssI.loopS > jssI.size ||
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
682 jssI.loopE > jssI.size ||
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
683 jssI.loopS > jssI.loopE)
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
684 {
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
685 JSSERROR(DMERR_INVALID_DATA, DMERR_INVALID_DATA,
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
686 "Invalid or corrupted sample instrument #%d.\n",
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
687 index);
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
688 }
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
689
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
690 // Allocate instrument
1311
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
691 inst = module->instruments[index] = jssAllocateInstrument();
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
692 if (inst == NULL)
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
693 {
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
694 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
695 "Could not allocate sample instrument structure #%d\n",
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
696 index);
f1c4b9b074ad Fixes to jssmod loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1310
diff changeset
697 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
698
1231
a275b7382ffa Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1219
diff changeset
699 // Copy data
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
700 inst->size = jssI.size;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
701 inst->loopS = jssI.loopS;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
702 inst->loopE = jssI.loopE;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
703 inst->flags = jssI.flags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
704 inst->C4BaseSpeed = jssI.C4BaseSpeed;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
705 inst->ERelNote = jssI.ERelNote;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
706 inst->EFineTune = jssI.EFineTune;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
707 inst->EPanning = jssI.EPanning;
1247
5ae2ce21c7ae Some work on refactoring the JSSMOD loader.
Matti Hamalainen <ccr@tnsp.org>
parents: 1239
diff changeset
708 inst->volume = jssI.volume;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 inst->convFlags = jssI.convFlags;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
710 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 #ifdef JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 // Read sample data
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 for (index = 0; index < module->ninstruments; index++)
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716 JSSInstrument *inst = module->instruments[index];
1312
4eb394c9e682 Clearer flag check.
Matti Hamalainen <ccr@tnsp.org>
parents: 1311
diff changeset
717 if (inst != NULL && (inst->convFlags & jsampHasData) != 0)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
718 {
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
719 int ret;
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
720 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
721 bsize *= inst->size;
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722
1316
817a4d0c70b5 Comment clarifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 1314
diff changeset
723 // Allocate sample data memory
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
724 if ((inst->data = dmMalloc(bsize)) == NULL)
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
725 {
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
726 JSSERROR(DMERR_MALLOC, DMERR_MALLOC,
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
727 "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
728 bsize, index);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730
1316
817a4d0c70b5 Comment clarifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 1314
diff changeset
731 // Read data
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
732 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
733 {
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
734 JSSERROR(DMERR_FREAD, DMERR_FREAD,
1213
505317227ab4 Rename variable, improve two error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1212
diff changeset
735 "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
736 bsize, index);
777
ed60a7ee3ebb Change JSSMOD loader to use DMResources.
Matti Hamalainen <ccr@tnsp.org>
parents: 658
diff changeset
737 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 // Convert, if needed
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 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
741 ret = jssDecodeSample16(inst->data, inst->size, inst->convFlags);
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
742 else
1129
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
743 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
744
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
745 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
746 {
e466d10dae6d Change API of jssDecodeSample{8,16}() functions to return dmlib error codes
Matti Hamalainen <ccr@tnsp.org>
parents: 1127
diff changeset
747 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
748 "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
749 }
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751 }
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
753 # warning Not including JSSMOD sample loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 #endif // JM_SUP_SAMPLES
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
756 # warning Not including JSSMOD instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
757 #endif // JM_SUP_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 #else
282
175328b20341 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
759 # warning Not including JSSMOD ext.instrument loading!
0
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
760 #endif // JM_SUP_EXT_INSTR
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 return DMERR_OK;
32250b436bca Initial re-import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 }