|
|
1.1 root 1: //
2: // nono
1.1.1.3 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"
1.1.1.9 root 10: #include "monitor.h"
1.1 root 11: #include "scheduler.h"
1.1.1.10! root 12: #include <array>
1.1 root 13:
14: struct MFP
15: {
16: static const int GPIP = 0; // $E88001
17: static const int AER = 1; // $E88003
18: static const int DDR = 2; // $E88005
19: static const int IERA = 3; // $E88007
20: static const int IERB = 4; // $E88009
21: static const int IPRA = 5; // $E8800B
22: static const int IPRB = 6; // $E8800D
23: static const int ISRA = 7; // $E8800F
24: static const int ISRB = 8; // $E88011
25: static const int IMRA = 9; // $E88013
26: static const int IMRB = 10; // $E88015
27: static const int VR = 11; // $E88017
28: static const int TACR = 12; // $E88019
29: static const int TBCR = 13; // $E8801B
30: static const int TCDCR = 14; // $E8801D
31: static const int TADR = 15; // $E8801F
32: static const int TBDR = 16; // $E88021
33: static const int TCDR = 17; // $E88023
34: static const int TDDR = 18; // $E88025
35: static const int SCR = 19; // $E88027
36: static const int UCR = 20; // $E88029
37: static const int RSR = 21; // $E8802B
38: static const int TSR = 22; // $E8802D
39: static const int UDR = 23; // $E8802F
40:
41: union ir16 {
42: uint16 w;
43: struct {
44: #if BYTE_ORDER == LITTLE_ENDIAN
45: uint8 b, a;
46: #else
47: uint8 a, b;
48: #endif
49: };
50: };
51:
52: // ハードウェア未実装ビットは書き込み時に '0' にする
53:
54: uint8 gpip;
55: uint8 aer;
56: uint8 ddr;
57: static const int GPIP_HSYNC = 7;
58: static const int GPIP_CIRQ = 6;
59: // 5 は常に '1'
60: static const int GPIP_VDISP = 4;
61: static const int GPIP_FMIRQ = 3;
62: static const int GPIP_POWSW = 2;
63: static const int GPIP_EXPON = 1;
64: static const int GPIP_ALARM = 0;
65:
1.1.1.3 root 66: static const uint INTR_RTC_ALARM = 0;
67: static const uint INTR_EXPON = 1;
68: static const uint INTR_POW_SW = 2;
69: static const uint INTR_FM_IRQ = 3;
70: static const uint INTR_TIMER_D = 4;
71: static const uint INTR_TIMER_C = 5;
72: static const uint INTR_VDISP = 6;
73: static const uint INTR_unused = 7;
74: static const uint INTR_TIMER_B = 8;
75: static const uint INTR_TXERR = 9;
76: static const uint INTR_TXEMPTY = 10;
77: static const uint INTR_RXERR = 11;
78: static const uint INTR_RXFULL = 12;
79: static const uint INTR_TIMER_A = 13;
80: static const uint INTR_CRTC_IRQ = 14;
81: static const uint INTR_HSYNC = 15;
1.1 root 82: ir16 ier;
83: ir16 ipr;
84: ir16 isr;
85: ir16 imr;
1.1.1.6 root 86:
87: //
88: // | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
89: // VR | V7 | V6 | V5 | V4 | S | --- | --- | --- |
90: // | | | | +------------ In-Service Register Enable
91: // +-----+-----+-----+------------------ Vector Number
92: uint8 vr_vec; // ベクタの上位4ビット
93: uint8 vr_s; // %1:ソフトウェアEOI(ISR有効)、%0:自動EOI(ISR無効)
94: uint8 GetVR() const { return vr_vec | vr_s; }
1.1 root 95:
96: // TDR のカウンタをメインカウンタと呼び、このメインカウンタを
97: // 1減らすためのカウンタをプリスケーラカウンタと呼ぶ。
98: // 実際のハードウェアは 4MHz のクロック入力ごとにプリスケーラカウンタを
99: // カウントしていき指定回数カウントすればメインカウンタを1減らすのだが、
1.1.1.6 root 100: // この実装ではどちらのカウンタも持たず、タイマー終了時刻と現在時刻で
101: // 管理する。そのためメインカウンタの値はこの時間差から求める。
1.1 root 102:
1.1.1.6 root 103: // tcr は書き込み値、現在のモードを保持する。
1.1 root 104: uint8 tcr[4]; // --- --- --- RST AC3 AC2 AC1 AC0 : TACR
105: // --- --- --- RST BC3 BC2 BC1 BC0 : TBCR
106: // --- CC2 CC1 CC0 --- DC2 DC1 DC0 : TCDCR
107:
1.1.1.6 root 108: // tdr はカウンタの現在値。
1.1 root 109: uint8 tdr[4];
110:
111: // initial_tdr はカウントダウン開始時点での TxDR の値。
112: // カウンタが 1 から 0 になるタイミングで tdr の値をリロードする。
113: // tdr に $00 を書き込むと 256 カウントになるため、
114: // initial_tdr は 1..256 の値をとる。
115: uint initial_tdr[4];
116:
117: uint8 scr;
1.1.1.3 root 118:
119: // | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
120: // UCR | CLK | WL | ST | PE | E/O | --- |
121: // | | | | +--------- %1で偶数パリティ
122: // | | | +--------------- %1でパリティエラー
123: // | | +------------------- スタート/ストップビット
124: // | +--- データ長 %00 同期
125: // | %00:8bit, %01:7bit %01 非同期 1bit/1bit
126: // | %10:6bit, %11:5bit %10 非同期 1bit/1.5bit
127: // | %11 非同期 1bit/2bit
128: // |
129: // +------------------------------------- %1 送受信速度が入力の1/16
130: static const uint32 UCR_CLK = 0x80;
131: static const uint32 UCR_WL = 0x60;
132: static const uint32 UCR_ST = 0x18;
133: static const uint32 UCR_PE = 0x04;
134: static const uint32 UCR_EO = 0x02;
135: uint8 ucr;
136:
137: // | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
138: // RSR | BF | OE | PE | FE | B | CIP | SS | RE |
139: // | | | | | | | +--- %1 RX Enable
140: // | | | | | | +--------- Sync Stop
141: // | | | | | +--------------- 非同期なら
142: // | | | | | %1 Detect Start Bit
143: // | | | | | %0 Detect Stop Bit
144: // | | | | +--------------------- %1 非同期ならBreak
145: // | | | +--------------------------- %1 Framing Error
146: // | | +--------------------------------- %1 Parity Error
147: // | +--------------------------------------- %1 Overflow Error
148: // +--------------------------------------------- %1 RX Buffer Full
149: static const uint32 RSR_BF = 0x80;
150: static const uint32 RSR_OE = 0x40;
151: static const uint32 RSR_PE = 0x20;
152: static const uint32 RSR_FE = 0x10;
153: static const uint32 RSR_B = 0x08;
154: static const uint32 RSR_CIP = 0x04;
155: static const uint32 RSR_SS = 0x02;
156: static const uint32 RSR_RE = 0x01;
1.1 root 157: uint8 rsr;
1.1.1.3 root 158:
159: // | b7 | b6 | b5 | b4 | b3 | b2 | b1 | b0 |
160: // TSR | BE | UE | AT | END | B | H | L | TE |
161: // | | | +--- %1 TX Enable
162: // | | +--------------------------- %1 TX Disabled
163: // | +--------------------------------------- %1 Underrun Error
164: // +--------------------------------------------- %1 TX Buffer Empty
165: static const uint32 TSR_BE = 0x80;
166: static const uint32 TSR_UE = 0x40;
167: static const uint32 TSR_AT = 0x20;
168: static const uint32 TSR_END = 0x10;
169: static const uint32 TSR_B = 0x08;
170: static const uint32 TSR_H = 0x04;
171: static const uint32 TSR_L = 0x02;
172: static const uint32 TSR_TE = 0x01;
1.1 root 173: uint8 tsr;
174:
1.1.1.3 root 175: // 送受信レジスタ。
176: // 受信データがなければ -1 にする
177: uint16 udr;
1.1 root 178: };
179:
1.1.1.9 root 180: class MFPDevice : public IODevice
1.1 root 181: {
1.1.1.3 root 182: using inherited = IODevice;
1.1 root 183:
184: static const int baseaddr = 0xe88000;
185:
186: public:
187: MFPDevice();
1.1.1.6 root 188: virtual ~MFPDevice() override;
1.1 root 189:
1.1.1.5 root 190: void ResetHard() override;
1.1 root 191:
1.1.1.6 root 192: // 割り込みアクノリッジ
193: int InterruptAcknowledge();
194:
1.1 root 195: // VDisp 入力
196: void SetVDisp(bool vdisp);
197:
1.1.1.3 root 198: // KEY CTRL 状態を設定する
199: void SetKeyCtrl(bool ctrl);
200:
1.1.1.8 root 201: // キーボードからの送信が可能なら true を返す。
202: bool RxIsReady() const;
1.1.1.3 root 203:
204: // キーボードからデータを受信
205: void Rx(uint32 data);
1.1.1.2 root 206:
1.1.1.3 root 207: protected:
208: // BusIO インタフェース
209: static const uint32 NPORT = 0x20;
1.1.1.7 root 210: uint64 Read(uint32 offset);
211: uint64 Write(uint32 offset, uint32 data);
212: uint64 Peek(uint32 offset);
1.1.1.3 root 213:
214: private:
1.1 root 215: void SetTCR(int ch, uint32 data);
1.1.1.2 root 216: uint8 GetTDR(int ch) const;
1.1 root 217: void SetTDR(int ch, uint32 data);
218:
219: // GPIP の信号状態をセットする
220: void SetGPIP(int num, bool val);
221:
1.1.1.3 root 222: void SetUCR(uint32 data);
223: void SetRSR(uint32 data);
224: void SetUDR(uint32 data);
225:
1.1.1.8 root 226: // RSR::BF ビットの状態を変える
227: void SetBF();
228: void ClearBF();
229: // MFP の RR 線の状態を返す
230: bool IsRR() const;
231:
1.1.1.3 root 232: // イベントコールバック
1.1.1.5 root 233: void TimerCallback(Event& ev);
234: void KeyCallback(Event& ev);
1.1 root 235:
1.1.1.6 root 236: // 必要なら割り込みを上げる
237: void SetInterrupt(uint ch);
238:
239: // 割り込み信号線の状態を変える
240: void ChangeInterrupt();
241:
1.1.1.9 root 242: DECLARE_MONITOR_CALLBACK(MonitorUpdate);
243:
1.1 root 244: struct MFP mfp {};
1.1.1.10! root 245: std::array<Event, 4> event {};
1.1.1.9 root 246: Event key_event { this };
247:
248: Monitor monitor { this };
1.1.1.3 root 249:
1.1 root 250: static const char *intrname[];
251: static const char *gpipname[];
252: static const int prescale_ns[8];
253: static const char *prescale_str[8];
254: static const int timer_vector[4];
255: };
256:
1.1.1.2 root 257: extern std::unique_ptr<MFPDevice> gMFP;
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.