--- nono/vm/pio.h 2026/04/29 17:04:32 1.1.1.1 +++ nono/vm/pio.h 2026/04/29 17:05:10 1.1.1.9 @@ -1,24 +1,30 @@ // // nono -// Copyright (C) 2017 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt +// + +// +// PIO/PPI (i8255) // #pragma once -#include "device.h" -#include "scheduler.h" +#include "event.h" +#include "monitor.h" // Intel 82C55 の仕様書にはコントロールポートからの読み出しは明記してある。 // NEC uPD8255 の仕様書にはコントロールポートからの読み出しについての記載が // ない (禁止とも書いてない)。 -class i8255Device - : public IODevice +class i8255Device : public IODevice { - typedef IODevice inherited; + using inherited = IODevice; public: - i8255Device(); - virtual ~i8255Device(); + i8255Device(const std::string& objname_); + virtual ~i8255Device() override; + + void ResetHard(bool poweron) override; protected: // コントロールポートの読み出し @@ -26,7 +32,7 @@ class i8255Device // コントロールポートへの書き込み void WriteCtrl(uint32); // PortC への個別書き込み - virtual void SetPC(int, int); + virtual void SetPC(int, int) = 0; // 7 6 5 4 3 2 1 0 // 1 AM AM AD CHD BM BD CLD @@ -51,90 +57,94 @@ class i8255Device }; -class PPIDevice - : public i8255Device +class PPIDevice : public i8255Device { - typedef i8255Device inherited; - private: + using inherited = i8255Device; + static const int baseaddr = 0xe9a000; public: PPIDevice(); - virtual ~PPIDevice(); + virtual ~PPIDevice() override; protected: // BusIO インタフェース static const uint32 NPORT = 4; - uint64 Read(uint32 addr); - uint64 Write(uint32 addr, uint32 data); - uint64 Peek(uint32 addr); + uint64 Read(uint32 offset); + uint64 Write(uint32 offset, uint32 data); + uint64 Peek(uint32 offset); + + private: + void SetPC(int, int) override; }; -class PIO0Device - : public i8255Device +class PIO0Device : public i8255Device { - typedef i8255Device inherited; + using inherited = i8255Device; public: PIO0Device(); - virtual ~PIO0Device(); + virtual ~PIO0Device() override; - virtual bool Init(); + bool Init() override; - // DIP-SW1 の状態を取得 (ROM エミュレーション用) - // - // b7 b6 b5 b4 b3 b2 b1 b0 - // +------+------+------+------+------+------+------+------+ - // | #1-8 | #1-7 | #1-6 | #1-5 | #1-4 | #1-3 | #1-2 | #1-1 | - // +------+------+------+------+------+------+------+------+ - // %1 が UP、%0 が DOWN - uint32 GetDIPSW1() const { return GetPA(); } + // DIPSW #1-1 が Up なら true を返す (ROM エミュレーション用) + bool IsDIPSW11Up() const { return dipsw1[0]; } protected: // BusIO インタフェース static const uint32 NPORT = 4; - uint64 Read(uint32 addr); - uint64 Write(uint32 addr, uint32 data); - uint64 Peek(uint32 addr); + uint64 Read(uint32 offset); + uint64 Write(uint32 offset, uint32 data); + uint64 Peek(uint32 offset); private: uint32 GetPA() const; uint32 GetPB() const; uint32 GetPC() const; - virtual void SetPC(int, int); + void SetPC(int, int) override; + + DECLARE_MONITOR_CALLBACK(MonitorUpdate); bool dipsw1[8] {}; bool dipsw2[8] {}; - bool int1rq = false; // $01 INT1 割り込み要求 - bool int1en = false; // $04 INT1 割り込み許可 - bool int5rq = false; // $08 INT5 割り込み要求 - bool int5en = false; // $10 INT5 割り込み許可 - bool parity = false; // $40 パリティ有効/無効 - bool xp_reset = false; // $80 XP リセット + bool msb_first {}; // DIP-SW の1番が MSB なら true (LUNA88K) + bool int1rq {}; // $01 INT1 割り込み要求 + bool int1en {}; // $04 INT1 割り込み許可 + bool int5rq {}; // $08 INT5 割り込み要求 + bool int5en {}; // $10 INT5 割り込み許可 + bool parity {}; // $40 パリティ有効/無効 + bool xp_reset {}; // $80 XP リセット + + Monitor monitor { this }; }; -class PIO1Device - : public i8255Device +class PIO1Device : public i8255Device { - typedef i8255Device inherited; + using inherited = i8255Device; public: PIO1Device(); - virtual ~PIO1Device(); + virtual ~PIO1Device() override; + + void ResetHard(bool poweron) override; protected: // BusIO インタフェース static const uint32 NPORT = 4; - uint64 Read(uint32 addr); - uint64 Write(uint32 addr, uint32 data); - uint64 Peek(uint32 addr); + uint64 Read(uint32 offset); + uint64 Write(uint32 offset, uint32 data); + uint64 Peek(uint32 offset); private: - virtual void SetPC(int, int); - void PowerOffCallback(int); + void SetPC(int, int) override; + void PowerOffCallback(Event& ev); + + bool power {}; // パワーダウン (false で電源オフ指示) + bool xp_intreq {}; // XP 割り込み要求。あり(true)なら %0 - bool power = false; // パワーダウン (false で電源オフ指示) - bool xp_intreq = false; // XP 割り込み要求。あり(true)なら %0 - Event poffevent {}; // 電源オフイベント + // 電源オフイベント + Event poffevent { this }; }; -extern std::unique_ptr gPIO0; -extern std::unique_ptr gPIO1; +extern PPIDevice *gPPI; +extern PIO0Device *gPIO0; +extern PIO1Device *gPIO1;