--- nono/vm/sio.h 2026/04/29 17:04:29 1.1.1.2 +++ nono/vm/sio.h 2026/04/29 17:05:17 1.1.1.10 @@ -1,30 +1,82 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// 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 { - typedef uPD7201Device inherited; + using inherited = MPSCCDevice; public: SIODevice(); - virtual ~SIODevice(); + virtual ~SIODevice() override; - virtual void ResetHard(); + bool Init() override; + void ResetHard(bool poweron) override; - virtual uint64 Read8(uint32); - virtual uint64 Read16(uint32); - virtual uint64 Write8(uint32, uint32); - virtual uint64 Write16(uint32, uint32); + // BusIO インタフェース + // (内蔵 ROM からのアクセス用に特別に public にしてある) + uint64 Read(uint32 offset); + uint64 Write(uint32 offset, uint32 data); + + protected: + // BusIO インタフェース + static const uint32 NPORT = 4; + uint64 Peek(uint32 offset); + + void Tx(int ch, uint32 data) override; + uint GetHighestInt() const override; private: - virtual void Interrupt(); + // 指定のレジスタ名を返す + 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 SIODevice *gSIO; +static inline SIODevice *GetSIODevice() { + return Object::GetObject(OBJ_MPSCC); +}