diff options
Diffstat (limited to 'apps/codecs/libgme/rom_data.h')
-rw-r--r-- | apps/codecs/libgme/rom_data.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/apps/codecs/libgme/rom_data.h b/apps/codecs/libgme/rom_data.h new file mode 100644 index 0000000000..28b34f2a70 --- /dev/null +++ b/apps/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 | |||
14 | extern const char gme_wrong_file_type []; // declared in gme.h | ||
15 | |||
16 | enum { pad_extra = 8 }; | ||
17 | enum { max_bank_size = 0x4000 }; | ||
18 | enum { max_pad_size = max_bank_size + pad_extra }; | ||
19 | enum { max_rom_size = 2 * max_pad_size }; | ||
20 | |||
21 | struct Rom_Data { | ||
22 | byte* file_data; | ||
23 | blargg_ulong file_size; | ||
24 | |||
25 | blargg_long rom_addr; | ||
26 | blargg_long bank_size; | ||
27 | blargg_long rom_size; | ||
28 | blargg_ulong pad_size; | ||
29 | blargg_long mask; | ||
30 | blargg_long size; // TODO: eliminate | ||
31 | blargg_long rsize_; | ||
32 | |||
33 | // Unmapped space | ||
34 | byte unmapped [max_rom_size]; | ||
35 | }; | ||
36 | |||
37 | // Initialize rom | ||
38 | static inline void Rom_init( struct Rom_Data* this, blargg_long 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'. | ||
47 | blargg_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 | ||
50 | void Rom_set_addr( struct Rom_Data* this, long addr ); | ||
51 | |||
52 | // Mask address to nearest power of two greater than size() | ||
53 | static inline blargg_long mask_addr( blargg_long addr, blargg_long 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. | ||
62 | static inline byte* Rom_at_addr( struct Rom_Data* this, blargg_long addr ) | ||
63 | { | ||
64 | blargg_ulong offset = mask_addr( addr, this->mask ) - this->rom_addr; | ||
65 | if ( offset > (blargg_ulong) (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 | ||