openMSX
MSXS1990.cc
Go to the documentation of this file.
1#include "MSXS1990.hh"
2#include "MSXCPU.hh"
3#include "MSXMotherBoard.hh"
4#include "PanasonicMemory.hh"
5#include "narrow.hh"
6#include "outer.hh"
7#include "serialize.hh"
8#include "unreachable.hh"
9
10namespace openmsx {
11
13 : MSXDevice(config)
14 , debuggable(getMotherBoard(), getName())
15 , firmwareSwitch(config)
16{
17 reset(EmuTime::dummy());
18}
19
20void MSXS1990::reset(EmuTime::param /*time*/)
21{
22 registerSelect = 0; // TODO check this
23 setCPUStatus(96);
24}
25
26byte MSXS1990::readIO(word port, EmuTime::param time)
27{
28 return peekIO(port, time);
29}
30
31byte MSXS1990::peekIO(word port, EmuTime::param /*time*/) const
32{
33 switch (port & 0x01) {
34 case 0:
35 return registerSelect;
36 case 1:
37 return readRegister(registerSelect);
38 default:
40 }
41}
42
43void MSXS1990::writeIO(word port, byte value, EmuTime::param /*time*/)
44{
45 switch (port & 0x01) {
46 case 0:
47 registerSelect = value;
48 break;
49 case 1:
50 writeRegister(registerSelect, value);
51 break;
52 default:
54 }
55}
56
57byte MSXS1990::readRegister(byte reg) const
58{
59 switch (reg) {
60 case 5:
61 return firmwareSwitch.getStatus() ? 0x40 : 0x00;
62 case 6:
63 return cpuStatus;
64 case 13:
65 return 0x03; // TODO
66 case 14:
67 return 0x2F; // TODO
68 case 15:
69 return 0x8B; // TODO
70 default:
71 return 0xFF;
72 }
73}
74
75void MSXS1990::writeRegister(byte reg, byte value)
76{
77 switch (reg) {
78 case 6:
79 setCPUStatus(value);
80 break;
81 }
82}
83
84void MSXS1990::setCPUStatus(byte value)
85{
86 cpuStatus = value & 0x60;
87 getCPU().setActiveCPU((cpuStatus & 0x20) ? MSXCPU::CPU_Z80 :
88 MSXCPU::CPU_R800);
89 bool dram = (cpuStatus & 0x40) == 0;
90 getCPU().setDRAMmode(dram);
92 // TODO bit 7 -> reset MSX ?????
93}
94
95
96MSXS1990::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
97 : SimpleDebuggable(motherBoard_, name_ + " regs", "S1990 registers", 16)
98{
99}
100
101byte MSXS1990::Debuggable::read(unsigned address)
102{
103 auto& s1990 = OUTER(MSXS1990, debuggable);
104 return s1990.readRegister(narrow<byte>(address));
105}
106
107void MSXS1990::Debuggable::write(unsigned address, byte value)
108{
109 auto& s1990 = OUTER(MSXS1990, debuggable);
110 s1990.writeRegister(narrow<byte>(address), value);
111}
112
113
114template<typename Archive>
115void MSXS1990::serialize(Archive& ar, unsigned /*version*/)
116{
117 ar.template serializeBase<MSXDevice>(*this);
118 ar.serialize("registerSelect", registerSelect,
119 "cpuStatus", cpuStatus);
120 if constexpr (Archive::IS_LOADER) {
121 setCPUStatus(cpuStatus);
122 }
123}
126
127} // namespace openmsx
#define REGISTER_MSXDEVICE(CLASS, NAME)
Definition MSXDevice.hh:356
void setActiveCPU(CPUType cpu)
Switch between Z80/R800.
Definition MSXCPU.cc:90
void setDRAMmode(bool dram)
Sets DRAM or ROM mode (influences memory access speed for R800).
Definition MSXCPU.cc:101
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX.
Definition MSXDevice.hh:36
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition MSXDevice.cc:70
MSXCPU & getCPU() const
Definition MSXDevice.cc:129
PanasonicMemory & getPanasonicMemory()
This class implements the MSX-engine found in a MSX Turbo-R (S1990)
Definition MSXS1990.hh:16
void serialize(Archive &ar, unsigned version)
Definition MSXS1990.cc:115
void writeIO(word port, byte value, EmuTime::param time) override
Write a byte to a given IO port at a certain time to this device.
Definition MSXS1990.cc:43
MSXS1990(const DeviceConfig &config)
Definition MSXS1990.cc:12
void reset(EmuTime::param time) override
This method is called on reset.
Definition MSXS1990.cc:20
byte readIO(word port, EmuTime::param time) override
Read a byte from an IO port at a certain time from this device.
Definition MSXS1990.cc:26
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition MSXS1990.cc:31
This file implemented 3 utility functions:
Definition Autofire.cc:11
uint16_t word
16 bit unsigned integer
Definition openmsx.hh:29
#define OUTER(type, member)
Definition outer.hh:42
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
#define UNREACHABLE