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