--- nono/vm/sio.h 2026/04/29 17:05:07 1.1.1.8 +++ nono/vm/sio.h 2026/04/29 17:05:17 1.1.1.10 @@ -4,18 +4,27 @@ // Licensed under nono-license.txt // +// +// SIO (uPD7201) +// + #pragma once #include "device.h" -#include "upd7201.h" +#include "mpscc.h" + +class Keyboard; -class SIODevice : public uPD7201Device +class SIODevice : public MPSCCDevice { - using inherited = uPD7201Device; + using inherited = MPSCCDevice; public: SIODevice(); virtual ~SIODevice() override; + bool Init() override; + void ResetHard(bool poweron) override; + // BusIO インタフェース // (内蔵 ROM からのアクセス用に特別に public にしてある) uint64 Read(uint32 offset); @@ -27,9 +36,47 @@ class SIODevice : public uPD7201Device uint64 Peek(uint32 offset); void Tx(int ch, uint32 data) override; + uint GetHighestInt() const override; private: - void Interrupt() override; + // 指定のレジスタ名を返す + const char *CRName(const MPSCCChan&, int n) const override; + const char *SRName(const MPSCCChan&, int n) const override; + // 現在のレジスタ名を返す + const char *CRName(const MPSCCChan& chan) const { + return CRName(chan, chan.ptr); + } + const char *SRName(const MPSCCChan& chan) const { + return SRName(chan, chan.ptr); + } + + void ResetChannel(MPSCCChan&); + + uint8 ReadCtrl(MPSCCChan&); + void WriteCtrl(MPSCCChan&, uint32 data); + uint8 PeekCtrl(const MPSCCChan&) const; + + uint8 GetCR1(const MPSCCChan&) const; + uint8 GetCR2A() const; + uint8 GetCR2B() const; + uint8 GetSR0(const MPSCCChan&) const; + + void WriteCR0(MPSCCChan&, uint32 data); + void WriteCR1(MPSCCChan&, uint32 data); + void WriteCR2(MPSCCChan&, uint32 data); + + // VIS モードを更新 + void SetVIS(); + + DECLARE_MONITOR_CALLBACK(MonitorUpdate); + void MonitorUpdateCh(TextScreen&, int ch, int xbase, int ybase); + + Keyboard *keyboard {}; + + static const char * const crnames[16]; + static const char * const srnames[16]; }; -extern std::unique_ptr gSIO; +static inline SIODevice *GetSIODevice() { + return Object::GetObject(OBJ_MPSCC); +}