| 1 |
#include "MSXKanji12.hh" |
| 2 |
|
| 3 |
#include "MSXException.hh" |
| 4 |
#include "TclObject.hh" |
| 5 |
#include "serialize.hh" |
| 6 |
|
| 7 |
#include "narrow.hh" |
| 8 |
#include "one_of.hh" |
| 9 |
|
| 10 |
namespace openmsx { |
| 11 |
|
| 12 |
static constexpr byte ID = 0xF7; |
| 13 |
|
| 14 |
MSXKanji12::MSXKanji12(DeviceConfig& config) |
| 15 |
: MSXDevice(config) |
| 16 |
, MSXSwitchedDevice(getMotherBoard(), ID) |
| 17 |
, rom(getName(), "Kanji-12 ROM", config) |
| 18 |
{ |
| 19 |
if (rom.size() != one_of(0x20000u, 0x40000u)) { |
| 20 |
throw MSXException("MSXKanji12: wrong kanji ROM, it should be either 128kB or 256kB."); |
| 21 |
} |
| 22 |
|
| 23 |
reset(EmuTime::dummy()); |
| 24 |
} |
| 25 |
|
| 26 |
void MSXKanji12::reset(EmuTime ) |
| 27 |
{ |
| 28 |
address = 0; |
| 29 |
} |
| 30 |
|
| 31 |
byte MSXKanji12::readSwitchedIO(uint16_t port, EmuTime time) |
| 32 |
{ |
| 33 |
byte result = peekSwitchedIO(port, time); |
| 34 |
switch (port & 0x0F) { |
| 35 |
case 9: |
| 36 |
address++; |
| 37 |
break; |
| 38 |
} |
| 39 |
return result; |
| 40 |
} |
| 41 |
|
| 42 |
byte MSXKanji12::peekSwitchedIO(uint16_t port, EmuTime ) const |
| 43 |
{ |
| 44 |
switch (port & 0x0F) { |
| 45 |
case 0: |
| 46 |
return byte(~ID); |
| 47 |
case 1: |
| 48 |
return 0x08; |
| 49 |
case 9: |
| 50 |
if (address < rom.size()) { |
| 51 |
return rom[address]; |
| 52 |
} else { |
| 53 |
return 0xFF; |
| 54 |
} |
| 55 |
default: |
| 56 |
return 0xFF; |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
void MSXKanji12::writeSwitchedIO(uint16_t port, byte value, EmuTime ) |
| 61 |
{ |
| 62 |
switch (port & 0x0F) { |
| 63 |
case 2: |
| 64 |
|
| 65 |
break; |
| 66 |
case 7: { |
| 67 |
byte row = value; |
| 68 |
byte col = narrow<byte>(((address - 0x800) / 18) % 192); |
| 69 |
address = 0x800 + (row * 192 + col) * 18; |
| 70 |
break; |
| 71 |
} |
| 72 |
case 8: { |
| 73 |
byte row = narrow<byte>((address - 0x800) / (18 * 192)); |
| 74 |
byte col = value; |
| 75 |
address = 0x800 + (row * 192 + col) * 18; |
| 76 |
break; |
| 77 |
} |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
void MSXKanji12::getExtraDeviceInfo(TclObject& result) const |
| 82 |
{ |
| 83 |
rom.getInfo(result); |
| 84 |
} |
| 85 |
|
| 86 |
template<typename Archive> |
| 87 |
void MSXKanji12::serialize(Archive& ar, unsigned ) |
| 88 |
{ |
| 89 |
ar.template serializeBase<MSXDevice>(*this); |
| 90 |
|
| 91 |
|
| 92 |
ar.serialize("address", address); |
| 93 |
} |
| 94 |
INSTANTIATE_SERIALIZE_METHODS(MSXKanji12); |
| 95 |
REGISTER_MSXDEVICE(MSXKanji12, "Kanji12"); |
| 96 |
|
| 97 |
} |