openMSX
BeerIDE.cc
Go to the documentation of this file.
1 #include "BeerIDE.hh"
2 #include "IDEDeviceFactory.hh"
3 #include "IDEDevice.hh"
4 #include "GlobalSettings.hh"
5 #include "serialize.hh"
6 
7 namespace openmsx {
8 
10  : MSXDevice(config)
11  , i8255(*this, getCurrentTime(), config.getGlobalSettings().getInvalidPpiModeSetting())
12  , rom(getName() + " ROM", "rom", config)
13 {
14  device = IDEDeviceFactory::create(
15  DeviceConfig(config, config.findChild("idedevice")));
16 
18 }
19 
20 BeerIDE::~BeerIDE() = default;
21 
22 void BeerIDE::reset(EmuTime::param time)
23 {
24  controlReg = 0;
25  dataReg = 0;
26  device->reset(time);
27  i8255.reset(time);
28 }
29 
30 byte BeerIDE::readMem(word address, EmuTime::param /*time*/)
31 {
32  if (0x4000 <= address && address < 0x8000) {
33  return rom[address & 0x3FFF];
34  }
35  return 0xFF;
36 }
37 
38 const byte* BeerIDE::getReadCacheLine(word start) const
39 {
40  if (0x4000 <= start && start < 0x8000) {
41  return &rom[start & 0x3FFF];
42  }
43  return unmappedRead;
44 }
45 
46 byte BeerIDE::readIO(word port, EmuTime::param time)
47 {
48  return i8255.read(port & 0x03, time);
49 }
50 
51 byte BeerIDE::peekIO(word port, EmuTime::param time) const
52 {
53  return i8255.peek(port & 0x03, time);
54 }
55 
56 void BeerIDE::writeIO(word port, byte value, EmuTime::param time)
57 {
58  i8255.write(port & 0x03, value, time);
59 }
60 
61 // I8255Interface
62 
63 byte BeerIDE::readA(EmuTime::param time)
64 {
65  return peekA(time);
66 }
67 byte BeerIDE::peekA(EmuTime::param /*time*/) const
68 {
69  return (dataReg & 0xFF);
70 }
71 void BeerIDE::writeA(byte value, EmuTime::param /*time*/)
72 {
73  dataReg &= 0xFF00;
74  dataReg |= value;
75 }
76 
77 byte BeerIDE::readB(EmuTime::param time)
78 {
79  return peekB(time);
80 }
81 byte BeerIDE::peekB(EmuTime::param /*time*/) const
82 {
83  return (dataReg >> 8);
84 }
85 void BeerIDE::writeB(byte value, EmuTime::param /*time*/)
86 {
87  dataReg &= 0x00FF;
88  dataReg |= (value << 8);
89 }
90 
91 nibble BeerIDE::readC1(EmuTime::param time)
92 {
93  return peekC1(time);
94 }
95 nibble BeerIDE::peekC1(EmuTime::param /*time*/) const
96 {
97  return 0; // TODO check this
98 }
99 nibble BeerIDE::readC0(EmuTime::param time)
100 {
101  return peekC0(time);
102 }
103 nibble BeerIDE::peekC0(EmuTime::param /*time*/) const
104 {
105  return 0; // TODO check this
106 }
107 void BeerIDE::writeC1(nibble value, EmuTime::param time)
108 {
109  changeControl((controlReg & 0x0F) | (value << 4), time);
110 }
111 void BeerIDE::writeC0(nibble value, EmuTime::param time)
112 {
113  changeControl((controlReg & 0xF0) | value, time);
114 }
115 void BeerIDE::changeControl(byte value, EmuTime::param time)
116 {
117  byte diff = controlReg ^ value;
118  controlReg = value;
119  if ((diff & 0xE7) == 0) return; // nothing relevant changed
120 
121  byte address = controlReg & 7;
122  switch (value & 0xE0) {
123  case 0x40: // read /IORD=0, /IOWR=1, /CS0=0
124  if (address == 0) {
125  dataReg = device->readData(time);
126  } else {
127  dataReg = device->readReg(address, time);
128  }
129  break;
130  case 0x80: // write /IORD=1, /IOWR=0, /CS0=0
131  if (address == 0) {
132  device->writeData(dataReg, time);
133  } else {
134  device->writeReg(address, dataReg & 0xFF, time);
135  }
136  break;
137  default: // all (6) other cases, nothing
138  break;
139  }
140 }
141 
142 template<typename Archive>
143 void BeerIDE::serialize(Archive& ar, unsigned /*version*/)
144 {
145  ar.template serializeBase<MSXDevice>(*this);
146  ar.serialize("i8255", i8255);
147  ar.serializePolymorphic("device", *device);
148  ar.serialize("dataReg", dataReg,
149  "controlReg", controlReg);
150 }
153 
154 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
openmsx::BeerIDE::readMem
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
Definition: BeerIDE.cc:30
serialize.hh
openmsx::I8255::write
void write(byte port, byte value, EmuTime::param time)
Definition: I8255.cc:76
openmsx::I8255::peek
byte peek(byte port, EmuTime::param time) const
Definition: I8255.cc:59
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
IDEDevice.hh
openmsx::BeerIDE
Definition: BeerIDE.hh:50
openmsx::YM2413NukeYKT::rom
constexpr Rom rom
Definition: YM2413NukeYKT.cc:71
openmsx::BeerIDE::serialize
void serialize(Archive &ar, unsigned version)
Definition: BeerIDE.cc:143
openmsx::DeviceConfig::findChild
const XMLElement * findChild(std::string_view name) const
Definition: DeviceConfig.cc:61
openmsx::BeerIDE::readIO
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition: BeerIDE.cc:46
BeerIDE.hh
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::IDEDeviceFactory::create
std::unique_ptr< IDEDevice > create(const DeviceConfig &config)
Definition: IDEDeviceFactory.cc:11
openmsx::I8255::reset
void reset(EmuTime::param time)
Definition: I8255.cc:33
openmsx::BeerIDE::writeIO
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
Definition: BeerIDE.cc:56
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:740
openmsx::nibble
uint8_t nibble
4 bit integer
Definition: openmsx.hh:23
openmsx::BeerIDE::~BeerIDE
~BeerIDE() override
openmsx::MSXDevice::getCurrentTime
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:131
openmsx::BeerIDE::peekIO
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: BeerIDE.cc:51
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::I8255::read
byte read(byte port, EmuTime::param time)
Definition: I8255.cc:42
GlobalSettings.hh
openmsx::BeerIDE::BeerIDE
BeerIDE(const DeviceConfig &config)
Definition: BeerIDE.cc:9
IDEDeviceFactory.hh
openmsx::MSXDevice::unmappedRead
static byte unmappedRead[0x10000]
Definition: MSXDevice.hh:300
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::BeerIDE::getReadCacheLine
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
Definition: BeerIDE.cc:38
openmsx
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
openmsx::MSXDevice::powerUp
virtual void powerUp(EmuTime::param time)
This method is called when MSX is powered up.
Definition: MSXDevice.cc:376
openmsx::BeerIDE::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: BeerIDE.cc:22