openMSX
MSXCPU.hh
Go to the documentation of this file.
1 #ifndef MSXCPU_HH
2 #define MSXCPU_HH
3 
4 #include "InfoTopic.hh"
5 #include "SimpleDebuggable.hh"
6 #include "Observer.hh"
7 #include "BooleanSetting.hh"
8 #include "EmuTime.hh"
9 #include "TclCallback.hh"
10 #include "serialize_meta.hh"
11 #include "openmsx.hh"
12 #include "array_ref.hh"
13 #include <memory>
14 
15 namespace openmsx {
16 
17 class MSXMotherBoard;
18 class MSXCPUInterface;
19 class CPUClock;
20 class CPURegs;
21 class Z80TYPE;
22 class R800TYPE;
23 template <typename T> class CPUCore;
24 class TclObject;
25 class Interpreter;
26 
27 class MSXCPU final : private Observer<Setting>
28 {
29 public:
31 
32  explicit MSXCPU(MSXMotherBoard& motherboard);
33  ~MSXCPU();
34 
39  void doReset(EmuTime::param time);
40 
42  void setActiveCPU(CPUType cpu);
43 
45  void setDRAMmode(bool dram);
46 
49  void updateVisiblePage(byte page, byte primarySlot, byte secondarySlot);
50 
54  void invalidateMemCache(word start, unsigned size);
55 
61  void raiseIRQ();
62 
67  void lowerIRQ();
68 
74  void raiseNMI();
75 
80  void lowerNMI();
81 
87  bool isM1Cycle(unsigned address) const;
88 
90  void exitCPULoopSync();
92  void exitCPULoopAsync();
93 
95  bool isR800Active() const { return !z80Active; }
96 
98  void setZ80Freq(unsigned freq);
99 
100  void setInterface(MSXCPUInterface* interf);
101 
102  void disasmCommand(Interpreter& interp,
103  array_ref<TclObject> tokens,
104  TclObject& result) const;
105 
108  void setPaused(bool paused);
109 
110  void setNextSyncPoint(EmuTime::param time);
111 
112  void wait(EmuTime::param time);
113  EmuTime waitCycles(EmuTime::param time, unsigned cycles);
114  EmuTime waitCyclesR800(EmuTime::param time, unsigned cycles);
115 
117 
118  template<typename Archive>
119  void serialize(Archive& ar, unsigned version);
120 
121 private:
122  // only for MSXMotherBoard
123  void execute(bool fastForward);
124  friend class MSXMotherBoard;
125 
131  EmuTime::param getCurrentTime() const;
132 
133  // Observer<Setting>
134  void update(const Setting& setting) override;
135 
136  MSXMotherBoard& motherboard;
137  BooleanSetting traceSetting;
138  TclCallback diHaltCallback;
139  const std::unique_ptr<CPUCore<Z80TYPE>> z80;
140  const std::unique_ptr<CPUCore<R800TYPE>> r800; // can be nullptr
141 
142  struct TimeInfoTopic final : InfoTopic {
143  explicit TimeInfoTopic(InfoCommand& machineInfoCommand);
144  void execute(array_ref<TclObject> tokens,
145  TclObject& result) const override;
146  std::string help (const std::vector<std::string>& tokens) const override;
147  } timeInfo;
148 
149  class CPUFreqInfoTopic final : public InfoTopic {
150  public:
151  CPUFreqInfoTopic(InfoCommand& machineInfoCommand,
152  const std::string& name, CPUClock& clock);
153  void execute(array_ref<TclObject> tokens,
154  TclObject& result) const override;
155  std::string help (const std::vector<std::string>& tokens) const override;
156  private:
157  CPUClock& clock;
158  };
159  CPUFreqInfoTopic z80FreqInfo; // always present
160  const std::unique_ptr<CPUFreqInfoTopic> r800FreqInfo; // can be nullptr
161 
162  struct Debuggable final : SimpleDebuggable {
163  explicit Debuggable(MSXMotherBoard& motherboard);
164  byte read(unsigned address) override;
165  void write(unsigned address, byte value) override;
166  } debuggable;
167 
168  EmuTime reference;
169  bool z80Active;
170  bool newZ80Active;
171 };
173 
174 } // namespace openmsx
175 
176 #endif
EmuTime waitCyclesR800(EmuTime::param time, unsigned cycles)
Definition: MSXCPU.cc:197
void raiseNMI()
This method raises a non-maskable interrupt.
Definition: MSXCPU.cc:163
void updateVisiblePage(byte page, byte primarySlot, byte secondarySlot)
Inform CPU of bank switch.
Definition: MSXCPU.cc:141
void disasmCommand(Interpreter &interp, array_ref< TclObject > tokens, TclObject &result) const
Definition: MSXCPU.cc:221
void lowerIRQ()
This methods lowers the maskable interrupt again.
Definition: MSXCPU.cc:158
void setNextSyncPoint(EmuTime::param time)
Definition: MSXCPU.cc:135
void exitCPULoopAsync()
See CPUCore::exitCPULoopAsync()
Definition: MSXCPU.cc:123
uint8_t byte
8 bit unsigned integer
Definition: openmsx.hh:26
CPURegs & getRegisters()
Definition: MSXCPU.cc:203
void doReset(EmuTime::param time)
Reset CPU.
Definition: MSXCPU.cc:80
void setPaused(bool paused)
(un)pause CPU.
Definition: MSXCPU.cc:229
MSXCPU(MSXMotherBoard &motherboard)
Definition: MSXCPU.cc:21
bool isR800Active() const
Is the R800 currently active?
Definition: MSXCPU.hh:95
void invalidateMemCache(word start, unsigned size)
Invalidate the CPU its cache for the interval [start, start + size) For example MSXMemoryMapper and M...
Definition: MSXCPU.cc:147
void setDRAMmode(bool dram)
Sets DRAM or ROM mode (influences memory access speed for R800).
Definition: MSXCPU.cc:99
void wait(EmuTime::param time)
Definition: MSXCPU.cc:185
This class implements a subset of the proposal for std::array_ref (proposed for the next c++ standard...
Definition: array_ref.hh:19
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)
EmuTime waitCycles(EmuTime::param time, unsigned cycles)
Definition: MSXCPU.cc:191
void serialize(Archive &ar, unsigned version)
Definition: MSXCPU.cc:396
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
size_t size() const
void raiseIRQ()
This method raises a maskable interrupt.
Definition: MSXCPU.cc:153
uint16_t word
16 bit unsigned integer
Definition: openmsx.hh:29
void lowerNMI()
This methods lowers the non-maskable interrupt again.
Definition: MSXCPU.cc:168
void setInterface(MSXCPUInterface *interf)
Definition: MSXCPU.cc:74
void setZ80Freq(unsigned freq)
Switch the Z80 clock freq.
Definition: MSXCPU.cc:180
void exitCPULoopSync()
See CPUCore::exitCPULoopsync()
Definition: MSXCPU.cc:118
void setActiveCPU(CPUType cpu)
Switch between Z80/R800.
Definition: MSXCPU.cc:88
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
bool isM1Cycle(unsigned address) const
Should only be used from within a MSXDevice::readMem() method.
Definition: MSXCPU.cc:174