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  switch (port & 0x0F) {
41  case 0:
42  return byte(~ID);
43  case 1:
44  return 0x08; // TODO what is this
45  case 9:
46  if (address < rom.getSize()) {
47  return rom[address];
48  } else {
49  return 0xFF;
50  }
51  default:
52  return 0xFF;
53  }
54 }
55 
56 void MSXKanji12::writeSwitchedIO(word port, byte value, EmuTime::param /*time*/)
57 {
58  switch (port & 0x0F) {
59  case 2:
60  // TODO what is this?
61  break;
62  case 7: {
63  byte row = value;
64  byte col = ((address - 0x800) / 18) % 192;
65  address = 0x800 + (row * 192 + col) * 18;
66  break;
67  }
68  case 8: {
69  byte row = (address - 0x800) / (18 * 192);
70  byte col = value;
71  address = 0x800 + (row * 192 + col) * 18;
72  break;
73  }
74  }
75 }
76 
77 template<typename Archive>
78 void MSXKanji12::serialize(Archive& ar, unsigned /*version*/)
79 {
80  ar.template serializeBase<MSXDevice>(*this);
81  // no need to serialize MSXSwitchedDevice base class
82 
83  ar.serialize("address", address);
84 }
87 
88 } // namespace openmsx
Definition: one_of.hh:7
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition: MSXDevice.hh:32
byte readSwitchedIO(word port, EmuTime::param time) override
Definition: MSXKanji12.cc:27
byte peekSwitchedIO(word port, EmuTime::param time) const override
Definition: MSXKanji12.cc:38
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXKanji12.cc:22
void writeSwitchedIO(word port, byte value, EmuTime::param time) override
Definition: MSXKanji12.cc:56
MSXKanji12(const DeviceConfig &config)
Definition: MSXKanji12.cc:10
void serialize(Archive &ar, unsigned version)
Definition: MSXKanji12.cc:78
unsigned getSize() const
Definition: Rom.hh:34
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:742
This file implemented 3 utility functions:
Definition: Autofire.cc:5
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
constexpr byte ID
Definition: MSXKanji12.cc:8
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:983