| e8555c89 Andy McCall |
1 |
#ifndef MSXCPU_HH |
| 2 |
#define MSXCPU_HH |
| 3 |
|
| 4 |
#include "CacheLine.hh" |
| 5 |
|
| 6 |
#include "BooleanSetting.hh" |
| 7 |
#include "EmuTime.hh" |
| 8 |
#include "InfoTopic.hh" |
| 9 |
#include "Observer.hh" |
| 10 |
#include "SimpleDebuggable.hh" |
| 11 |
#include "TclCallback.hh" |
| 12 |
#include "serialize_meta.hh" |
| 13 |
|
| 14 |
#include <array> |
| 15 |
#include <cstdint> |
| 16 |
#include <memory> |
| 17 |
#include <span> |
| 18 |
|
| 19 |
namespace openmsx { |
| 20 |
|
| 21 |
class MSXMotherBoard; |
| 22 |
class MSXCPUInterface; |
| 23 |
class CPUClock; |
| 24 |
class CPURegs; |
| 25 |
class Z80TYPE; |
| 26 |
class R800TYPE; |
| 27 |
template<typename T> class CPUCore; |
| 28 |
class TclObject; |
| 29 |
class Interpreter; |
| 30 |
|
| 31 |
class MSXCPU final : private Observer<Setting> |
| 32 |
{ |
| 33 |
public: |
| 34 |
enum class Type : uint8_t { Z80, R800 }; |
| 35 |
|
| 36 |
explicit MSXCPU(MSXMotherBoard& motherboard); |
| 37 |
~MSXCPU(); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
void doReset(EmuTime time); |
| 44 |
|
| 45 |
|
| 46 |
void setActiveCPU(Type cpu); |
| 47 |
|
| 48 |
|
| 49 |
void setDRAMmode(bool dram); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
void updateVisiblePage(uint8_t page, uint8_t primarySlot, uint8_t secondarySlot); |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
void invalidateAllSlotsRWCache(uint16_t start, unsigned size); |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
void invalidateRWCache(unsigned start, unsigned size, int ps, int ss, |
| 66 |
std::span<const uint8_t, 256> disallowRead, |
| 67 |
std::span<const uint8_t, 256> disallowWrite); |
| 68 |
void invalidateRCache (unsigned start, unsigned size, int ps, int ss, |
| 69 |
std::span<const uint8_t, 256> disallowRead, |
| 70 |
std::span<const uint8_t, 256> disallowWrite); |
| 71 |
void invalidateWCache (unsigned start, unsigned size, int ps, int ss, |
| 72 |
std::span<const uint8_t, 256> disallowRead, |
| 73 |
std::span<const uint8_t, 256> disallowWrite); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
void fillRWCache(unsigned start, unsigned size, const uint8_t* rData, uint8_t* wData, int ps, int ss, |
| 85 |
std::span<const uint8_t, 256> disallowRead, |
| 86 |
std::span<const uint8_t, 256> disallowWrite); |
| 87 |
void fillRCache (unsigned start, unsigned size, const uint8_t* rData, int ps, int ss, |
| 88 |
std::span<const uint8_t, 256> disallowRead, |
| 89 |
std::span<const uint8_t, 256> disallowWrite); |
| 90 |
void fillWCache (unsigned start, unsigned size, uint8_t* wData, int ps, int ss, |
| 91 |
std::span<const uint8_t, 256> disallowRead, |
| 92 |
std::span<const uint8_t, 256> disallowWrite); |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
void raiseIRQ(); |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
void lowerIRQ(); |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
void raiseNMI(); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
void lowerNMI(); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
[[nodiscard]] bool isM1Cycle(unsigned address) const; |
| 126 |
|
| 127 |
|
| 128 |
void exitCPULoopSync(); |
| 129 |
|
| 130 |
void exitCPULoopAsync(); |
| 131 |
|
| 132 |
|
| 133 |
[[nodiscard]] bool isR800Active() const { return !z80Active; } |
| 134 |
|
| 135 |
|
| 136 |
void setZ80Freq(unsigned freq); |
| 137 |
|
| 138 |
void setInterface(MSXCPUInterface* interface); |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
void setPaused(bool paused); |
| 143 |
|
| 144 |
void setNextSyncPoint(EmuTime time); |
| 145 |
|
| 146 |
void wait(EmuTime time); |
| 147 |
EmuTime waitCyclesZ80(EmuTime time, unsigned cycles); |
| 148 |
EmuTime waitCyclesR800(EmuTime time, unsigned cycles); |
| 149 |
|
| 150 |
[[nodiscard]] CPURegs& getRegisters(); |
| 151 |
|
| 152 |
[[nodiscard]] auto* getZ80() { return z80.get(); } |
| 153 |
[[nodiscard]] auto* getR800() { return r800.get(); } |
| 154 |
|
| 155 |
template<typename Archive> |
| 156 |
void serialize(Archive& ar, unsigned version); |
| 157 |
|
| 158 |
private: |
| 159 |
void invalidateMemCacheSlot(); |
| 160 |
|
| 161 |
|
| 162 |
void execute(bool fastForward); |
| 163 |
friend class MSXMotherBoard; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
EmuTime getCurrentTime() const; |
| 171 |
|
| 172 |
|
| 173 |
void update(const Setting& setting) noexcept override; |
| 174 |
|
| 175 |
template<bool READ, bool WRITE, bool SUB_START> |
| 176 |
void setRWCache(unsigned start, unsigned size, const uint8_t* rData, uint8_t* wData, int ps, int ss, |
| 177 |
std::span<const uint8_t, 256> disallowRead, std::span<const uint8_t, 256> disallowWrite); |
| 178 |
|
| 179 |
private: |
| 180 |
MSXMotherBoard& motherboard; |
| 181 |
TclCallback diHaltCallback; |
| 182 |
const std::unique_ptr<CPUCore<Z80TYPE>> z80; |
| 183 |
const std::unique_ptr<CPUCore<R800TYPE>> r800; |
| 184 |
|
| 185 |
std::array<std::array<const uint8_t*, CacheLine::NUM>, 16> slotReadLines; |
| 186 |
std::array<std::array< uint8_t*, CacheLine::NUM>, 16> slotWriteLines; |
| 187 |
std::array<uint8_t, 4> slots; |
| 188 |
|
| 189 |
struct TimeInfoTopic final : InfoTopic { |
| 190 |
explicit TimeInfoTopic(InfoCommand& machineInfoCommand); |
| 191 |
void execute(std::span<const TclObject> tokens, |
| 192 |
TclObject& result) const override; |
| 193 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 194 |
} timeInfo; |
| 195 |
|
| 196 |
class CPUFreqInfoTopic final : public InfoTopic { |
| 197 |
public: |
| 198 |
CPUFreqInfoTopic(InfoCommand& machineInfoCommand, |
| 199 |
const std::string& name, CPUClock& clock); |
| 200 |
void execute(std::span<const TclObject> tokens, |
| 201 |
TclObject& result) const override; |
| 202 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 203 |
private: |
| 204 |
CPUClock& clock; |
| 205 |
}; |
| 206 |
CPUFreqInfoTopic z80FreqInfo; |
| 207 |
const std::unique_ptr<CPUFreqInfoTopic> r800FreqInfo; |
| 208 |
|
| 209 |
struct Debuggable final : SimpleDebuggable { |
| 210 |
explicit Debuggable(MSXMotherBoard& motherboard); |
| 211 |
[[nodiscard]] uint8_t read(unsigned address) override; |
| 212 |
void write(unsigned address, uint8_t value) override; |
| 213 |
} debuggable; |
| 214 |
|
| 215 |
bool z80Active{true}; |
| 216 |
bool newZ80Active{true}; |
| 217 |
|
| 218 |
MSXCPUInterface* interface{nullptr}; |
| 219 |
}; |
| 220 |
SERIALIZE_CLASS_VERSION(MSXCPU, 3); |
| 221 |
|
| 222 |
} |
| 223 |
|
| 224 |
#endif |