openMSX
MSXPac.cc
Go to the documentation of this file.
1 #include "MSXPac.hh"
2 #include "CacheLine.hh"
3 #include "serialize.hh"
4 
5 namespace openmsx {
6 
7 constexpr const char* const PAC_Header = "PAC2 BACKUP DATA";
8 
10  : MSXDevice(config)
11  , sram(getName() + " SRAM", 0x1FFE, config, PAC_Header)
12 {
13  reset(EmuTime::dummy());
14 }
15 
16 void MSXPac::reset(EmuTime::param /*time*/)
17 {
18  sramEnabled = false;
19  r1ffe = r1fff = 0xFF; // TODO check
20 }
21 
22 byte MSXPac::readMem(word address, EmuTime::param /*time*/)
23 {
24  address &= 0x3FFF;
25  if (sramEnabled) {
26  if (address < 0x1FFE) {
27  return sram[address];
28  } else if (address == 0x1FFE) {
29  return r1ffe;
30  } else if (address == 0x1FFF) {
31  return r1fff;
32  } else {
33  return 0xFF;
34  }
35  } else {
36  return 0xFF;
37  }
38 }
39 
40 const byte* MSXPac::getReadCacheLine(word address) const
41 {
42  address &= 0x3FFF;
43  if (sramEnabled) {
44  if (address < (0x1FFE & CacheLine::HIGH)) {
45  return &sram[address];
46  } else if (address == (0x1FFE & CacheLine::HIGH)) {
47  return nullptr;
48  } else {
49  return unmappedRead;
50  }
51  } else {
52  return unmappedRead;
53  }
54 }
55 
56 void MSXPac::writeMem(word address, byte value, EmuTime::param /*time*/)
57 {
58  address &= 0x3FFF;
59  switch (address) {
60  case 0x1FFE:
61  r1ffe = value;
62  checkSramEnable();
63  break;
64  case 0x1FFF:
65  r1fff = value;
66  checkSramEnable();
67  break;
68  default:
69  if (sramEnabled && (address < 0x1FFE)) {
70  sram.write(address, value);
71  }
72  }
73 }
74 
75 byte* MSXPac::getWriteCacheLine(word address) const
76 {
77  address &= 0x3FFF;
78  if (address == (0x1FFE & CacheLine::HIGH)) {
79  return nullptr;
80  }
81  if (sramEnabled && (address < 0x1FFE)) {
82  return nullptr;
83  } else {
84  return unmappedWrite;
85  }
86 }
87 
88 void MSXPac::checkSramEnable()
89 {
90  bool newEnabled = (r1ffe == 0x4D) && (r1fff == 0x69);
91  if (sramEnabled != newEnabled) {
92  sramEnabled = newEnabled;
94  }
95 }
96 
97 template<typename Archive>
98 void MSXPac::serialize(Archive& ar, unsigned /*version*/)
99 {
100  ar.template serializeBase<MSXDevice>(*this);
101  ar.serialize("SRAM", sram,
102  "r1ffe", r1ffe,
103  "r1fff", r1fff);
104  if (ar.isLoader()) {
105  checkSramEnable();
106  }
107 }
110 
111 } // namespace openmsx
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
static byte unmappedRead[0x10000]
Definition: MSXDevice.hh:300
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
Definition: MSXDevice.hh:208
static byte unmappedWrite[0x10000]
Definition: MSXDevice.hh:301
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXPac.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: MSXPac.cc:56
MSXPac(const DeviceConfig &config)
Definition: MSXPac.cc:9
void serialize(Archive &ar, unsigned version)
Definition: MSXPac.cc:98
byte * getWriteCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
Definition: MSXPac.cc:75
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: MSXPac.cc:22
const byte * getReadCacheLine(word address) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: MSXPac.cc:40
void write(unsigned addr, byte value)
Definition: SRAM.cc:67
constexpr unsigned HIGH
Definition: CacheLine.hh:10
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:742
This file implemented 3 utility functions:
Definition: Autofire.cc:5
constexpr const char *const PAC_Header
Definition: MSXPac.cc:7
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983