openMSX
PanasonicMemory.cc
Go to the documentation of this file.
1 #include "PanasonicMemory.hh"
2 #include "MSXMotherBoard.hh"
3 #include "MSXCPU.hh"
4 #include "Ram.hh"
5 #include "Rom.hh"
6 #include "DeviceConfig.hh"
7 #include "HardwareConfig.hh"
8 #include "XMLElement.hh"
9 #include "MSXException.hh"
10 #include <memory>
11 
12 namespace openmsx {
13 
14 static std::unique_ptr<Rom> createRom(MSXMotherBoard& motherBoard)
15 {
16  const XMLElement* elem = motherBoard.getMachineConfig()->
17  getConfig().findChild("PanasonicRom");
18  if (!elem) return nullptr;
19 
20  const HardwareConfig* hwConf = motherBoard.getMachineConfig();
21  assert(hwConf);
22  return std::make_unique<Rom>(
23  "PanasonicRom", "Turbor-R main ROM",
24  DeviceConfig(*hwConf, *elem));
25 }
26 
28  : msxcpu(motherBoard.getCPU())
29  , rom(createRom(motherBoard))
30  , ram(nullptr), ramSize(0)
31  , dram(false)
32 {
33 }
34 
36 
38 {
39  ram = &ram_[0];
40  ramSize = ram_.getSize();
41 }
42 
43 const byte* PanasonicMemory::getRomBlock(unsigned block)
44 {
45  if (!rom) {
46  throw MSXException("Missing PanasonicRom.");
47  }
48  if (dram &&
49  (((0x28 <= block) && (block < 0x2C)) ||
50  ((0x38 <= block) && (block < 0x3C)))) {
51  assert(ram);
52  unsigned offset = (block & 0x03) * 0x2000;
53  unsigned ramOffset = (block < 0x30) ? ramSize - 0x10000 :
54  ramSize - 0x08000;
55  return ram + ramOffset + offset;
56  } else {
57  unsigned offset = block * 0x2000;
58  if (offset >= rom->getSize()) {
59  offset &= rom->getSize() - 1;
60  }
61  return &(*rom)[offset];
62  }
63 }
64 
65 const byte* PanasonicMemory::getRomRange(unsigned first, unsigned last)
66 {
67  if (!rom) {
68  throw MSXException("Missing PanasonicRom.");
69  }
70  if (last < first) {
71  throw MSXException("Error in config file: firstblock must "
72  "be smaller than lastblock");
73  }
74  unsigned start = first * 0x2000;
75  if (start >= rom->getSize()) {
76  throw MSXException("Error in config file: firstblock lies "
77  "outside of rom image.");
78  }
79  unsigned stop = (last + 1) * 0x2000;
80  if (stop > rom->getSize()) {
81  throw MSXException("Error in config file: lastblock lies "
82  "outside of rom image.");
83  }
84  return &(*rom)[start];
85 }
86 
87 byte* PanasonicMemory::getRamBlock(unsigned block)
88 {
89  if (!ram) return nullptr;
90 
91  unsigned offset = block * 0x2000;
92  if (offset >= ramSize) {
93  offset &= ramSize - 1;
94  }
95  return ram + offset;
96 }
97 
98 void PanasonicMemory::setDRAM(bool dram_)
99 {
100  if (dram_ != dram) {
101  dram = dram_;
102  msxcpu.invalidateAllSlotsRWCache(0x0000, 0x10000);
103  }
104 }
105 
106 bool PanasonicMemory::isWritable(unsigned address) const
107 {
108  return !dram || (address < (ramSize - 0x10000));
109 }
110 
111 } // namespace openmsx
openmsx::HardwareConfig
HardwareConfig
Definition: HardwareConfig.cc:459
HardwareConfig.hh
openmsx::PanasonicMemory::~PanasonicMemory
~PanasonicMemory()
openmsx::PanasonicMemory::PanasonicMemory
PanasonicMemory(MSXMotherBoard &motherBoard)
Definition: PanasonicMemory.cc:27
Rom.hh
openmsx::YM2413NukeYKT::rom
constexpr Rom rom
Definition: YM2413NukeYKT.cc:71
MSXCPU.hh
openmsx::XMLElement
XMLElement
Definition: XMLElement.cc:348
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:10
openmsx::PanasonicMemory::getRomBlock
const byte * getRomBlock(unsigned block)
Definition: PanasonicMemory.cc:43
XMLElement.hh
openmsx::PanasonicMemory::getRamBlock
byte * getRamBlock(unsigned block)
Note that this is always unchecked RAM! There is no UMR detection when accessing Ram in DRAM mode or ...
Definition: PanasonicMemory.cc:87
openmsx::PanasonicMemory::isWritable
bool isWritable(unsigned address) const
Definition: PanasonicMemory.cc:106
Ram.hh
openmsx::PanasonicMemory::registerRam
void registerRam(Ram &ram)
Pass reference of the actual Ram block for use in DRAM mode and RAM access via the ROM mapper.
Definition: PanasonicMemory.cc:37
openmsx::MSXCPU::invalidateAllSlotsRWCache
void invalidateAllSlotsRWCache(word start, unsigned size)
Invalidate the CPU its cache for the interval [start, start + size) For example MSXMemoryMapper and M...
Definition: MSXCPU.cc:182
openmsx::PanasonicMemory::getRomRange
const byte * getRomRange(unsigned first, unsigned last)
Definition: PanasonicMemory.cc:65
openmsx::MSXMotherBoard
Definition: MSXMotherBoard.hh:60
openmsx::Ram
Definition: Ram.hh:16
DeviceConfig.hh
PanasonicMemory.hh
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
MSXMotherBoard.hh
openmsx::PanasonicMemory::setDRAM
void setDRAM(bool dram)
Definition: PanasonicMemory.cc:98
openmsx::Ram::getSize
unsigned getSize() const
Definition: Ram.hh:33