Debian Codegraph @

ext/psmplug/load_psm.cpp

raw symbols SCIP
1 /*
2 * This source code is public domain.
3 *
4 * Authors: Olivier Lapicque <[email protected]>
5 */
6
7
8 ///////////////////////////////////////////////////
9 //
10 // PSM module loader
11 //
12 ///////////////////////////////////////////////////
13 #include "stdafx.h"cxx . . $ `<file>/ext/psmplug/stdafx.h`/
14 #include "sndfile.h"cxx . . $ `<file>/ext/psmplug/sndfile.h`/
15
16 //#define PSM_LOG
17
18 #define PSM_ID_NEWcxx . . $ `ext/psmplug/load_psm.cpp:18:9`! 0x204d5350
19 #define PSM_ID_OLDcxx . . $ `ext/psmplug/load_psm.cpp:19:9`! 0xfe4d5350
20 #define IFFID_FILEcxx . . $ `ext/psmplug/load_psm.cpp:20:9`! 0x454c4946
21 #define IFFID_TITLcxx . . $ `ext/psmplug/load_psm.cpp:21:9`! 0x4c544954
22 #define IFFID_SDFTcxx . . $ `ext/psmplug/load_psm.cpp:22:9`! 0x54464453
23 #define IFFID_PBODcxx . . $ `ext/psmplug/load_psm.cpp:23:9`! 0x444f4250
24 #define IFFID_SONGcxx . . $ `ext/psmplug/load_psm.cpp:24:9`! 0x474e4f53
25 #define IFFID_PATTcxx . . $ `ext/psmplug/load_psm.cpp:25:9`! 0x54544150
26 #define IFFID_DSMPcxx . . $ `ext/psmplug/load_psm.cpp:26:9`! 0x504d5344
27 #define IFFID_OPLHcxx . . $ `ext/psmplug/load_psm.cpp:27:9`! 0x484c504f
28
29 #pragma pack(1)
30
31 typedef struct _PSMCHUNKcxx . . $ _PSMCHUNK#
32 {
33 DWORDcxx . . $ DWORD# idcxx . . $ _PSMCHUNK#id.;
34 DWORDcxx . . $ DWORD# lencxx . . $ _PSMCHUNK#len.;
35 DWORDcxx . . $ DWORD# listidcxx . . $ _PSMCHUNK#listid.;
36 } PSMCHUNKcxx . . $ PSMCHUNK#;
37
38 typedef struct _PSMSONGHDRcxx . . $ _PSMSONGHDR#
39 {
40 CHARcxx . . $ CHAR# songnamecxx . . $ _PSMSONGHDR#songname.[8]; // "MAINSONG"
41 BYTEcxx . . $ BYTE# reserved1cxx . . $ _PSMSONGHDR#reserved1.;
42 BYTEcxx . . $ BYTE# reserved2cxx . . $ _PSMSONGHDR#reserved2.;
43 BYTEcxx . . $ BYTE# channelscxx . . $ _PSMSONGHDR#channels.;
44 } PSMSONGHDRcxx . . $ PSMSONGHDR#;
45
46 typedef struct _PSMPATTERNcxx . . $ _PSMPATTERN#
47 {
48 DWORDcxx . . $ DWORD# sizecxx . . $ _PSMPATTERN#size.;
49 DWORDcxx . . $ DWORD# namecxx . . $ _PSMPATTERN#name.;
50 WORDcxx . . $ WORD# rowscxx . . $ _PSMPATTERN#rows.;
51 WORDcxx . . $ WORD# reserved1cxx . . $ _PSMPATTERN#reserved1.;
52 BYTEcxx . . $ BYTE# datacxx . . $ _PSMPATTERN#data.[4];
53 } PSMPATTERNcxx . . $ PSMPATTERN#;
54
55 typedef struct _PSMSAMPLEcxx . . $ _PSMSAMPLE#
56 {
57 BYTEcxx . . $ BYTE# flagscxx . . $ _PSMSAMPLE#flags.;
58 CHARcxx . . $ CHAR# songnamecxx . . $ _PSMSAMPLE#songname.[8];
59 DWORDcxx . . $ DWORD# smpidcxx . . $ _PSMSAMPLE#smpid.;
60 CHARcxx . . $ CHAR# samplenamecxx . . $ _PSMSAMPLE#samplename.[34];
61 DWORDcxx . . $ DWORD# reserved1cxx . . $ _PSMSAMPLE#reserved1.;
62 BYTEcxx . . $ BYTE# reserved2cxx . . $ _PSMSAMPLE#reserved2.;
63 BYTEcxx . . $ BYTE# insnocxx . . $ _PSMSAMPLE#insno.;
64 BYTEcxx . . $ BYTE# reserved3cxx . . $ _PSMSAMPLE#reserved3.;
65 DWORDcxx . . $ DWORD# lengthcxx . . $ _PSMSAMPLE#length.;
66 DWORDcxx . . $ DWORD# loopstartcxx . . $ _PSMSAMPLE#loopstart.;
67 DWORDcxx . . $ DWORD# loopendcxx . . $ _PSMSAMPLE#loopend.;
68 WORDcxx . . $ WORD# reserved4cxx . . $ _PSMSAMPLE#reserved4.;
69 BYTEcxx . . $ BYTE# defvolcxx . . $ _PSMSAMPLE#defvol.;
70 DWORDcxx . . $ DWORD# reserved5cxx . . $ _PSMSAMPLE#reserved5.;
71 DWORDcxx . . $ DWORD# sampleratecxx . . $ _PSMSAMPLE#samplerate.;
72 BYTEcxx . . $ BYTE# reserved6cxx . . $ _PSMSAMPLE#reserved6.[19];
73 } PSMSAMPLEcxx . . $ PSMSAMPLE#;
74
75 #pragma pack()
76
77 static void swap_PSMCHUNKcxx . . $ swap_PSMCHUNK(9d2488b5dfe0c8bf).(PSMCHUNKcxx . . $ PSMCHUNK#* p){
78 p->idcxx . . $ _PSMCHUNK#id. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->id);
79 p->lencxx . . $ _PSMCHUNK#len. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->len);
80 p->listidcxx . . $ _PSMCHUNK#listid. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->listid);
81 }
82
83 static void swap_PSMPATTERNcxx . . $ swap_PSMPATTERN(c165ae789b3ece68).(PSMPATTERNcxx . . $ PSMPATTERN#* p){
84 p->sizecxx . . $ _PSMPATTERN#size. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->size);
85 p->namecxx . . $ _PSMPATTERN#name. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->name);
86 p->rowscxx . . $ _PSMPATTERN#rows. = bswapLE16cxx . . $ `ext/psmplug/sndfile.h:989:9`!(p->rows);
87 }
88
89 static void swap_PSMSAMPLEcxx . . $ swap_PSMSAMPLE(82ee71c04485e572).(PSMSAMPLEcxx . . $ PSMSAMPLE#* p){
90 p->smpidcxx . . $ _PSMSAMPLE#smpid. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->smpid);
91 p->lengthcxx . . $ _PSMSAMPLE#length. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->length);
92 p->loopstartcxx . . $ _PSMSAMPLE#loopstart. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->loopstart);
93 p->loopendcxx . . $ _PSMSAMPLE#loopend. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->loopend);
94 p->sampleratecxx . . $ _PSMSAMPLE#samplerate. = bswapLE32cxx . . $ `ext/psmplug/sndfile.h:990:9`!(p->samplerate);
95 }
96
97 BOOLcxx . . $ BOOL# CSoundFilecxx . . $ CSoundFile#::ReadPSMcxx . . $ CSoundFile#ReadPSM(41ee87f0602ae969).(LPCBYTEcxx . . $ LPCBYTE# lpStream, DWORDcxx . . $ DWORD# dwMemLength)
98 //-----------------------------------------------------------
99 {
100 PSMCHUNKcxx . . $ PSMCHUNK# *pfh = (PSMCHUNKcxx . . $ PSMCHUNK# *)lpStream;
101 DWORDcxx . . $ DWORD# dwMemPos, dwSongPos;
102 DWORDcxx . . $ DWORD# patptrs[MAX_PATTERNScxx . . $ `ext/psmplug/sndfile.h:24:9`!];
103 BYTEcxx . . $ BYTE# samplemap[MAX_SAMPLEScxx . . $ `ext/psmplug/sndfile.h:25:9`!];
104 UINTcxx . . $ UINT# nPatterns;
105
106 if (dwMemLength < 256) return FALSEcxx . . $ `ext/psmplug/stdafx.h:93:9`!;
107
108 // Swap chunk
109 swap_PSMCHUNKcxx . . $ swap_PSMCHUNK(9d2488b5dfe0c8bf).(pfh);
110
111 // Chunk0: "PSM ",filesize,"FILE"
112 if (pfh->idcxx . . $ _PSMCHUNK#id. == PSM_ID_OLDcxx . . $ `ext/psmplug/load_psm.cpp:19:9`!)
113 {
114 #ifdef PSM_LOG
115 Log("Old PSM format not supported\n");
116 #endif
117 return FALSEcxx . . $ `ext/psmplug/stdafx.h:93:9`!;
118 }
119 if ((pfh->idcxx . . $ _PSMCHUNK#id. != PSM_ID_NEWcxx . . $ `ext/psmplug/load_psm.cpp:18:9`!) || (pfh->lencxx . . $ _PSMCHUNK#len.+12 > dwMemLength) || (pfh->listidcxx . . $ _PSMCHUNK#listid. != IFFID_FILEcxx . . $ `ext/psmplug/load_psm.cpp:20:9`!)) return FALSEcxx . . $ `ext/psmplug/stdafx.h:93:9`!;
120 m_nTypecxx . . $ CSoundFile#m_nType. = MOD_TYPE_PSMcxx . . $ `ext/psmplug/sndfile.h:62:9`!;
121 m_nChannelscxx . . $ CSoundFile#m_nChannels. = 16;
122 m_nSamplescxx . . $ CSoundFile#m_nSamples. = 0;
123 nPatterns = 0;
124 dwMemPos = 12;
125 dwSongPos = 0;
126 for (UINTcxx . . $ UINT# iChPan=0; iChPan<16; iChPan++)
127 {
128 UINTcxx . . $ UINT# pan = (((iChPan & 3) == 1) || ((iChPan&3)==2)) ? 0xC0 : 0x40;
129 ChnSettingscxx . . $ CSoundFile#ChnSettings.[iChPan].nPancxx . . $ _MODCHANNELSETTINGS#nPan. = pan;
130 }
131 while (dwMemPos+8 < dwMemLength)
132 {
133 PSMCHUNKcxx . . $ PSMCHUNK# *pchunk = (PSMCHUNKcxx . . $ PSMCHUNK# *)(lpStream+dwMemPos);
134 swap_PSMCHUNKcxx . . $ swap_PSMCHUNK(9d2488b5dfe0c8bf).(pchunk);
135 if ((pchunk->lencxx . . $ _PSMCHUNK#len. >= dwMemLength - 8) || (dwMemPos + pchunk->lencxx . . $ _PSMCHUNK#len. + 8 > dwMemLength)) break;
136 dwMemPos += 8;
137 PUCHARcxx . . $ PUCHAR# pdata = (PUCHARcxx . . $ PUCHAR#)(lpStream+dwMemPos);
138 ULONGcxx . . $ ULONG# len = pchunk->lencxx . . $ _PSMCHUNK#len.;
139 if (len) switch(pchunk->idcxx . . $ _PSMCHUNK#id.)
140 {
141 // "TITL": Song title
142 case IFFID_TITLcxx . . $ `ext/psmplug/load_psm.cpp:21:9`!:
143 if (!pdata[0]) { pdata++; len--; }
144 memcpy(m_szNamescxx . . $ CSoundFile#m_szNames.[0], pdata, (len>31) ? 31 : len);
145 m_szNamescxx . . $ CSoundFile#m_szNames.[0][31] = 0;
146 break;
147 // "PBOD": Pattern
148 case IFFID_PBODcxx . . $ `ext/psmplug/load_psm.cpp:23:9`!:
149 if ((len >= 12) && (nPatterns < MAX_PATTERNScxx . . $ `ext/psmplug/sndfile.h:24:9`!))
150 {
151 patptrs[nPatterns++] = dwMemPos-8;
152 }
153 break;
154 // "SONG": Song description
155 case IFFID_SONGcxx . . $ `ext/psmplug/load_psm.cpp:24:9`!:
156 if ((len >= sizeof(PSMSONGHDRcxx . . $ PSMSONGHDR#)+8) && (!dwSongPos))
157 {
158 dwSongPos = dwMemPos - 8;
159 }
160 break;
161 // "DSMP": Sample Data
162 case IFFID_DSMPcxx . . $ `ext/psmplug/load_psm.cpp:26:9`!:
163 if ((len >= sizeof(PSMSAMPLEcxx . . $ PSMSAMPLE#)) && (m_nSamplescxx . . $ CSoundFile#m_nSamples.+1 < MAX_SAMPLEScxx . . $ `ext/psmplug/sndfile.h:25:9`!))
164 {
165 m_nSamplescxx . . $ CSoundFile#m_nSamples.++;
166 MODINSTRUMENTcxx . . $ MODINSTRUMENT# *pins = &Inscxx . . $ CSoundFile#Ins.[m_nSamplescxx . . $ CSoundFile#m_nSamples.];
167 PSMSAMPLEcxx . . $ PSMSAMPLE# *psmp = (PSMSAMPLEcxx . . $ PSMSAMPLE# *)pdata;
168 swap_PSMSAMPLEcxx . . $ swap_PSMSAMPLE(82ee71c04485e572).(psmp);
169 memcpy(m_szNamescxx . . $ CSoundFile#m_szNames.[m_nSamplescxx . . $ CSoundFile#m_nSamples.], psmp->samplenamecxx . . $ _PSMSAMPLE#samplename., 31);
170 m_szNamescxx . . $ CSoundFile#m_szNames.[m_nSamplescxx . . $ CSoundFile#m_nSamples.][31] = 0;
171 samplemap[m_nSamplescxx . . $ CSoundFile#m_nSamples.-1] = (BYTEcxx . . $ BYTE#)m_nSamplescxx . . $ CSoundFile#m_nSamples.;
172 // Init sample
173 pins->nGlobalVolcxx . . $ _MODINSTRUMENT#nGlobalVol. = 0x40;
174 pins->nC4Speedcxx . . $ _MODINSTRUMENT#nC4Speed. = psmp->sampleratecxx . . $ _PSMSAMPLE#samplerate.;
175 pins->nLengthcxx . . $ _MODINSTRUMENT#nLength. = psmp->lengthcxx . . $ _PSMSAMPLE#length.;
176 pins->nLoopStartcxx . . $ _MODINSTRUMENT#nLoopStart. = psmp->loopstartcxx . . $ _PSMSAMPLE#loopstart.;
177 pins->nLoopEndcxx . . $ _MODINSTRUMENT#nLoopEnd. = psmp->loopendcxx . . $ _PSMSAMPLE#loopend.;
178 pins->nPancxx . . $ _MODINSTRUMENT#nPan. = 128;
179 pins->nVolumecxx . . $ _MODINSTRUMENT#nVolume. = (psmp->defvolcxx . . $ _PSMSAMPLE#defvol.+1) * 2;
180 pins->uFlagscxx . . $ _MODINSTRUMENT#uFlags. = (psmp->flagscxx . . $ _PSMSAMPLE#flags. & 0x80) ? CHN_LOOPcxx . . $ `ext/psmplug/sndfile.h:74:9`! : 0;
181 if (pins->nLoopStartcxx . . $ _MODINSTRUMENT#nLoopStart. > 0) pins->nLoopStartcxx . . $ _MODINSTRUMENT#nLoopStart.--;
182 // Point to sample data
183 pdata += 0x60;
184 len -= 0x60;
185 // Load sample data
186 if ((pins->nLengthcxx . . $ _MODINSTRUMENT#nLength. > 3) && (len > 3))
187 {
188 ReadSamplecxx . . $ CSoundFile#ReadSample(c75afd520c6e07d).(pins, RS_PCM8Dcxx . . $ `ext/psmplug/sndfile.h:173:9`!, (LPCSTRcxx . . $ LPCSTR#)pdata, len);
189 } else
190 {
191 pins->nLengthcxx . . $ _MODINSTRUMENT#nLength. = 0;
192 }
193 }
194 break;
195 #if 0
196 default:
197 {
198 CHAR s[8], s2[64];
199 *(DWORD *)s = pchunk->id;
200 s[4] = 0;
201 wsprintfA(s2, "%s: %4d bytes @ %4d\n", s, pchunk->len, dwMemPos);
202 OutputDebugString(s2);
203 }
204 #endif
205 }
206 dwMemPos += pchunk->lencxx . . $ _PSMCHUNK#len.;
207 }
208 // Step #1: convert song structure
209 PSMSONGHDRcxx . . $ PSMSONGHDR# *pSong = (PSMSONGHDRcxx . . $ PSMSONGHDR# *)(lpStream+dwSongPos+8);
210 if ((!dwSongPos) || (pSong->channelscxx . . $ _PSMSONGHDR#channels. < 2) || (pSong->channelscxx . . $ _PSMSONGHDR#channels. > 32)) return TRUEcxx . . $ `ext/psmplug/stdafx.h:97:9`!;
211 m_nChannelscxx . . $ CSoundFile#m_nChannels. = pSong->channelscxx . . $ _PSMSONGHDR#channels.;
212 // Valid song header -> convert attached chunks
213 {
214 DWORDcxx . . $ DWORD# dwSongEnd = dwSongPos + 8 + READ_LE32cxx . . $ READ_LE32(ca1608e2c87725e2).(lpStream+dwSongPos+4);
215 dwMemPos = dwSongPos + 8 + 11; // sizeof(PSMCHUNK)+sizeof(PSMSONGHDR)
216 while (dwMemPos + 8 < dwSongEnd)
217 {
218 PSMCHUNKcxx . . $ PSMCHUNK# *pchunk = (PSMCHUNKcxx . . $ PSMCHUNK# *)(lpStream+dwMemPos);
219 swap_PSMCHUNKcxx . . $ swap_PSMCHUNK(9d2488b5dfe0c8bf).(pchunk);
220 dwMemPos += 8;
221 if ((pchunk->lencxx . . $ _PSMCHUNK#len. > dwSongEnd) || (dwMemPos + pchunk->lencxx . . $ _PSMCHUNK#len. > dwSongEnd)) break;
222 PUCHARcxx . . $ PUCHAR# pdata = (PUCHARcxx . . $ PUCHAR#)(lpStream+dwMemPos);
223 ULONGcxx . . $ ULONG# len = pchunk->lencxx . . $ _PSMCHUNK#len.;
224 switch(pchunk->idcxx . . $ _PSMCHUNK#id.)
225 {
226 case IFFID_OPLHcxx . . $ `ext/psmplug/load_psm.cpp:27:9`!:
227 if (len >= 0x20)
228 {
229 UINTcxx . . $ UINT# pos = len - 3;
230 while (pos > 5)
231 {
232 BOOLcxx . . $ BOOL# bFound = FALSEcxx . . $ `ext/psmplug/stdafx.h:93:9`!;
233 pos -= 5;
234 DWORDcxx . . $ DWORD# dwName = READ_LE32cxx . . $ READ_LE32(ca1608e2c87725e2).(pdata+pos);
235 for (UINTcxx . . $ UINT# i=0; i<nPatterns; i++)
236 {
237 DWORDcxx . . $ DWORD# dwPatName = READ_LE32cxx . . $ READ_LE32(ca1608e2c87725e2).(lpStream+patptrs[i]+12);
238 if (dwName == dwPatName)
239 {
240 bFound = TRUEcxx . . $ `ext/psmplug/stdafx.h:97:9`!;
241 break;
242 }
243 }
244 if ((!bFound) && (pdata[pos+1] > 0) && (pdata[pos+1] <= 0x10)
245 && (pdata[pos+3] > 0x40) && (pdata[pos+3] < 0xC0))
246 {
247 m_nDefaultSpeedcxx . . $ CSoundFile#m_nDefaultSpeed. = pdata[pos+1];
248 m_nDefaultTempocxx . . $ CSoundFile#m_nDefaultTempo. = pdata[pos+3];
249 break;
250 }
251 }
252 UINTcxx . . $ UINT# iOrd = 0;
253 while ((pos+5<len) && (iOrd < MAX_ORDERScxx . . $ `ext/psmplug/sndfile.h:23:9`!))
254 {
255 DWORDcxx . . $ DWORD# dwName = READ_LE32cxx . . $ READ_LE32(ca1608e2c87725e2).(pdata+pos);
256 for (UINTcxx . . $ UINT# i=0; i<nPatterns; i++)
257 {
258 DWORDcxx . . $ DWORD# dwPatName = READ_LE32cxx . . $ READ_LE32(ca1608e2c87725e2).(lpStream+patptrs[i]+12);
259 if (dwName == dwPatName)
260 {
261 Ordercxx . . $ CSoundFile#Order.[iOrd++] = i;
262 break;
263 }
264 }
265 pos += 5;
266 }
267 }
268 break;
269 }
270 dwMemPos += pchunk->lencxx . . $ _PSMCHUNK#len.;
271 }
272 }
273
274 // Step #2: convert patterns
275 for (UINTcxx . . $ UINT# nPat=0; nPat<nPatterns; nPat++)
276 {
277 PSMPATTERNcxx . . $ PSMPATTERN# *pPsmPat = (PSMPATTERNcxx . . $ PSMPATTERN# *)(lpStream+patptrs[nPat]+8);
278 swap_PSMPATTERNcxx . . $ swap_PSMPATTERN(c165ae789b3ece68).(pPsmPat);
279 ULONGcxx . . $ ULONG# len = *(DWORDcxx . . $ DWORD# *)(lpStream+patptrs[nPat]+4) - 12;
280 UINTcxx . . $ UINT# nRows = pPsmPat->rowscxx . . $ _PSMPATTERN#rows.;
281 if (len > pPsmPat->sizecxx . . $ _PSMPATTERN#size.) len = pPsmPat->sizecxx . . $ _PSMPATTERN#size.;
282 if ((nRows < 64) || (nRows > 256)) nRows = 64;
283 PatternSizecxx . . $ CSoundFile#PatternSize.[nPat] = nRows;
284 if ((Patternscxx . . $ CSoundFile#Patterns.[nPat] = AllocatePatterncxx . . $ CSoundFile#AllocatePattern(697652e068d7f138).(nRows, m_nChannelscxx . . $ CSoundFile#m_nChannels.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) break;
285 MODCOMMANDcxx . . $ MODCOMMAND# *m = Patternscxx . . $ CSoundFile#Patterns.[nPat];
286 BYTEcxx . . $ BYTE# *p = pPsmPat->datacxx . . $ _PSMPATTERN#data.;
287 MODCOMMANDcxx . . $ MODCOMMAND# *sp, dummy;
288 UINTcxx . . $ UINT# pos = 0;
289 UINTcxx . . $ UINT# row = 0;
290 UINTcxx . . $ UINT# rowlim;
291 #ifdef PSM_LOG
292 Log("Pattern %d at offset 0x%04X\n", nPat, (DWORD)(p - (BYTE *)lpStream));
293 #endif
294 UINTcxx . . $ UINT# flags, ch;
295 rowlim = bswapLE16cxx . . $ `ext/psmplug/sndfile.h:989:9`!(pPsmPat->reserved1)-2;
296 while ((row < nRows) && (pos+3 < len))
297 {
298 if ((pos+1) >= rowlim) {
299 pos = rowlim;
300 rowlim = (((int)p[pos+1])<<8)
301 | ((int)p[pos+0]);
302 m += m_nChannelscxx . . $ CSoundFile#m_nChannels.;
303 row++;
304 rowlim += pos;
305 pos += 2;
306 }
307 if (row >= nRows) continue;
308
309 flags = p[pos++];
310 ch = p[pos++];
311 if (ch >= m_nChannelscxx . . $ CSoundFile#m_nChannels.) {
312 sp = &dummy;
313 } else {
314 sp = &m[ch];
315 }
316 // Note + Instr
317 if ((flags & 0x80) && (pos+1 < len))
318 {
319 UINTcxx . . $ UINT# note = p[pos++];
320 note = (note>>4)*12+(note&0x0f)+12+1;
321 if (note > 0x80) note = 0;
322 sp->notecxx . . $ _MODCOMMAND#note. = note;
323 }
324 if ((flags & 0x40) && (pos+1 < len))
325 {
326 UINTcxx . . $ UINT# nins = p[pos++];
327 #ifdef PSM_LOG
328 //if (!nPat) Log("note+ins: %02X.%02X\n", note, nins);
329 if ((!nPat) && (nins >= m_nSamples)) Log("WARNING: invalid instrument number (%d)\n", nins);
330 #endif
331 sp->instrcxx . . $ _MODCOMMAND#instr. = samplemap[nins];
332 }
333 // Volume
334 if ((flags & 0x20) && (pos < len))
335 {
336 sp->volcmdcxx . . $ _MODCOMMAND#volcmd. = VOLCMD_VOLUMEcxx . . $ `ext/psmplug/sndfile.h:154:9`!;
337 sp->volcxx . . $ _MODCOMMAND#vol. = p[pos++] / 2;
338 }
339 // Effect
340 if ((flags & 0x10) && (pos+1 < len))
341 {
342 UINTcxx . . $ UINT# command = p[pos++];
343 UINTcxx . . $ UINT# param = p[pos++];
344 // Convert effects
345 switch(command)
346 {
347 // 01: fine volslide up
348 case 0x01: command = CMD_VOLUMESLIDEcxx . . $ `ext/psmplug/sndfile.h:130:9`!; param |= 0x0f;
349 if (param == 15) param=31;
350 break;
351 // 02: volslide up
352 case 0x02: command = CMD_VOLUMESLIDEcxx . . $ `ext/psmplug/sndfile.h:130:9`!; param>>=1; param<<=4; break;
353 // 03: fine volslide down
354 case 0x03: command = CMD_VOLUMESLIDEcxx . . $ `ext/psmplug/sndfile.h:130:9`!; param>>=4; param |= 0xf0;
355 if (param == 240) param=241;
356 break;
357 // 04: fine volslide down
358 case 0x04: command = CMD_VOLUMESLIDEcxx . . $ `ext/psmplug/sndfile.h:130:9`!; param>>=4; param |= 0xf0; break;
359 // 0C: portamento up
360 case 0x0C: command = CMD_PORTAMENTOUPcxx . . $ `ext/psmplug/sndfile.h:121:9`!; param = (param+1)/2; break;
361 // 0E: portamento down
362 case 0x0E: command = CMD_PORTAMENTODOWNcxx . . $ `ext/psmplug/sndfile.h:122:9`!; param = (param+1)/2; break;
363 // 0F: tone portamento
364 case 0x0F: command = CMD_TONEPORTAMENTOcxx . . $ `ext/psmplug/sndfile.h:123:9`!; param = param/4; break;
365 // 15: vibrato
366 case 0x15: command = CMD_VIBRATOcxx . . $ `ext/psmplug/sndfile.h:124:9`!; break;
367 // 29: sample offset
368 case 0x29: pos += 2; break;
369 // 2A: retrigger note
370 case 0x2A: command = CMD_RETRIGcxx . . $ `ext/psmplug/sndfile.h:134:9`!; break;
371 // 33: Position Jump
372 case 0x33: command = CMD_POSITIONJUMPcxx . . $ `ext/psmplug/sndfile.h:131:9`!; break;
373 // 34: Pattern break
374 case 0x34: command = CMD_PATTERNBREAKcxx . . $ `ext/psmplug/sndfile.h:133:9`!; break;
375 // 3D: speed
376 case 0x3D: command = CMD_SPEEDcxx . . $ `ext/psmplug/sndfile.h:135:9`!; break;
377 // 3E: tempo
378 case 0x3E: command = CMD_TEMPOcxx . . $ `ext/psmplug/sndfile.h:136:9`!; break;
379 // Unknown
380 default:
381 #ifdef PSM_LOG
382 Log("Unknown PSM effect pat=%d row=%d ch=%d: %02X.%02X\n", nPat, row, ch, command, param);
383 #endif
384 command = param = 0;
385 }
386 sp->commandcxx . . $ _MODCOMMAND#command. = (BYTEcxx . . $ BYTE#)command;
387 sp->paramcxx . . $ _MODCOMMAND#param. = (BYTEcxx . . $ BYTE#)param;
388 }
389 }
390 #ifdef PSM_LOG
391 if (pos < len)
392 {
393 Log("Pattern %d: %d/%d[%d] rows (%d bytes) -> %d bytes left\n", nPat, row, nRows, pPsmPat->rows, pPsmPat->size, len-pos);
394 }
395 #endif
396 }
397
398 // Done (finally!)
399 return TRUEcxx . . $ `ext/psmplug/stdafx.h:97:9`!;
400 }
401
402
403 //////////////////////////////////////////////////////////////
404 //
405 // PSM Old Format
406 //
407
408 /*
409
410 CONST
411 c_PSM_MaxOrder = $FF;
412 c_PSM_MaxSample = $FF;
413 c_PSM_MaxChannel = $0F;
414
415 TYPE
416 PPSM_Header = ^TPSM_Header;
417 TPSM_Header = RECORD
418 PSM_Sign : ARRAY[01..04] OF CHAR; { PSM + #254 }
419 PSM_SongName : ARRAY[01..58] OF CHAR;
420 PSM_Byte00 : BYTE;
421 PSM_Byte1A : BYTE;
422 PSM_Unknown00 : BYTE;
423 PSM_Unknown01 : BYTE;
424 PSM_Unknown02 : BYTE;
425 PSM_Speed : BYTE;
426 PSM_Tempo : BYTE;
427 PSM_Unknown03 : BYTE;
428 PSM_Unknown04 : WORD;
429 PSM_OrderLength : WORD;
430 PSM_PatternNumber : WORD;
431 PSM_SampleNumber : WORD;
432 PSM_ChannelNumber : WORD;
433 PSM_ChannelUsed : WORD;
434 PSM_OrderPosition : LONGINT;
435 PSM_ChannelSettingPosition : LONGINT;
436 PSM_PatternPosition : LONGINT;
437 PSM_SamplePosition : LONGINT;
438 { *** perhaps there are some more infos in a larger header,
439 but i have not decoded it and so it apears here NOT }
440 END;
441
442 PPSM_Sample = ^TPSM_Sample;
443 TPSM_Sample = RECORD
444 PSM_SampleFileName : ARRAY[01..12] OF CHAR;
445 PSM_SampleByte00 : BYTE;
446 PSM_SampleName : ARRAY[01..22] OF CHAR;
447 PSM_SampleUnknown00 : ARRAY[01..02] OF BYTE;
448 PSM_SamplePosition : LONGINT;
449 PSM_SampleUnknown01 : ARRAY[01..04] OF BYTE;
450 PSM_SampleNumber : BYTE;
451 PSM_SampleFlags : WORD;
452 PSM_SampleLength : LONGINT;
453 PSM_SampleLoopBegin : LONGINT;
454 PSM_SampleLoopEnd : LONGINT;
455 PSM_Unknown03 : BYTE;
456 PSM_SampleVolume : BYTE;
457 PSM_SampleC5Speed : WORD;
458 END;
459
460 PPSM_SampleList = ^TPSM_SampleList;
461 TPSM_SampleList = ARRAY[01..c_PSM_MaxSample] OF TPSM_Sample;
462
463 PPSM_Order = ^TPSM_Order;
464 TPSM_Order = ARRAY[00..c_PSM_MaxOrder] OF BYTE;
465
466 PPSM_ChannelSettings = ^TPSM_ChannelSettings;
467 TPSM_ChannelSettings = ARRAY[00..c_PSM_MaxChannel] OF BYTE;
468
469 CONST
470 PSM_NotesInPattern : BYTE = $00;
471 PSM_ChannelInPattern : BYTE = $00;
472
473 CONST
474 c_PSM_SetSpeed = 60;
475
476 FUNCTION PSM_Size(FileName : STRING;FilePosition : LONGINT) : LONGINT;
477 BEGIN
478 END;
479
480 PROCEDURE PSM_UnpackPattern(VAR Source,Destination;PatternLength : WORD);
481 VAR
482 Witz : ARRAY[00..04] OF WORD;
483 I1,I2 : WORD;
484 I3,I4 : WORD;
485 TopicalByte : ^BYTE;
486 Pattern : PUnpackedPattern;
487 ChannelP : BYTE;
488 NoteP : BYTE;
489 InfoByte : BYTE;
490 CodeByte : BYTE;
491 InfoWord : WORD;
492 Effect : BYTE;
493 Opperand : BYTE;
494 Panning : BYTE;
495 Volume : BYTE;
496 PrevInfo : BYTE;
497 InfoIndex : BYTE;
498 BEGIN
499 Pattern := @Destination;
500 TopicalByte := @Source;
501 { *** Initialize patttern }
502 FOR I2 := 0 TO c_Maximum_NoteIndex DO
503 FOR I3 := 0 TO c_Maximum_ChannelIndex DO
504 BEGIN
505 Pattern^[I2,I3,c_Pattern_NoteIndex] := $FF;
506 Pattern^[I2,I3,c_Pattern_SampleIndex] := $00;
507 Pattern^[I2,I3,c_Pattern_VolumeIndex] := $FF;
508 Pattern^[I2,I3,c_Pattern_PanningIndex] := $FF;
509 Pattern^[I2,I3,c_Pattern_EffectIndex] := $00;
510 Pattern^[I2,I3,c_Pattern_OpperandIndex] := $00;
511 END;
512 { *** Byte-pointer on first pattern-entry }
513 ChannelP := $00;
514 NoteP := $00;
515 InfoByte := $00;
516 PrevInfo := $00;
517 InfoIndex := $02;
518 { *** read notes in pattern }
519 PSM_NotesInPattern := TopicalByte^; INC(TopicalByte); DEC(PatternLength); INC(InfoIndex);
520 PSM_ChannelInPattern := TopicalByte^; INC(TopicalByte); DEC(PatternLength); INC(InfoIndex);
521 { *** unpack pattern }
522 WHILE (INTEGER(PatternLength) > 0) AND (NoteP < c_Maximum_NoteIndex) DO
523 BEGIN
524 { *** Read info-byte }
525 InfoByte := TopicalByte^; INC(TopicalByte); DEC(PatternLength); INC(InfoIndex);
526 IF InfoByte <> $00 THEN
527 BEGIN
528 ChannelP := InfoByte AND $0F;
529 IF InfoByte AND 128 = 128 THEN { note and sample }
530 BEGIN
531 { *** read note }
532 CodeByte := TopicalByte^; INC(TopicalByte); DEC(PatternLength);
533 DEC(CodeByte);
534 CodeByte := CodeByte MOD 12 * 16 + CodeByte DIV 12 + 2;
535 Pattern^[NoteP,ChannelP,c_Pattern_NoteIndex] := CodeByte;
536 { *** read sample }
537 CodeByte := TopicalByte^; INC(TopicalByte); DEC(PatternLength);
538 Pattern^[NoteP,ChannelP,c_Pattern_SampleIndex] := CodeByte;
539 END;
540 IF InfoByte AND 64 = 64 THEN { Volume }
541 BEGIN
542 CodeByte := TopicalByte^; INC(TopicalByte); DEC(PatternLength);
543 Pattern^[NoteP,ChannelP,c_Pattern_VolumeIndex] := CodeByte;
544 END;
545 IF InfoByte AND 32 = 32 THEN { effect AND opperand }
546 BEGIN
547 Effect := TopicalByte^; INC(TopicalByte); DEC(PatternLength);
548 Opperand := TopicalByte^; INC(TopicalByte); DEC(PatternLength);
549 CASE Effect OF
550 c_PSM_SetSpeed:
551 BEGIN
552 Effect := c_I_Set_Speed;
553 END;
554 ELSE
555 BEGIN
556 Effect := c_I_NoEffect;
557 Opperand := $00;
558 END;
559 END;
560 Pattern^[NoteP,ChannelP,c_Pattern_EffectIndex] := Effect;
561 Pattern^[NoteP,ChannelP,c_Pattern_OpperandIndex] := Opperand;
562 END;
563 END ELSE INC(NoteP);
564 END;
565 END;
566
567 PROCEDURE PSM_Load(FileName : STRING;FilePosition : LONGINT;VAR Module : PModule;VAR ErrorCode : WORD);
568 { *** caution : Module has to be inited before!!!! }
569 VAR
570 Header : PPSM_Header;
571 Sample : PPSM_SampleList;
572 Order : PPSM_Order;
573 ChannelSettings : PPSM_ChannelSettings;
574 MultiPurposeBuffer : PByteArray;
575 PatternBuffer : PUnpackedPattern;
576 TopicalParaPointer : WORD;
577
578 InFile : FILE;
579 I1,I2 : WORD;
580 I3,I4 : WORD;
581 TempW : WORD;
582 TempB : BYTE;
583 TempP : PByteArray;
584 TempI : INTEGER;
585 { *** copy-vars for loop-extension }
586 CopySource : LONGINT;
587 CopyDestination : LONGINT;
588 CopyLength : LONGINT;
589 BEGIN
590 { *** try to open file }
591 ASSIGN(InFile,FileName);
592 {$I-}
593 RESET(InFile,1);
594 {$I+}
595 IF IORESULT <> $00 THEN
596 BEGIN
597 EXIT;
598 END;
599 {$I-}
600 { *** seek start of module }
601 IF FILESIZE(InFile) < FilePosition THEN
602 BEGIN
603 EXIT;
604 END;
605 SEEK(InFile,FilePosition);
606 { *** look for enough memory for temporary variables }
607 IF MEMAVAIL < SIZEOF(TPSM_Header) + SIZEOF(TPSM_SampleList) +
608 SIZEOF(TPSM_Order) + SIZEOF(TPSM_ChannelSettings) +
609 SIZEOF(TByteArray) + SIZEOF(TUnpackedPattern)
610 THEN
611 BEGIN
612 EXIT;
613 END;
614 { *** init dynamic variables }
615 NEW(Header);
616 NEW(Sample);
617 NEW(Order);
618 NEW(ChannelSettings);
619 NEW(MultiPurposeBuffer);
620 NEW(PatternBuffer);
621 { *** read header }
622 BLOCKREAD(InFile,Header^,SIZEOF(TPSM_Header));
623 { *** test if this is a DSM-file }
624 IF NOT ((Header^.PSM_Sign[1] = 'P') AND (Header^.PSM_Sign[2] = 'S') AND
625 (Header^.PSM_Sign[3] = 'M') AND (Header^.PSM_Sign[4] = #254)) THEN
626 BEGIN
627 ErrorCode := c_NoValidFileFormat;
628 CLOSE(InFile);
629 EXIT;
630 END;
631 { *** read order }
632 SEEK(InFile,FilePosition + Header^.PSM_OrderPosition);
633 BLOCKREAD(InFile,Order^,Header^.PSM_OrderLength);
634 { *** read channelsettings }
635 SEEK(InFile,FilePosition + Header^.PSM_ChannelSettingPosition);
636 BLOCKREAD(InFile,ChannelSettings^,SIZEOF(TPSM_ChannelSettings));
637 { *** read samplelist }
638 SEEK(InFile,FilePosition + Header^.PSM_SamplePosition);
639 BLOCKREAD(InFile,Sample^,Header^.PSM_SampleNumber * SIZEOF(TPSM_Sample));
640 { *** copy header to intern NTMIK-structure }
641 Module^.Module_Sign := 'MF';
642 Module^.Module_FileFormatVersion := $0100;
643 Module^.Module_SampleNumber := Header^.PSM_SampleNumber;
644 Module^.Module_PatternNumber := Header^.PSM_PatternNumber;
645 Module^.Module_OrderLength := Header^.PSM_OrderLength;
646 Module^.Module_ChannelNumber := Header^.PSM_ChannelNumber+1;
647 Module^.Module_Initial_GlobalVolume := 64;
648 Module^.Module_Initial_MasterVolume := $C0;
649 Module^.Module_Initial_Speed := Header^.PSM_Speed;
650 Module^.Module_Initial_Tempo := Header^.PSM_Tempo;
651 { *** paragraph 01 start }
652 Module^.Module_Flags := c_Module_Flags_ZeroVolume * BYTE(1) +
653 c_Module_Flags_Stereo * BYTE(1) +
654 c_Module_Flags_ForceAmigaLimits * BYTE(0) +
655 c_Module_Flags_Panning * BYTE(1) +
656 c_Module_Flags_Surround * BYTE(1) +
657 c_Module_Flags_QualityMixing * BYTE(1) +
658 c_Module_Flags_FastVolumeSlides * BYTE(0) +
659 c_Module_Flags_SpecialCustomData * BYTE(0) +
660 c_Module_Flags_SongName * BYTE(1);
661 I1 := $01;
662 WHILE (Header^.PSM_SongName[I1] > #00) AND (I1 < c_Module_SongNameLength) DO
663 BEGIN
664 Module^.Module_Name[I1] := Header^.PSM_SongName[I1];
665 INC(I1);
666 END;
667 Module^.Module_Name[c_Module_SongNameLength] := #00;
668 { *** Init channelsettings }
669 FOR I1 := 0 TO c_Maximum_ChannelIndex DO
670 BEGIN
671 IF I1 < Header^.PSM_ChannelUsed THEN
672 BEGIN
673 { *** channel enabled }
674 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_GlobalVolume := 64;
675 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_Panning := (ChannelSettings^[I1]) * $08;
676 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_Code := I1 + $10 * BYTE(ChannelSettings^[I1] > $08) +
677 c_ChannelSettings_Code_ChannelEnabled * BYTE(1) +
678 c_ChannelSettings_Code_ChannelDigital * BYTE(1);
679 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_Controls :=
680 c_ChannelSettings_Controls_EnhancedMode * BYTE(1) +
681 c_ChannelSettings_Controls_SurroundMode * BYTE(0);
682 END
683 ELSE
684 BEGIN
685 { *** channel disabled }
686 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_GlobalVolume := $00;
687 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_Panning := $00;
688 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_Code := $00;
689 Module^.Module_ChannelSettingPointer^[I1].ChannelSettings_Controls := $00;
690 END;
691 END;
692 { *** init and copy order }
693 FILLCHAR(Module^.Module_OrderPointer^,c_Maximum_OrderIndex+1,$FF);
694 MOVE(Order^,Module^.Module_OrderPointer^,Header^.PSM_OrderLength);
695 { *** read pattern }
696 SEEK(InFile,FilePosition + Header^.PSM_PatternPosition);
697 NTMIK_LoaderPatternNumber := Header^.PSM_PatternNumber-1;
698 FOR I1 := 0 TO Header^.PSM_PatternNumber-1 DO
699 BEGIN
700 NTMIK_LoadPatternProcedure;
701 { *** read length }
702 BLOCKREAD(InFile,TempW,2);
703 { *** read pattern }
704 BLOCKREAD(InFile,MultiPurposeBuffer^,TempW-2);
705 { *** unpack pattern and set notes per channel to 64 }
706 PSM_UnpackPattern(MultiPurposeBuffer^,PatternBuffer^,TempW);
707 NTMIK_PackPattern(MultiPurposeBuffer^,PatternBuffer^,PSM_NotesInPattern);
708 TempW := WORD(256) * MultiPurposeBuffer^[01] + MultiPurposeBuffer^[00];
709 GETMEM(Module^.Module_PatternPointer^[I1],TempW);
710 MOVE(MultiPurposeBuffer^,Module^.Module_PatternPointer^[I1]^,TempW);
711 { *** next pattern }
712 END;
713 { *** read samples }
714 NTMIK_LoaderSampleNumber := Header^.PSM_SampleNumber;
715 FOR I1 := 1 TO Header^.PSM_SampleNumber DO
716 BEGIN
717 NTMIK_LoadSampleProcedure;
718 { *** get index for sample }
719 I3 := Sample^[I1].PSM_SampleNumber;
720 { *** clip PSM-sample }
721 IF Sample^[I1].PSM_SampleLoopEnd > Sample^[I1].PSM_SampleLength
722 THEN Sample^[I1].PSM_SampleLoopEnd := Sample^[I1].PSM_SampleLength;
723 { *** init intern sample }
724 NEW(Module^.Module_SamplePointer^[I3]);
725 FILLCHAR(Module^.Module_SamplePointer^[I3]^,SIZEOF(TSample),$00);
726 FILLCHAR(Module^.Module_SamplePointer^[I3]^.Sample_SampleName,c_Sample_SampleNameLength,#32);
727 FILLCHAR(Module^.Module_SamplePointer^[I3]^.Sample_FileName,c_Sample_FileNameLength,#32);
728 { *** copy informations to intern sample }
729 I2 := $01;
730 WHILE (Sample^[I1].PSM_SampleName[I2] > #00) AND (I2 < c_Sample_SampleNameLength) DO
731 BEGIN
732 Module^.Module_SamplePointer^[I3]^.Sample_SampleName[I2] := Sample^[I1].PSM_SampleName[I2];
733 INC(I2);
734 END;
735 Module^.Module_SamplePointer^[I3]^.Sample_Sign := 'DF';
736 Module^.Module_SamplePointer^[I3]^.Sample_FileFormatVersion := $00100;
737 Module^.Module_SamplePointer^[I3]^.Sample_Position := $00000000;
738 Module^.Module_SamplePointer^[I3]^.Sample_Selector := $0000;
739 Module^.Module_SamplePointer^[I3]^.Sample_Volume := Sample^[I1].PSM_SampleVolume;
740 Module^.Module_SamplePointer^[I3]^.Sample_LoopCounter := $00;
741 Module^.Module_SamplePointer^[I3]^.Sample_C5Speed := Sample^[I1].PSM_SampleC5Speed;
742 Module^.Module_SamplePointer^[I3]^.Sample_Length := Sample^[I1].PSM_SampleLength;
743 Module^.Module_SamplePointer^[I3]^.Sample_LoopBegin := Sample^[I1].PSM_SampleLoopBegin;
744 Module^.Module_SamplePointer^[I3]^.Sample_LoopEnd := Sample^[I1].PSM_SampleLoopEnd;
745 { *** now it's time for the flags }
746 Module^.Module_SamplePointer^[I3]^.Sample_Flags :=
747 c_Sample_Flags_DigitalSample * BYTE(1) +
748 c_Sample_Flags_8BitSample * BYTE(1) +
749 c_Sample_Flags_UnsignedSampleData * BYTE(1) +
750 c_Sample_Flags_Packed * BYTE(0) +
751 c_Sample_Flags_LoopCounter * BYTE(0) +
752 c_Sample_Flags_SampleName * BYTE(1) +
753 c_Sample_Flags_LoopActive *
754 BYTE(Sample^[I1].PSM_SampleFlags AND (LONGINT(1) SHL 15) = (LONGINT(1) SHL 15));
755 { *** alloc memory for sample-data }
756 E_Getmem(Module^.Module_SamplePointer^[I3]^.Sample_Selector,
757 Module^.Module_SamplePointer^[I3]^.Sample_Position,
758 Module^.Module_SamplePointer^[I3]^.Sample_Length + c_LoopExtensionSize);
759 { *** read out data }
760 EPT(TempP).p_Selector := Module^.Module_SamplePointer^[I3]^.Sample_Selector;
761 EPT(TempP).p_Offset := $0000;
762 SEEK(InFile,Sample^[I1].PSM_SamplePosition);
763 E_BLOCKREAD(InFile,TempP^,Module^.Module_SamplePointer^[I3]^.Sample_Length);
764 { *** 'coz the samples are signed in a DSM-file -> PC-fy them }
765 IF Module^.Module_SamplePointer^[I3]^.Sample_Length > 4 THEN
766 BEGIN
767 CopyLength := Module^.Module_SamplePointer^[I3]^.Sample_Length;
768 { *** decode sample }
769 ASM
770 DB 066h; MOV CX,WORD PTR CopyLength
771 { *** load sample selector }
772 MOV ES,WORD PTR TempP[00002h]
773 DB 066h; XOR SI,SI
774 DB 066h; XOR DI,DI
775 XOR AH,AH
776 { *** conert all bytes }
777 @@MainLoop:
778 DB 026h; DB 067h; LODSB
779 ADD AL,AH
780 MOV AH,AL
781 DB 067h; STOSB
782 DB 066h; LOOP @@MainLoop
783 END;
784 { *** make samples unsigned }
785 ASM
786 DB 066h; MOV CX,WORD PTR CopyLength
787 { *** load sample selector }
788 MOV ES,WORD PTR TempP[00002h]
789 DB 066h; XOR SI,SI
790 DB 066h; XOR DI,DI
791 { *** conert all bytes }
792 @@MainLoop:
793 DB 026h; DB 067h; LODSB
794 SUB AL,080h
795 DB 067h; STOSB
796 DB 066h; LOOP @@MainLoop
797 END;
798 { *** Create Loop-Extension }
799 IF Module^.Module_SamplePointer^[I3]^.Sample_Flags AND c_Sample_Flags_LoopActive = c_Sample_Flags_LoopActive THEN
800 BEGIN
801 CopySource := Module^.Module_SamplePointer^[I3]^.Sample_LoopBegin;
802 CopyDestination := Module^.Module_SamplePointer^[I3]^.Sample_LoopEnd;
803 CopyLength := CopyDestination - CopySource;
804 ASM
805 { *** load sample-selector }
806 MOV ES,WORD PTR TempP[00002h]
807 DB 066h; MOV DI,WORD PTR CopyDestination
808 { *** calculate number of full sample-loops to copy }
809 XOR DX,DX
810 MOV AX,c_LoopExtensionSize
811 MOV BX,WORD PTR CopyLength
812 DIV BX
813 OR AX,AX
814 JE @@NoFullLoop
815 { *** copy some full-loops (size=bx) }
816 MOV CX,AX
817 @@InnerLoop:
818 PUSH CX
819 DB 066h; MOV SI,WORD PTR CopySource
820 MOV CX,BX
821 DB 0F3h; DB 026h,067h,0A4h { REP MOVS BYTE PTR ES:[EDI],ES:[ESI] }
822 POP CX
823 LOOP @@InnerLoop
824 @@NoFullLoop:
825 { *** calculate number of rest-bytes to copy }
826 DB 066h; MOV SI,WORD PTR CopySource
827 MOV CX,DX
828 DB 0F3h; DB 026h,067h,0A4h { REP MOVS BYTE PTR ES:[EDI],ES:[ESI] }
829 END;
830 END
831 ELSE
832 BEGIN
833 CopyDestination := Module^.Module_SamplePointer^[I3]^.Sample_Length;
834 ASM
835 { *** load sample-selector }
836 MOV ES,WORD PTR TempP[00002h]
837 DB 066h; MOV DI,WORD PTR CopyDestination
838 { *** clear extension }
839 MOV CX,c_LoopExtensionSize
840 MOV AL,080h
841 DB 0F3h; DB 067h,0AAh { REP STOS BYTE PTR ES:[EDI] }
842 END;
843 END;
844 END;
845 { *** next sample }
846 END;
847 { *** init period-ranges }
848 NTMIK_MaximumPeriod := $0000D600 SHR 1;
849 NTMIK_MinimumPeriod := $0000D600 SHR 8;
850 { *** close file }
851 CLOSE(InFile);
852 { *** dispose all dynamic variables }
853 DISPOSE(Header);
854 DISPOSE(Sample);
855 DISPOSE(Order);
856 DISPOSE(ChannelSettings);
857 DISPOSE(MultiPurposeBuffer);
858 DISPOSE(PatternBuffer);
859 { *** set errorcode to noerror }
860 ErrorCode := c_NoError;
861 END;
862
863 */