openMSX
RomMSXtra.cc
Go to the documentation of this file.
1#include "RomMSXtra.hh"
2#include "serialize.hh"
3#include "xrange.hh"
4
5namespace openmsx {
6
7RomMSXtra::RomMSXtra(const DeviceConfig& config, Rom&& rom_)
8 : MSXRom(config, std::move(rom_))
9 , ram(config, getName() + " RAM", "MSXtra RAM", 0x0800)
10{
11 for (auto i : xrange(0x800)) {
12 ram[i] = (i & 1) ? 0x5a : 0xa5;
13 }
14}
15
16byte RomMSXtra::readMem(word address, EmuTime::param /*time*/)
17{
18 if ((0x4000 <= address) && (address < 0x6000)) {
19 return rom[address & 0x1fff];
20 } else if ((0x6000 <= address) && (address < 0x8000)) {
21 return ram[address & 0x07ff];
22 } else {
23 return 0xff;
24 }
25}
26
27const byte* RomMSXtra::getReadCacheLine(word address) const
28{
29 if ((0x4000 <= address) && (address < 0x6000)) {
30 return &rom[address & 0x1fff];
31 } else if ((0x6000 <= address) && (address < 0x8000)) {
32 return &ram[address & 0x07ff];
33 } else {
34 return unmappedRead.data();
35 }
36}
37
38// default peekMem() implementation is OK
39
40void RomMSXtra::writeMem(word address, byte value, EmuTime::param /*time*/)
41{
42 if ((0x6000 <= address) && (address < 0x8000)) {
43 ram[address & 0x07ff] = value;
44 }
45}
46
48{
49 if ((0x6000 <= address) && (address < 0x8000)) {
50 return const_cast<byte*>(&ram[address & 0x07ff]);
51 } else {
52 return unmappedWrite.data();
53 }
54}
55
56template<typename Archive>
57void RomMSXtra::serialize(Archive& ar, unsigned /*version*/)
58{
59 // skip MSXRom base class
60 ar.template serializeBase<MSXDevice>(*this);
61 ar.serialize("ram", ram);
62}
65
66} // namespace openmsx
static std::array< byte, 0x10000 > unmappedRead
Definition: MSXDevice.hh:302
static std::array< byte, 0x10000 > unmappedWrite
Definition: MSXDevice.hh:303
void serialize(Archive &ar, unsigned version)
Definition: RomMSXtra.cc:57
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomMSXtra.cc:16
void writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
Definition: RomMSXtra.cc:40
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomMSXtra.cc:47
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomMSXtra.cc:27
RomMSXtra(const DeviceConfig &config, Rom &&rom)
Definition: RomMSXtra.cc:7
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
STL namespace.
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021
constexpr auto xrange(T e)
Definition: xrange.hh:133