openMSX
RomNational.cc
Go to the documentation of this file.
1 #include "RomNational.hh"
2 #include "CacheLine.hh"
3 #include "SRAM.hh"
4 #include "one_of.hh"
5 #include "serialize.hh"
6 #include <memory>
7 
8 namespace openmsx {
9 
11  : Rom16kBBlocks(config, std::move(rom_))
12 {
13  sram = std::make_unique<SRAM>(getName() + " SRAM", 0x1000, config);
14  reset(EmuTime::dummy());
15 }
16 
17 void RomNational::reset(EmuTime::param /*time*/)
18 {
19  control = 0;
20  for (int region = 0; region < 4; ++region) {
21  setRom(region, 0);
22  bankSelect[region] = 0;
23  invalidateDeviceRCache((region * 0x4000) + (0x3FF0 & CacheLine::HIGH),
25  }
26  sramAddr = 0; // TODO check this
27 }
28 
29 byte RomNational::peekMem(word address, EmuTime::param time) const
30 {
31  if ((control & 0x04) && ((address & 0x7FF9) == 0x7FF0)) {
32  // TODO check mirrored
33  // 7FF0 7FF2 7FF4 7FF6 bank select read back
34  int bank = (address & 6) / 2;
35  return bankSelect[bank];
36  }
37  if ((control & 0x02) && ((address & 0x3FFF) == 0x3FFD)) {
38  // SRAM read
39  return (*sram)[sramAddr & 0x0FFF];
40  }
41  return Rom16kBBlocks::peekMem(address, time);
42 }
43 
44 byte RomNational::readMem(word address, EmuTime::param time)
45 {
46  byte result = RomNational::peekMem(address, time);
47  if ((control & 0x02) && ((address & 0x3FFF) == 0x3FFD)) {
48  ++sramAddr;
49  }
50  return result;
51 }
52 
53 const byte* RomNational::getReadCacheLine(word address) const
54 {
55  if ((0x3FF0 & CacheLine::HIGH) == (address & 0x3FFF)) {
56  return nullptr;
57  } else {
58  return Rom16kBBlocks::getReadCacheLine(address);
59  }
60 }
61 
62 void RomNational::writeMem(word address, byte value, EmuTime::param /*time*/)
63 {
64  // TODO bank switch address mirrored?
65  if (address == 0x6000) {
66  bankSelect[1] = value;
67  setRom(1, value); // !!
69  } else if (address == 0x6400) {
70  bankSelect[0] = value;
71  setRom(0, value); // !!
73  } else if (address == 0x7000) {
74  bankSelect[2] = value;
75  setRom(2, value);
77  } else if (address == 0x7400) {
78  bankSelect[3] = value;
79  setRom(3, value);
81  } else if (address == 0x7FF9) {
82  // write control byte
83  control = value;
84  } else if (control & 0x02) {
85  address &= 0x3FFF;
86  if (address == 0x3FFA) {
87  // SRAM address bits 23-16
88  sramAddr = (sramAddr & 0x00FFFF) | value << 16;
89  } else if (address == 0x3FFB) {
90  // SRAM address bits 15-8
91  sramAddr = (sramAddr & 0xFF00FF) | value << 8;
92  } else if (address == 0x3FFC) {
93  // SRAM address bits 7-0
94  sramAddr = (sramAddr & 0xFFFF00) | value;
95  } else if (address == 0x3FFD) {
96  sram->write((sramAddr++ & 0x0FFF), value);
97  }
98  }
99 }
100 
102 {
103  if (address == one_of(0x6000 & CacheLine::HIGH,
104  0x6400 & CacheLine::HIGH,
105  0x7000 & CacheLine::HIGH,
106  0x7400 & CacheLine::HIGH,
107  0x7FF9 & CacheLine::HIGH)) {
108  return nullptr;
109  } else if ((address & 0x3FFF) == (0x3FFA & CacheLine::HIGH)) {
110  return nullptr;
111  } else {
112  return unmappedWrite;
113  }
114 }
115 
116 template<typename Archive>
117 void RomNational::serialize(Archive& ar, unsigned /*version*/)
118 {
119  ar.template serializeBase<Rom16kBBlocks>(*this);
120  ar.serialize("control", control,
121  "sramAddr", sramAddr,
122  "bankSelect", bankSelect);
123 }
126 
127 } // namespace openmsx
one_of.hh
openmsx::RomBlocks::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomBlocks.cc:59
openmsx::RomNational::peekMem
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
Definition: RomNational.cc:29
serialize.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::RomNational::RomNational
RomNational(const DeviceConfig &config, Rom &&rom)
Definition: RomNational.cc:10
RomNational.hh
openmsx::MSXDevice::unmappedWrite
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
openmsx::RomBlocks::sram
std::unique_ptr< SRAM > sram
Definition: RomBlocks.hh:83
openmsx::CacheLine::HIGH
constexpr unsigned HIGH
Definition: CacheLine.hh:10
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::RomBlocks::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomBlocks.cc:71
openmsx::RomBlocks::setRom
void setRom(byte region, unsigned block)
Selects a block of the ROM image for reading in a certain region.
Definition: RomBlocks.cc:104
one_of
Definition: one_of.hh:7
openmsx::RomBlocks
Definition: RomBlocks.hh:14
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::CacheLine::SIZE
constexpr unsigned SIZE
Definition: CacheLine.hh:7
CacheLine.hh
openmsx::Rom
Definition: Rom.hh:21
openmsx::MSXDevice::invalidateDeviceRCache
void invalidateDeviceRCache()
Definition: MSXDevice.hh:209
openmsx::RomNational::writeMem
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: RomNational.cc:62
SRAM.hh
openmsx::RomNational::serialize
void serialize(Archive &ar, unsigned version)
Definition: RomNational.cc:117
openmsx::RomNational
Definition: RomNational.hh:9
openmsx::MSXDevice::getName
virtual std::string getName() const
Returns a human-readable name for this device.
Definition: MSXDevice.cc:381
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::RomNational::getWriteCacheLine
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: RomNational.cc:101
openmsx::RomNational::getReadCacheLine
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: RomNational.cc:53
openmsx::RomNational::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: RomNational.cc:44
openmsx::RomNational::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: RomNational.cc:17
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5