Annotation of nono/vm/pio.h, revision 1.1.1.5

1.1       root        1: //
                      2: // nono
1.1.1.2   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
                      7: #pragma once
                      8: 
                      9: #include "device.h"
                     10: #include "scheduler.h"
                     11: 
                     12: // Intel 82C55 の仕様書にはコントロールポートからの読み出しは明記してある。
                     13: // NEC uPD8255 の仕様書にはコントロールポートからの読み出しについての記載が
                     14: // ない (禁止とも書いてない)。
                     15: class i8255Device
                     16:        : public IODevice
                     17: {
1.1.1.2   root       18:        using inherited = IODevice;
1.1       root       19: 
                     20:  public:
                     21:        i8255Device();
1.1.1.5 ! root       22:        virtual ~i8255Device() override;
1.1       root       23: 
1.1.1.4   root       24:        void ResetHard() override;
                     25: 
1.1       root       26:  protected:
                     27:        // コントロールポートの読み出し
                     28:        uint32 ReadCtrl() const { return ctrl; }
                     29:        // コントロールポートへの書き込み
                     30:        void WriteCtrl(uint32);
                     31:        // PortC への個別書き込み
                     32:        virtual void SetPC(int, int);
                     33: 
                     34:        // 7  6  5  4  3   2  1  0
                     35:        // 1  AM AM AD CHD BM BD CLD
                     36:        //    |  |  |  |   |  |  +--- ポートC下位グループの方向。入力なら1
                     37:        //    |  |  |  |   |  +------ ポートB の方向。入力なら1
                     38:        //    |  |  |  |   +--------- ポートB のモード。
                     39:        //    |  |  |  +------------- ポートC上位グループの方向。入力なら1
                     40:        //    |  |  +---------------- ポートA の方向。入力なら1
                     41:        //    +--+------------------- ポートA のモード。
                     42:        uint8 ctrl = 0;                 // コントロールポートの値
                     43: 
                     44:        static const uint DIR_IN  = 1;
                     45:        static const uint DIR_OUT = 0;
                     46:        // グループA/B (ポートA/B) のモード
                     47:        uint GetGroupAMode() const      { return (ctrl >> 5) & 3; }
                     48:        uint GetGroupBMode() const      { return (ctrl >> 2) & 1; }
                     49:        // ポート A/B/C上位/C下位 の入出力方向
                     50:        uint PortADir() const   { return (ctrl & 0x10) ? DIR_IN : DIR_OUT; }
                     51:        uint PortBDir() const   { return (ctrl & 0x02) ? DIR_IN : DIR_OUT; }
                     52:        uint PortCHDir() const  { return (ctrl & 0x08) ? DIR_IN : DIR_OUT; }
                     53:        uint PortCLDir() const  { return (ctrl & 0x01) ? DIR_IN : DIR_OUT; }
                     54: };
                     55: 
                     56: 
                     57: class PPIDevice
                     58:        : public i8255Device
                     59: {
1.1.1.2   root       60:        using inherited = i8255Device;
1.1       root       61:  private:
                     62:        static const int baseaddr = 0xe9a000;
                     63: 
                     64:  public:
                     65:        PPIDevice();
1.1.1.5 ! root       66:        virtual ~PPIDevice() override;
1.1       root       67: 
                     68:  protected:
                     69:        // BusIO インタフェース
                     70:        static const uint32 NPORT = 4;
                     71:        uint64 Read(uint32 addr);
                     72:        uint64 Write(uint32 addr, uint32 data);
                     73:        uint64 Peek(uint32 addr);
                     74: };
                     75: 
                     76: class PIO0Device
                     77:        : public i8255Device
                     78: {
1.1.1.2   root       79:        using inherited = i8255Device;
1.1       root       80:  public:
                     81:        PIO0Device();
1.1.1.5 ! root       82:        virtual ~PIO0Device() override;
1.1       root       83: 
1.1.1.2   root       84:        bool Init() override;
1.1.1.3   root       85: 
                     86:        void MonitorUpdate(TextScreen&) override;
1.1       root       87: 
                     88:        // DIP-SW1 の状態を取得 (ROM エミュレーション用)
                     89:        //
                     90:        //    b7     b6     b5     b4     b3     b2     b1     b0
                     91:        // +------+------+------+------+------+------+------+------+
                     92:        // | #1-8 | #1-7 | #1-6 | #1-5 | #1-4 | #1-3 | #1-2 | #1-1 |
                     93:        // +------+------+------+------+------+------+------+------+
                     94:        // %1 が UP、%0 が DOWN
                     95:        uint32 GetDIPSW1() const { return GetPA(); }
                     96: 
                     97:  protected:
                     98:        // BusIO インタフェース
                     99:        static const uint32 NPORT = 4;
                    100:        uint64 Read(uint32 addr);
                    101:        uint64 Write(uint32 addr, uint32 data);
                    102:        uint64 Peek(uint32 addr);
                    103: 
                    104:  private:
                    105:        uint32 GetPA() const;
                    106:        uint32 GetPB() const;
                    107:        uint32 GetPC() const;
1.1.1.2   root      108:        void SetPC(int, int) override;
1.1       root      109: 
                    110:        bool dipsw1[8] {};
                    111:        bool dipsw2[8] {};
1.1.1.4   root      112:        bool int1rq {};                 // $01 INT1 割り込み要求
                    113:        bool int1en {};                 // $04 INT1 割り込み許可
                    114:        bool int5rq {};                 // $08 INT5 割り込み要求
                    115:        bool int5en {};                 // $10 INT5 割り込み許可
                    116:        bool parity {};                 // $40 パリティ有効/無効
                    117:        bool xp_reset {};               // $80 XP リセット
1.1       root      118: };
                    119: 
                    120: class PIO1Device
                    121:        : public i8255Device
                    122: {
1.1.1.2   root      123:        using inherited = i8255Device;
1.1       root      124:  public:
                    125:        PIO1Device();
1.1.1.5 ! root      126:        virtual ~PIO1Device() override;
1.1       root      127: 
1.1.1.4   root      128:        void ResetHard() override;
                    129: 
1.1       root      130:  protected:
                    131:        // BusIO インタフェース
                    132:        static const uint32 NPORT = 4;
                    133:        uint64 Read(uint32 addr);
                    134:        uint64 Write(uint32 addr, uint32 data);
                    135:        uint64 Peek(uint32 addr);
                    136: 
                    137:  private:
1.1.1.2   root      138:        void SetPC(int, int) override;
1.1.1.4   root      139:        void PowerOffCallback(Event& ev);
1.1       root      140: 
1.1.1.4   root      141:        bool power {};                  // パワーダウン (false で電源オフ指示)
                    142:        bool xp_intreq {};              // XP 割り込み要求。あり(true)なら %0
1.1       root      143:        Event poffevent {};             // 電源オフイベント
                    144: };
                    145: 
                    146: extern std::unique_ptr<PIO0Device> gPIO0;
                    147: extern std::unique_ptr<PIO1Device> gPIO1;

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.