gosu 0.15.2 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. checksums.yaml +4 -4
  2. data/dependencies/SDL/include/SDL.h +138 -0
  3. data/dependencies/SDL/include/SDL_assert.h +293 -0
  4. data/dependencies/SDL/include/SDL_atomic.h +295 -0
  5. data/dependencies/SDL/include/SDL_audio.h +859 -0
  6. data/dependencies/SDL/include/SDL_bits.h +121 -0
  7. data/dependencies/SDL/include/SDL_blendmode.h +123 -0
  8. data/dependencies/SDL/include/SDL_clipboard.h +71 -0
  9. data/dependencies/SDL/include/SDL_config.h +55 -0
  10. data/dependencies/SDL/include/SDL_config_android.h +182 -0
  11. data/dependencies/SDL/include/SDL_config_iphoneos.h +207 -0
  12. data/dependencies/SDL/include/SDL_config_macosx.h +266 -0
  13. data/dependencies/SDL/include/SDL_config_minimal.h +85 -0
  14. data/dependencies/SDL/include/SDL_config_os2.h +188 -0
  15. data/dependencies/SDL/include/SDL_config_pandora.h +135 -0
  16. data/dependencies/SDL/include/SDL_config_psp.h +165 -0
  17. data/dependencies/SDL/include/SDL_config_windows.h +288 -0
  18. data/dependencies/SDL/include/SDL_config_winrt.h +243 -0
  19. data/dependencies/SDL/include/SDL_config_wiz.h +149 -0
  20. data/dependencies/SDL/include/SDL_copying.h +20 -0
  21. data/dependencies/SDL/include/SDL_cpuinfo.h +299 -0
  22. data/dependencies/SDL/include/SDL_egl.h +1676 -0
  23. data/dependencies/SDL/include/SDL_endian.h +263 -0
  24. data/dependencies/SDL/include/SDL_error.h +112 -0
  25. data/dependencies/SDL/include/SDL_events.h +827 -0
  26. data/dependencies/SDL/include/SDL_filesystem.h +136 -0
  27. data/dependencies/SDL/include/SDL_gamecontroller.h +541 -0
  28. data/dependencies/SDL/include/SDL_gesture.h +87 -0
  29. data/dependencies/SDL/include/SDL_haptic.h +1247 -0
  30. data/dependencies/SDL/include/SDL_hints.h +1578 -0
  31. data/dependencies/SDL/include/SDL_joystick.h +499 -0
  32. data/dependencies/SDL/include/SDL_keyboard.h +217 -0
  33. data/dependencies/SDL/include/SDL_keycode.h +351 -0
  34. data/dependencies/SDL/include/SDL_loadso.h +81 -0
  35. data/dependencies/SDL/include/SDL_locale.h +101 -0
  36. data/dependencies/SDL/include/SDL_log.h +211 -0
  37. data/dependencies/SDL/include/SDL_main.h +180 -0
  38. data/dependencies/SDL/include/SDL_messagebox.h +146 -0
  39. data/dependencies/SDL/include/SDL_metal.h +117 -0
  40. data/dependencies/SDL/include/SDL_misc.h +75 -0
  41. data/dependencies/SDL/include/SDL_mouse.h +302 -0
  42. data/dependencies/SDL/include/SDL_mutex.h +251 -0
  43. data/dependencies/SDL/include/SDL_name.h +33 -0
  44. data/dependencies/SDL/include/SDL_opengl.h +2183 -0
  45. data/dependencies/SDL/include/SDL_opengl_glext.h +11180 -0
  46. data/dependencies/SDL/include/SDL_opengles.h +39 -0
  47. data/dependencies/SDL/include/SDL_opengles2.h +52 -0
  48. data/dependencies/SDL/include/SDL_opengles2_gl2.h +621 -0
  49. data/dependencies/SDL/include/SDL_opengles2_gl2ext.h +2050 -0
  50. data/dependencies/SDL/include/SDL_opengles2_gl2platform.h +30 -0
  51. data/dependencies/SDL/include/SDL_opengles2_khrplatform.h +282 -0
  52. data/dependencies/SDL/include/SDL_pixels.h +479 -0
  53. data/dependencies/SDL/include/SDL_platform.h +198 -0
  54. data/dependencies/SDL/include/SDL_power.h +75 -0
  55. data/dependencies/SDL/include/SDL_quit.h +58 -0
  56. data/dependencies/SDL/include/SDL_rect.h +174 -0
  57. data/dependencies/SDL/include/SDL_render.h +1158 -0
  58. data/dependencies/SDL/include/SDL_revision.h +2 -0
  59. data/dependencies/SDL/include/SDL_rwops.h +283 -0
  60. data/dependencies/SDL/include/SDL_scancode.h +413 -0
  61. data/dependencies/SDL/include/SDL_sensor.h +267 -0
  62. data/dependencies/SDL/include/SDL_shape.h +144 -0
  63. data/dependencies/SDL/include/SDL_stdinc.h +647 -0
  64. data/dependencies/SDL/include/SDL_surface.h +563 -0
  65. data/dependencies/SDL/include/SDL_system.h +325 -0
  66. data/dependencies/SDL/include/SDL_syswm.h +354 -0
  67. data/dependencies/SDL/include/SDL_test.h +69 -0
  68. data/dependencies/SDL/include/SDL_test_assert.h +105 -0
  69. data/dependencies/SDL/include/SDL_test_common.h +218 -0
  70. data/dependencies/SDL/include/SDL_test_compare.h +69 -0
  71. data/dependencies/SDL/include/SDL_test_crc32.h +124 -0
  72. data/dependencies/SDL/include/SDL_test_font.h +81 -0
  73. data/dependencies/SDL/include/SDL_test_fuzzer.h +384 -0
  74. data/dependencies/SDL/include/SDL_test_harness.h +134 -0
  75. data/dependencies/SDL/include/SDL_test_images.h +78 -0
  76. data/dependencies/SDL/include/SDL_test_log.h +67 -0
  77. data/dependencies/SDL/include/SDL_test_md5.h +129 -0
  78. data/dependencies/SDL/include/SDL_test_memory.h +63 -0
  79. data/dependencies/SDL/include/SDL_test_random.h +115 -0
  80. data/dependencies/SDL/include/SDL_thread.h +366 -0
  81. data/dependencies/SDL/include/SDL_timer.h +115 -0
  82. data/dependencies/SDL/include/SDL_touch.h +102 -0
  83. data/dependencies/SDL/include/SDL_types.h +29 -0
  84. data/dependencies/SDL/include/SDL_version.h +162 -0
  85. data/dependencies/SDL/include/SDL_video.h +1282 -0
  86. data/dependencies/SDL/include/SDL_vulkan.h +276 -0
  87. data/dependencies/SDL/include/begin_code.h +166 -0
  88. data/dependencies/SDL/include/close_code.h +40 -0
  89. data/dependencies/SDL/lib/x64/libSDL2.dll.a +0 -0
  90. data/dependencies/SDL/lib/x86/libSDL2.dll.a +0 -0
  91. data/dependencies/SDL_sound/SDL_sound.c +795 -0
  92. data/dependencies/SDL_sound/SDL_sound.h +725 -0
  93. data/dependencies/SDL_sound/SDL_sound_aiff.c +537 -0
  94. data/dependencies/SDL_sound/SDL_sound_au.c +352 -0
  95. data/dependencies/SDL_sound/SDL_sound_coreaudio.c +747 -0
  96. data/dependencies/SDL_sound/SDL_sound_flac.c +182 -0
  97. data/dependencies/SDL_sound/SDL_sound_internal.h +304 -0
  98. data/dependencies/SDL_sound/SDL_sound_modplug.c +228 -0
  99. data/dependencies/SDL_sound/SDL_sound_mp3.c +184 -0
  100. data/dependencies/SDL_sound/SDL_sound_raw.c +164 -0
  101. data/dependencies/SDL_sound/SDL_sound_shn.c +1309 -0
  102. data/dependencies/SDL_sound/SDL_sound_voc.c +550 -0
  103. data/dependencies/SDL_sound/SDL_sound_vorbis.c +223 -0
  104. data/dependencies/SDL_sound/SDL_sound_wav.c +783 -0
  105. data/dependencies/SDL_sound/dr_flac.h +5906 -0
  106. data/dependencies/SDL_sound/dr_mp3.h +2832 -0
  107. data/dependencies/SDL_sound/libmodplug/fastmix.c +1748 -0
  108. data/dependencies/SDL_sound/libmodplug/libmodplug.h +1001 -0
  109. data/dependencies/SDL_sound/libmodplug/load_669.c +188 -0
  110. data/dependencies/SDL_sound/libmodplug/load_abc.c +4725 -0
  111. data/dependencies/SDL_sound/libmodplug/load_amf.c +403 -0
  112. data/dependencies/SDL_sound/libmodplug/load_ams.c +587 -0
  113. data/dependencies/SDL_sound/libmodplug/load_dbm.c +357 -0
  114. data/dependencies/SDL_sound/libmodplug/load_dmf.c +531 -0
  115. data/dependencies/SDL_sound/libmodplug/load_dsm.c +232 -0
  116. data/dependencies/SDL_sound/libmodplug/load_far.c +253 -0
  117. data/dependencies/SDL_sound/libmodplug/load_it.c +796 -0
  118. data/dependencies/SDL_sound/libmodplug/load_mdl.c +488 -0
  119. data/dependencies/SDL_sound/libmodplug/load_med.c +757 -0
  120. data/dependencies/SDL_sound/libmodplug/load_mid.c +1405 -0
  121. data/dependencies/SDL_sound/libmodplug/load_mod.c +269 -0
  122. data/dependencies/SDL_sound/libmodplug/load_mt2.c +546 -0
  123. data/dependencies/SDL_sound/libmodplug/load_mtm.c +142 -0
  124. data/dependencies/SDL_sound/libmodplug/load_okt.c +192 -0
  125. data/dependencies/SDL_sound/libmodplug/load_pat.c +1143 -0
  126. data/dependencies/SDL_sound/libmodplug/load_pat.h +25 -0
  127. data/dependencies/SDL_sound/libmodplug/load_psm.c +350 -0
  128. data/dependencies/SDL_sound/libmodplug/load_ptm.c +204 -0
  129. data/dependencies/SDL_sound/libmodplug/load_s3m.c +325 -0
  130. data/dependencies/SDL_sound/libmodplug/load_stm.c +180 -0
  131. data/dependencies/SDL_sound/libmodplug/load_ult.c +206 -0
  132. data/dependencies/SDL_sound/libmodplug/load_umx.c +51 -0
  133. data/dependencies/SDL_sound/libmodplug/load_xm.c +554 -0
  134. data/dependencies/SDL_sound/libmodplug/mmcmp.c +382 -0
  135. data/dependencies/SDL_sound/libmodplug/modplug.c +170 -0
  136. data/dependencies/SDL_sound/libmodplug/modplug.h +90 -0
  137. data/dependencies/SDL_sound/libmodplug/snd_dsp.c +301 -0
  138. data/dependencies/SDL_sound/libmodplug/snd_flt.c +63 -0
  139. data/dependencies/SDL_sound/libmodplug/snd_fx.c +2350 -0
  140. data/dependencies/SDL_sound/libmodplug/sndfile.c +1169 -0
  141. data/dependencies/SDL_sound/libmodplug/sndmix.c +1034 -0
  142. data/dependencies/SDL_sound/libmodplug/tables.h +371 -0
  143. data/{src/stb_vorbis.c → dependencies/SDL_sound/stb_vorbis.h} +143 -78
  144. data/dependencies/al_soft/AL/al.h +655 -0
  145. data/dependencies/al_soft/AL/alc.h +270 -0
  146. data/dependencies/al_soft/AL/alext.h +585 -0
  147. data/dependencies/al_soft/AL/efx-creative.h +3 -0
  148. data/dependencies/al_soft/AL/efx-presets.h +402 -0
  149. data/dependencies/al_soft/AL/efx.h +762 -0
  150. data/dependencies/al_soft/x64/libOpenAL32.dll.a +0 -0
  151. data/dependencies/al_soft/x86/libOpenAL32.dll.a +0 -0
  152. data/{src → dependencies/stb}/stb_image.h +330 -127
  153. data/{src → dependencies/stb}/stb_image_write.h +156 -85
  154. data/{src → dependencies/stb}/stb_truetype.h +192 -69
  155. data/{src → dependencies/utf8proc}/utf8proc.c +0 -0
  156. data/{src → dependencies/utf8proc}/utf8proc.h +0 -0
  157. data/{src → dependencies/utf8proc}/utf8proc_data.h +0 -0
  158. data/ext/gosu/extconf.rb +56 -22
  159. data/{Gosu → include/Gosu}/Audio.hpp +6 -8
  160. data/{Gosu → include/Gosu}/AutoLink.hpp +0 -0
  161. data/include/Gosu/Bitmap.hpp +100 -0
  162. data/{Gosu → include/Gosu}/Buttons.hpp +94 -35
  163. data/{Gosu → include/Gosu}/Channel.h +0 -0
  164. data/{Gosu → include/Gosu}/Color.h +0 -0
  165. data/{Gosu → include/Gosu}/Color.hpp +0 -0
  166. data/{Gosu → include/Gosu}/Directories.hpp +0 -0
  167. data/{Gosu → include/Gosu}/Font.h +0 -0
  168. data/{Gosu → include/Gosu}/Font.hpp +0 -0
  169. data/{Gosu → include/Gosu}/Fwd.hpp +0 -0
  170. data/{Gosu → include/Gosu}/Gosu.h +3 -0
  171. data/{Gosu → include/Gosu}/Gosu.hpp +0 -0
  172. data/{Gosu → include/Gosu}/Graphics.hpp +0 -0
  173. data/{Gosu → include/Gosu}/GraphicsBase.hpp +0 -0
  174. data/{Gosu → include/Gosu}/IO.hpp +0 -0
  175. data/{Gosu → include/Gosu}/Image.h +0 -0
  176. data/{Gosu → include/Gosu}/Image.hpp +7 -6
  177. data/{Gosu → include/Gosu}/ImageData.hpp +0 -0
  178. data/{Gosu → include/Gosu}/Input.hpp +30 -15
  179. data/{Gosu → include/Gosu}/Inspection.hpp +0 -0
  180. data/{Gosu → include/Gosu}/Math.hpp +0 -0
  181. data/{Gosu → include/Gosu}/Platform.hpp +0 -0
  182. data/{Gosu → include/Gosu}/Sample.h +0 -0
  183. data/{Gosu → include/Gosu}/Song.h +0 -0
  184. data/{Gosu → include/Gosu}/Text.hpp +0 -0
  185. data/{Gosu → include/Gosu}/TextInput.h +0 -0
  186. data/{Gosu → include/Gosu}/TextInput.hpp +0 -0
  187. data/{Gosu → include/Gosu}/Timing.hpp +0 -0
  188. data/{Gosu → include/Gosu}/Utility.hpp +1 -1
  189. data/{Gosu → include/Gosu}/Version.hpp +0 -0
  190. data/{Gosu → include/Gosu}/Window.h +2 -0
  191. data/{Gosu → include/Gosu}/Window.hpp +21 -13
  192. data/lib/OpenAL32.dll +0 -0
  193. data/lib/SDL2.dll +0 -0
  194. data/lib/gosu.rb +0 -3
  195. data/lib/gosu/patches.rb +0 -9
  196. data/lib/gosu/swig_patches.rb +3 -2
  197. data/lib/libmpg123.dll +0 -0
  198. data/lib/libsndfile.dll +0 -0
  199. data/lib64/OpenAL32.dll +0 -0
  200. data/lib64/SDL2.dll +0 -0
  201. data/lib64/libmpg123.dll +0 -0
  202. data/lib64/libsndfile.dll +0 -0
  203. data/rdoc/gosu.rb +95 -20
  204. data/src/Audio.cpp +50 -224
  205. data/src/AudioFile.hpp +17 -37
  206. data/src/AudioFileAudioToolbox.cpp +237 -0
  207. data/src/AudioFileSDLSound.cpp +147 -0
  208. data/src/AudioImpl.cpp +3 -12
  209. data/src/AudioImpl.hpp +3 -1
  210. data/src/Bitmap.cpp +85 -83
  211. data/src/BitmapIO.cpp +52 -58
  212. data/src/Constants.cpp +80 -33
  213. data/src/Font.cpp +3 -1
  214. data/src/GosuWrapper.cpp +19 -0
  215. data/src/Graphics.cpp +7 -4
  216. data/src/Image.cpp +13 -16
  217. data/src/Input.cpp +408 -159
  218. data/src/LargeImageData.cpp +1 -1
  219. data/src/MarkupParser.cpp +2 -1
  220. data/src/RubyGosu.cxx +349 -83
  221. data/src/RubyGosu.h +4 -2
  222. data/src/TexChunk.cpp +1 -1
  223. data/src/TextBuilder.cpp +3 -1
  224. data/src/Texture.cpp +1 -1
  225. data/src/TrueTypeFont.cpp +1 -1
  226. data/src/Utility.cpp +11 -7
  227. data/src/Window.cpp +30 -39
  228. data/src/WindowWrapper.cpp +28 -0
  229. metadata +207 -52
  230. data/Gosu/Bitmap.hpp +0 -113
  231. data/src/AudioToolboxFile.hpp +0 -210
  232. data/src/OggFile.hpp +0 -92
  233. data/src/SndFile.hpp +0 -174
  234. data/src/WinMain.cpp +0 -64
@@ -0,0 +1,382 @@
1
+ /*
2
+ * This source code is public domain.
3
+ *
4
+ * Handles unpacking of Powerpack PP20
5
+ * Authors: Olivier Lapicque <olivierl@jps.net>
6
+ */
7
+
8
+ #include "libmodplug.h"
9
+
10
+ BOOL PP20_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength);
11
+
12
+ typedef struct MMCMPFILEHEADER
13
+ {
14
+ DWORD id_ziRC; // "ziRC"
15
+ DWORD id_ONia; // "ONia"
16
+ WORD hdrsize;
17
+ } MMCMPFILEHEADER, *LPMMCMPFILEHEADER;
18
+
19
+ typedef struct MMCMPHEADER
20
+ {
21
+ WORD version;
22
+ WORD nblocks;
23
+ DWORD filesize;
24
+ DWORD blktable;
25
+ BYTE glb_comp;
26
+ BYTE fmt_comp;
27
+ } MMCMPHEADER, *LPMMCMPHEADER;
28
+
29
+ typedef struct MMCMPBLOCK
30
+ {
31
+ DWORD unpk_size;
32
+ DWORD pk_size;
33
+ DWORD xor_chk;
34
+ WORD sub_blk;
35
+ WORD flags;
36
+ WORD tt_entries;
37
+ USHORT num_bits;
38
+ } MMCMPBLOCK, *LPMMCMPBLOCK;
39
+
40
+ typedef struct MMCMPSUBBLOCK
41
+ {
42
+ DWORD unpk_pos;
43
+ DWORD unpk_size;
44
+ } MMCMPSUBBLOCK, *LPMMCMPSUBBLOCK;
45
+
46
+ #define MMCMP_COMP 0x0001
47
+ #define MMCMP_DELTA 0x0002
48
+ #define MMCMP_16BIT 0x0004
49
+ #define MMCMP_STEREO 0x0100
50
+ #define MMCMP_ABS16 0x0200
51
+ #define MMCMP_ENDIAN 0x0400
52
+
53
+ typedef struct MMCMPBITBUFFER
54
+ {
55
+ UINT bitcount;
56
+ DWORD bitbuffer;
57
+ LPCBYTE pSrc;
58
+ LPCBYTE pEnd;
59
+ } MMCMPBITBUFFER;
60
+
61
+
62
+ static DWORD MMCMPBITBUFFER_GetBits(MMCMPBITBUFFER *_this, UINT nBits)
63
+ //---------------------------------------
64
+ {
65
+ DWORD d;
66
+ if (!nBits) return 0;
67
+ while (_this->bitcount < 24)
68
+ {
69
+ _this->bitbuffer |= ((_this->pSrc < _this->pEnd) ? *_this->pSrc++ : 0) << _this->bitcount;
70
+ _this->bitcount += 8;
71
+ }
72
+ d = _this->bitbuffer & ((1 << nBits) - 1);
73
+ _this->bitbuffer >>= nBits;
74
+ _this->bitcount -= nBits;
75
+ return d;
76
+ }
77
+
78
+ const DWORD MMCMP8BitCommands[8] =
79
+ {
80
+ 0x01, 0x03, 0x07, 0x0F, 0x1E, 0x3C, 0x78, 0xF8
81
+ };
82
+
83
+ const UINT MMCMP8BitFetch[8] =
84
+ {
85
+ 3, 3, 3, 3, 2, 1, 0, 0
86
+ };
87
+
88
+ const DWORD MMCMP16BitCommands[16] =
89
+ {
90
+ 0x01, 0x03, 0x07, 0x0F, 0x1E, 0x3C, 0x78, 0xF0,
91
+ 0x1F0, 0x3F0, 0x7F0, 0xFF0, 0x1FF0, 0x3FF0, 0x7FF0, 0xFFF0
92
+ };
93
+
94
+ const UINT MMCMP16BitFetch[16] =
95
+ {
96
+ 4, 4, 4, 4, 3, 2, 1, 0,
97
+ 0, 0, 0, 0, 0, 0, 0, 0
98
+ };
99
+
100
+
101
+ BOOL MMCMP_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength)
102
+ //---------------------------------------------------------
103
+ {
104
+ DWORD dwMemLength = *pdwMemLength;
105
+ LPCBYTE lpMemFile = *ppMemFile;
106
+ LPBYTE pBuffer;
107
+ LPMMCMPFILEHEADER pmfh = (LPMMCMPFILEHEADER)(lpMemFile);
108
+ LPMMCMPHEADER pmmh = (LPMMCMPHEADER)(lpMemFile+10);
109
+ LPDWORD pblk_table;
110
+ DWORD dwFileSize;
111
+
112
+ if (PP20_Unpack(ppMemFile, pdwMemLength))
113
+ {
114
+ return TRUE;
115
+ }
116
+ if ((dwMemLength < 256) || (!pmfh) || (pmfh->id_ziRC != 0x4352697A) || (pmfh->id_ONia != 0x61694e4f) || (pmfh->hdrsize < 14)
117
+ || (!pmmh->nblocks) || (pmmh->filesize < 16) || (pmmh->filesize > 0x8000000)
118
+ || (pmmh->blktable >= dwMemLength) || (pmmh->blktable + 4*pmmh->nblocks > dwMemLength)) return FALSE;
119
+ dwFileSize = pmmh->filesize;
120
+ if ((pBuffer = (LPBYTE)GlobalAllocPtr(GHND, (dwFileSize + 31) & ~15)) == NULL) return FALSE;
121
+ pblk_table = (LPDWORD)(lpMemFile+pmmh->blktable);
122
+ for (UINT nBlock=0; nBlock<pmmh->nblocks; nBlock++)
123
+ {
124
+ DWORD dwMemPos = pblk_table[nBlock];
125
+ LPMMCMPBLOCK pblk = (LPMMCMPBLOCK)(lpMemFile+dwMemPos);
126
+ LPMMCMPSUBBLOCK psubblk = (LPMMCMPSUBBLOCK)(lpMemFile+dwMemPos+20);
127
+
128
+ if ((dwMemPos + 20 >= dwMemLength) || (dwMemPos + 20 + pblk->sub_blk*8 >= dwMemLength)) break;
129
+ dwMemPos += 20 + pblk->sub_blk*8;
130
+ // Data is not packed
131
+ if (!(pblk->flags & MMCMP_COMP))
132
+ {
133
+ for (UINT i=0; i<pblk->sub_blk; i++)
134
+ {
135
+ if ((psubblk->unpk_pos >= dwFileSize) ||
136
+ (psubblk->unpk_size >= dwFileSize) ||
137
+ (psubblk->unpk_size > dwFileSize - psubblk->unpk_pos)) break;
138
+ SDL_memcpy(pBuffer+psubblk->unpk_pos, lpMemFile+dwMemPos, psubblk->unpk_size);
139
+ dwMemPos += psubblk->unpk_size;
140
+ psubblk++;
141
+ }
142
+ } else
143
+ // Data is 16-bit packed
144
+ if (pblk->flags & MMCMP_16BIT && pblk->num_bits < 16)
145
+ {
146
+ MMCMPBITBUFFER bb;
147
+ LPWORD pDest = (LPWORD)(pBuffer + psubblk->unpk_pos);
148
+ DWORD dwSize = psubblk->unpk_size >> 1;
149
+ DWORD dwPos = 0;
150
+ UINT numbits = pblk->num_bits;
151
+ UINT subblk = 0, oldval = 0;
152
+ bb.bitcount = 0;
153
+ bb.bitbuffer = 0;
154
+ bb.pSrc = lpMemFile+dwMemPos+pblk->tt_entries;
155
+ bb.pEnd = lpMemFile+dwMemPos+pblk->pk_size;
156
+ while (subblk < pblk->sub_blk)
157
+ {
158
+ UINT newval = 0x10000;
159
+ DWORD d = MMCMPBITBUFFER_GetBits(&bb, numbits+1);
160
+
161
+ if (d >= MMCMP16BitCommands[numbits])
162
+ {
163
+ UINT nFetch = MMCMP16BitFetch[numbits];
164
+ UINT newbits = MMCMPBITBUFFER_GetBits(&bb, nFetch) + ((d - MMCMP16BitCommands[numbits]) << nFetch);
165
+ if (newbits != numbits)
166
+ {
167
+ numbits = newbits & 0x0F;
168
+ } else
169
+ {
170
+ if ((d = MMCMPBITBUFFER_GetBits(&bb, 4)) == 0x0F)
171
+ {
172
+ if (MMCMPBITBUFFER_GetBits(&bb, 1)) break;
173
+ newval = 0xFFFF;
174
+ } else
175
+ {
176
+ newval = 0xFFF0 + d;
177
+ }
178
+ }
179
+ } else
180
+ {
181
+ newval = d;
182
+ }
183
+ if (newval < 0x10000)
184
+ {
185
+ newval = (newval & 1) ? (UINT)(-(LONG)((newval+1) >> 1)) : (UINT)(newval >> 1);
186
+ if (pblk->flags & MMCMP_DELTA)
187
+ {
188
+ newval += oldval;
189
+ oldval = newval;
190
+ } else
191
+ if (!(pblk->flags & MMCMP_ABS16))
192
+ {
193
+ newval ^= 0x8000;
194
+ }
195
+ pDest[dwPos++] = (WORD)newval;
196
+ }
197
+ if (dwPos >= dwSize)
198
+ {
199
+ subblk++;
200
+ dwPos = 0;
201
+ dwSize = psubblk[subblk].unpk_size >> 1;
202
+ pDest = (LPWORD)(pBuffer + psubblk[subblk].unpk_pos);
203
+ }
204
+ }
205
+ } else if (pblk->num_bits < 8)
206
+ // Data is 8-bit packed
207
+ {
208
+ MMCMPBITBUFFER bb;
209
+ LPBYTE pDest = pBuffer + psubblk->unpk_pos;
210
+ DWORD dwSize = psubblk->unpk_size;
211
+ DWORD dwPos = 0;
212
+ UINT numbits = pblk->num_bits;
213
+ UINT subblk = 0, oldval = 0;
214
+ LPCBYTE ptable = lpMemFile+dwMemPos;
215
+
216
+ bb.bitcount = 0;
217
+ bb.bitbuffer = 0;
218
+ bb.pSrc = lpMemFile+dwMemPos+pblk->tt_entries;
219
+ bb.pEnd = lpMemFile+dwMemPos+pblk->pk_size;
220
+ while (subblk < pblk->sub_blk)
221
+ {
222
+ UINT newval = 0x100;
223
+ DWORD d = MMCMPBITBUFFER_GetBits(&bb, numbits+1);
224
+
225
+ if (d >= MMCMP8BitCommands[numbits])
226
+ {
227
+ UINT nFetch = MMCMP8BitFetch[numbits];
228
+ UINT newbits = MMCMPBITBUFFER_GetBits(&bb, nFetch) + ((d - MMCMP8BitCommands[numbits]) << nFetch);
229
+ if (newbits != numbits)
230
+ {
231
+ numbits = newbits & 0x07;
232
+ } else
233
+ {
234
+ if ((d = MMCMPBITBUFFER_GetBits(&bb, 3)) == 7)
235
+ {
236
+ if (MMCMPBITBUFFER_GetBits(&bb, 1)) break;
237
+ newval = 0xFF;
238
+ } else
239
+ {
240
+ newval = 0xF8 + d;
241
+ }
242
+ }
243
+ } else
244
+ {
245
+ newval = d;
246
+ }
247
+ if (newval < 0x100)
248
+ {
249
+ int n = ptable[newval];
250
+ if (pblk->flags & MMCMP_DELTA)
251
+ {
252
+ n += oldval;
253
+ oldval = n;
254
+ }
255
+ pDest[dwPos++] = (BYTE)n;
256
+ }
257
+ if (dwPos >= dwSize)
258
+ {
259
+ subblk++;
260
+ dwPos = 0;
261
+ dwSize = psubblk[subblk].unpk_size;
262
+ pDest = pBuffer + psubblk[subblk].unpk_pos;
263
+ }
264
+ }
265
+ } else
266
+ {
267
+ return FALSE;
268
+ }
269
+ }
270
+ *ppMemFile = pBuffer;
271
+ *pdwMemLength = dwFileSize;
272
+ return TRUE;
273
+ }
274
+
275
+
276
+ //////////////////////////////////////////////////////////////////////////////
277
+ //
278
+ // PowerPack PP20 Unpacker
279
+ //
280
+
281
+ typedef struct _PPBITBUFFER
282
+ {
283
+ UINT bitcount;
284
+ ULONG bitbuffer;
285
+ LPCBYTE pStart;
286
+ LPCBYTE pSrc;
287
+ } PPBITBUFFER;
288
+
289
+
290
+ static ULONG PPBITBUFFER_GetBits(PPBITBUFFER *_this, UINT n)
291
+ {
292
+ ULONG result = 0;
293
+
294
+ for (UINT i=0; i<n; i++)
295
+ {
296
+ if (!_this->bitcount)
297
+ {
298
+ _this->bitcount = 8;
299
+ if (_this->pSrc != _this->pStart) _this->pSrc--;
300
+ _this->bitbuffer = *_this->pSrc;
301
+ }
302
+ result = (result<<1) | (_this->bitbuffer&1);
303
+ _this->bitbuffer >>= 1;
304
+ _this->bitcount--;
305
+ }
306
+ return result;
307
+ }
308
+
309
+
310
+ VOID PP20_DoUnpack(const BYTE *pSrc, UINT nSrcLen, BYTE *pDst, UINT nDstLen)
311
+ {
312
+ PPBITBUFFER BitBuffer;
313
+ ULONG nBytesLeft;
314
+
315
+ BitBuffer.pStart = pSrc;
316
+ BitBuffer.pSrc = pSrc + nSrcLen - 4;
317
+ BitBuffer.bitbuffer = 0;
318
+ BitBuffer.bitcount = 0;
319
+ PPBITBUFFER_GetBits(&BitBuffer, pSrc[nSrcLen-1]);
320
+ nBytesLeft = nDstLen;
321
+ while (nBytesLeft > 0)
322
+ {
323
+ if (!PPBITBUFFER_GetBits(&BitBuffer, 1))
324
+ {
325
+ UINT n = 1;
326
+ while (n < nBytesLeft)
327
+ {
328
+ UINT code = PPBITBUFFER_GetBits(&BitBuffer, 2);
329
+ n += code;
330
+ if (code != 3) break;
331
+ }
332
+ for (UINT i=0; i<n; i++)
333
+ {
334
+ pDst[--nBytesLeft] = (BYTE)PPBITBUFFER_GetBits(&BitBuffer, 8);
335
+ }
336
+ if (!nBytesLeft) break;
337
+ }
338
+ {
339
+ UINT n = PPBITBUFFER_GetBits(&BitBuffer, 2)+1;
340
+ UINT nbits = pSrc[n-1];
341
+ UINT nofs;
342
+ if (n==4)
343
+ {
344
+ nofs = PPBITBUFFER_GetBits(&BitBuffer, (PPBITBUFFER_GetBits(&BitBuffer, 1)) ? nbits : 7 );
345
+ while (n < nBytesLeft)
346
+ {
347
+ UINT code = PPBITBUFFER_GetBits(&BitBuffer, 3);
348
+ n += code;
349
+ if (code != 7) break;
350
+ }
351
+ } else
352
+ {
353
+ nofs = PPBITBUFFER_GetBits(&BitBuffer, nbits);
354
+ }
355
+ for (UINT i=0; i<=n; i++)
356
+ {
357
+ pDst[nBytesLeft-1] = (nBytesLeft+nofs < nDstLen) ? pDst[nBytesLeft+nofs] : 0;
358
+ if (!--nBytesLeft) break;
359
+ }
360
+ }
361
+ }
362
+ }
363
+
364
+
365
+ BOOL PP20_Unpack(LPCBYTE *ppMemFile, LPDWORD pdwMemLength)
366
+ {
367
+ DWORD dwMemLength = *pdwMemLength;
368
+ LPCBYTE lpMemFile = *ppMemFile;
369
+ DWORD dwDstLen;
370
+ LPBYTE pBuffer;
371
+
372
+ if ((!lpMemFile) || (dwMemLength < 256) || (*(DWORD *)lpMemFile != 0x30325050)) return FALSE;
373
+ dwDstLen = (lpMemFile[dwMemLength-4]<<16) | (lpMemFile[dwMemLength-3]<<8) | (lpMemFile[dwMemLength-2]);
374
+ //Log("PP20 detected: Packed length=%d, Unpacked length=%d\n", dwMemLength, dwDstLen);
375
+ if ((dwDstLen < 512) || (dwDstLen > 0x400000) || (dwDstLen > 16*dwMemLength)) return FALSE;
376
+ if ((pBuffer = (LPBYTE)GlobalAllocPtr(GHND, (dwDstLen + 31) & ~15)) == NULL) return FALSE;
377
+ PP20_DoUnpack(lpMemFile+4, dwMemLength-4, pBuffer, dwDstLen);
378
+ *ppMemFile = pBuffer;
379
+ *pdwMemLength = dwDstLen;
380
+ return TRUE;
381
+ }
382
+
@@ -0,0 +1,170 @@
1
+ /*
2
+ * This source code is public domain.
3
+ *
4
+ * Authors: Kenton Varda <temporal@gauge3d.org> (C interface wrapper)
5
+ */
6
+
7
+ #include "modplug.h"
8
+ #include "libmodplug.h"
9
+
10
+ void ModPlug_Quit(void) { /* does nothing. */ }
11
+
12
+ int ModPlug_Init(void)
13
+ {
14
+ extern void init_modplug_filters(void);
15
+ init_modplug_filters();
16
+ return 1;
17
+ }
18
+
19
+ ModPlugFile* ModPlug_Load(const void* data, int size, const ModPlug_Settings *settings)
20
+ {
21
+ return (ModPlugFile *) new_CSoundFile((const BYTE*)data, size, settings);
22
+ }
23
+
24
+ void ModPlug_Unload(ModPlugFile* file)
25
+ {
26
+ delete_CSoundFile((CSoundFile *) file);
27
+ }
28
+
29
+ int ModPlug_Read(ModPlugFile* file, void* buffer, int size)
30
+ {
31
+ CSoundFile *sndfile = (CSoundFile *) file;
32
+ return CSoundFile_Read(sndfile, buffer, size) * sndfile->gSampleSize;
33
+ }
34
+
35
+ int ModPlug_GetLength(ModPlugFile* file)
36
+ {
37
+ return CSoundFile_GetLength((CSoundFile *) file, FALSE, TRUE) * 1000;
38
+ }
39
+
40
+ void ModPlug_Seek(ModPlugFile* file, int millisecond)
41
+ {
42
+ int maxpos;
43
+ int maxtime = CSoundFile_GetLength((CSoundFile *) file, FALSE, TRUE) * 1000;
44
+ float postime;
45
+
46
+ if(millisecond > maxtime)
47
+ millisecond = maxtime;
48
+ maxpos = CSoundFile_GetMaxPosition((CSoundFile *) file);
49
+ postime = 0.0f;
50
+ if (maxtime != 0.0f)
51
+ postime = (float)maxpos / (float)maxtime;
52
+
53
+ CSoundFile_SetCurrentPos((CSoundFile *) file, (int)(millisecond * postime));
54
+ }
55
+
56
+ // inefficient, but oh well.
57
+ char *rwops_fgets(char *buf, int buflen, SDL_RWops *rwops)
58
+ {
59
+ char *retval = buf;
60
+ if (!buflen) return buf;
61
+ while (buflen > 1) {
62
+ char ch;
63
+ if (SDL_RWread(rwops, &ch, 1, 1) != 1) {
64
+ break;
65
+ }
66
+ *(buf++) = ch;
67
+ buflen--;
68
+ if (ch == '\n') {
69
+ break;
70
+ }
71
+ }
72
+ *(buf) = '\0';
73
+ return retval;
74
+ }
75
+
76
+ long mmftell(MMFILE *mmfile)
77
+ {
78
+ return mmfile->pos;
79
+ }
80
+
81
+ void mmfseek(MMFILE *mmfile, long p, int whence)
82
+ {
83
+ int newpos = mmfile->pos;
84
+ switch(whence) {
85
+ case SEEK_SET:
86
+ newpos = p;
87
+ break;
88
+ case SEEK_CUR:
89
+ newpos += p;
90
+ break;
91
+ case SEEK_END:
92
+ newpos = mmfile->sz + p;
93
+ break;
94
+ }
95
+ if (newpos < mmfile->sz)
96
+ mmfile->pos = newpos;
97
+ else {
98
+ mmfile->error = 1;
99
+ // printf("WARNING: seeking too far\n");
100
+ }
101
+ }
102
+
103
+ void mmreadUBYTES(BYTE *buf, long sz, MMFILE *mmfile)
104
+ {
105
+ int sztr = sz;
106
+ // do not overread.
107
+ if (sz > mmfile->sz - mmfile->pos)
108
+ sztr = mmfile->sz - mmfile->pos;
109
+ SDL_memcpy(buf, &mmfile->mm[mmfile->pos], sztr);
110
+ mmfile->pos += sz;
111
+ // if truncated read, populate the rest of the array with zeros.
112
+ if (sz > sztr)
113
+ SDL_memset(buf+sztr, 0, sz-sztr);
114
+ }
115
+
116
+ void mmreadSBYTES(char *buf, long sz, MMFILE *mmfile)
117
+ {
118
+ // do not overread.
119
+ if (sz > mmfile->sz - mmfile->pos)
120
+ sz = mmfile->sz - mmfile->pos;
121
+ SDL_memcpy(buf, &mmfile->mm[mmfile->pos], sz);
122
+ mmfile->pos += sz;
123
+ }
124
+
125
+ BYTE mmreadUBYTE(MMFILE *mmfile)
126
+ {
127
+ BYTE b;
128
+ b = (BYTE)mmfile->mm[mmfile->pos];
129
+ mmfile->pos++;
130
+ return b;
131
+ }
132
+
133
+ void mmfclose(MMFILE *mmfile)
134
+ {
135
+ SDL_free(mmfile);
136
+ }
137
+
138
+ int mmfeof(MMFILE *mmfile)
139
+ {
140
+ if( mmfile->pos < 0 ) return TRUE;
141
+ if( mmfile->pos < mmfile->sz ) return FALSE;
142
+ return TRUE;
143
+ }
144
+
145
+ int mmfgetc(MMFILE *mmfile)
146
+ {
147
+ int b = EOF;
148
+ if( mmfeof(mmfile) ) return EOF;
149
+ b = mmfile->mm[mmfile->pos];
150
+ mmfile->pos++;
151
+ if( b=='\r' && !mmfeof(mmfile) && mmfile->mm[mmfile->pos] == '\n' ) {
152
+ b = '\n';
153
+ mmfile->pos++;
154
+ }
155
+ return b;
156
+ }
157
+
158
+ void mmfgets(char buf[], unsigned int bufsz, MMFILE *mmfile)
159
+ {
160
+ int i = 0;
161
+ int b;
162
+ for( i=0; i<(int)bufsz-1; i++ ) {
163
+ b = mmfgetc(mmfile);
164
+ if( b==EOF ) break;
165
+ buf[i] = b;
166
+ if( b == '\n' ) break;
167
+ }
168
+ buf[i] = '\0';
169
+ }
170
+