openMSX
MSXKanji12.cc
Go to the documentation of this file.
1 #include "MSXKanji12.hh"
2 #include "MSXException.hh"
3 #include "one_of.hh"
4 #include "serialize.hh"
5 
6 namespace openmsx {
7 
8 constexpr byte ID = 0xF7;
9 
11  : MSXDevice(config)
12  , MSXSwitchedDevice(getMotherBoard(), ID)
13  , rom(getName(), "Kanji-12 ROM", config)
14 {
15  if (rom.getSize() != one_of(0x20000u, 0x40000u)) {
16  throw MSXException("MSXKanji12: wrong kanji ROM, it should be either 128kB or 256kB.");
17  }
18 
19  reset(EmuTime::dummy());
20 }
21 
22 void MSXKanji12::reset(EmuTime::param /*time*/)
23 {
24  address = 0; // TODO check this
25 }
26 
27 byte MSXKanji12::readSwitchedIO(word port, EmuTime::param time)
28 {
29  byte result = peekSwitchedIO(port, time);
30  switch (port & 0x0F) {
31  case 9:
32  address++;
33  break;
34  }
35  return result;
36 }
37 
38 byte MSXKanji12::peekSwitchedIO(word port, EmuTime::param /*time*/) const
39 {
40  byte result;
41  switch (port & 0x0F) {
42  case 0:
43  result = byte(~ID);
44  break;
45  case 1:
46  result = 0x08; // TODO what is this
47  break;
48  case 9:
49  if (address < rom.getSize()) {
50  result = rom[address];
51  } else {
52  result = 0xFF;
53  }
54  break;
55  default:
56  result = 0xFF;
57  break;
58  }
59  return result;
60 }
61 
62 void MSXKanji12::writeSwitchedIO(word port, byte value, EmuTime::param /*time*/)
63 {
64  switch (port & 0x0F) {
65  case 2:
66  // TODO what is this?
67  break;
68  case 7: {
69  byte row = value;
70  byte col = ((address - 0x800) / 18) % 192;
71  address = 0x800 + (row * 192 + col) * 18;
72  break;
73  }
74  case 8: {
75  byte row = (address - 0x800) / (18 * 192);
76  byte col = value;
77  address = 0x800 + (row * 192 + col) * 18;
78  break;
79  }
80  }
81 }
82 
83 template<typename Archive>
84 void MSXKanji12::serialize(Archive& ar, unsigned /*version*/)
85 {
86  ar.template serializeBase<MSXDevice>(*this);
87  // no need to serialize MSXSwitchedDevice base class
88 
89  ar.serialize("address", address);
90 }
93 
94 } // namespace openmsx
openmsx::MSXDevice
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
one_of.hh
openmsx::MSXKanji12::writeSwitchedIO
void writeSwitchedIO(word port, byte value, EmuTime::param time) override
Definition: MSXKanji12.cc:62
serialize.hh
openmsx::DeviceConfig
Definition: DeviceConfig.hh:20
openmsx::MSXSwitchedDevice
Definition: MSXSwitchedDevice.hh:12
openmsx::byte
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
MSXException.hh
openmsx::MSXException
Definition: MSXException.hh:10
openmsx::REGISTER_MSXDEVICE
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
openmsx::MSXKanji12::MSXKanji12
MSXKanji12(const DeviceConfig &config)
Definition: MSXKanji12.cc:10
openmsx::Keys::getName
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:740
openmsx::MSXKanji12::reset
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXKanji12.cc:22
one_of
Definition: one_of.hh:7
INSTANTIATE_SERIALIZE_METHODS
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:981
openmsx::MSXKanji12::peekSwitchedIO
byte peekSwitchedIO(word port, EmuTime::param time) const override
Definition: MSXKanji12.cc:38
MSXKanji12.hh
openmsx::MSXKanji12::serialize
void serialize(Archive &ar, unsigned version)
Definition: MSXKanji12.cc:84
openmsx::ID
constexpr byte ID
Definition: MSXKanji12.cc:8
openmsx::MSXKanji12
Definition: MSXKanji12.hh:11
openmsx::word
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
openmsx::MSXKanji12::readSwitchedIO
byte readSwitchedIO(word port, EmuTime::param time) override
Definition: MSXKanji12.cc:27
openmsx::Rom::getSize
unsigned getSize() const
Definition: Rom.hh:32
openmsx
This file implemented 3 utility functions:
Definition: Autofire.cc:5