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 "outer.hh"
6 #include "serialize.hh"
7 #include "unreachable.hh"
8 
9 namespace openmsx {
10 
12  : MSXDevice(config)
13  , debuggable(getMotherBoard(), getName())
14  , firmwareSwitch(config)
15 {
16  reset(EmuTime::dummy());
17 }
18 
19 void MSXS1990::reset(EmuTime::param /*time*/)
20 {
21  registerSelect = 0; // TODO check this
22  setCPUStatus(96);
23 }
24 
25 byte MSXS1990::readIO(word port, EmuTime::param time)
26 {
27  return peekIO(port, time);
28 }
29 
30 byte MSXS1990::peekIO(word port, EmuTime::param /*time*/) const
31 {
32  switch (port & 0x01) {
33  case 0:
34  return registerSelect;
35  case 1:
36  return readRegister(registerSelect);
37  default: // unreachable, avoid warning
39  return 0;
40  }
41 }
42 
43 void 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 
57 byte 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 
75 void MSXS1990::writeRegister(byte reg, byte value)
76 {
77  switch (reg) {
78  case 6:
79  setCPUStatus(value);
80  break;
81  }
82 }
83 
84 void MSXS1990::setCPUStatus(byte value)
85 {
86  cpuStatus = value & 0x60;
87  getCPU().setActiveCPU((cpuStatus & 0x20) ? MSXCPU::CPU_Z80 :
89  bool dram = (cpuStatus & 0x40) == 0;
90  getCPU().setDRAMmode(dram);
92  // TODO bit 7 -> reset MSX ?????
93 }
94 
95 
96 MSXS1990::Debuggable::Debuggable(MSXMotherBoard& motherBoard_, const std::string& name_)
97  : SimpleDebuggable(motherBoard_, name_ + " regs", "S1990 registers", 16)
98 {
99 }
100 
101 byte MSXS1990::Debuggable::read(unsigned address)
102 {
103  auto& s1990 = OUTER(MSXS1990, debuggable);
104  return s1990.readRegister(address);
105 }
106 
107 void MSXS1990::Debuggable::write(unsigned address, byte value)
108 {
109  auto& s1990 = OUTER(MSXS1990, debuggable);
110  s1990.writeRegister(address, value);
111 }
112 
113 
114 template<typename Archive>
115 void MSXS1990::serialize(Archive& ar, unsigned /*version*/)
116 {
117  ar.template serializeBase<MSXDevice>(*this);
118  ar.serialize("registerSelect", registerSelect);
119  ar.serialize("cpuStatus", cpuStatus);
120  if (ar.isLoader()) {
121  setCPUStatus(cpuStatus);
122  }
123 }
125 REGISTER_MSXDEVICE(MSXS1990, "S1990");
126 
127 } // namespace openmsx
MSXS1990(const DeviceConfig &config)
Definition: MSXS1990.cc:11
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
REGISTER_MSXDEVICE(ChakkariCopy, "ChakkariCopy")
void serialize(Archive &ar, unsigned version)
Definition: MSXS1990.cc:115
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:25
void setDRAMmode(bool dram)
Sets DRAM or ROM mode (influences memory access speed for R800).
Definition: MSXCPU.cc:99
PanasonicMemory & getPanasonicMemory()
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
An MSXDevice is an emulated hardware component connected to the bus of the emulated MSX...
Definition: MSXDevice.hh:31
MSXMotherBoard & getMotherBoard() const
Get the mother board this device belongs to.
Definition: MSXDevice.cc:77
MSXCPU & getCPU() const
Definition: MSXDevice.cc:137
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
#define INSTANTIATE_SERIALIZE_METHODS(CLASS)
Definition: serialize.hh:840
string getName(KeyCode keyCode)
Translate key code to key name.
Definition: Keys.cc:589
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
This class implements the MSX-engine found in a MSX Turbo-R (S1990)
Definition: MSXS1990.hh:15
void setActiveCPU(CPUType cpu)
Switch between Z80/R800.
Definition: MSXCPU.cc:88
void reset(EmuTime::param time) override
This method is called on reset.
Definition: MSXS1990.cc:19
#define OUTER(type, member)
Definition: outer.hh:38
byte peekIO(word port, EmuTime::param time) const override
Read a byte from a given IO port.
Definition: MSXS1990.cc:30
#define UNREACHABLE
Definition: unreachable.hh:38