From acb0917556fc33681c1df5a530cf754193e67705 Mon Sep 17 00:00:00 2001 From: Andree Buschmann Date: Sun, 7 Aug 2011 20:01:04 +0000 Subject: 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 --- apps/codecs/libgme/rom_data.h | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 apps/codecs/libgme/rom_data.h (limited to 'apps/codecs/libgme/rom_data.h') 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 @@ +// Common aspects of emulators which use rom data + +// Game_Music_Emu 0.5.2 +#ifndef ROM_DATA_H +#define ROM_DATA_H + +#include "blargg_common.h" +#include "blargg_source.h" + +// ROM data handler, used by several Classic_Emu derivitives. Loads file data +// with padding on both sides, allowing direct use in bank mapping. The main purpose +// is to allow all file data to be loaded with only one read() call (for efficiency). + +extern const char gme_wrong_file_type []; // declared in gme.h + +enum { pad_extra = 8 }; +enum { max_bank_size = 0x4000 }; +enum { max_pad_size = max_bank_size + pad_extra }; +enum { max_rom_size = 2 * max_pad_size }; + +struct Rom_Data { + byte* file_data; + blargg_ulong file_size; + + blargg_long rom_addr; + blargg_long bank_size; + blargg_long rom_size; + blargg_ulong pad_size; + blargg_long mask; + blargg_long size; // TODO: eliminate + blargg_long rsize_; + + // Unmapped space + byte unmapped [max_rom_size]; +}; + +// Initialize rom +static inline void Rom_init( struct Rom_Data* this, blargg_long bank_size ) +{ + this->bank_size = bank_size; + this->pad_size = this->bank_size + pad_extra; + this->rom_size = 2 * this->pad_size; +} + +// Load file data, using already-loaded header 'h' if not NULL. Copy header +// from loaded file data into *out and fill unmapped bytes with 'fill'. +blargg_err_t Rom_load( struct Rom_Data* this, const void* data, long size, int header_size, void* header_out, int fill ); + +// Set address that file data should start at +void Rom_set_addr( struct Rom_Data* this, long addr ); + +// Mask address to nearest power of two greater than size() +static inline blargg_long mask_addr( blargg_long addr, blargg_long mask ) +{ + #ifdef check + check( addr <= mask ); + #endif + return addr & mask; +} + +// Pointer to page starting at addr. Returns unmapped() if outside data. +static inline byte* Rom_at_addr( struct Rom_Data* this, blargg_long addr ) +{ + blargg_ulong offset = mask_addr( addr, this->mask ) - this->rom_addr; + if ( offset > (blargg_ulong) (this->rsize_ - this->pad_size) ) + offset = 0; // unmapped + + if ( offset < this->pad_size ) return &this->unmapped [offset]; + else return &this->file_data [offset - this->pad_size]; +} + + +#ifndef GME_APU_HOOK + #define GME_APU_HOOK( emu, addr, data ) ((void) 0) +#endif + +#ifndef GME_FRAME_HOOK + #define GME_FRAME_HOOK( emu ) ((void) 0) +#else + #define GME_FRAME_HOOK_DEFINED 1 +#endif + +#endif -- cgit v1.2.3