|
|
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:
1.1.1.9 ! root 7: //
! 8: // PIO/PPI (i8255)
! 9: //
! 10:
1.1 root 11: #pragma once
12:
1.1.1.9 ! root 13: #include "event.h"
! 14: #include "monitor.h"
1.1 root 15:
16: // Intel 82C55 の仕様書にはコントロールポートからの読み出しは明記してある。
17: // NEC uPD8255 の仕様書にはコントロールポートからの読み出しについての記載が
18: // ない (禁止とも書いてない)。
1.1.1.7 root 19: class i8255Device : public IODevice
1.1 root 20: {
1.1.1.2 root 21: using inherited = IODevice;
1.1 root 22:
23: public:
1.1.1.7 root 24: i8255Device(const std::string& objname_);
1.1.1.5 root 25: virtual ~i8255Device() override;
1.1 root 26:
1.1.1.9 ! root 27: void ResetHard(bool poweron) override;
1.1.1.4 root 28:
1.1 root 29: protected:
30: // コントロールポートの読み出し
31: uint32 ReadCtrl() const { return ctrl; }
32: // コントロールポートへの書き込み
33: void WriteCtrl(uint32);
34: // PortC への個別書き込み
1.1.1.9 ! root 35: virtual void SetPC(int, int) = 0;
1.1 root 36:
37: // 7 6 5 4 3 2 1 0
38: // 1 AM AM AD CHD BM BD CLD
39: // | | | | | | +--- ポートC下位グループの方向。入力なら1
40: // | | | | | +------ ポートB の方向。入力なら1
41: // | | | | +--------- ポートB のモード。
42: // | | | +------------- ポートC上位グループの方向。入力なら1
43: // | | +---------------- ポートA の方向。入力なら1
44: // +--+------------------- ポートA のモード。
45: uint8 ctrl = 0; // コントロールポートの値
46:
47: static const uint DIR_IN = 1;
48: static const uint DIR_OUT = 0;
49: // グループA/B (ポートA/B) のモード
50: uint GetGroupAMode() const { return (ctrl >> 5) & 3; }
51: uint GetGroupBMode() const { return (ctrl >> 2) & 1; }
52: // ポート A/B/C上位/C下位 の入出力方向
53: uint PortADir() const { return (ctrl & 0x10) ? DIR_IN : DIR_OUT; }
54: uint PortBDir() const { return (ctrl & 0x02) ? DIR_IN : DIR_OUT; }
55: uint PortCHDir() const { return (ctrl & 0x08) ? DIR_IN : DIR_OUT; }
56: uint PortCLDir() const { return (ctrl & 0x01) ? DIR_IN : DIR_OUT; }
57: };
58:
59:
1.1.1.7 root 60: class PPIDevice : public i8255Device
1.1 root 61: {
1.1.1.2 root 62: using inherited = i8255Device;
1.1.1.9 ! root 63:
1.1 root 64: static const int baseaddr = 0xe9a000;
65:
66: public:
67: PPIDevice();
1.1.1.5 root 68: virtual ~PPIDevice() override;
1.1 root 69:
70: protected:
71: // BusIO インタフェース
72: static const uint32 NPORT = 4;
1.1.1.6 root 73: uint64 Read(uint32 offset);
74: uint64 Write(uint32 offset, uint32 data);
75: uint64 Peek(uint32 offset);
1.1.1.9 ! root 76:
! 77: private:
! 78: void SetPC(int, int) override;
1.1 root 79: };
80:
1.1.1.7 root 81: class PIO0Device : public i8255Device
1.1 root 82: {
1.1.1.2 root 83: using inherited = i8255Device;
1.1 root 84: public:
85: PIO0Device();
1.1.1.5 root 86: virtual ~PIO0Device() override;
1.1 root 87:
1.1.1.2 root 88: bool Init() override;
1.1.1.3 root 89:
1.1.1.9 ! root 90: // DIPSW #1-1 が Up なら true を返す (ROM エミュレーション用)
! 91: bool IsDIPSW11Up() const { return dipsw1[0]; }
1.1 root 92:
93: protected:
94: // BusIO インタフェース
95: static const uint32 NPORT = 4;
1.1.1.6 root 96: uint64 Read(uint32 offset);
97: uint64 Write(uint32 offset, uint32 data);
98: uint64 Peek(uint32 offset);
1.1 root 99:
100: private:
101: uint32 GetPA() const;
102: uint32 GetPB() const;
103: uint32 GetPC() const;
1.1.1.2 root 104: void SetPC(int, int) override;
1.1 root 105:
1.1.1.7 root 106: DECLARE_MONITOR_CALLBACK(MonitorUpdate);
107:
1.1 root 108: bool dipsw1[8] {};
109: bool dipsw2[8] {};
1.1.1.8 root 110: bool msb_first {}; // DIP-SW の1番が MSB なら true (LUNA88K)
1.1.1.4 root 111: bool int1rq {}; // $01 INT1 割り込み要求
112: bool int1en {}; // $04 INT1 割り込み許可
113: bool int5rq {}; // $08 INT5 割り込み要求
114: bool int5en {}; // $10 INT5 割り込み許可
115: bool parity {}; // $40 パリティ有効/無効
116: bool xp_reset {}; // $80 XP リセット
1.1.1.7 root 117:
118: Monitor monitor { this };
1.1 root 119: };
120:
1.1.1.7 root 121: class PIO1Device : public i8255Device
1.1 root 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.9 ! root 128: void ResetHard(bool poweron) override;
1.1.1.4 root 129:
1.1 root 130: protected:
131: // BusIO インタフェース
132: static const uint32 NPORT = 4;
1.1.1.6 root 133: uint64 Read(uint32 offset);
134: uint64 Write(uint32 offset, uint32 data);
135: uint64 Peek(uint32 offset);
1.1 root 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.1.7 root 143:
144: // 電源オフイベント
145: Event poffevent { this };
1.1 root 146: };
147:
1.1.1.9 ! root 148: extern PPIDevice *gPPI;
! 149: extern PIO0Device *gPIO0;
! 150: extern PIO1Device *gPIO1;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.