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