13 , romBlockDebug(*this)
14 , rom(getName() +
" ROM",
"rom", config)
15 , internalBank(
subspan<0x4000>(rom))
37 device[0]->reset(time);
38 device[1]->reset(time);
43 if (ideRegsEnabled && ((address & 0x3E00) == 0x3C00)) {
45 if ((address & 1) == 0) {
46 return readDataLow(time);
48 return readDataHigh(time);
51 if (ideRegsEnabled && ((address & 0x3F00) == 0x3E00)) {
53 return readReg(address & 0xF, time);
55 if ((0x4000 <= address) && (address < 0x8000)) {
57 return internalBank[address & 0x3FFF];
65 if (ideRegsEnabled && ((start & 0x3E00) == 0x3C00)) {
68 if (ideRegsEnabled && ((start & 0x3F00) == 0x3E00)) {
71 if ((0x4000 <= start) && (start < 0x8000)) {
72 return &internalBank[start & 0x3FFF];
79 if ((address & 0xBF04) == 0x0104) {
84 if (ideRegsEnabled && ((address & 0x3E00) == 0x3C00)) {
86 if ((address & 1) == 0) {
89 writeDataHigh(value, time);
93 if (ideRegsEnabled && ((address & 0x3F00) == 0x3E00)) {
95 writeReg(address & 0xF, value, time);
101byte SunriseIDE::getBank()
const
104 if (bank >= (rom.
size() / 0x4000)) {
105 bank &= narrow_cast<byte>((rom.
size() / 0x4000) - 1);
110void SunriseIDE::writeControl(
byte value)
113 if (ideRegsEnabled != (control & 1)) {
114 ideRegsEnabled = control & 1;
121 size_t bank = getBank();
122 if (internalBank.data() != &rom[0x4000 * bank]) {
123 internalBank = subspan<0x4000>(rom, 0x4000 * bank);
128byte SunriseIDE::readDataLow(EmuTime::param time)
130 word temp = readData(time);
131 readLatch = narrow_cast<byte>(temp >> 8);
132 return narrow_cast<byte>(temp & 0xFF);
134byte SunriseIDE::readDataHigh(EmuTime::param )
const
138word SunriseIDE::readData(EmuTime::param time)
140 return device[selectedDevice]->readData(time);
143byte SunriseIDE::readReg(
nibble reg, EmuTime::param time)
159 return narrow_cast<byte>(readData(time) & 0xFF);
161 byte result = device[selectedDevice]->readReg(reg, time);
164 result |= selectedDevice ? 0x10 : 0x00;
171void SunriseIDE::writeDataLow(
byte value)
175void SunriseIDE::writeDataHigh(
byte value, EmuTime::param time)
177 auto temp =
word((value << 8) | writeLatch);
178 writeData(temp, time);
180void SunriseIDE::writeData(
word value, EmuTime::param time)
182 device[selectedDevice]->writeData(value, time);
185void SunriseIDE::writeReg(
nibble reg,
byte value, EmuTime::param time)
188 if ((reg == 14) && !(value & 0x04)) {
195 writeData(narrow_cast<word>((value << 8) | value), time);
197 if ((reg == 14) && (value & 0x04)) {
200 device[0]->reset(time);
201 device[1]->reset(time);
204 selectedDevice = (value & 0x10) ? 1 : 0;
206 device[selectedDevice]->writeReg(reg, value, time);
212template<
typename Archive>
215 ar.template serializeBase<MSXDevice>(*
this);
216 ar.serializePolymorphic(
"master", *device[0]);
217 ar.serializePolymorphic(
"slave", *device[1]);
218 ar.serialize(
"readLatch", readLatch,
219 "writeLatch", writeLatch,
220 "selectedDevice", selectedDevice,
222 "softReset", softReset);
224 if constexpr (Archive::IS_LOADER) {
226 writeControl(control);
233SunriseIDE::Blocks::Blocks(
const SunriseIDE& device)
238byte SunriseIDE::Blocks::read(
unsigned address)
240 if ((address < 0x4000) || (address >= 0x8000))
return 255;
241 const auto& ide =
OUTER(SunriseIDE, romBlockDebug);
242 return ide.getBank();
#define REGISTER_MSXDEVICE(CLASS, NAME)
const XMLElement * findChild(std::string_view name) const
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
void invalidateDeviceRCache()
static std::array< byte, 0x10000 > unmappedRead
EmuTime::param getCurrentTime() const
void reset(EmuTime::param time) override
This method is called on reset.
SunriseIDE(const DeviceConfig &config)
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.
void serialize(Archive &ar, unsigned version)
const byte * getReadCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for reading.
void powerUp(EmuTime::param time) override
This method is called when MSX is powered up.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
constexpr uint8_t reverseByte(uint8_t a)
Reverse the bits in a byte.
std::unique_ptr< IDEDevice > create(const DeviceConfig &config)
This file implemented 3 utility functions:
uint8_t nibble
4 bit integer
uint16_t word
16 bit unsigned integer
#define OUTER(type, member)
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)