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 
15  : msxcpu(motherBoard.getCPU())
16  , rom([&]() -> std::optional<Rom> {
17  const auto* elem = motherBoard.getMachineConfig()->
18  getConfig().findChild("PanasonicRom");
19  if (!elem) return std::nullopt;
20 
21  const HardwareConfig* hwConf = motherBoard.getMachineConfig();
22  assert(hwConf);
23  return std::optional<Rom>(std::in_place,
24  "PanasonicRom", "Turbor-R main ROM",
25  DeviceConfig(*hwConf, *elem));
26  }())
27 {
28 }
29 
31 {
32  ram = &ram_[0];
33  ramSize = ram_.getSize();
34 }
35 
36 const byte* PanasonicMemory::getRomBlock(unsigned block)
37 {
38  if (!rom) {
39  throw MSXException("Missing PanasonicRom.");
40  }
41  if (dram &&
42  (((0x28 <= block) && (block < 0x2C)) ||
43  ((0x38 <= block) && (block < 0x3C)))) {
44  assert(ram);
45  unsigned offset = (block & 0x03) * 0x2000;
46  unsigned ramOffset = (block < 0x30) ? ramSize - 0x10000 :
47  ramSize - 0x08000;
48  return ram + ramOffset + offset;
49  } else {
50  unsigned offset = block * 0x2000;
51  if (offset >= rom->getSize()) {
52  offset &= rom->getSize() - 1;
53  }
54  return &(*rom)[offset];
55  }
56 }
57 
58 const byte* PanasonicMemory::getRomRange(unsigned first, unsigned last)
59 {
60  if (!rom) {
61  throw MSXException("Missing PanasonicRom.");
62  }
63  if (last < first) {
64  throw MSXException("Error in config file: firstblock must "
65  "be smaller than lastblock");
66  }
67  unsigned start = first * 0x2000;
68  if (start >= rom->getSize()) {
69  throw MSXException("Error in config file: firstblock lies "
70  "outside of rom image.");
71  }
72  unsigned stop = (last + 1) * 0x2000;
73  if (stop > rom->getSize()) {
74  throw MSXException("Error in config file: lastblock lies "
75  "outside of rom image.");
76  }
77  return &(*rom)[start];
78 }
79 
80 byte* PanasonicMemory::getRamBlock(unsigned block)
81 {
82  if (!ram) return nullptr;
83 
84  unsigned offset = block * 0x2000;
85  if (offset >= ramSize) {
86  offset &= ramSize - 1;
87  }
88  return ram + offset;
89 }
90 
91 void PanasonicMemory::setDRAM(bool dram_)
92 {
93  if (dram_ != dram) {
94  dram = dram_;
95  msxcpu.invalidateAllSlotsRWCache(0x0000, 0x10000);
96  }
97 }
98 
99 bool PanasonicMemory::isWritable(unsigned address) const
100 {
101  return !dram || (address < (ramSize - 0x10000));
102 }
103 
104 } // namespace openmsx
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:180
const HardwareConfig * getMachineConfig() const
void registerRam(Ram &ram)
Pass reference of the actual Ram block for use in DRAM mode and RAM access via the ROM mapper.
bool isWritable(unsigned address) const
const byte * getRomBlock(unsigned block)
PanasonicMemory(MSXMotherBoard &motherBoard)
const byte * getRomRange(unsigned first, unsigned last)
byte * getRamBlock(unsigned block)
Note that this is always unchecked RAM! There is no UMR detection when accessing Ram in DRAM mode or ...
unsigned getSize() const
Definition: Ram.hh:44
This file implemented 3 utility functions:
Definition: Autofire.cc:9