diff options
author | Michiel Van Der Kolk <not.valid@email.address> | 2005-03-17 20:50:03 +0000 |
---|---|---|
committer | Michiel Van Der Kolk <not.valid@email.address> | 2005-03-17 20:50:03 +0000 |
commit | 27be5bc72855a0fbbdae230bc144624c9eb85f5e (patch) | |
tree | b553f1321df924c4b744ffcab48dce5f4f081f7d /apps/codecs/dumb/src/allegro | |
parent | 7e7662bb716917ca431204f0113d400c1014f2e8 (diff) | |
download | rockbox-27be5bc72855a0fbbdae230bc144624c9eb85f5e.tar.gz rockbox-27be5bc72855a0fbbdae230bc144624c9eb85f5e.zip |
Initial check in dumb 0.9.2 - has a few usages of floating point that should
be rewritten to fixed point. seems to compile cleanly for iriver.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6197 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/dumb/src/allegro')
-rw-r--r-- | apps/codecs/dumb/src/allegro/alplay.c | 270 | ||||
-rw-r--r-- | apps/codecs/dumb/src/allegro/datduh.c | 60 | ||||
-rw-r--r-- | apps/codecs/dumb/src/allegro/datit.c | 62 | ||||
-rw-r--r-- | apps/codecs/dumb/src/allegro/datmod.c | 61 | ||||
-rw-r--r-- | apps/codecs/dumb/src/allegro/dats3m.c | 61 | ||||
-rw-r--r-- | apps/codecs/dumb/src/allegro/datunld.c | 31 | ||||
-rw-r--r-- | apps/codecs/dumb/src/allegro/datxm.c | 62 | ||||
-rw-r--r-- | apps/codecs/dumb/src/allegro/packfile.c | 98 |
8 files changed, 705 insertions, 0 deletions
diff --git a/apps/codecs/dumb/src/allegro/alplay.c b/apps/codecs/dumb/src/allegro/alplay.c new file mode 100644 index 0000000000..983bde105b --- /dev/null +++ b/apps/codecs/dumb/src/allegro/alplay.c | |||
@@ -0,0 +1,270 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * alplay.c - Functions to play a DUH through / / \ \ | ||
12 | * an Allegro audio stream. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By entheh. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | #include <stdlib.h> | ||
21 | |||
22 | #include <allegro.h> | ||
23 | |||
24 | #include "aldumb.h" | ||
25 | |||
26 | |||
27 | |||
28 | #define ADP_PLAYING 1 | ||
29 | |||
30 | struct AL_DUH_PLAYER | ||
31 | { | ||
32 | int flags; | ||
33 | long bufsize; | ||
34 | int freq; | ||
35 | AUDIOSTREAM *stream; | ||
36 | DUH_SIGRENDERER *sigrenderer; /* If this is NULL, stream is invalid. */ | ||
37 | float volume; | ||
38 | int silentcount; | ||
39 | }; | ||
40 | |||
41 | |||
42 | |||
43 | AL_DUH_PLAYER *al_start_duh(DUH *duh, int n_channels, long pos, float volume, long bufsize, int freq) | ||
44 | { | ||
45 | AL_DUH_PLAYER *dp; | ||
46 | |||
47 | /* This restriction is imposed by Allegro. */ | ||
48 | ASSERT(n_channels > 0); | ||
49 | ASSERT(n_channels <= 2); | ||
50 | |||
51 | if (!duh) | ||
52 | return NULL; | ||
53 | |||
54 | dp = malloc(sizeof(*dp)); | ||
55 | if (!dp) | ||
56 | return NULL; | ||
57 | |||
58 | dp->flags = ADP_PLAYING; | ||
59 | dp->bufsize = bufsize; | ||
60 | dp->freq = freq; | ||
61 | |||
62 | dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128); | ||
63 | |||
64 | if (!dp->stream) { | ||
65 | free(dp); | ||
66 | return NULL; | ||
67 | } | ||
68 | |||
69 | voice_set_priority(dp->stream->voice, 255); | ||
70 | |||
71 | dp->sigrenderer = duh_start_sigrenderer(duh, 0, n_channels, pos); | ||
72 | |||
73 | if (!dp->sigrenderer) { | ||
74 | stop_audio_stream(dp->stream); | ||
75 | free(dp); | ||
76 | return NULL; | ||
77 | } | ||
78 | |||
79 | dp->volume = volume; | ||
80 | dp->silentcount = 0; | ||
81 | |||
82 | return dp; | ||
83 | } | ||
84 | |||
85 | |||
86 | |||
87 | void al_stop_duh(AL_DUH_PLAYER *dp) | ||
88 | { | ||
89 | if (dp) { | ||
90 | if (dp->sigrenderer) { | ||
91 | duh_end_sigrenderer(dp->sigrenderer); | ||
92 | stop_audio_stream(dp->stream); | ||
93 | } | ||
94 | free(dp); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | |||
99 | |||
100 | void al_pause_duh(AL_DUH_PLAYER *dp) | ||
101 | { | ||
102 | if (dp && dp->sigrenderer && (dp->flags & ADP_PLAYING)) { | ||
103 | voice_stop(dp->stream->voice); | ||
104 | dp->flags &= ~ADP_PLAYING; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | |||
109 | |||
110 | void al_resume_duh(AL_DUH_PLAYER *dp) | ||
111 | { | ||
112 | if (dp && dp->sigrenderer && !(dp->flags & ADP_PLAYING)) { | ||
113 | voice_start(dp->stream->voice); | ||
114 | dp->flags |= ADP_PLAYING; | ||
115 | } | ||
116 | } | ||
117 | |||
118 | |||
119 | |||
120 | void al_duh_set_priority(AL_DUH_PLAYER *dp, int priority) | ||
121 | { | ||
122 | if (dp && dp->sigrenderer) | ||
123 | voice_set_priority(dp->stream->voice, priority); | ||
124 | } | ||
125 | |||
126 | |||
127 | |||
128 | void al_duh_set_volume(AL_DUH_PLAYER *dp, float volume) | ||
129 | { | ||
130 | if (dp) | ||
131 | dp->volume = volume; | ||
132 | } | ||
133 | |||
134 | |||
135 | |||
136 | int al_poll_duh(AL_DUH_PLAYER *dp) | ||
137 | { | ||
138 | unsigned short *sptr; | ||
139 | long n; | ||
140 | long size; | ||
141 | int n_channels; | ||
142 | |||
143 | if (!dp || !dp->sigrenderer) | ||
144 | return 1; | ||
145 | |||
146 | if (!(dp->flags & ADP_PLAYING)) | ||
147 | return 0; | ||
148 | |||
149 | sptr = get_audio_stream_buffer(dp->stream); | ||
150 | |||
151 | if (!sptr) | ||
152 | return 0; | ||
153 | |||
154 | n = duh_render(dp->sigrenderer, 16, 1, dp->volume, 65536.0 / dp->freq, dp->bufsize, sptr); | ||
155 | |||
156 | if (n == 0) { | ||
157 | if (++dp->silentcount >= 2) { | ||
158 | duh_end_sigrenderer(dp->sigrenderer); | ||
159 | free_audio_stream_buffer(dp->stream); | ||
160 | stop_audio_stream(dp->stream); | ||
161 | dp->sigrenderer = NULL; | ||
162 | return 1; | ||
163 | } | ||
164 | } | ||
165 | |||
166 | n_channels = duh_sigrenderer_get_n_channels(dp->sigrenderer); | ||
167 | n *= n_channels; | ||
168 | size = dp->bufsize * n_channels; | ||
169 | for (; n < size; n++) | ||
170 | sptr[n] = 0x8000; | ||
171 | |||
172 | free_audio_stream_buffer(dp->stream); | ||
173 | |||
174 | return 0; | ||
175 | } | ||
176 | |||
177 | |||
178 | |||
179 | long al_duh_get_position(AL_DUH_PLAYER *dp) | ||
180 | { | ||
181 | return dp ? duh_sigrenderer_get_position(dp->sigrenderer) : -1; | ||
182 | } | ||
183 | |||
184 | |||
185 | |||
186 | AL_DUH_PLAYER *al_duh_encapsulate_sigrenderer(DUH_SIGRENDERER *sigrenderer, float volume, long bufsize, int freq) | ||
187 | { | ||
188 | AL_DUH_PLAYER *dp; | ||
189 | int n_channels; | ||
190 | |||
191 | if (!sigrenderer) | ||
192 | return NULL; | ||
193 | |||
194 | dp = malloc(sizeof(*dp)); | ||
195 | if (!dp) | ||
196 | return NULL; | ||
197 | |||
198 | n_channels = duh_sigrenderer_get_n_channels(sigrenderer); | ||
199 | |||
200 | /* This restriction is imposed by Allegro. */ | ||
201 | ASSERT(n_channels > 0); | ||
202 | ASSERT(n_channels <= 2); | ||
203 | |||
204 | dp->flags = ADP_PLAYING; | ||
205 | dp->bufsize = bufsize; | ||
206 | dp->freq = freq; | ||
207 | |||
208 | dp->stream = play_audio_stream(bufsize, 16, n_channels - 1, freq, 255, 128); | ||
209 | |||
210 | if (!dp->stream) { | ||
211 | free(dp); | ||
212 | return NULL; | ||
213 | } | ||
214 | |||
215 | voice_set_priority(dp->stream->voice, 255); | ||
216 | |||
217 | dp->sigrenderer = sigrenderer; | ||
218 | |||
219 | dp->volume = volume; | ||
220 | dp->silentcount = 0; | ||
221 | |||
222 | return dp; | ||
223 | } | ||
224 | |||
225 | |||
226 | |||
227 | DUH_SIGRENDERER *al_duh_get_sigrenderer(AL_DUH_PLAYER *dp) | ||
228 | { | ||
229 | return dp ? dp->sigrenderer : NULL; | ||
230 | } | ||
231 | |||
232 | |||
233 | |||
234 | /* IMPORTANT: This function will return NULL if the music has ended. */ | ||
235 | // Should this be changed? User might want to hack the underlying SIGRENDERER | ||
236 | // and resurrect it (e.g. change pattern number), before it gets destroyed... | ||
237 | DUH_SIGRENDERER *al_duh_decompose_to_sigrenderer(AL_DUH_PLAYER *dp) | ||
238 | { | ||
239 | if (dp) { | ||
240 | DUH_SIGRENDERER *sigrenderer = dp->sigrenderer; | ||
241 | if (sigrenderer) stop_audio_stream(dp->stream); | ||
242 | free(dp); | ||
243 | return sigrenderer; | ||
244 | } | ||
245 | return NULL; | ||
246 | } | ||
247 | |||
248 | |||
249 | |||
250 | /* DEPRECATED */ | ||
251 | AL_DUH_PLAYER *al_duh_encapsulate_renderer(DUH_SIGRENDERER *dr, float volume, long bufsize, int freq) | ||
252 | { | ||
253 | return al_duh_encapsulate_sigrenderer(dr, volume, bufsize, freq); | ||
254 | } | ||
255 | |||
256 | |||
257 | |||
258 | /* DEPRECATED */ | ||
259 | DUH_SIGRENDERER *al_duh_get_renderer(AL_DUH_PLAYER *dp) | ||
260 | { | ||
261 | return al_duh_get_sigrenderer(dp); | ||
262 | } | ||
263 | |||
264 | |||
265 | |||
266 | /* DEPRECATED */ | ||
267 | DUH_SIGRENDERER *al_duh_decompose_to_renderer(AL_DUH_PLAYER *dp) | ||
268 | { | ||
269 | return al_duh_decompose_to_sigrenderer(dp); | ||
270 | } | ||
diff --git a/apps/codecs/dumb/src/allegro/datduh.c b/apps/codecs/dumb/src/allegro/datduh.c new file mode 100644 index 0000000000..672e3c820c --- /dev/null +++ b/apps/codecs/dumb/src/allegro/datduh.c | |||
@@ -0,0 +1,60 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * datduh.c - Integration with Allegro's / / \ \ | ||
12 | * datafiles. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By entheh. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | #include <allegro.h> | ||
21 | |||
22 | #include "aldumb.h" | ||
23 | #include "internal/aldumb.h" | ||
24 | |||
25 | |||
26 | |||
27 | static void *dat_read_duh(PACKFILE *f, long size) | ||
28 | { | ||
29 | DUMBFILE *df; | ||
30 | DUH *duh; | ||
31 | |||
32 | (void)size; | ||
33 | |||
34 | df = dumbfile_open_packfile(f); | ||
35 | |||
36 | if (!df) | ||
37 | return NULL; | ||
38 | |||
39 | duh = read_duh(df); | ||
40 | |||
41 | dumbfile_close(df); | ||
42 | |||
43 | return duh; | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | /* dumb_register_dat_duh(): tells Allegro about the DUH datafile object. If | ||
49 | * you intend to load a datafile containing a DUH object, you must call this | ||
50 | * function first. It is recommended you pass DAT_DUH, but you may have a | ||
51 | * reason to use a different type (apart from pride, that doesn't count). | ||
52 | */ | ||
53 | void dumb_register_dat_duh(long type) | ||
54 | { | ||
55 | register_datafile_object( | ||
56 | type, | ||
57 | &dat_read_duh, | ||
58 | &_dat_unload_duh | ||
59 | ); | ||
60 | } | ||
diff --git a/apps/codecs/dumb/src/allegro/datit.c b/apps/codecs/dumb/src/allegro/datit.c new file mode 100644 index 0000000000..8f58f14234 --- /dev/null +++ b/apps/codecs/dumb/src/allegro/datit.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * datit.c - Integration of IT files with / / \ \ | ||
12 | * Allegro's datafiles. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By entheh. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | #include <allegro.h> | ||
21 | |||
22 | #include "aldumb.h" | ||
23 | #include "internal/aldumb.h" | ||
24 | |||
25 | |||
26 | |||
27 | static void *dat_read_it(PACKFILE *f, long size) | ||
28 | { | ||
29 | DUMBFILE *df; | ||
30 | DUH *duh; | ||
31 | |||
32 | (void)size; | ||
33 | |||
34 | df = dumbfile_open_packfile(f); | ||
35 | |||
36 | if (!df) | ||
37 | return NULL; | ||
38 | |||
39 | duh = dumb_read_it(df); | ||
40 | |||
41 | dumbfile_close(df); | ||
42 | |||
43 | return duh; | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | /* dumb_register_dat_it(): tells Allegro about the IT datafile object. If you | ||
49 | * intend to load a datafile containing an IT object, you must call this | ||
50 | * function first. It is recommended you pass DUMB_DAT_IT, but you may have a | ||
51 | * reason to use a different type (perhaps you already have a datafile with | ||
52 | * IT files in and they use a different type). | ||
53 | */ | ||
54 | void dumb_register_dat_it(long type) | ||
55 | { | ||
56 | register_datafile_object( | ||
57 | type, | ||
58 | &dat_read_it, | ||
59 | &_dat_unload_duh | ||
60 | ); | ||
61 | } | ||
62 | |||
diff --git a/apps/codecs/dumb/src/allegro/datmod.c b/apps/codecs/dumb/src/allegro/datmod.c new file mode 100644 index 0000000000..850b17b444 --- /dev/null +++ b/apps/codecs/dumb/src/allegro/datmod.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * datmod.c - Integration of MOD files with / / \ \ | ||
12 | * Allegro's datafiles. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By entheh. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | #include <allegro.h> | ||
21 | |||
22 | #include "aldumb.h" | ||
23 | #include "internal/aldumb.h" | ||
24 | |||
25 | |||
26 | |||
27 | static void *dat_read_mod(PACKFILE *f, long size) | ||
28 | { | ||
29 | DUMBFILE *df; | ||
30 | DUH *duh; | ||
31 | |||
32 | (void)size; | ||
33 | |||
34 | df = dumbfile_open_packfile(f); | ||
35 | |||
36 | if (!df) | ||
37 | return NULL; | ||
38 | |||
39 | duh = dumb_read_mod(df); | ||
40 | |||
41 | dumbfile_close(df); | ||
42 | |||
43 | return duh; | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | /* dumb_register_dat_mod(): tells Allegro about the MOD datafile object. If | ||
49 | * you intend to load a datafile containing a MOD object, you must call this | ||
50 | * function first. It is recommended you pass DUMB_DAT_MOD, but you may have | ||
51 | * a reason to use a different type (perhaps you already have a datafile with | ||
52 | * MOD files in and they use a different type). | ||
53 | */ | ||
54 | void dumb_register_dat_mod(long type) | ||
55 | { | ||
56 | register_datafile_object( | ||
57 | type, | ||
58 | &dat_read_mod, | ||
59 | &_dat_unload_duh | ||
60 | ); | ||
61 | } | ||
diff --git a/apps/codecs/dumb/src/allegro/dats3m.c b/apps/codecs/dumb/src/allegro/dats3m.c new file mode 100644 index 0000000000..a0fc74420e --- /dev/null +++ b/apps/codecs/dumb/src/allegro/dats3m.c | |||
@@ -0,0 +1,61 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * dats3m.c - Integration of S3M files with / / \ \ | ||
12 | * Allegro's datafiles. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By entheh. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | #include <allegro.h> | ||
21 | |||
22 | #include "aldumb.h" | ||
23 | #include "internal/aldumb.h" | ||
24 | |||
25 | |||
26 | |||
27 | static void *dat_read_s3m(PACKFILE *f, long size) | ||
28 | { | ||
29 | DUMBFILE *df; | ||
30 | DUH *duh; | ||
31 | |||
32 | (void)size; | ||
33 | |||
34 | df = dumbfile_open_packfile(f); | ||
35 | |||
36 | if (!df) | ||
37 | return NULL; | ||
38 | |||
39 | duh = dumb_read_s3m(df); | ||
40 | |||
41 | dumbfile_close(df); | ||
42 | |||
43 | return duh; | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | /* dumb_register_dat_s3m(): tells Allegro about the S3M datafile object. If | ||
49 | * you intend to load a datafile containing an S3M object, you must call this | ||
50 | * function first. It is recommended you pass DUMB_DAT_S3M, but you may have | ||
51 | * a reason to use a different type (perhaps you already have a datafile with | ||
52 | * S3M files in and they use a different type). | ||
53 | */ | ||
54 | void dumb_register_dat_s3m(long type) | ||
55 | { | ||
56 | register_datafile_object( | ||
57 | type, | ||
58 | &dat_read_s3m, | ||
59 | &_dat_unload_duh | ||
60 | ); | ||
61 | } | ||
diff --git a/apps/codecs/dumb/src/allegro/datunld.c b/apps/codecs/dumb/src/allegro/datunld.c new file mode 100644 index 0000000000..71906445e0 --- /dev/null +++ b/apps/codecs/dumb/src/allegro/datunld.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * datunld.c - Unload function for integration / / \ \ | ||
12 | * with Allegro's datafiles. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By entheh. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | #include <allegro.h> | ||
21 | |||
22 | #include "aldumb.h" | ||
23 | #include "internal/aldumb.h" | ||
24 | |||
25 | |||
26 | |||
27 | void _dat_unload_duh(void *duh) | ||
28 | { | ||
29 | unload_duh(duh); | ||
30 | } | ||
31 | |||
diff --git a/apps/codecs/dumb/src/allegro/datxm.c b/apps/codecs/dumb/src/allegro/datxm.c new file mode 100644 index 0000000000..6cb98d87c1 --- /dev/null +++ b/apps/codecs/dumb/src/allegro/datxm.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * datxm.c - Integration of XM files with / / \ \ | ||
12 | * Allegro's datafiles. | < / \_ | ||
13 | * | \/ /\ / | ||
14 | * By entheh. \_ / > / | ||
15 | * | \ / / | ||
16 | * | ' / | ||
17 | * \__/ | ||
18 | */ | ||
19 | |||
20 | #include <allegro.h> | ||
21 | |||
22 | #include "aldumb.h" | ||
23 | #include "internal/aldumb.h" | ||
24 | |||
25 | |||
26 | |||
27 | static void *dat_read_xm(PACKFILE *f, long size) | ||
28 | { | ||
29 | DUMBFILE *df; | ||
30 | DUH *duh; | ||
31 | |||
32 | (void)size; | ||
33 | |||
34 | df = dumbfile_open_packfile(f); | ||
35 | |||
36 | if (!df) | ||
37 | return NULL; | ||
38 | |||
39 | duh = dumb_read_xm(df); | ||
40 | |||
41 | dumbfile_close(df); | ||
42 | |||
43 | return duh; | ||
44 | } | ||
45 | |||
46 | |||
47 | |||
48 | /* dumb_register_dat_xm(): tells Allegro about the XM datafile object. If you | ||
49 | * intend to load a datafile containing an XM object, you must call this | ||
50 | * function first. It is recommended you pass DUMB_DAT_XM, but you may have a | ||
51 | * reason to use a different type (perhaps you already have a datafile with | ||
52 | * XM files in and they use a different type). | ||
53 | */ | ||
54 | void dumb_register_dat_xm(long type) | ||
55 | { | ||
56 | register_datafile_object( | ||
57 | type, | ||
58 | &dat_read_xm, | ||
59 | &_dat_unload_duh | ||
60 | ); | ||
61 | } | ||
62 | |||
diff --git a/apps/codecs/dumb/src/allegro/packfile.c b/apps/codecs/dumb/src/allegro/packfile.c new file mode 100644 index 0000000000..525baebd4e --- /dev/null +++ b/apps/codecs/dumb/src/allegro/packfile.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /* _______ ____ __ ___ ___ | ||
2 | * \ _ \ \ / \ / \ \ / / ' ' ' | ||
3 | * | | \ \ | | || | \/ | . . | ||
4 | * | | | | | | || ||\ /| | | ||
5 | * | | | | | | || || \/ | | ' ' ' | ||
6 | * | | | | | | || || | | . . | ||
7 | * | |_/ / \ \__// || | | | ||
8 | * /_______/ynamic \____/niversal /__\ /____\usic /| . . ibliotheque | ||
9 | * / \ | ||
10 | * / . \ | ||
11 | * packfile.c - Packfile input module. / / \ \ | ||
12 | * | < / \_ | ||
13 | * By entheh. | \/ /\ / | ||
14 | * \_ / > / | ||
15 | * Note that this does not use file compression; | \ / / | ||
16 | * for that you must open the file yourself and | ' / | ||
17 | * then use dumbfile_open_packfile(). \__/ | ||
18 | */ | ||
19 | |||
20 | #include <allegro.h> | ||
21 | |||
22 | #include "aldumb.h" | ||
23 | |||
24 | |||
25 | |||
26 | static void *dumb_packfile_open(const char *filename) | ||
27 | { | ||
28 | return pack_fopen(filename, F_READ); | ||
29 | } | ||
30 | |||
31 | |||
32 | |||
33 | static int dumb_packfile_skip(void *f, long n) | ||
34 | { | ||
35 | return pack_fseek(f, n); | ||
36 | } | ||
37 | |||
38 | |||
39 | |||
40 | static int dumb_packfile_getc(void *f) | ||
41 | { | ||
42 | return pack_getc(f); | ||
43 | } | ||
44 | |||
45 | |||
46 | |||
47 | static long dumb_packfile_getnc(char *ptr, long n, void *f) | ||
48 | { | ||
49 | return pack_fread(ptr, n, f); | ||
50 | } | ||
51 | |||
52 | |||
53 | |||
54 | static void dumb_packfile_close(void *f) | ||
55 | { | ||
56 | pack_fclose(f); | ||
57 | } | ||
58 | |||
59 | |||
60 | |||
61 | static DUMBFILE_SYSTEM packfile_dfs = { | ||
62 | &dumb_packfile_open, | ||
63 | &dumb_packfile_skip, | ||
64 | &dumb_packfile_getc, | ||
65 | &dumb_packfile_getnc, | ||
66 | &dumb_packfile_close | ||
67 | }; | ||
68 | |||
69 | |||
70 | |||
71 | void dumb_register_packfiles(void) | ||
72 | { | ||
73 | register_dumbfile_system(&packfile_dfs); | ||
74 | } | ||
75 | |||
76 | |||
77 | |||
78 | static DUMBFILE_SYSTEM packfile_dfs_leave_open = { | ||
79 | NULL, | ||
80 | &dumb_packfile_skip, | ||
81 | &dumb_packfile_getc, | ||
82 | &dumb_packfile_getnc, | ||
83 | NULL | ||
84 | }; | ||
85 | |||
86 | |||
87 | |||
88 | DUMBFILE *dumbfile_open_packfile(PACKFILE *p) | ||
89 | { | ||
90 | return dumbfile_open_ex(p, &packfile_dfs_leave_open); | ||
91 | } | ||
92 | |||
93 | |||
94 | |||
95 | DUMBFILE *dumbfile_from_packfile(PACKFILE *p) | ||
96 | { | ||
97 | return p ? dumbfile_open_ex(p, &packfile_dfs) : NULL; | ||
98 | } | ||