gosu 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +108 -14
  3. data/dependencies/SDL/include/SDL_assert.h +81 -50
  4. data/dependencies/SDL/include/SDL_atomic.h +135 -35
  5. data/dependencies/SDL/include/SDL_audio.h +960 -355
  6. data/dependencies/SDL/include/SDL_bits.h +11 -6
  7. data/dependencies/SDL/include/SDL_blendmode.h +91 -14
  8. data/dependencies/SDL/include/SDL_clipboard.h +30 -7
  9. data/dependencies/SDL/include/SDL_config.h +277 -27
  10. data/dependencies/SDL/include/SDL_config_android.h +13 -38
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +21 -62
  12. data/dependencies/SDL/include/SDL_config_macosx.h +23 -92
  13. data/dependencies/SDL/include/SDL_config_minimal.h +1 -4
  14. data/dependencies/SDL/include/SDL_config_pandora.h +15 -22
  15. data/dependencies/SDL/include/SDL_config_psp.h +16 -37
  16. data/dependencies/SDL/include/SDL_config_windows.h +28 -91
  17. data/dependencies/SDL/include/SDL_config_winrt.h +33 -61
  18. data/dependencies/SDL/include/SDL_config_wiz.h +28 -56
  19. data/dependencies/SDL/include/SDL_copying.h +1 -1
  20. data/dependencies/SDL/include/SDL_cpuinfo.h +331 -71
  21. data/dependencies/SDL/include/SDL_egl.h +906 -280
  22. data/dependencies/SDL/include/SDL_endian.h +101 -47
  23. data/dependencies/SDL/include/SDL_error.h +70 -19
  24. data/dependencies/SDL/include/SDL_events.h +387 -79
  25. data/dependencies/SDL/include/SDL_filesystem.h +73 -64
  26. data/dependencies/SDL/include/SDL_gamecontroller.h +585 -125
  27. data/dependencies/SDL/include/SDL_gesture.h +36 -6
  28. data/dependencies/SDL/include/SDL_haptic.h +304 -210
  29. data/dependencies/SDL/include/SDL_hidapi.h +451 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1286 -897
  31. data/dependencies/SDL/include/SDL_joystick.h +577 -130
  32. data/dependencies/SDL/include/SDL_keyboard.h +162 -63
  33. data/dependencies/SDL/include/SDL_keycode.h +7 -5
  34. data/dependencies/SDL/include/SDL_loadso.h +42 -8
  35. data/dependencies/SDL/include/SDL_locale.h +34 -32
  36. data/dependencies/SDL/include/SDL_log.h +212 -19
  37. data/dependencies/SDL/include/SDL_main.h +72 -17
  38. data/dependencies/SDL/include/SDL_messagebox.h +70 -23
  39. data/dependencies/SDL/include/SDL_metal.h +27 -32
  40. data/dependencies/SDL/include/SDL_misc.h +19 -15
  41. data/dependencies/SDL/include/SDL_mouse.h +262 -110
  42. data/dependencies/SDL/include/SDL_mutex.h +286 -66
  43. data/dependencies/SDL/include/SDL_name.h +1 -1
  44. data/dependencies/SDL/include/SDL_opengl.h +1 -1
  45. data/dependencies/SDL/include/SDL_opengles.h +1 -1
  46. data/dependencies/SDL/include/SDL_opengles2.h +2 -2
  47. data/dependencies/SDL/include/SDL_pixels.h +199 -34
  48. data/dependencies/SDL/include/SDL_platform.h +39 -2
  49. data/dependencies/SDL/include/SDL_power.h +23 -10
  50. data/dependencies/SDL/include/SDL_quit.h +1 -1
  51. data/dependencies/SDL/include/SDL_rect.h +78 -28
  52. data/dependencies/SDL/include/SDL_render.h +1204 -472
  53. data/dependencies/SDL/include/SDL_revision.h +2 -2
  54. data/dependencies/SDL/include/SDL_rwops.h +605 -33
  55. data/dependencies/SDL/include/SDL_scancode.h +1 -1
  56. data/dependencies/SDL/include/SDL_sensor.h +76 -42
  57. data/dependencies/SDL/include/SDL_shape.h +38 -27
  58. data/dependencies/SDL/include/SDL_stdinc.h +96 -24
  59. data/dependencies/SDL/include/SDL_surface.h +571 -139
  60. data/dependencies/SDL/include/SDL_system.h +339 -101
  61. data/dependencies/SDL/include/SDL_syswm.h +50 -20
  62. data/dependencies/SDL/include/SDL_test.h +1 -1
  63. data/dependencies/SDL/include/SDL_test_assert.h +2 -2
  64. data/dependencies/SDL/include/SDL_test_common.h +23 -6
  65. data/dependencies/SDL/include/SDL_test_compare.h +1 -1
  66. data/dependencies/SDL/include/SDL_test_crc32.h +1 -1
  67. data/dependencies/SDL/include/SDL_test_font.h +3 -3
  68. data/dependencies/SDL/include/SDL_test_fuzzer.h +28 -26
  69. data/dependencies/SDL/include/SDL_test_harness.h +6 -6
  70. data/dependencies/SDL/include/SDL_test_images.h +1 -1
  71. data/dependencies/SDL/include/SDL_test_log.h +1 -1
  72. data/dependencies/SDL/include/SDL_test_md5.h +1 -1
  73. data/dependencies/SDL/include/SDL_test_memory.h +1 -1
  74. data/dependencies/SDL/include/SDL_test_random.h +2 -2
  75. data/dependencies/SDL/include/SDL_thread.h +226 -128
  76. data/dependencies/SDL/include/SDL_timer.h +129 -22
  77. data/dependencies/SDL/include/SDL_touch.h +48 -8
  78. data/dependencies/SDL/include/SDL_types.h +1 -1
  79. data/dependencies/SDL/include/SDL_version.h +72 -46
  80. data/dependencies/SDL/include/SDL_video.h +1266 -460
  81. data/dependencies/SDL/include/SDL_vulkan.h +100 -161
  82. data/dependencies/SDL/include/begin_code.h +22 -1
  83. data/dependencies/SDL/include/close_code.h +1 -1
  84. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  85. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  86. data/dependencies/SDL_sound/SDL_sound.c +83 -7
  87. data/dependencies/SDL_sound/SDL_sound.h +4 -4
  88. data/dependencies/SDL_sound/SDL_sound_aiff.c +9 -12
  89. data/dependencies/SDL_sound/SDL_sound_au.c +7 -7
  90. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +3 -3
  91. data/dependencies/SDL_sound/SDL_sound_flac.c +1 -1
  92. data/dependencies/SDL_sound/SDL_sound_internal.h +17 -10
  93. data/dependencies/SDL_sound/SDL_sound_modplug.c +25 -27
  94. data/dependencies/SDL_sound/SDL_sound_mp3.c +5 -17
  95. data/dependencies/SDL_sound/SDL_sound_raw.c +11 -11
  96. data/dependencies/SDL_sound/SDL_sound_shn.c +8 -7
  97. data/dependencies/SDL_sound/SDL_sound_voc.c +6 -4
  98. data/dependencies/SDL_sound/SDL_sound_vorbis.c +6 -11
  99. data/dependencies/SDL_sound/SDL_sound_wav.c +35 -29
  100. data/dependencies/SDL_sound/dr_flac.h +618 -220
  101. data/dependencies/SDL_sound/dr_mp3.h +263 -94
  102. data/dependencies/SDL_sound/libmodplug/fastmix.c +58 -64
  103. data/dependencies/SDL_sound/libmodplug/libmodplug.h +25 -103
  104. data/dependencies/SDL_sound/libmodplug/load_669.c +14 -17
  105. data/dependencies/SDL_sound/libmodplug/load_amf.c +11 -7
  106. data/dependencies/SDL_sound/libmodplug/load_ams.c +65 -22
  107. data/dependencies/SDL_sound/libmodplug/load_dbm.c +8 -4
  108. data/dependencies/SDL_sound/libmodplug/load_dmf.c +55 -25
  109. data/dependencies/SDL_sound/libmodplug/load_far.c +9 -13
  110. data/dependencies/SDL_sound/libmodplug/load_gdm.c +448 -0
  111. data/dependencies/SDL_sound/libmodplug/load_it.c +45 -49
  112. data/dependencies/SDL_sound/libmodplug/load_mdl.c +80 -53
  113. data/dependencies/SDL_sound/libmodplug/load_med.c +20 -12
  114. data/dependencies/SDL_sound/libmodplug/load_mod.c +40 -15
  115. data/dependencies/SDL_sound/libmodplug/load_mt2.c +29 -17
  116. data/dependencies/SDL_sound/libmodplug/load_okt.c +12 -8
  117. data/dependencies/SDL_sound/libmodplug/load_psm.c +101 -78
  118. data/dependencies/SDL_sound/libmodplug/load_ptm.c +18 -17
  119. data/dependencies/SDL_sound/libmodplug/load_s3m.c +9 -7
  120. data/dependencies/SDL_sound/libmodplug/load_stm.c +3 -2
  121. data/dependencies/SDL_sound/libmodplug/load_ult.c +2 -2
  122. data/dependencies/SDL_sound/libmodplug/load_umx.c +315 -35
  123. data/dependencies/SDL_sound/libmodplug/load_xm.c +25 -21
  124. data/dependencies/SDL_sound/libmodplug/mmcmp.c +295 -149
  125. data/dependencies/SDL_sound/libmodplug/modplug.c +7 -123
  126. data/dependencies/SDL_sound/libmodplug/modplug.h +32 -29
  127. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +0 -1
  128. data/dependencies/SDL_sound/libmodplug/snd_flt.c +2 -2
  129. data/dependencies/SDL_sound/libmodplug/snd_fx.c +24 -18
  130. data/dependencies/SDL_sound/libmodplug/sndfile.c +55 -156
  131. data/dependencies/SDL_sound/libmodplug/sndmix.c +7 -12
  132. data/dependencies/SDL_sound/libmodplug/tables.h +10 -15
  133. data/dependencies/SDL_sound/stb_vorbis.h +508 -325
  134. data/dependencies/{al_soft → mojoAL}/AL/al.h +38 -30
  135. data/dependencies/{al_soft → mojoAL}/AL/alc.h +27 -56
  136. data/dependencies/mojoAL/mojoal.c +4594 -0
  137. data/ext/gosu/extconf.rb +29 -30
  138. data/include/Gosu/Audio.hpp +70 -85
  139. data/include/Gosu/Color.hpp +19 -11
  140. data/include/Gosu/Font.hpp +40 -44
  141. data/include/Gosu/Graphics.hpp +58 -71
  142. data/include/Gosu/GraphicsBase.hpp +26 -33
  143. data/include/Gosu/Image.hpp +56 -62
  144. data/include/Gosu/ImageData.hpp +23 -27
  145. data/include/Gosu/Inspection.hpp +1 -4
  146. data/include/Gosu/TextInput.hpp +34 -40
  147. data/include/Gosu/Version.hpp +1 -1
  148. data/include/Gosu/Window.hpp +71 -70
  149. data/lib/SDL2.dll +0 -0
  150. data/lib/gosu/compat.rb +24 -37
  151. data/lib/gosu.rb +2 -2
  152. data/lib64/SDL2.dll +0 -0
  153. data/src/Audio.cpp +86 -86
  154. data/src/AudioFile.hpp +6 -6
  155. data/src/AudioFileAudioToolbox.cpp +1 -1
  156. data/src/AudioFileSDLSound.cpp +1 -1
  157. data/src/AudioImpl.hpp +5 -5
  158. data/src/BitmapIO.cpp +0 -20
  159. data/src/BlockAllocator.cpp +2 -1
  160. data/src/Channel.cpp +22 -20
  161. data/src/Color.cpp +12 -9
  162. data/src/EmptyImageData.hpp +15 -17
  163. data/src/FileUnix.cpp +1 -1
  164. data/src/FileWin.cpp +1 -1
  165. data/src/Font.cpp +48 -53
  166. data/src/Graphics.cpp +135 -143
  167. data/src/Image.cpp +41 -42
  168. data/src/Input.cpp +1 -1
  169. data/src/InputUIKit.cpp +1 -1
  170. data/src/LargeImageData.cpp +108 -101
  171. data/src/LargeImageData.hpp +17 -15
  172. data/src/Log.hpp +6 -6
  173. data/src/Macro.cpp +35 -37
  174. data/src/Macro.hpp +11 -11
  175. data/src/Math.cpp +8 -1
  176. data/src/Resolution.cpp +12 -7
  177. data/src/RubyGosu.cxx +5 -5
  178. data/src/TexChunk.cpp +50 -41
  179. data/src/TexChunk.hpp +22 -22
  180. data/src/Text.cpp +37 -37
  181. data/src/TextBuilder.cpp +60 -57
  182. data/src/TextBuilder.hpp +20 -20
  183. data/src/TextInput.cpp +127 -135
  184. data/src/TrueTypeFont.cpp +107 -107
  185. data/src/TrueTypeFont.hpp +39 -38
  186. data/src/TrueTypeFontApple.cpp +19 -22
  187. data/src/TrueTypeFontUnix.cpp +21 -26
  188. data/src/TrueTypeFontWin.cpp +30 -30
  189. data/src/Window.cpp +95 -86
  190. data/src/WindowUIKit.cpp +46 -49
  191. metadata +7 -17
  192. data/dependencies/SDL/include/SDL_config_os2.h +0 -188
  193. data/dependencies/SDL_sound/libmodplug/load_abc.c +0 -4725
  194. data/dependencies/SDL_sound/libmodplug/load_mid.c +0 -1405
  195. data/dependencies/SDL_sound/libmodplug/load_pat.c +0 -1143
  196. data/dependencies/SDL_sound/libmodplug/load_pat.h +0 -25
  197. data/dependencies/al_soft/AL/alext.h +0 -585
  198. data/dependencies/al_soft/AL/efx-creative.h +0 -3
  199. data/dependencies/al_soft/AL/efx-presets.h +0 -402
  200. data/dependencies/al_soft/AL/efx.h +0 -762
  201. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  202. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  203. data/lib/OpenAL32.dll +0 -0
  204. data/lib64/OpenAL32.dll +0 -0
@@ -4,6 +4,7 @@
4
4
  * Authors: Olivier Lapicque <olivierl@jps.net>
5
5
  */
6
6
 
7
+
7
8
  ///////////////////////////////////////////////////
8
9
  //
9
10
  // PSM module loader
@@ -80,7 +81,9 @@ typedef struct _PSMSAMPLE
80
81
  BYTE reserved6[19];
81
82
  } PSMSAMPLE;
82
83
 
83
- void swap_PSMSAMPLE(PSMSAMPLE* p){
84
+ #pragma pack()
85
+
86
+ static void swap_PSMSAMPLE(PSMSAMPLE* p){
84
87
  p->smpid = bswapLE32(p->smpid);
85
88
  p->length = bswapLE32(p->length);
86
89
  p->loopstart = bswapLE32(p->loopstart);
@@ -88,29 +91,29 @@ void swap_PSMSAMPLE(PSMSAMPLE* p){
88
91
  p->samplerate = bswapLE32(p->samplerate);
89
92
  }
90
93
 
91
- #pragma pack()
92
-
93
94
 
94
95
  BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
95
96
  //-----------------------------------------------------------
96
97
  {
97
- PSMCHUNK *pfh = (PSMCHUNK *)lpStream;
98
+ PSMCHUNK pfh;
98
99
  DWORD dwMemPos, dwSongPos;
99
- DWORD smpnames[MAX_SAMPLES];
100
+ // DWORD smpnames[MAX_SAMPLES];
100
101
  DWORD patptrs[MAX_PATTERNS];
101
102
  BYTE samplemap[MAX_SAMPLES];
102
103
  UINT nPatterns;
103
-
104
+
105
+ if (dwMemLength < 256) return FALSE;
106
+
107
+ SDL_memcpy(&pfh, lpStream, sizeof(PSMCHUNK));
104
108
  // Swap chunk
105
- swap_PSMCHUNK(pfh);
109
+ swap_PSMCHUNK(&pfh);
106
110
 
107
111
  // Chunk0: "PSM ",filesize,"FILE"
108
- if (dwMemLength < 256) return FALSE;
109
- if (pfh->id == PSM_ID_OLD)
112
+ if (pfh.id == PSM_ID_OLD)
110
113
  {
111
114
  return FALSE;
112
115
  }
113
- if ((pfh->id != PSM_ID_NEW) || (pfh->len+12 > dwMemLength) || (pfh->listid != IFFID_FILE)) return FALSE;
116
+ if ((pfh.id != PSM_ID_NEW) || (pfh.len+12 > dwMemLength) || (pfh.listid != IFFID_FILE)) return FALSE;
114
117
  _this->m_nType = MOD_TYPE_PSM;
115
118
  _this->m_nChannels = 16;
116
119
  _this->m_nSamples = 0;
@@ -124,13 +127,14 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
124
127
  }
125
128
  while (dwMemPos+8 < dwMemLength)
126
129
  {
127
- PSMCHUNK *pchunk = (PSMCHUNK *)(lpStream+dwMemPos);
128
- swap_PSMCHUNK(pchunk);
129
- if ((pchunk->len >= dwMemLength - 8) || (dwMemPos + pchunk->len + 8 > dwMemLength)) break;
130
+ PSMCHUNK pchunk;
131
+ SDL_memcpy(&pchunk, lpStream+dwMemPos, sizeof(PSMCHUNK));
132
+ swap_PSMCHUNK(&pchunk);
133
+ if ((pchunk.len >= dwMemLength - 8) || (dwMemPos + pchunk.len + 8 > dwMemLength)) break;
130
134
  dwMemPos += 8;
131
135
  PUCHAR pdata = (PUCHAR)(lpStream+dwMemPos);
132
- ULONG len = pchunk->len;
133
- if (len) switch(pchunk->id)
136
+ ULONG len = pchunk.len;
137
+ if (len) switch(pchunk.id)
134
138
  {
135
139
  // "PBOD": Pattern
136
140
  case IFFID_PBOD:
@@ -152,19 +156,20 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
152
156
  {
153
157
  _this->m_nSamples++;
154
158
  MODINSTRUMENT *pins = &_this->Ins[_this->m_nSamples];
155
- PSMSAMPLE *psmp = (PSMSAMPLE *)pdata;
156
- swap_PSMSAMPLE(psmp);
157
- smpnames[_this->m_nSamples] = psmp->smpid;
159
+ PSMSAMPLE psmp;
160
+ SDL_memcpy(&psmp, pdata, sizeof(PSMSAMPLE));
161
+ swap_PSMSAMPLE(&psmp);
162
+ // smpnames[_this->m_nSamples] = psmp.smpid;
158
163
  samplemap[_this->m_nSamples-1] = (BYTE)_this->m_nSamples;
159
164
  // Init sample
160
165
  pins->nGlobalVol = 0x40;
161
- pins->nC4Speed = psmp->samplerate;
162
- pins->nLength = psmp->length;
163
- pins->nLoopStart = psmp->loopstart;
164
- pins->nLoopEnd = psmp->loopend;
166
+ pins->nC4Speed = psmp.samplerate;
167
+ pins->nLength = psmp.length;
168
+ pins->nLoopStart = psmp.loopstart;
169
+ pins->nLoopEnd = psmp.loopend;
165
170
  pins->nPan = 128;
166
- pins->nVolume = (psmp->defvol+1) * 2;
167
- pins->uFlags = (psmp->flags & 0x80) ? CHN_LOOP : 0;
171
+ pins->nVolume = (psmp.defvol+1) * 2;
172
+ pins->uFlags = (psmp.flags & 0x80) ? CHN_LOOP : 0;
168
173
  if (pins->nLoopStart > 0) pins->nLoopStart--;
169
174
  // Point to sample data
170
175
  pdata += 0x60;
@@ -180,10 +185,10 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
180
185
  }
181
186
  break;
182
187
  }
183
- dwMemPos += pchunk->len;
188
+ dwMemPos += pchunk.len;
184
189
  }
185
190
  // Step #1: convert song structure
186
- PSMSONGHDR *pSong = (PSMSONGHDR *)(lpStream+dwSongPos+8);
191
+ const PSMSONGHDR *pSong = (const PSMSONGHDR *)(lpStream+dwSongPos+8);
187
192
  if ((!dwSongPos) || (pSong->channels < 2) || (pSong->channels > 32)) return TRUE;
188
193
  _this->m_nChannels = pSong->channels;
189
194
  // Valid song header -> convert attached chunks
@@ -192,13 +197,14 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
192
197
  dwMemPos = dwSongPos + 8 + 11; // sizeof(PSMCHUNK)+sizeof(PSMSONGHDR)
193
198
  while (dwMemPos + 8 < dwSongEnd)
194
199
  {
195
- PSMCHUNK *pchunk = (PSMCHUNK *)(lpStream+dwMemPos);
196
- swap_PSMCHUNK(pchunk);
200
+ PSMCHUNK pchunk;
201
+ SDL_memcpy(&pchunk, lpStream+dwMemPos, sizeof(PSMCHUNK));
202
+ swap_PSMCHUNK(&pchunk);
197
203
  dwMemPos += 8;
198
- if ((pchunk->len > dwSongEnd) || (dwMemPos + pchunk->len > dwSongEnd)) break;
204
+ if ((pchunk.len > dwSongEnd) || (dwMemPos + pchunk.len > dwSongEnd)) break;
199
205
  PUCHAR pdata = (PUCHAR)(lpStream+dwMemPos);
200
- ULONG len = pchunk->len;
201
- switch(pchunk->id)
206
+ ULONG len = pchunk.len;
207
+ switch(pchunk.id)
202
208
  {
203
209
  case IFFID_OPLH:
204
210
  if (len >= 0x20)
@@ -211,7 +217,7 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
211
217
  DWORD dwName = *(DWORD *)(pdata+pos);
212
218
  for (UINT i=0; i<nPatterns; i++)
213
219
  {
214
- DWORD dwPatName = ((PSMPATTERN *)(lpStream+patptrs[i]+8))->name;
220
+ DWORD dwPatName = ((const PSMPATTERN *)(lpStream+patptrs[i]+8))->name;
215
221
  if (dwName == dwPatName)
216
222
  {
217
223
  bFound = TRUE;
@@ -232,7 +238,7 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
232
238
  DWORD dwName = *(DWORD *)(pdata+pos);
233
239
  for (UINT i=0; i<nPatterns; i++)
234
240
  {
235
- DWORD dwPatName = ((PSMPATTERN *)(lpStream+patptrs[i]+8))->name;
241
+ DWORD dwPatName = ((const PSMPATTERN *)(lpStream+patptrs[i]+8))->name;
236
242
  if (dwName == dwPatName)
237
243
  {
238
244
  _this->Order[iOrd++] = i;
@@ -244,70 +250,73 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
244
250
  }
245
251
  break;
246
252
  }
247
- dwMemPos += pchunk->len;
253
+ dwMemPos += pchunk.len;
248
254
  }
249
255
  }
250
256
 
251
257
  // Step #2: convert patterns
252
258
  for (UINT nPat=0; nPat<nPatterns; nPat++)
253
259
  {
254
- PSMPATTERN *pPsmPat = (PSMPATTERN *)(lpStream+patptrs[nPat]+8);
255
- swap_PSMPATTERN(pPsmPat);
256
- ULONG len = *(DWORD *)(lpStream+patptrs[nPat]+4) - 12;
257
- UINT nRows = pPsmPat->rows;
258
- if (len > pPsmPat->size) len = pPsmPat->size;
260
+ PSMPATTERN pPsmPat;
261
+ PSMCHUNK pchunk;
262
+ SDL_memcpy(&pPsmPat, lpStream+patptrs[nPat]+8, sizeof(PSMPATTERN));
263
+ swap_PSMPATTERN(&pPsmPat);
264
+ SDL_memcpy(&pchunk, lpStream+patptrs[nPat], sizeof(PSMCHUNK));
265
+ swap_PSMCHUNK(&pchunk);
266
+
267
+ ULONG len = pchunk.len - 12;
268
+ UINT nRows = pPsmPat.rows;
269
+ if (len > pPsmPat.size) len = pPsmPat.size;
259
270
  if ((nRows < 64) || (nRows > 256)) nRows = 64;
260
271
  _this->PatternSize[nPat] = nRows;
261
272
  if ((_this->Patterns[nPat] = CSoundFile_AllocatePattern(nRows, _this->m_nChannels)) == NULL) break;
262
273
  MODCOMMAND *m = _this->Patterns[nPat];
263
- BYTE *p = pPsmPat->data;
274
+ const BYTE *p = lpStream + patptrs[nPat] + 20;
275
+ MODCOMMAND *sp, dummy;
264
276
  UINT pos = 0;
265
277
  UINT row = 0;
266
- UINT oldch = 0;
267
- BOOL bNewRow = FALSE;
268
- while ((row < nRows) && (pos+1 < len))
278
+ UINT rowlim;
279
+ UINT flags, ch;
280
+ rowlim = bswapLE16(pPsmPat.reserved1)-2;
281
+ while ((row < nRows) && (pos+3 < len))
269
282
  {
270
- UINT flags = p[pos++];
271
- UINT ch = p[pos++];
272
-
273
- if (((flags & 0xf0) == 0x10) && (ch <= oldch) /*&& (!bNewRow)*/)
274
- {
275
- if ((pos+1<len) && (!(p[pos] & 0x0f)) && (p[pos+1] < _this->m_nChannels))
276
- {
277
- row++;
278
- m += _this->m_nChannels;
279
- oldch = ch;
280
- continue;
281
- }
282
- }
283
- if ((pos >= len) || (row >= nRows)) break;
284
- if (!(flags & 0xf0))
285
- {
286
- row++;
283
+ if ((pos+1) >= rowlim) {
284
+ pos = rowlim;
285
+ rowlim = (((int)p[pos+1])<<8)
286
+ | ((int)p[pos+0]);
287
287
  m += _this->m_nChannels;
288
- bNewRow = TRUE;
289
- oldch = ch;
290
- continue;
288
+ row++;
289
+ rowlim += pos;
290
+ pos += 2;
291
291
  }
292
- bNewRow = FALSE;
293
- if (ch >= _this->m_nChannels)
294
- {
295
- ch = 0;
292
+ if (row >= nRows) continue;
293
+
294
+ flags = p[pos++];
295
+ ch = p[pos++];
296
+ if (ch >= _this->m_nChannels) {
297
+ sp = &dummy;
298
+ } else {
299
+ sp = &m[ch];
296
300
  }
297
301
  // Note + Instr
298
- if ((flags & 0x40) && (pos+1 < len))
302
+ if ((flags & 0x80) && (pos+1 < len))
299
303
  {
300
304
  UINT note = p[pos++];
305
+ note = (note>>4)*12+(note&0x0f)+12+1;
306
+ if (note > 0x80) note = 0;
307
+ sp->note = note;
308
+ }
309
+ if ((flags & 0x40) && (pos+1 < len))
310
+ {
301
311
  UINT nins = p[pos++];
302
- if ((note) && (note < 0x80)) note = (note>>4)*12+(note&0x0f)+12+1;
303
- m[ch].instr = samplemap[nins];
304
- m[ch].note = note;
312
+ if (nins < MAX_SAMPLES)
313
+ sp->instr = samplemap[nins];
305
314
  }
306
315
  // Volume
307
316
  if ((flags & 0x20) && (pos < len))
308
317
  {
309
- m[ch].volcmd = VOLCMD_VOLUME;
310
- m[ch].vol = p[pos++] / 2;
318
+ sp->volcmd = VOLCMD_VOLUME;
319
+ sp->vol = p[pos++] / 2;
311
320
  }
312
321
  // Effect
313
322
  if ((flags & 0x10) && (pos+1 < len))
@@ -318,13 +327,29 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
318
327
  switch(command)
319
328
  {
320
329
  // 01: fine volslide up
321
- case 0x01: command = CMD_VOLUMESLIDE; param |= 0x0f; break;
330
+ case 0x01: command = CMD_VOLUMESLIDE; param |= 0x0f;
331
+ if (param == 15) param=31;
332
+ break;
333
+ // 02: volslide up
334
+ case 0x02: command = CMD_VOLUMESLIDE; param>>=1; param<<=4; break;
335
+ // 03: fine volslide down
336
+ case 0x03: command = CMD_VOLUMESLIDE; param>>=4; param |= 0xf0;
337
+ if (param == 240) param=241;
338
+ break;
322
339
  // 04: fine volslide down
323
340
  case 0x04: command = CMD_VOLUMESLIDE; param>>=4; param |= 0xf0; break;
324
341
  // 0C: portamento up
325
342
  case 0x0C: command = CMD_PORTAMENTOUP; param = (param+1)/2; break;
326
343
  // 0E: portamento down
327
344
  case 0x0E: command = CMD_PORTAMENTODOWN; param = (param+1)/2; break;
345
+ // 0F: tone portamento
346
+ case 0x0F: command = CMD_TONEPORTAMENTO; param = param/4; break;
347
+ // 15: vibrato
348
+ case 0x15: command = CMD_VIBRATO; break;
349
+ // 29: sample offset
350
+ case 0x29: pos += 2; break;
351
+ // 2A: retrigger note
352
+ case 0x2A: command = CMD_RETRIG; break;
328
353
  // 33: Position Jump
329
354
  case 0x33: command = CMD_POSITIONJUMP; break;
330
355
  // 34: Pattern break
@@ -337,14 +362,12 @@ BOOL CSoundFile_ReadPSM(CSoundFile *_this, LPCBYTE lpStream, DWORD dwMemLength)
337
362
  default:
338
363
  command = param = 0;
339
364
  }
340
- m[ch].command = (BYTE)command;
341
- m[ch].param = (BYTE)param;
365
+ sp->command = (BYTE)command;
366
+ sp->param = (BYTE)param;
342
367
  }
343
- oldch = ch;
344
368
  }
345
369
  }
346
370
 
347
371
  // Done (finally!)
348
372
  return TRUE;
349
373
  }
350
-
@@ -69,7 +69,7 @@ BOOL CSoundFile_ReadPTM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
69
69
 
70
70
  if ((!lpStream) || (dwMemLength < sizeof(PTMFILEHEADER))) return FALSE;
71
71
  PTMFILEHEADER pfh;
72
- SDL_memcpy(&pfh, lpStream, sizeof (pfh));
72
+ SDL_memcpy(&pfh, lpStream, sizeof (pfh));
73
73
 
74
74
  pfh.norders = bswapLE16(pfh.norders);
75
75
  pfh.nsamples = bswapLE16(pfh.nsamples);
@@ -104,6 +104,7 @@ BOOL CSoundFile_ReadPTM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
104
104
  {
105
105
  MODINSTRUMENT *pins = &_this->Ins[ismp+1];
106
106
  PTMSAMPLE *psmp = (PTMSAMPLE *)(lpStream+dwMemPos);
107
+
107
108
  pins->nGlobalVol = 64;
108
109
  pins->nPan = 128;
109
110
  pins->nVolume = psmp->volume << 2;
@@ -149,48 +150,49 @@ BOOL CSoundFile_ReadPTM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
149
150
  if (b)
150
151
  {
151
152
  UINT nChn = b & 0x1F;
153
+ MODCOMMAND *selm = &m[nChn < _this->m_nChannels ? nChn : 0];
152
154
 
153
155
  if (b & 0x20)
154
156
  {
155
157
  if (dwMemPos + 2 > dwMemLength) break;
156
- m[nChn].note = lpStream[dwMemPos++];
157
- m[nChn].instr = lpStream[dwMemPos++];
158
+ selm->note = lpStream[dwMemPos++];
159
+ selm->instr = lpStream[dwMemPos++];
158
160
  }
159
161
  if (b & 0x40)
160
162
  {
161
163
  if (dwMemPos + 2 > dwMemLength) break;
162
- m[nChn].command = lpStream[dwMemPos++];
163
- m[nChn].param = lpStream[dwMemPos++];
164
- if ((m[nChn].command == 0x0E) && ((m[nChn].param & 0xF0) == 0x80))
164
+ selm->command = lpStream[dwMemPos++];
165
+ selm->param = lpStream[dwMemPos++];
166
+ if ((selm->command == 0x0E) && ((selm->param & 0xF0) == 0x80))
165
167
  {
166
- m[nChn].command = CMD_S3MCMDEX;
168
+ selm->command = CMD_S3MCMDEX;
167
169
  } else
168
- if (m[nChn].command < 0x10)
170
+ if (selm->command < 0x10)
169
171
  {
170
- CSoundFile_ConvertModCommand(_this, &m[nChn]);
172
+ CSoundFile_ConvertModCommand(_this, selm);
171
173
  } else
172
174
  {
173
- switch(m[nChn].command)
175
+ switch(selm->command)
174
176
  {
175
177
  case 16:
176
- m[nChn].command = CMD_GLOBALVOLUME;
178
+ selm->command = CMD_GLOBALVOLUME;
177
179
  break;
178
180
  case 17:
179
- m[nChn].command = CMD_RETRIG;
181
+ selm->command = CMD_RETRIG;
180
182
  break;
181
183
  case 18:
182
- m[nChn].command = CMD_FINEVIBRATO;
184
+ selm->command = CMD_FINEVIBRATO;
183
185
  break;
184
186
  default:
185
- m[nChn].command = 0;
187
+ selm->command = 0;
186
188
  }
187
189
  }
188
190
  }
189
191
  if (b & 0x80)
190
192
  {
191
193
  if (dwMemPos >= dwMemLength) break;
192
- m[nChn].volcmd = VOLCMD_VOLUME;
193
- m[nChn].vol = lpStream[dwMemPos++];
194
+ selm->volcmd = VOLCMD_VOLUME;
195
+ selm->vol = lpStream[dwMemPos++];
194
196
  }
195
197
  } else
196
198
  {
@@ -201,4 +203,3 @@ BOOL CSoundFile_ReadPTM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
201
203
  }
202
204
  return TRUE;
203
205
  }
204
-
@@ -6,9 +6,8 @@
6
6
  */
7
7
 
8
8
  #include "libmodplug.h"
9
- #include "tables.h"
10
9
 
11
- //////////////////////////////////////////////////////
10
+ ////////////////////////////////////////////////////////
12
11
  // ScreamTracker S3M file support
13
12
 
14
13
  #pragma pack(1)
@@ -34,7 +33,6 @@ typedef struct tagS3MSAMPLESTRUCT
34
33
  CHAR scrs[4];
35
34
  } S3MSAMPLESTRUCT;
36
35
 
37
-
38
36
  typedef struct tagS3MFILEHEADER
39
37
  {
40
38
  CHAR name[28];
@@ -58,6 +56,7 @@ typedef struct tagS3MFILEHEADER
58
56
  WORD special;
59
57
  BYTE channels[32];
60
58
  } S3MFILEHEADER;
59
+ #pragma pack()
61
60
 
62
61
 
63
62
  void CSoundFile_S3MConvert(MODCOMMAND *m, BOOL bIT)
@@ -106,7 +105,6 @@ static DWORD boundInput(DWORD input, DWORD smin, DWORD smax)
106
105
  return(input);
107
106
  }
108
107
 
109
-
110
108
  BOOL CSoundFile_ReadS3M(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLength)
111
109
  //---------------------------------------------------------------
112
110
  {
@@ -118,7 +116,7 @@ BOOL CSoundFile_ReadS3M(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
118
116
 
119
117
  if ((!lpStream) || (dwMemLength <= sizeof(S3MFILEHEADER)+sizeof(S3MSAMPLESTRUCT)+64)) return FALSE;
120
118
  S3MFILEHEADER psfh;
121
- SDL_memcpy(&psfh, lpStream, sizeof (psfh));
119
+ SDL_memcpy(&psfh, lpStream, sizeof (psfh));
122
120
 
123
121
  psfh.reserved1 = bswapLE16(psfh.reserved1);
124
122
  psfh.ordnum = bswapLE16(psfh.ordnum);
@@ -169,6 +167,7 @@ BOOL CSoundFile_ReadS3M(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
169
167
  if (iord > MAX_ORDERS) iord = MAX_ORDERS;
170
168
  if (iord)
171
169
  {
170
+ if (dwMemPos + iord > dwMemLength) return FALSE;
172
171
  SDL_memcpy(_this->Order, lpStream+dwMemPos, iord);
173
172
  dwMemPos += iord;
174
173
  }
@@ -186,6 +185,8 @@ BOOL CSoundFile_ReadS3M(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
186
185
 
187
186
  if (nins+npat)
188
187
  {
188
+ if (2*(nins+npat) + dwMemPos > dwMemLength) return FALSE;
189
+
189
190
  SDL_memcpy(ptr, lpStream+dwMemPos, 2*(nins+npat));
190
191
  dwMemPos += 2*(nins+npat);
191
192
  for (UINT j = 0; j < (nins+npat); ++j) {
@@ -193,6 +194,8 @@ BOOL CSoundFile_ReadS3M(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
193
194
  }
194
195
  if (psfh.panning_present == 252)
195
196
  {
197
+ if (dwMemPos + 32 > dwMemLength) return FALSE;
198
+
196
199
  const BYTE *chnpan = lpStream+dwMemPos;
197
200
  for (UINT i=0; i<32; i++) if (chnpan[i] & 0x20)
198
201
  {
@@ -315,11 +318,10 @@ BOOL CSoundFile_ReadS3M(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
315
318
  if (inspack[iRaw-1] == 4) flags = RS_ADPCM4;
316
319
  dwMemPos = insfile[iRaw];
317
320
  if (dwMemPos < dwMemLength)
318
- dwMemPos += CSoundFile_ReadSample(_this, &_this->Ins[iRaw], flags, (LPSTR)(lpStream + dwMemPos), dwMemLength - dwMemPos);
321
+ CSoundFile_ReadSample(_this, &_this->Ins[iRaw], flags, (LPSTR)(lpStream + dwMemPos), dwMemLength - dwMemPos);
319
322
  }
320
323
  _this->m_nMinPeriod = 64;
321
324
  _this->m_nMaxPeriod = 32767;
322
325
  if (psfh.flags & 0x10) _this->m_dwSongFlags |= SONG_AMIGALIMITS;
323
326
  return TRUE;
324
327
  }
325
-
@@ -61,8 +61,8 @@ BOOL CSoundFile_ReadSTM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
61
61
 
62
62
  if ((!lpStream) || (dwMemLength < sizeof(STMHEADER))) return FALSE;
63
63
  if ((phdr->filetype != 2) || (phdr->unused != 0x1A)
64
- || ((SDL_strncasecmp(phdr->trackername, "!SCREAM!", 8))
65
- && (SDL_strncasecmp(phdr->trackername, "BMOD2STM", 8)))) return FALSE;
64
+ || ((SDL_strncmp(phdr->trackername, "!Scream!", 8))
65
+ && (SDL_strncmp(phdr->trackername, "BMOD2STM", 8)))) return FALSE;
66
66
  // Read STM header
67
67
  _this->m_nType = MOD_TYPE_STM;
68
68
  _this->m_nSamples = 31;
@@ -101,6 +101,7 @@ BOOL CSoundFile_ReadSTM(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
101
101
  dwMemPos = sizeof(STMHEADER);
102
102
  for (UINT nOrd=0; nOrd<MAX_ORDERS; nOrd++) if (_this->Order[nOrd] >= 99) _this->Order[nOrd] = 0xFF;
103
103
  UINT nPatterns = phdr->numpat;
104
+ if (nPatterns > MAX_PATTERNS) nPatterns = MAX_PATTERNS;
104
105
  for (UINT nPat=0; nPat<nPatterns; nPat++)
105
106
  {
106
107
  if (dwMemPos + 64*4*4 > dwMemLength) return TRUE;
@@ -137,11 +137,12 @@ BOOL CSoundFile_ReadUlt(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
137
137
  UINT row = 0;
138
138
  while (row < 64)
139
139
  {
140
- if (dwMemPos + 6 > dwMemLength) return TRUE;
140
+ if (dwMemPos + 5 > dwMemLength) return TRUE;
141
141
  UINT rep = 1;
142
142
  UINT note = lpStream[dwMemPos++];
143
143
  if (note == 0xFC)
144
144
  {
145
+ if (dwMemPos + 7 > dwMemLength) return TRUE;
145
146
  rep = lpStream[dwMemPos];
146
147
  note = lpStream[dwMemPos+1];
147
148
  dwMemPos += 2;
@@ -203,4 +204,3 @@ BOOL CSoundFile_ReadUlt(CSoundFile *_this, const BYTE *lpStream, DWORD dwMemLeng
203
204
  }
204
205
  return TRUE;
205
206
  }
206
-