summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/rom_data.h
diff options
context:
space:
mode:
authorSean Bartell <wingedtachikoma@gmail.com>2011-06-25 21:32:25 -0400
committerNils Wallménius <nils@rockbox.org>2012-04-25 22:13:20 +0200
commitf40bfc9267b13b54e6379dfe7539447662879d24 (patch)
tree9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libgme/rom_data.h
parenta0009907de7a0107d49040d8a180f140e2eff299 (diff)
downloadrockbox-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.h')
-rw-r--r--lib/rbcodec/codecs/libgme/rom_data.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/rom_data.h b/lib/rbcodec/codecs/libgme/rom_data.h
new file mode 100644
index 0000000000..b8bc54cd3f
--- /dev/null
+++ b/lib/rbcodec/codecs/libgme/rom_data.h
@@ -0,0 +1,83 @@
1// Common aspects of emulators which use rom data
2
3// Game_Music_Emu 0.5.2
4#ifndef ROM_DATA_H
5#define ROM_DATA_H
6
7#include "blargg_common.h"
8#include "blargg_source.h"
9
10// ROM data handler, used by several Classic_Emu derivitives. Loads file data
11// with padding on both sides, allowing direct use in bank mapping. The main purpose
12// is to allow all file data to be loaded with only one read() call (for efficiency).
13
14extern const char gme_wrong_file_type []; // declared in gme.h
15
16enum { pad_extra = 8 };
17enum { max_bank_size = 0x4000 };
18enum { max_pad_size = max_bank_size + pad_extra };
19enum { max_rom_size = 2 * max_pad_size };
20
21struct Rom_Data {
22 byte* file_data;
23 unsigned file_size;
24
25 int rom_addr;
26 int bank_size;
27 int rom_size;
28 unsigned pad_size;
29 int mask;
30 int size; // TODO: eliminate
31 int rsize_;
32
33 // Unmapped space
34 byte unmapped [max_rom_size];
35};
36
37// Initialize rom
38static inline void Rom_init( struct Rom_Data* this, int bank_size )
39{
40 this->bank_size = bank_size;
41 this->pad_size = this->bank_size + pad_extra;
42 this->rom_size = 2 * this->pad_size;
43}
44
45// Load file data, using already-loaded header 'h' if not NULL. Copy header
46// from loaded file data into *out and fill unmapped bytes with 'fill'.
47blargg_err_t Rom_load( struct Rom_Data* this, const void* data, long size, int header_size, void* header_out, int fill );
48
49// Set address that file data should start at
50void Rom_set_addr( struct Rom_Data* this, int addr );
51
52// Mask address to nearest power of two greater than size()
53static inline int mask_addr( int addr, int mask )
54{
55 #ifdef check
56 check( addr <= mask );
57 #endif
58 return addr & mask;
59}
60
61// Pointer to page starting at addr. Returns unmapped() if outside data.
62static inline byte* Rom_at_addr( struct Rom_Data* this, int addr )
63{
64 unsigned offset = mask_addr( addr, this->mask ) - this->rom_addr;
65 if ( offset > (unsigned) (this->rsize_ - this->pad_size) )
66 offset = 0; // unmapped
67
68 if ( offset < this->pad_size ) return &this->unmapped [offset];
69 else return &this->file_data [offset - this->pad_size];
70}
71
72
73#ifndef GME_APU_HOOK
74 #define GME_APU_HOOK( emu, addr, data ) ((void) 0)
75#endif
76
77#ifndef GME_FRAME_HOOK
78 #define GME_FRAME_HOOK( emu ) ((void) 0)
79#else
80 #define GME_FRAME_HOOK_DEFINED 1
81#endif
82
83#endif