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