bsnes/snes/memory/memory.hpp

115 lines
2.5 KiB
C++
Raw Normal View History

struct Memory {
virtual inline unsigned size() const;
virtual uint8 read(unsigned addr) = 0;
virtual void write(unsigned addr, uint8 data) = 0;
};
struct MMIO {
virtual uint8 mmio_read(unsigned addr) = 0;
virtual void mmio_write(unsigned addr, uint8 data) = 0;
};
struct UnmappedMemory : Memory {
unsigned size() const;
uint8 read(unsigned);
void write(unsigned, uint8);
};
struct UnmappedMMIO : MMIO {
uint8 mmio_read(unsigned);
void mmio_write(unsigned, uint8);
};
struct StaticRAM : Memory {
inline uint8* data();
inline unsigned size() const;
inline uint8 read(unsigned addr);
inline void write(unsigned addr, uint8 n);
inline uint8& operator[](unsigned addr);
inline const uint8& operator[](unsigned addr) const;
inline StaticRAM(unsigned size);
inline ~StaticRAM();
private:
uint8 *data_;
unsigned size_;
};
struct MappedRAM : Memory {
inline void reset();
inline void map(uint8*, unsigned);
inline void copy(const uint8*, unsigned);
inline void write_protect(bool status);
inline uint8* data();
inline unsigned size() const;
inline uint8 read(unsigned addr);
inline void write(unsigned addr, uint8 n);
inline const uint8& operator[](unsigned addr) const;
inline MappedRAM();
private:
uint8 *data_;
unsigned size_;
bool write_protect_;
};
struct MMIOAccess : Memory {
MMIO* handle(unsigned addr);
void map(unsigned addr, MMIO &access);
uint8 read(unsigned addr);
void write(unsigned addr, uint8 data);
MMIOAccess();
private:
Updated to v067r25 release. byuu says: Removed snes_spc, and the fast/smp + fast/dsp wrappers around it. Cloned dsp to fast/dsp, and re-added the state machine, affects Compatibility and Performance cores. Added debugger support to fast/cpu, with full properties list and Qt debugger functionality. Rewrote all debugger property functions to return data directly: - this avoids some annoying conflicts where ChipDebugger::foo() overshadows Chip::foo() - this removes the need for an extra 20-200 functions per debugger core - this makes the overall code size a good bit smaller - this currently makes PPU::oam_basesize() inaccessible, so the OAM viewer will show wrong sprite sizes Used an evil trick to simplify MMIO read/write address decoding: - MMIO *mmio[0x8000], where only 0x2000-5fff are used, allows direct indexing without -0x2000 adjust So end result: both save states and debugger support work on all three cores now. Dual Orb II sound is fixed. The speed hit was worse than I thought, -7% for compatibility, and -10% for performance. At this point, the compatibility core is the exact same code and speed as v067 official, and the performance core is now only ~36-40% faster than the compatibility core. Sigh, so much for my dream of using this on my netbook. At 53fps average now, compared to 39fps before. Profiling will only get that to ~58fps, and that's way too low for the more intensive scenes (Zelda 3 rain, CT black omen, etc.) It would probably be a good idea to find out why my DSP is so much slower than blargg's, given that it's based upon the same code. The simple ring buffer stuff can't possibly slow things down that much. More precisely, it would probably be best to leave blargg's DSP in the performance core since it's a pretty minor issue, but then I'd have to have three DSPs: accuracy=threaded, compatibility=state-machine, performance=blargg. Too much hassle. Only code in the core emulator now that wasn't at the very least rewritten for bsnes would be the DSP-3 and DSP-4 modules, which are really, really lazily done #define hacks around the original C code.
2010-08-19 06:54:15 +00:00
MMIO *mmio[0x8000];
};
struct Bus {
unsigned mirror(unsigned addr, unsigned size);
void map(unsigned addr, Memory &access, unsigned offset);
enum class MapMode : unsigned { Direct, Linear, Shadow };
void map(MapMode mode,
uint8 bank_lo, uint8 bank_hi,
uint16 addr_lo, uint16 addr_hi,
Memory &access, unsigned offset = 0, unsigned size = 0);
alwaysinline uint8 read(uint24 addr);
alwaysinline void write(uint24 addr, uint8 data);
bool load_cart();
void unload_cart();
void power();
void reset();
struct Page {
Memory *access;
unsigned offset;
} page[65536];
void serialize(serializer&);
private:
void map_reset();
void map_xml();
void map_system();
};
namespace memory {
extern MMIOAccess mmio; //S-CPU, S-PPU
extern StaticRAM wram; //S-CPU
extern StaticRAM apuram; //S-SMP, S-DSP
extern StaticRAM vram; //S-PPU
extern StaticRAM oam; //S-PPU
extern StaticRAM cgram; //S-PPU
extern UnmappedMemory memory_unmapped;
extern UnmappedMMIO mmio_unmapped;
};
extern Bus bus;