diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-07 20:01:04 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-07 20:01:04 +0000 |
commit | acb0917556fc33681c1df5a530cf754193e67705 (patch) | |
tree | 052a47097009a210e4aed9c207bd6aa4828cc000 /apps/codecs/libgme/inflate/bbfuncs.c | |
parent | 93c6f1329a5691a8be158cefe15641bd1daf9ef8 (diff) | |
download | rockbox-acb0917556fc33681c1df5a530cf754193e67705.tar.gz rockbox-acb0917556fc33681c1df5a530cf754193e67705.zip |
Submit initial patch from FS#12176. Adds support for several new game music formats (AY, GBS, HES, KSS, SGC, VGM and VGZ) and replaces the current NSF and NSFE with a new implementation based on a port of the Game Music Emu library 'GME'. This first submit does not cover the full functionality provided by the author's original patch: Coleco-SGV is not supported, some GME-specific m3u-support has been removed and IRAM is not used yet. Further changes are very likely to follow this submit. Thanks to Mauricio Garrido.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30264 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libgme/inflate/bbfuncs.c')
-rw-r--r-- | apps/codecs/libgme/inflate/bbfuncs.c | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/apps/codecs/libgme/inflate/bbfuncs.c b/apps/codecs/libgme/inflate/bbfuncs.c new file mode 100644 index 0000000000..3b23c3b6db --- /dev/null +++ b/apps/codecs/libgme/inflate/bbfuncs.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version 2 | ||
13 | * of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "bbfuncs.h" | ||
21 | |||
22 | #if defined(ROCKBOX) | ||
23 | #include "codeclib.h" | ||
24 | #endif | ||
25 | |||
26 | void error_die(const char* msg) | ||
27 | { | ||
28 | (void)msg; | ||
29 | } | ||
30 | |||
31 | void error_msg(const char* msg) | ||
32 | { | ||
33 | (void)msg; | ||
34 | } | ||
35 | |||
36 | size_t safe_read(struct mbreader_t *md, void *buf, size_t count) | ||
37 | { | ||
38 | ssize_t n; | ||
39 | |||
40 | do { | ||
41 | n = mbread(md, buf, count); | ||
42 | } while (n < 0&&n!=-1); | ||
43 | |||
44 | return n; | ||
45 | } | ||
46 | |||
47 | /* | ||
48 | * Read all of the supplied buffer from a file This does multiple reads as | ||
49 | *necessary. Returns the amount read, or -1 on an error. A short read is | ||
50 | *returned on an end of file. | ||
51 | */ | ||
52 | ssize_t full_read(struct mbreader_t *md, void *buf, size_t len) | ||
53 | { | ||
54 | ssize_t cc; | ||
55 | ssize_t total; | ||
56 | |||
57 | total = 0; | ||
58 | |||
59 | while (len) | ||
60 | { | ||
61 | cc = safe_read(md, buf, len); | ||
62 | |||
63 | if (cc < 0) | ||
64 | return cc; /* read() returns -1 on failure. */ | ||
65 | |||
66 | if (cc == 0) | ||
67 | break; | ||
68 | |||
69 | buf = ((char *)buf) + cc; | ||
70 | total += cc; | ||
71 | len -= cc; | ||
72 | } | ||
73 | |||
74 | return total; | ||
75 | } | ||
76 | |||
77 | /* Die with an error message if we can't read the entire buffer. */ | ||
78 | void xread(struct mbreader_t *md, void *buf, ssize_t count) | ||
79 | { | ||
80 | if (count) | ||
81 | { | ||
82 | ssize_t size = full_read(md, buf, count); | ||
83 | if (size != count) | ||
84 | error_die("short read"); | ||
85 | } | ||
86 | } | ||
87 | |||
88 | /* Die with an error message if we can't read one character. */ | ||
89 | unsigned char xread_char(struct mbreader_t *md) | ||
90 | { | ||
91 | unsigned char tmp; | ||
92 | |||
93 | xread(md, &tmp, 1); | ||
94 | |||
95 | return tmp; | ||
96 | } | ||
97 | |||
98 | void check_header_gzip(struct mbreader_t *src_md) | ||
99 | { | ||
100 | union { | ||
101 | unsigned char raw[8]; | ||
102 | struct { | ||
103 | unsigned char method; | ||
104 | unsigned char flags; | ||
105 | unsigned int mtime; | ||
106 | unsigned char xtra_flags; | ||
107 | unsigned char os_flags; | ||
108 | } formatted; | ||
109 | } header; | ||
110 | |||
111 | xread(src_md, header.raw, 8); | ||
112 | |||
113 | /* Check the compression method */ | ||
114 | if (header.formatted.method != 8) | ||
115 | error_die("Unknown compression method"); | ||
116 | |||
117 | if (header.formatted.flags & 0x04) | ||
118 | { | ||
119 | /* bit 2 set: extra field present */ | ||
120 | unsigned char extra_short; | ||
121 | |||
122 | extra_short = xread_char(src_md) + (xread_char(src_md) << 8); | ||
123 | while (extra_short > 0) | ||
124 | { | ||
125 | /* Ignore extra field */ | ||
126 | xread_char(src_md); | ||
127 | extra_short--; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | /* Discard original name if any */ | ||
132 | if (header.formatted.flags & 0x08) | ||
133 | /* bit 3 set: original file name present */ | ||
134 | while(xread_char(src_md) != 0) ; | ||
135 | |||
136 | /* Discard file comment if any */ | ||
137 | if (header.formatted.flags & 0x10) | ||
138 | /* bit 4 set: file comment present */ | ||
139 | while(xread_char(src_md) != 0) ; | ||
140 | |||
141 | /* Read the header checksum */ | ||
142 | if (header.formatted.flags & 0x02) | ||
143 | { | ||
144 | xread_char(src_md); | ||
145 | xread_char(src_md); | ||
146 | } | ||
147 | } | ||