openMSX
MSXPac.cc
Go to the documentation of this file.
1#include "MSXPac.hh"
2#include "CacheLine.hh"
3#include "serialize.hh"
4
5namespace openmsx {
6
7static 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
16void MSXPac::reset(EmuTime::param /*time*/)
17{
18 sramEnabled = false;
19 r1ffe = r1fff = 0xFF; // TODO check
20}
21
22byte 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
40const 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.data();
50 }
51 } else {
52 return unmappedRead.data();
53 }
54}
55
56void 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
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.data();
85 }
86}
87
88void MSXPac::checkSramEnable()
89{
90 bool newEnabled = (r1ffe == 0x4D) && (r1fff == 0x69);
91 if (sramEnabled != newEnabled) {
92 sramEnabled = newEnabled;
94 }
95}
96
97template<typename Archive>
98void 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 constexpr (Archive::IS_LOADER) {
105 checkSramEnable();
106 }
107}
110
111} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
static std::array< byte, 0x10000 > unmappedRead
Definition MSXDevice.hh:306
static std::array< byte, 0x10000 > unmappedWrite
Definition MSXDevice.hh:307
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
Definition MSXDevice.hh:214
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) 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(size_t addr, byte value)
Definition SRAM.cc:64
constexpr unsigned HIGH
Definition CacheLine.hh:10
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)