OXYGENHUB
◆ main openmsx / src / MSXS1990.cc
2.6 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "MSXS1990.hh"
2
3
#include "MSXCPU.hh"
4
#include "MSXMotherBoard.hh"
5
#include "PanasonicMemory.hh"
6
#include "serialize.hh"
7
8
#include "narrow.hh"
9
#include "outer.hh"
10
#include "unreachable.hh"
11
12
namespace openmsx {
13
14
MSXS1990::MSXS1990(const DeviceConfig& config)
15
	: MSXDevice(config)
16
	, debuggable(getMotherBoard(), getName())
17
	, firmwareSwitch(config)
18
{
19
	reset(EmuTime::dummy());
20
}
21
22
void MSXS1990::reset(EmuTime /*time*/)
23
{
24
	registerSelect = 0; // TODO check this
25
	setCPUStatus(96);
26
}
27
28
byte MSXS1990::readIO(uint16_t port, EmuTime time)
29
{
30
	return peekIO(port, time);
31
}
32
33
byte MSXS1990::peekIO(uint16_t port, EmuTime /*time*/) const
34
{
35
	switch (port & 0x01) {
36
	case 0:
37
		return registerSelect;
38
	case 1:
39
		return readRegister(registerSelect);
40
	default:
41
		UNREACHABLE;
42
	}
43
}
44
45
void MSXS1990::writeIO(uint16_t port, byte value, EmuTime /*time*/)
46
{
47
	switch (port & 0x01) {
48
	case 0:
49
		registerSelect = value;
50
		break;
51
	case 1:
52
		writeRegister(registerSelect, value);
53
		break;
54
	default:
55
		UNREACHABLE;
56
	}
57
}
58
59
byte MSXS1990::readRegister(byte reg) const
60
{
61
	switch (reg) {
62
	case 5:
63
		return firmwareSwitch.getStatus() ? 0x40 : 0x00;
64
	case 6:
65
		return cpuStatus;
66
	case 13:
67
		return 0x03; // TODO
68
	case 14:
69
		return 0x2F; // TODO
70
	case 15:
71
		return 0x8B; // TODO
72
	default:
73
		return 0xFF;
74
	}
75
}
76
77
void MSXS1990::writeRegister(byte reg, byte value)
78
{
79
	switch (reg) {
80
	case 6:
81
		setCPUStatus(value);
82
		break;
83
	}
84
}
85
86
void MSXS1990::setCPUStatus(byte value)
87
{
88
	cpuStatus = value & 0x60;
89
	getCPU().setActiveCPU((cpuStatus & 0x20) ? MSXCPU::Type::Z80 :
90
	                                           MSXCPU::Type::R800);
91
	bool dram = (cpuStatus & 0x40) == 0;
92
	getCPU().setDRAMmode(dram);
93
	getMotherBoard().getPanasonicMemory().setDRAM(dram);
94
	// TODO bit 7 -> reset MSX ?????
95
}
96
97
98
MSXS1990::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
99
	: SimpleDebuggable(motherBoard_, name_ + " regs", "S1990 registers", 16)
100
{
101
}
102
103
byte MSXS1990::Debuggable::read(unsigned address)
104
{
105
	const auto& s1990 = OUTER(MSXS1990, debuggable);
106
	return s1990.readRegister(narrow<byte>(address));
107
}
108
109
void MSXS1990::Debuggable::write(unsigned address, byte value)
110
{
111
	auto& s1990 = OUTER(MSXS1990, debuggable);
112
	s1990.writeRegister(narrow<byte>(address), value);
113
}
114
115
116
template<typename Archive>
117
void MSXS1990::serialize(Archive& ar, unsigned /*version*/)
118
{
119
	ar.template serializeBase<MSXDevice>(*this);
120
	ar.serialize("registerSelect", registerSelect,
121
	             "cpuStatus",      cpuStatus);
122
	if constexpr (Archive::IS_LOADER) {
123
		setCPUStatus(cpuStatus);
124
	}
125
}
126
INSTANTIATE_SERIALIZE_METHODS(MSXS1990);
127
REGISTER_MSXDEVICE(MSXS1990, "S1990");
128
129
} // namespace openmsx