--- nono/vm/pedec.h 2026/04/29 17:04:45 1.1 +++ nono/vm/pedec.h 2026/04/29 17:05:28 1.1.1.10 @@ -4,59 +4,66 @@ // Licensed under nono-license.txt // +// +// PEDEC +// + #pragma once -#include "device.h" #include "interrupt.h" -class PEDECDevice - : public InterruptDevice +class PEDECDevice : public InterruptDevice { using inherited = InterruptDevice; - private: - static const int baseaddr = 0xe9c000; + + static const uint32 baseaddr = 0xe9c000; + + public: + // SPC からの割り込みはここでマスク制御しないので intmap_enable には + // IntmapSPC を常に立てておくこと。 + static const uint32 IntmapSPC = 0x1000; + static const uint32 IntmapFDC = 0x0080; + static const uint32 IntmapFDD0 = 0x0800; + static const uint32 IntmapFDD1 = 0x0400; + static const uint32 IntmapFDD2 = 0x0200; + static const uint32 IntmapFDD3 = 0x0100; + static const uint32 IntmapFDD = 0x0f00; // FDD(0|1|2|3) + static const uint32 IntmapHDD = 0x0020; + static const uint32 IntmapPRT = 0x0010; public: PEDECDevice(); - virtual ~PEDECDevice() override; + ~PEDECDevice() override; - void ResetHard() override; + bool Init() override; + void ResetHard(bool poweron) override; // InterruptDevice インタフェース - void AssertINT(Device *source) override; - void NegateINT(Device *source) override; - int InterruptAcknowledge(int lv) override; + busdata InterruptAcknowledge(int lv) override; + + // 割り込みコントローラからのモニタ表示 + void MonitorUpdate(TextScreen& screen, uint intr_level, int y); protected: // BusIO インタフェース static const uint32 NPORT = 8; - uint64 Read(uint32 addr); - uint64 Write(uint32 addr, uint32 data); - uint64 Peek(uint32 addr); + busdata ReadPort(uint32 offset); + busdata WritePort(uint32 offset, uint32 data); + busdata PeekPort(uint32 offset); + bool PokePort(uint32 offset, uint32 data); private: // 割り込みステータスレジスタの値を取得 uint32 GetStat() const; // 割り込み信号線の状態を変える - void ChangeInterrupt(); + void ChangeInterrupt() override; - // int_asserted が下位デバイスからの割り込み信号線 (%1 でアサート)。 - // int_enabled がマスク (%1 なら割り込み許可)。 - // よって二者を AND とれば上位に割り込みを上げるかどうかが求まる。 - // SPC からの割り込みはここでマスク制御しないので int_enabled には - // IntmapSPC を常に立てておくこと。 - // $e9c001 (割り込みステータスレジスタ) のビット順は - // これとは全然違うので注意のこと。 - static const uint32 IntmapSPC = 0x10; - static const uint32 IntmapFDC = 0x08; - static const uint32 IntmapFDD = 0x04; - static const uint32 IntmapHDD = 0x02; - static const uint32 IntmapPRT = 0x01; - - uint32 int_asserted {}; - uint32 int_enabled {}; uint8 vector {}; + + InterruptDevice *interrupt {}; }; -extern std::unique_ptr gPEDEC; +static inline PEDECDevice *GetPEDECDevice() { + return Object::GetObject(OBJ_PEDEC); +}