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: // unreachable, avoid warning
40 return 0;
41 }
42}
43
44void MSXS1990::writeIO(word port, byte value, EmuTime::param /*time*/)
45{
46 switch (port & 0x01) {
47 case 0:
48 registerSelect = value;
49 break;
50 case 1:
51 writeRegister(registerSelect, value);
52 break;
53 default:
55 }
56}
57
58byte MSXS1990::readRegister(byte reg) const
59{
60 switch (reg) {
61 case 5:
62 return firmwareSwitch.getStatus() ? 0x40 : 0x00;
63 case 6:
64 return cpuStatus;
65 case 13:
66 return 0x03; // TODO
67 case 14:
68 return 0x2F; // TODO
69 case 15:
70 return 0x8B; // TODO
71 default:
72 return 0xFF;
73 }
74}
75
76void MSXS1990::writeRegister(byte reg, byte value)
77{
78 switch (reg) {
79 case 6:
80 setCPUStatus(value);
81 break;
82 }
83}
84
85void MSXS1990::setCPUStatus(byte value)
86{
87 cpuStatus = value & 0x60;
88 getCPU().setActiveCPU((cpuStatus & 0x20) ? MSXCPU::CPU_Z80 :
90 bool dram = (cpuStatus & 0x40) == 0;
91 getCPU().setDRAMmode(dram);
93 // TODO bit 7 -> reset MSX ?????
94}
95
96
97MSXS1990::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
98 : SimpleDebuggable(motherBoard_, name_ + " regs", "S1990 registers", 16)
99{
100}
101
102byte MSXS1990::Debuggable::read(unsigned address)
103{
104 auto& s1990 = OUTER(MSXS1990, debuggable);
105 return s1990.readRegister(narrow<byte>(address));
106}
107
108void MSXS1990::Debuggable::write(unsigned address, byte value)
109{
110 auto& s1990 = OUTER(MSXS1990, debuggable);
111 s1990.writeRegister(narrow<byte>(address), value);
112}
113
114
115template<typename Archive>
116void MSXS1990::serialize(Archive& ar, unsigned /*version*/)
117{
118 ar.template serializeBase<MSXDevice>(*this);
119 ar.serialize("registerSelect", registerSelect,
120 "cpuStatus", cpuStatus);
121 if constexpr (Archive::IS_LOADER) {
122 setCPUStatus(cpuStatus);
123 }
124}
127
128} // namespace openmsx
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:116
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:44
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
std::string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:730
This file implemented 3 utility functions:
Definition: Autofire.cc:9
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define OUTER(type, member)
Definition: outer.hh:41
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:1021
#define UNREACHABLE
Definition: unreachable.hh:38