| 1 |
#ifndef MSXCPUINTERFACE_HH |
| 2 |
#define MSXCPUINTERFACE_HH |
| 3 |
|
| 4 |
#include "BreakPoint.hh" |
| 5 |
#include "CacheLine.hh" |
| 6 |
#include "DebugCondition.hh" |
| 7 |
#include "WatchPoint.hh" |
| 8 |
|
| 9 |
#include "InfoTopic.hh" |
| 10 |
#include "MSXDevice.hh" |
| 11 |
#include "ProfileCounters.hh" |
| 12 |
#include "SimpleDebuggable.hh" |
| 13 |
|
| 14 |
#include "narrow.hh" |
| 15 |
|
| 16 |
#include <array> |
| 17 |
#include <bitset> |
| 18 |
#include <concepts> |
| 19 |
#include <cstdint> |
| 20 |
#include <memory> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
namespace openmsx { |
| 24 |
|
| 25 |
class BooleanSetting; |
| 26 |
class BreakPoint; |
| 27 |
class CliComm; |
| 28 |
class DummyDevice; |
| 29 |
class MSXCPU; |
| 30 |
class MSXMotherBoard; |
| 31 |
class VDPIODelay; |
| 32 |
|
| 33 |
inline constexpr bool PROFILE_CACHELINES = false; |
| 34 |
enum class CacheLineCounters : uint8_t { |
| 35 |
NonCachedRead, |
| 36 |
NonCachedWrite, |
| 37 |
GetReadCacheLine, |
| 38 |
GetWriteCacheLine, |
| 39 |
SlowRead, |
| 40 |
SlowWrite, |
| 41 |
DisallowCacheRead, |
| 42 |
DisallowCacheWrite, |
| 43 |
InvalidateAllSlots, |
| 44 |
InvalidateReadWrite, |
| 45 |
InvalidateRead, |
| 46 |
InvalidateWrite, |
| 47 |
FillReadWrite, |
| 48 |
FillRead, |
| 49 |
FillWrite, |
| 50 |
NUM |
| 51 |
}; |
| 52 |
std::ostream& operator<<(std::ostream& os, EnumTypeName<CacheLineCounters>); |
| 53 |
std::ostream& operator<<(std::ostream& os, EnumValueName<CacheLineCounters> evn); |
| 54 |
|
| 55 |
class MSXCPUInterface : public ProfileCounters<PROFILE_CACHELINES, CacheLineCounters> |
| 56 |
{ |
| 57 |
public: |
| 58 |
explicit MSXCPUInterface(MSXMotherBoard& motherBoard); |
| 59 |
MSXCPUInterface(const MSXCPUInterface&) = delete; |
| 60 |
MSXCPUInterface(MSXCPUInterface&&) = delete; |
| 61 |
MSXCPUInterface& operator=(const MSXCPUInterface&) = delete; |
| 62 |
MSXCPUInterface& operator=(MSXCPUInterface&&) = delete; |
| 63 |
~MSXCPUInterface(); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
void register_IO_In(uint8_t port, MSXDevice* device); |
| 71 |
void unregister_IO_In(uint8_t port, MSXDevice* device); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
void register_IO_Out(uint8_t port, MSXDevice* device); |
| 79 |
void unregister_IO_Out(uint8_t port, MSXDevice* device); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
void register_IO_InOut(uint8_t port, MSXDevice* device); |
| 85 |
void register_IO_In_range(uint8_t port, unsigned num, MSXDevice* device); |
| 86 |
void register_IO_Out_range(uint8_t port, unsigned num, MSXDevice* device); |
| 87 |
void register_IO_InOut_range(uint8_t port, unsigned num, MSXDevice* device); |
| 88 |
void unregister_IO_InOut(uint8_t port, MSXDevice* device); |
| 89 |
void unregister_IO_In_range(uint8_t port, unsigned num, MSXDevice* device); |
| 90 |
void unregister_IO_Out_range(uint8_t port, unsigned num, MSXDevice* device); |
| 91 |
void unregister_IO_InOut_range(uint8_t port, unsigned num, MSXDevice* device); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
bool replace_IO_In (uint8_t port, MSXDevice* oldDevice, MSXDevice* newDevice); |
| 109 |
bool replace_IO_Out(uint8_t port, MSXDevice* oldDevice, MSXDevice* newDevice); |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
void registerMemDevice(MSXDevice& device, |
| 118 |
int ps, int ss, unsigned base, unsigned size); |
| 119 |
void unregisterMemDevice(MSXDevice& device, |
| 120 |
int ps, int ss, unsigned base, unsigned size); |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
void registerGlobalWrite(MSXDevice& device, uint16_t address); |
| 126 |
void unregisterGlobalWrite(MSXDevice& device, uint16_t address); |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
void registerGlobalRead(MSXDevice& device, uint16_t address); |
| 132 |
void unregisterGlobalRead(MSXDevice& device, uint16_t address); |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
void reset(); |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
uint8_t readMem(uint16_t address, EmuTime time) { |
| 143 |
tick(CacheLineCounters::SlowRead); |
| 144 |
if (disallowReadCache[address >> CacheLine::BITS]) [[unlikely]] { |
| 145 |
return readMemSlow(address, time); |
| 146 |
} |
| 147 |
return visibleDevices[address >> 14]->readMem(address, time); |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
void writeMem(uint16_t address, uint8_t value, EmuTime time) { |
| 154 |
tick(CacheLineCounters::SlowWrite); |
| 155 |
if (disallowWriteCache[address >> CacheLine::BITS]) [[unlikely]] { |
| 156 |
writeMemSlow(address, value, time); |
| 157 |
return; |
| 158 |
} |
| 159 |
visibleDevices[address>>14]->writeMem(address, value, time); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
uint8_t readIO(uint16_t port, EmuTime time) { |
| 167 |
return IO_In[port & 0xFF]->readIO(port, time); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
void writeIO(uint16_t port, uint8_t value, EmuTime time) { |
| 175 |
IO_Out[port & 0xFF]->writeIO(port, value, time); |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
[[nodiscard]] const uint8_t* getReadCacheLine(uint16_t start) const { |
| 191 |
tick(CacheLineCounters::GetReadCacheLine); |
| 192 |
if (disallowReadCache[start >> CacheLine::BITS]) [[unlikely]] { |
| 193 |
return nullptr; |
| 194 |
} |
| 195 |
return visibleDevices[start >> 14]->getReadCacheLine(start); |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
[[nodiscard]] uint8_t* getWriteCacheLine(uint16_t start) { |
| 211 |
tick(CacheLineCounters::GetWriteCacheLine); |
| 212 |
if (disallowWriteCache[start >> CacheLine::BITS]) [[unlikely]] { |
| 213 |
return nullptr; |
| 214 |
} |
| 215 |
return visibleDevices[start >> 14]->getWriteCacheLine(start); |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
[[nodiscard]] uint8_t readIRQVector() const; |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
void setPrimarySlots(uint8_t value); |
| 229 |
|
| 230 |
|
| 231 |
void invalidateRWCache(uint16_t start, unsigned size, int ps, int ss); |
| 232 |
void invalidateRCache (uint16_t start, unsigned size, int ps, int ss); |
| 233 |
void invalidateWCache (uint16_t start, unsigned size, int ps, int ss); |
| 234 |
|
| 235 |
|
| 236 |
void fillRWCache(unsigned start, unsigned size, const uint8_t* rData, uint8_t* wData, int ps, int ss); |
| 237 |
void fillRCache (unsigned start, unsigned size, const uint8_t* rData, int ps, int ss); |
| 238 |
void fillWCache (unsigned start, unsigned size, uint8_t* wData, int ps, int ss); |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
[[nodiscard]] uint8_t peekMem(uint16_t address, EmuTime time) const; |
| 245 |
[[nodiscard]] uint8_t peekSlottedMem(unsigned address, EmuTime time) const; |
| 246 |
void peekSlottedMemBlock(unsigned address, std::span<uint8_t> output, EmuTime time) const; |
| 247 |
uint8_t readSlottedMem(unsigned address, EmuTime time); |
| 248 |
void writeSlottedMem(unsigned address, uint8_t value, |
| 249 |
EmuTime time); |
| 250 |
|
| 251 |
void setExpanded(int ps); |
| 252 |
void unsetExpanded(int ps); |
| 253 |
void testUnsetExpanded(int ps, |
| 254 |
std::span<const std::unique_ptr<MSXDevice>> allowed) const; |
| 255 |
[[nodiscard]] bool isExpanded(int ps) const { return expanded[ps] != 0; } |
| 256 |
void changeExpanded(bool newExpanded); |
| 257 |
|
| 258 |
[[nodiscard]] auto getPrimarySlot (int page) const { return primarySlotState[page]; } |
| 259 |
[[nodiscard]] auto getSecondarySlot(int page) const { return secondarySlotState[page]; } |
| 260 |
|
| 261 |
[[nodiscard]] DummyDevice& getDummyDevice() { return *dummyDevice; } |
| 262 |
|
| 263 |
void insertBreakPoint(BreakPoint bp); |
| 264 |
void removeBreakPoint(const BreakPoint& bp); |
| 265 |
void removeBreakPoint(unsigned id); |
| 266 |
using BreakPoints = std::vector<BreakPoint>; |
| 267 |
[[nodiscard]] static BreakPoints& getBreakPoints() { return breakPoints; } |
| 268 |
|
| 269 |
void setWatchPoint(const std::shared_ptr<WatchPoint>& watchPoint); |
| 270 |
void removeWatchPoint(std::shared_ptr<WatchPoint> watchPoint); |
| 271 |
void removeWatchPoint(unsigned id); |
| 272 |
|
| 273 |
using WatchPoints = std::vector<std::shared_ptr<WatchPoint>>; |
| 274 |
[[nodiscard]] const WatchPoints& getWatchPoints() const { return watchPoints; } |
| 275 |
[[nodiscard]] WatchPoints& getWatchPoints() { return watchPoints; } |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
struct ScopedChangeWatchpoint { |
| 281 |
ScopedChangeWatchpoint(const ScopedChangeWatchpoint&) = delete; |
| 282 |
ScopedChangeWatchpoint(ScopedChangeWatchpoint&&) = delete; |
| 283 |
ScopedChangeWatchpoint& operator=(const ScopedChangeWatchpoint&) = delete; |
| 284 |
ScopedChangeWatchpoint& operator=(ScopedChangeWatchpoint&&) = delete; |
| 285 |
|
| 286 |
ScopedChangeWatchpoint(MSXCPUInterface& interface_, std::shared_ptr<WatchPoint> wp_) |
| 287 |
: interface(interface_), wp(std::move(wp_)) { |
| 288 |
interface.unregisterWatchPoint(*wp); |
| 289 |
} |
| 290 |
~ScopedChangeWatchpoint() { |
| 291 |
interface.registerWatchPoint(*wp); |
| 292 |
} |
| 293 |
private: |
| 294 |
MSXCPUInterface& interface; |
| 295 |
std::shared_ptr<WatchPoint> wp; |
| 296 |
}; |
| 297 |
[[nodiscard]] auto getScopedChangeWatchpoint(std::shared_ptr<WatchPoint> wp) { |
| 298 |
return ScopedChangeWatchpoint(*this, std::move(wp)); |
| 299 |
} |
| 300 |
|
| 301 |
void setCondition(DebugCondition cond); |
| 302 |
void removeCondition(const DebugCondition& cond); |
| 303 |
void removeCondition(unsigned id); |
| 304 |
using Conditions = std::vector<DebugCondition>; |
| 305 |
[[nodiscard]] static Conditions& getConditions() { return conditions; } |
| 306 |
|
| 307 |
[[nodiscard]] static bool isBreaked() { return breaked; } |
| 308 |
void doBreak(); |
| 309 |
void doStep(); |
| 310 |
void doContinue(); |
| 311 |
|
| 312 |
|
| 313 |
[[nodiscard]] static bool anyBreakPoints() |
| 314 |
{ |
| 315 |
return !breakPoints.empty() || !conditions.empty(); |
| 316 |
} |
| 317 |
[[nodiscard]] bool checkBreakPoints(unsigned pc); |
| 318 |
|
| 319 |
|
| 320 |
static void cleanup(); |
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
void setFastForward(bool fastForward_) { fastForward = fastForward_; } |
| 325 |
[[nodiscard]] bool isFastForward() const { return fastForward; } |
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
[[nodiscard]] MSXDevice* getMSXDevice(int ps, int ss, int page); |
| 330 |
[[nodiscard]] MSXDevice* getVisibleMSXDevice(int page) { return visibleDevices[page]; } |
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
[[nodiscard]] MSXDevice* getIODevice(uint8_t port, bool isIn) { |
| 337 |
return getDevicePtr(port, isIn); |
| 338 |
} |
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
[[nodiscard]] uint8_t peekIO(uint16_t port, EmuTime time) const { |
| 345 |
return IO_In[port & 0xFF]->peekIO(port, time); |
| 346 |
} |
| 347 |
|
| 348 |
template<typename Archive> |
| 349 |
void serialize(Archive& ar, unsigned version); |
| 350 |
|
| 351 |
private: |
| 352 |
uint8_t readMemSlow(uint16_t address, EmuTime time); |
| 353 |
void writeMemSlow(uint16_t address, uint8_t value, EmuTime time); |
| 354 |
|
| 355 |
MSXDevice*& getDevicePtr(uint8_t port, bool isIn); |
| 356 |
|
| 357 |
void register_IO (int port, bool isIn, |
| 358 |
MSXDevice*& devicePtr, MSXDevice* device); |
| 359 |
void unregister_IO(MSXDevice*& devicePtr, MSXDevice* device); |
| 360 |
void testRegisterSlot(const MSXDevice& device, |
| 361 |
int ps, int ss, unsigned base, unsigned size); |
| 362 |
void registerSlot(MSXDevice& device, |
| 363 |
int ps, int ss, unsigned base, unsigned size); |
| 364 |
void unregisterSlot(MSXDevice& device, |
| 365 |
int ps, int ss, unsigned base, unsigned size); |
| 366 |
|
| 367 |
void registerWatchPoint(WatchPoint& wp); |
| 368 |
void unregisterWatchPoint(WatchPoint& wp); |
| 369 |
|
| 370 |
void removeAllWatchPoints(); |
| 371 |
void updateMemWatch(WatchPoint::Type type); |
| 372 |
void executeMemWatch(WatchPoint::Type type, unsigned address, |
| 373 |
unsigned value = ~0u); |
| 374 |
|
| 375 |
struct MemoryDebug final : SimpleDebuggable { |
| 376 |
explicit MemoryDebug(MSXMotherBoard& motherBoard); |
| 377 |
[[nodiscard]] uint8_t read(unsigned address, EmuTime time) override; |
| 378 |
void write(unsigned address, uint8_t value, EmuTime time) override; |
| 379 |
} memoryDebug; |
| 380 |
|
| 381 |
struct SlottedMemoryDebug final : SimpleDebuggable { |
| 382 |
explicit SlottedMemoryDebug(MSXMotherBoard& motherBoard); |
| 383 |
[[nodiscard]] uint8_t read(unsigned address, EmuTime time) override; |
| 384 |
void readBlock(unsigned start, std::span<uint8_t> output) override; |
| 385 |
void write(unsigned address, uint8_t value, EmuTime time) override; |
| 386 |
} slottedMemoryDebug; |
| 387 |
|
| 388 |
struct IODebug final : SimpleDebuggable { |
| 389 |
explicit IODebug(MSXMotherBoard& motherBoard); |
| 390 |
[[nodiscard]] uint8_t read(unsigned address, EmuTime time) override; |
| 391 |
void write(unsigned address, uint8_t value, EmuTime time) override; |
| 392 |
} ioDebug; |
| 393 |
|
| 394 |
struct SlotInfo final : InfoTopic { |
| 395 |
explicit SlotInfo(InfoCommand& machineInfoCommand); |
| 396 |
void execute(std::span<const TclObject> tokens, |
| 397 |
TclObject& result) const override; |
| 398 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 399 |
} slotInfo; |
| 400 |
|
| 401 |
struct SubSlottedInfo final : InfoTopic { |
| 402 |
explicit SubSlottedInfo(InfoCommand& machineInfoCommand); |
| 403 |
void execute(std::span<const TclObject> tokens, |
| 404 |
TclObject& result) const override; |
| 405 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 406 |
} subSlottedInfo; |
| 407 |
|
| 408 |
struct ExternalSlotInfo final : InfoTopic { |
| 409 |
explicit ExternalSlotInfo(InfoCommand& machineInfoCommand); |
| 410 |
void execute(std::span<const TclObject> tokens, |
| 411 |
TclObject& result) const override; |
| 412 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 413 |
} externalSlotInfo; |
| 414 |
|
| 415 |
struct IOInfo : InfoTopic { |
| 416 |
IOInfo(InfoCommand& machineInfoCommand, const char* name); |
| 417 |
void helper(std::span<const TclObject> tokens, |
| 418 |
TclObject& result, std::span<MSXDevice*, 256> devices) const; |
| 419 |
[[nodiscard]] std::string help(std::span<const TclObject> tokens) const override; |
| 420 |
protected: |
| 421 |
~IOInfo() = default; |
| 422 |
}; |
| 423 |
struct IInfo final : IOInfo { |
| 424 |
explicit IInfo(InfoCommand& machineInfoCommand) |
| 425 |
: IOInfo(machineInfoCommand, "input_port") {} |
| 426 |
void execute(std::span<const TclObject> tokens, |
| 427 |
TclObject& result) const override; |
| 428 |
} inputPortInfo; |
| 429 |
struct OInfo final : IOInfo { |
| 430 |
explicit OInfo(InfoCommand& machineInfoCommand) |
| 431 |
: IOInfo(machineInfoCommand, "output_port") {} |
| 432 |
void execute(std::span<const TclObject> tokens, |
| 433 |
TclObject& result) const override; |
| 434 |
} outputPortInfo; |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
void updateVisible(uint8_t page); |
| 443 |
inline void updateVisible(uint8_t page, uint8_t ps, uint8_t ss); |
| 444 |
void setSubSlot(uint8_t primSlot, uint8_t value); |
| 445 |
|
| 446 |
std::unique_ptr<DummyDevice> dummyDevice; |
| 447 |
MSXCPU& msxcpu; |
| 448 |
CliComm& cliComm; |
| 449 |
MSXMotherBoard& motherBoard; |
| 450 |
BooleanSetting& pauseSetting; |
| 451 |
|
| 452 |
std::unique_ptr<VDPIODelay> delayDevice; |
| 453 |
|
| 454 |
std::array<uint8_t, CacheLine::NUM> disallowReadCache; |
| 455 |
std::array<uint8_t, CacheLine::NUM> disallowWriteCache; |
| 456 |
std::array<std::bitset<CacheLine::SIZE>, CacheLine::NUM> readWatchSet; |
| 457 |
std::array<std::bitset<CacheLine::SIZE>, CacheLine::NUM> writeWatchSet; |
| 458 |
|
| 459 |
struct GlobalRwInfo { |
| 460 |
MSXDevice* device; |
| 461 |
uint16_t addr; |
| 462 |
[[nodiscard]] constexpr bool operator==(const GlobalRwInfo&) const = default; |
| 463 |
}; |
| 464 |
std::vector<GlobalRwInfo> globalReads; |
| 465 |
std::vector<GlobalRwInfo> globalWrites; |
| 466 |
|
| 467 |
std::array<MSXDevice*, 256> IO_In; |
| 468 |
std::array<MSXDevice*, 256> IO_Out; |
| 469 |
std::array<std::array<std::array<MSXDevice*, 4>, 4>, 4> slotLayout; |
| 470 |
std::array<MSXDevice*, 4> visibleDevices; |
| 471 |
std::array<uint8_t, 4> subSlotRegister; |
| 472 |
std::array<uint8_t, 4> primarySlotState; |
| 473 |
std::array<uint8_t, 4> secondarySlotState; |
| 474 |
uint8_t initialPrimarySlots; |
| 475 |
std::array<unsigned, 4> expanded; |
| 476 |
|
| 477 |
bool fastForward = false; |
| 478 |
|
| 479 |
|
| 480 |
static inline BreakPoints breakPoints; |
| 481 |
WatchPoints watchPoints; |
| 482 |
static inline Conditions conditions; |
| 483 |
static inline bool breaked = false; |
| 484 |
}; |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
template<unsigned BEGIN, unsigned END = BEGIN + 1> |
| 490 |
struct CT_Interval |
| 491 |
{ |
| 492 |
[[nodiscard]] unsigned begin() const { return BEGIN; } |
| 493 |
[[nodiscard]] unsigned end() const { return END; } |
| 494 |
}; |
| 495 |
|
| 496 |
|
| 497 |
inline void foreach_ct_interval(std::invocable<unsigned> auto action, auto ct_interval) |
| 498 |
{ |
| 499 |
for (auto i = ct_interval.begin(); i != ct_interval.end(); ++i) { |
| 500 |
action(i); |
| 501 |
} |
| 502 |
} |
| 503 |
inline void foreach_ct_interval(std::invocable<unsigned> auto action, |
| 504 |
auto front_interval, auto... tail_intervals) |
| 505 |
{ |
| 506 |
foreach_ct_interval(action, front_interval); |
| 507 |
foreach_ct_interval(action, tail_intervals...); |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
template<typename MSXDEVICE, typename... CT_INTERVALS> |
| 512 |
struct GlobalRWHelper |
| 513 |
{ |
| 514 |
void execute(std::invocable<MSXCPUInterface&, MSXDevice&, unsigned> auto action) |
| 515 |
{ |
| 516 |
auto& dev = static_cast<MSXDEVICE&>(*this); |
| 517 |
auto& cpu = dev.getCPUInterface(); |
| 518 |
foreach_ct_interval( |
| 519 |
[&](unsigned addr) { action(cpu, dev, addr); }, |
| 520 |
CT_INTERVALS()...); |
| 521 |
} |
| 522 |
}; |
| 523 |
|
| 524 |
template<typename MSXDEVICE, typename... CT_INTERVALS> |
| 525 |
struct GlobalWriteClient : GlobalRWHelper<MSXDEVICE, CT_INTERVALS...> |
| 526 |
{ |
| 527 |
GlobalWriteClient(const GlobalWriteClient&) = delete; |
| 528 |
GlobalWriteClient(GlobalWriteClient&&) = delete; |
| 529 |
GlobalWriteClient& operator=(const GlobalWriteClient&) = delete; |
| 530 |
GlobalWriteClient& operator=(GlobalWriteClient&&) = delete; |
| 531 |
|
| 532 |
GlobalWriteClient() |
| 533 |
{ |
| 534 |
this->execute([](MSXCPUInterface& cpu, MSXDevice& dev, unsigned addr) { |
| 535 |
cpu.registerGlobalWrite(dev, narrow<uint16_t>(addr)); |
| 536 |
}); |
| 537 |
} |
| 538 |
|
| 539 |
~GlobalWriteClient() |
| 540 |
{ |
| 541 |
this->execute([](MSXCPUInterface& cpu, MSXDevice& dev, unsigned addr) { |
| 542 |
cpu.unregisterGlobalWrite(dev, narrow<uint16_t>(addr)); |
| 543 |
}); |
| 544 |
} |
| 545 |
}; |
| 546 |
|
| 547 |
template<typename MSXDEVICE, typename... CT_INTERVALS> |
| 548 |
struct GlobalReadClient : GlobalRWHelper<MSXDEVICE, CT_INTERVALS...> |
| 549 |
{ |
| 550 |
GlobalReadClient(const GlobalReadClient&) = delete; |
| 551 |
GlobalReadClient(GlobalReadClient&&) = delete; |
| 552 |
GlobalReadClient& operator=(const GlobalReadClient&) = delete; |
| 553 |
GlobalReadClient& operator=(GlobalReadClient&&) = delete; |
| 554 |
|
| 555 |
GlobalReadClient() |
| 556 |
{ |
| 557 |
this->execute([](MSXCPUInterface& cpu, MSXDevice& dev, unsigned addr) { |
| 558 |
cpu.registerGlobalRead(dev, narrow<uint16_t>(addr)); |
| 559 |
}); |
| 560 |
} |
| 561 |
|
| 562 |
~GlobalReadClient() |
| 563 |
{ |
| 564 |
this->execute([](MSXCPUInterface& cpu, MSXDevice& dev, unsigned addr) { |
| 565 |
cpu.unregisterGlobalRead(dev, narrow<uint16_t>(addr)); |
| 566 |
}); |
| 567 |
} |
| 568 |
}; |
| 569 |
|
| 570 |
} |
| 571 |
|
| 572 |
#endif |