1 2 // NES cartridge data (PRG, CHR, mapper) 3 4 // Nes_Emu 0.7.0 5 6 #ifndef NES_CART_H 7 #define NES_CART_H 8 9 #include <stdint.h> 10 #include "blargg_common.h" 11 #include "abstract_file.h" 12 13 class Nes_Cart { 14 public: 15 Nes_Cart(); 16 ~Nes_Cart(); 17 18 // Load iNES file 19 const char * load_ines( Auto_File_Reader ); 20 static const char not_ines_file []; 21 22 // to do: support UNIF? 23 24 // True if data is currently loaded loaded()25 bool loaded() const { return prg_ != NULL; } 26 27 // Free data 28 void clear(); 29 30 // True if cartridge claims to have battery-backed memory 31 bool has_battery_ram() const; 32 33 // Size of PRG data prg_size()34 long prg_size() const { return prg_size_; } 35 36 // Size of CHR data chr_size()37 long chr_size() const { return chr_size_; } 38 39 // Change size of PRG (code) data 40 const char * resize_prg( long ); 41 42 // Change size of CHR (graphics) data 43 const char * resize_chr( long ); 44 45 // Set mapper and information bytes. LSB and MSB are the standard iNES header 46 // bytes at offsets 6 and 7. 47 void set_mapper( int mapper_lsb, int mapper_msb ); 48 mapper_data()49 unsigned mapper_data() const { return mapper; } 50 51 // Initial mirroring setup mirroring()52 int mirroring() const { return mapper & 0x09; } 53 54 // iNES mapper code 55 int mapper_code() const; 56 57 // Pointer to beginning of PRG data prg()58 uint8_t * prg() { return prg_; } prg()59 uint8_t const* prg() const { return prg_; } 60 61 // Pointer to beginning of CHR data chr()62 uint8_t * chr() { return chr_; } chr()63 uint8_t const* chr() const { return chr_; } 64 65 // End of public interface 66 private: 67 enum { bank_size = 8 * 1024L }; // bank sizes must be a multiple of this 68 uint8_t *prg_; 69 uint8_t *chr_; 70 long prg_size_; 71 long chr_size_; 72 unsigned mapper; 73 long round_to_bank_size( long n ); 74 }; 75 has_battery_ram()76inline bool Nes_Cart::has_battery_ram() const { return mapper & 0x02; } 77 set_mapper(int mapper_lsb,int mapper_msb)78inline void Nes_Cart::set_mapper( int mapper_lsb, int mapper_msb ) 79 { 80 mapper = mapper_msb * 0x100 + mapper_lsb; 81 } 82 mapper_code()83inline int Nes_Cart::mapper_code() const { return ((mapper >> 8) & 0xf0) | ((mapper >> 4) & 0x0f); } 84 85 #endif 86