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
7namespace openmsx {
8
10 : MSXDevice(config)
11 , i8255(*this, getCurrentTime(), config.getGlobalSettings().getInvalidPpiModeSetting())
12 , rom(getName() + " ROM", "rom", config)
13{
15 DeviceConfig(config, config.findChild("idedevice")));
16
18}
19
20BeerIDE::~BeerIDE() = default;
21
22void BeerIDE::reset(EmuTime::param time)
23{
24 controlReg = 0;
25 dataReg = 0;
26 device->reset(time);
27 i8255.reset(time);
28}
29
30byte 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
38const byte* BeerIDE::getReadCacheLine(word start) const
39{
40 if (0x4000 <= start && start < 0x8000) {
41 return &rom[start & 0x3FFF];
42 }
43 return unmappedRead.data();
44}
45
46byte BeerIDE::readIO(word port, EmuTime::param time)
47{
48 return i8255.read(port & 0x03, time);
49}
50
51byte BeerIDE::peekIO(word port, EmuTime::param time) const
52{
53 return i8255.peek(port & 0x03, time);
54}
55
56void BeerIDE::writeIO(word port, byte value, EmuTime::param time)
57{
58 i8255.write(port & 0x03, value, time);
59}
60
61// I8255Interface
62
63byte BeerIDE::readA(EmuTime::param time)
64{
65 return peekA(time);
66}
67byte BeerIDE::peekA(EmuTime::param /*time*/) const
68{
69 return (dataReg & 0xFF);
70}
71void BeerIDE::writeA(byte value, EmuTime::param /*time*/)
72{
73 dataReg &= 0xFF00;
74 dataReg |= value;
75}
76
77byte BeerIDE::readB(EmuTime::param time)
78{
79 return peekB(time);
80}
81byte BeerIDE::peekB(EmuTime::param /*time*/) const
82{
83 return (dataReg >> 8);
84}
85void BeerIDE::writeB(byte value, EmuTime::param /*time*/)
86{
87 dataReg &= 0x00FF;
88 dataReg |= (value << 8);
89}
90
91nibble BeerIDE::readC1(EmuTime::param time)
92{
93 return peekC1(time);
94}
95nibble BeerIDE::peekC1(EmuTime::param /*time*/) const
96{
97 return 0; // TODO check this
98}
99nibble BeerIDE::readC0(EmuTime::param time)
100{
101 return peekC0(time);
102}
103nibble BeerIDE::peekC0(EmuTime::param /*time*/) const
104{
105 return 0; // TODO check this
106}
107void BeerIDE::writeC1(nibble value, EmuTime::param time)
108{
109 changeControl((controlReg & 0x0F) | (value << 4), time);
110}
111void BeerIDE::writeC0(nibble value, EmuTime::param time)
112{
113 changeControl((controlReg & 0xF0) | value, time);
114}
115void 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
142template<typename Archive>
143void 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
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: BeerIDE.cc:51
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
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
void reset(EmuTime::param time) override
This method is called on reset.
Definition: BeerIDE.cc:22
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
BeerIDE(const DeviceConfig &config)
Definition: BeerIDE.cc:9
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
void serialize(Archive &ar, unsigned version)
Definition: BeerIDE.cc:143
~BeerIDE() override
const XMLElement * findChild(std::string_view name) const
Definition: DeviceConfig.cc:66
void reset(EmuTime::param time)
Definition: I8255.cc:33
byte peek(byte port, EmuTime::param time) const
Definition: I8255.cc:59
byte read(byte port, EmuTime::param time)
Definition: I8255.cc:42
void write(byte port, byte value, EmuTime::param time)
Definition: I8255.cc:76
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:34
virtual void powerUp(EmuTime::param time)
This method is called when MSX is powered up.
Definition: MSXDevice.cc:370
static std::array< byte, 0x10000 > unmappedRead
Definition: MSXDevice.hh:302
EmuTime::param getCurrentTime() const
Definition: MSXDevice.cc:125
std::unique_ptr< IDEDevice > create(const DeviceConfig &config)
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730
This file implemented 3 utility functions:
Definition: Autofire.cc:9
uint8_t nibble
4 bit integer
Definition: openmsx.hh:23
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021