|
|
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;
! 83: bool MonitorUpdate() override;
1.1 root 84:
85: // DIP-SW1 の状態を取得 (ROM エミュレーション用)
86: //
87: // b7 b6 b5 b4 b3 b2 b1 b0
88: // +------+------+------+------+------+------+------+------+
89: // | #1-8 | #1-7 | #1-6 | #1-5 | #1-4 | #1-3 | #1-2 | #1-1 |
90: // +------+------+------+------+------+------+------+------+
91: // %1 が UP、%0 が DOWN
92: uint32 GetDIPSW1() const { return GetPA(); }
93:
94: protected:
95: // BusIO インタフェース
96: static const uint32 NPORT = 4;
97: uint64 Read(uint32 addr);
98: uint64 Write(uint32 addr, uint32 data);
99: uint64 Peek(uint32 addr);
100:
101: private:
102: uint32 GetPA() const;
103: uint32 GetPB() const;
104: uint32 GetPC() const;
1.1.1.2 ! root 105: void SetPC(int, int) override;
1.1 root 106:
107: bool dipsw1[8] {};
108: bool dipsw2[8] {};
109: bool int1rq = false; // $01 INT1 割り込み要求
110: bool int1en = false; // $04 INT1 割り込み許可
111: bool int5rq = false; // $08 INT5 割り込み要求
112: bool int5en = false; // $10 INT5 割り込み許可
113: bool parity = false; // $40 パリティ有効/無効
114: bool xp_reset = false; // $80 XP リセット
115: };
116:
117: class PIO1Device
118: : public i8255Device
119: {
1.1.1.2 ! root 120: using inherited = i8255Device;
1.1 root 121: public:
122: PIO1Device();
1.1.1.2 ! root 123: ~PIO1Device() override;
1.1 root 124:
125: protected:
126: // BusIO インタフェース
127: static const uint32 NPORT = 4;
128: uint64 Read(uint32 addr);
129: uint64 Write(uint32 addr, uint32 data);
130: uint64 Peek(uint32 addr);
131:
132: private:
1.1.1.2 ! root 133: void SetPC(int, int) override;
1.1 root 134: void PowerOffCallback(int);
135:
136: bool power = false; // パワーダウン (false で電源オフ指示)
137: bool xp_intreq = false; // XP 割り込み要求。あり(true)なら %0
138: Event poffevent {}; // 電源オフイベント
139: };
140:
141: extern std::unique_ptr<PIO0Device> gPIO0;
142: 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.