openMSX
MSXToshibaTcx200x.cc
Go to the documentation of this file.
2#include "CacheLine.hh"
3#include "serialize.hh"
4
5namespace openmsx {
6
7// 7FFF is mapper control register
8//
9// x11xxxxx select SRAM in page 2 (8000H-87FFH, or perhaps mirrored in page 2), R/W
10// x00xxxxx select ROM in page 2, R/W
11// xxxxxx00 select ROM segment 0 in page 2 (screen copy, japanese word processor), R/W
12// xxxxxx01 select ROM segment 1 in page 2 (japanese word processor), R/W
13// xxxxxx10 select ROM segment 2 in page 2 (european word processor), R/W
14// xxxxxx11 select ROM segment 3 in page 2 (japanese word processor), R/W
15// kxxxxxxx COPY key, 0 is pressed (R)
16
17// b6,b5 = SRAM select. Only pattern 00 and 11 are used, not sure what pattern 01 and 10 do
18// Assumption that SRAM is only visible in page 2, because the ROM segment
19// select is also for page 2 only
20
22 : MSXDevice(config)
23 , rs232Rom(getName() + " RS232C ROM", "rom", config, "rs232")
24 , wordProcessorRom(getName() + " Word Processor ROM", "rom", config, "wordpro")
25 , sram(getName() + " SRAM", 0x800, config)
26 , copyButtonPressed(getCommandController(), "copy_button_pressed",
27 "pressed status of the COPY button", false)
28{
29 reset(EmuTime::dummy());
30}
31
32void MSXToshibaTcx200x::reset(EmuTime::param time)
33{
34 copyButtonPressed.setBoolean(false);
35 writeMem(0x7FFF, 0, time);
36}
37
38bool MSXToshibaTcx200x::sramEnabled() const
39{
40 return (controlReg & 0b0110'0000) == 0b0110'0000;
41 // note: we don't know what the hardware does if only one bit is on 1
42}
43
44byte MSXToshibaTcx200x::getSelectedSegment() const
45{
46 return controlReg & 0b0000'0011;
47}
48
49byte MSXToshibaTcx200x::peekMem(word address, EmuTime::param /*time*/) const
50{
51 if (address == 0x7FFF) {
52 return byte(controlReg | ((copyButtonPressed.getBoolean() ? 0 : 1) << 7));
53 } else if ((0x4000 <= address) && (address < 0x7FFF)) {
54 return rs232Rom[address - 0x4000];
55 } else if ((0x8000 <= address) && (address < 0xC000)) {
56 if (sramEnabled()) {
57 // TODO: assuming SRAM mirrors all over page 2. Not verified!
58 return sram[address & (sram.size() - 1)];
59 } else {
60 return wordProcessorRom[(address - 0x8000) + getSelectedSegment() * 0x4000];
61 }
62 } else {
63 return 0xFF;
64 }
65}
66
67byte MSXToshibaTcx200x::readMem(word address, EmuTime::param time)
68{
69 return peekMem(address, time);
70}
71
72void MSXToshibaTcx200x::writeMem(word address, byte value, EmuTime::param /*time*/)
73{
74 if (address == 0x7FFF) {
75 controlReg = value & 0b0110'0011; // TODO which bits can be read back?
76 invalidateDeviceRWCache(0x8000, 0x4000);
77 } else if ((0x8000 <= address) && (address < 0xC000) && sramEnabled()) {
78 sram.write(address & (sram.size() - 1), value);
79 }
80}
81
83{
84 if ((start & CacheLine::HIGH) == (0x7FFF & CacheLine::HIGH)) {
85 return nullptr;
86 } else if ((0x4000 <= start) && (start < 0x7FFF)) {
87 return &rs232Rom[start - 0x4000];
88 } else if ((0x8000 <= start) && (start < 0xC000)) {
89 if (sramEnabled()) {
90 return &sram[start & (sram.size() - 1)];
91 } else {
92 return &wordProcessorRom[(start - 0x8000) + getSelectedSegment() * 0x4000];
93 }
94 }
95 return unmappedRead.data();
96}
97
99{
100 if ((start & CacheLine::HIGH) == (0x7FFF & CacheLine::HIGH)) {
101 return nullptr;
102 } else if ((0x8000 <= start) && (start < 0xC000) && sramEnabled()) {
103 return nullptr;
104 } else {
105 return unmappedWrite.data();
106 }
107}
108
109template<typename Archive>
110void MSXToshibaTcx200x::serialize(Archive& ar, unsigned /*version*/)
111{
112 ar.template serializeBase<MSXDevice>(*this);
113 ar.serialize("sram", sram,
114 "controlReg", controlReg);
115}
118
119} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:354
bool getBoolean() const noexcept
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
static std::array< byte, 0x10000 > unmappedRead
Definition MSXDevice.hh:304
static std::array< byte, 0x10000 > unmappedWrite
Definition MSXDevice.hh:305
void invalidateDeviceRWCache()
Calls MSXCPUInterface::invalidateXXCache() for the specific (part of) the slot that this device is lo...
Definition MSXDevice.hh:212
void reset(EmuTime::param time) override
This method is called on reset.
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 writeMem(word address, byte value, EmuTime::param time) override
Write a given byte to a given location at a certain time to this device.
byte readMem(word address, EmuTime::param time) override
Read a byte from a location at a certain time from this device.
byte peekMem(word address, EmuTime::param time) const override
Read a byte from a given memory location.
MSXToshibaTcx200x(const DeviceConfig &config)
byte * getWriteCacheLine(word start) const override
Test that the memory in the interval [start, start + CacheLine::SIZE) is cacheable for writing.
void write(size_t addr, byte value)
Definition SRAM.cc:65
size_t size() const
Definition SRAM.hh:35
constexpr unsigned HIGH
Definition CacheLine.hh:10
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)