diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libgme/rom_data.c | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libgme/rom_data.c')
-rw-r--r-- | lib/rbcodec/codecs/libgme/rom_data.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/rom_data.c b/lib/rbcodec/codecs/libgme/rom_data.c new file mode 100644 index 0000000000..9c36a99d2d --- /dev/null +++ b/lib/rbcodec/codecs/libgme/rom_data.c | |||
@@ -0,0 +1,68 @@ | |||
1 | // Game_Music_Emu 0.5.2. http://www.slack.net/~ant/ | ||
2 | |||
3 | #include "rom_data.h" | ||
4 | |||
5 | /* Copyright (C) 2003-2006 Shay Green. This module is free software; you | ||
6 | can redistribute it and/or modify it under the terms of the GNU Lesser | ||
7 | General Public License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. This | ||
9 | module is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
11 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
12 | details. You should have received a copy of the GNU Lesser General Public | ||
13 | License along with this module; if not, write to the Free Software Foundation, | ||
14 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
15 | |||
16 | #include <string.h> | ||
17 | #include "blargg_source.h" | ||
18 | |||
19 | // Rom_Data | ||
20 | |||
21 | blargg_err_t Rom_load( struct Rom_Data* this, const void* data, long size, | ||
22 | int header_size, void* header_out, int fill ) | ||
23 | { | ||
24 | int file_offset = this->pad_size; | ||
25 | |||
26 | this->rom_addr = 0; | ||
27 | this->mask = 0; | ||
28 | this->size = 0; | ||
29 | |||
30 | if ( size <= header_size ) // <= because there must be data after header | ||
31 | return gme_wrong_file_type; | ||
32 | |||
33 | // Read header | ||
34 | memcpy( header_out, data, header_size ); | ||
35 | |||
36 | this->file_size = size - header_size; | ||
37 | this->file_data = (byte*) data + header_size; | ||
38 | |||
39 | memset( this->unmapped, fill, this->rom_size ); | ||
40 | memcpy( &this->unmapped [file_offset], this->file_data, | ||
41 | this->file_size < this->pad_size ? this->file_size : this->pad_size ); | ||
42 | |||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | void Rom_set_addr( struct Rom_Data* this, int addr ) | ||
47 | { | ||
48 | this->rom_addr = addr - this->bank_size - pad_extra; | ||
49 | |||
50 | int rounded = (addr + this->file_size + this->bank_size - 1) / this->bank_size * this->bank_size; | ||
51 | if ( rounded <= 0 ) | ||
52 | { | ||
53 | rounded = 0; | ||
54 | } | ||
55 | else | ||
56 | { | ||
57 | int shift = 0; | ||
58 | unsigned int max_addr = (unsigned int) (rounded - 1); | ||
59 | while ( max_addr >> shift ) | ||
60 | shift++; | ||
61 | this->mask = (1L << shift) - 1; | ||
62 | } | ||
63 | |||
64 | if ( addr < 0 ) | ||
65 | addr = 0; | ||
66 | this->size = rounded; | ||
67 | this->rsize_ = rounded - this->rom_addr + pad_extra; | ||
68 | } | ||