|
|
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:
1.1.1.11 root 7: //
8: // MFP (MC68901)
9: //
10:
1.1 root 11: #pragma once
12:
13: #include "device.h"
1.1.1.10 root 14: #include <array>
1.1 root 15:
1.1.1.13 root 16: class InterruptDevice;
1.1.1.18 root 17: class Syncer;
1.1.1.13 root 18: class X68030Keyboard;
19:
1.1 root 20: struct MFP
21: {
1.1.1.15 root 22: static const uint GPIP = 0; // $E88001
23: static const uint AER = 1; // $E88003
24: static const uint DDR = 2; // $E88005
25: static const uint IERA = 3; // $E88007
26: static const uint IERB = 4; // $E88009
27: static const uint IPRA = 5; // $E8800B
28: static const uint IPRB = 6; // $E8800D
29: static const uint ISRA = 7; // $E8800F
30: static const uint ISRB = 8; // $E88011
31: static const uint IMRA = 9; // $E88013
32: static const uint IMRB = 10; // $E88015
33: static const uint VR = 11; // $E88017
34: static const uint TACR = 12; // $E88019
35: static const uint TBCR = 13; // $E8801B
36: static const uint TCDCR = 14; // $E8801D
37: static const uint TADR = 15; // $E8801F
38: static const uint TBDR = 16; // $E88021
39: static const uint TCDR = 17; // $E88023
40: static const uint TDDR = 18; // $E88025
41: static const uint SCR = 19; // $E88027
42: static const uint UCR = 20; // $E88029
43: static const uint RSR = 21; // $E8802B
44: static const uint TSR = 22; // $E8802D
45: static const uint UDR = 23; // $E8802F
46: static const uint RegMax = 24;
1.1 root 47:
48: union ir16 {
49: uint16 w;
50: struct {
51: #if BYTE_ORDER == LITTLE_ENDIAN
52: uint8 b, a;
53: #else
54: uint8 a, b;
55: #endif
56: };
57: };
58:
59: // ハードウェア未実装ビットは書き込み時に '0' にする
60:
61: uint8 gpip;
62: uint8 aer;
63: uint8 ddr;
1.1.1.15 root 64: static const uint GPIP_HSYNC = 7;
65: static const uint GPIP_CIRQ = 6;
1.1 root 66: // 5 は常に '1'
1.1.1.15 root 67: static const uint GPIP_VDISP = 4;
68: static const uint GPIP_FMIRQ = 3;
69: static const uint GPIP_POWSW = 2;
70: static const uint GPIP_EXPON = 1;
71: static const uint GPIP_ALARM = 0;
1.1 root 72:
1.1.1.3 root 73: static const uint INTR_RTC_ALARM = 0;
74: static const uint INTR_EXPON = 1;
75: static const uint INTR_POW_SW = 2;
76: static const uint INTR_FM_IRQ = 3;
77: static const uint INTR_TIMER_D = 4;
78: static const uint INTR_TIMER_C = 5;
79: static const uint INTR_VDISP = 6;
80: static const uint INTR_unused = 7;
81: static const uint INTR_TIMER_B = 8;
82: static const uint INTR_TXERR = 9;
83: static const uint INTR_TXEMPTY = 10;
84: static const uint INTR_RXERR = 11;
85: static const uint INTR_RXFULL = 12;
86: static const uint INTR_TIMER_A = 13;
87: static const uint INTR_CRTC_IRQ = 14;
88: static const uint INTR_HSYNC = 15;
1.1 root 89: ir16 ier;
90: ir16 ipr;
91: ir16 isr;
92: ir16 imr;
1.1.1.6 root 93:
1.1.1.17 root 94: // b7 b6 b5 b4 b3 b2 b1 b0
95: // +-----+-----+-----+-----+-----+-----+-----+-----+
1.1.1.6 root 96: // VR | V7 | V6 | V5 | V4 | S | --- | --- | --- |
1.1.1.17 root 97: // +-----+-----+-----+-----+-----+-----+-----+-----+
98: // | | | | |
1.1.1.6 root 99: // | | | | +------------ In-Service Register Enable
100: // +-----+-----+-----+------------------ Vector Number
101: uint8 vr_vec; // ベクタの上位4ビット
102: uint8 vr_s; // %1:ソフトウェアEOI(ISR有効)、%0:自動EOI(ISR無効)
103: uint8 GetVR() const { return vr_vec | vr_s; }
1.1 root 104:
1.1.1.15 root 105: // タイマー
1.1.1.18 root 106: struct Timer {
107: // タイマー停止中は、カウンタの現在値 (1-256) を保持。
108: // タイマー動作中は、現在カウントダウン中のカウントの初期値(1-256)。
109: // TxDR レジスタ値際は、タイマー動作中/停止中どちらでも
110: // これではなく GetTDR() を使うこと。
1.1.1.15 root 111: uint32 tdr;
112:
1.1.1.18 root 113: // 次回の TxDR のリロード値 (1-256)。
1.1.1.15 root 114: uint32 next_tdr;
115:
1.1.1.18 root 116: // タイマーの開始時刻。
117: uint64 start;
118:
1.1.1.15 root 119: // tcr は書き込み値、現在のモードを保持する。
120: // TACR: --- --- --- RST AC3 AC2 AC1 AC0
121: // TBCR: --- --- --- RST BC3 BC2 BC1 BC0
122: // TCDCR: --- CC2 CC1 CC0 --- DC2 DC1 DC0
123: uint8 tcr;
1.1.1.18 root 124:
125: bool IsStopped() const noexcept { return (tcr == 0); }
126: bool IsDelay() const noexcept { return (0 < tcr && tcr < 8); }
127: bool IsEvent() const noexcept { return (tcr == 8); }
128: bool IsPulseWidth() const noexcept { return (tcr > 8); }
129:
130: // 現在時刻 now とメインカウンタ周期 period から
131: // 現在のメインカウンタの値を求める。
132: // タイマー動作中のみ呼ぶこと。
133: uint8 GetCounter(uint64 now, uint64 period) const;
1.1.1.15 root 134: } timer[4];
135:
136: // TCDCR の値
137: uint8 GetTCDCR() const {
138: return (timer[2].tcr << 4) | timer[3].tcr;
139: }
1.1 root 140:
141: uint8 scr;
1.1.1.3 root 142:
1.1.1.17 root 143: // b7 b6 b5 b4 b3 b2 b1 b0
144: // +-----+-----+-----+-----+-----+-----+-----+-----+
1.1.1.3 root 145: // UCR | CLK | WL | ST | PE | E/O | --- |
1.1.1.17 root 146: // +-----+-----+-----+-----+-----+-----+-----+-----+
147: // | | | | |
1.1.1.3 root 148: // | | | | +--------- %1で偶数パリティ
149: // | | | +--------------- %1でパリティエラー
150: // | | +------------------- スタート/ストップビット
151: // | +--- データ長 %00 同期
152: // | %00:8bit, %01:7bit %01 非同期 1bit/1bit
153: // | %10:6bit, %11:5bit %10 非同期 1bit/1.5bit
154: // | %11 非同期 1bit/2bit
155: // |
156: // +------------------------------------- %1 送受信速度が入力の1/16
157: static const uint32 UCR_CLK = 0x80;
158: static const uint32 UCR_WL = 0x60;
159: static const uint32 UCR_ST = 0x18;
160: static const uint32 UCR_PE = 0x04;
161: static const uint32 UCR_EO = 0x02;
162: uint8 ucr;
163:
1.1.1.17 root 164: // b7 b6 b5 b4 b3 b2 b1 b0
165: // +-----+-----+-----+-----+-----+-----+-----+-----+
1.1.1.3 root 166: // RSR | BF | OE | PE | FE | B | CIP | SS | RE |
1.1.1.17 root 167: // +-----+-----+-----+-----+-----+-----+-----+-----+
168: // | | | | | | | |
1.1.1.3 root 169: // | | | | | | | +--- %1 RX Enable
170: // | | | | | | +--------- Sync Stop
171: // | | | | | +--------------- 非同期なら
172: // | | | | | %1 Detect Start Bit
173: // | | | | | %0 Detect Stop Bit
174: // | | | | +--------------------- %1 非同期ならBreak
175: // | | | +--------------------------- %1 Framing Error
176: // | | +--------------------------------- %1 Parity Error
177: // | +--------------------------------------- %1 Overflow Error
178: // +--------------------------------------------- %1 RX Buffer Full
179: static const uint32 RSR_BF = 0x80;
180: static const uint32 RSR_OE = 0x40;
181: static const uint32 RSR_PE = 0x20;
182: static const uint32 RSR_FE = 0x10;
183: static const uint32 RSR_B = 0x08;
184: static const uint32 RSR_CIP = 0x04;
185: static const uint32 RSR_SS = 0x02;
186: static const uint32 RSR_RE = 0x01;
1.1 root 187: uint8 rsr;
1.1.1.3 root 188:
1.1.1.17 root 189: // b7 b6 b5 b4 b3 b2 b1 b0
190: // +-----+-----+-----+-----+-----+-----+-----+-----+
1.1.1.3 root 191: // TSR | BE | UE | AT | END | B | H | L | TE |
1.1.1.17 root 192: // +-----+-----+-----+-----+-----+-----+-----+-----+
193: // | | | |
1.1.1.3 root 194: // | | | +--- %1 TX Enable
195: // | | +--------------------------- %1 TX Disabled
196: // | +--------------------------------------- %1 Underrun Error
197: // +--------------------------------------------- %1 TX Buffer Empty
198: static const uint32 TSR_BE = 0x80;
199: static const uint32 TSR_UE = 0x40;
200: static const uint32 TSR_AT = 0x20;
201: static const uint32 TSR_END = 0x10;
202: static const uint32 TSR_B = 0x08;
203: static const uint32 TSR_H = 0x04;
204: static const uint32 TSR_L = 0x02;
205: static const uint32 TSR_TE = 0x01;
1.1 root 206: uint8 tsr;
207:
1.1.1.3 root 208: // 送受信レジスタ。
209: // 受信データがなければ -1 にする
210: uint16 udr;
1.1 root 211: };
212:
1.1.1.9 root 213: class MFPDevice : public IODevice
1.1 root 214: {
1.1.1.3 root 215: using inherited = IODevice;
1.1 root 216:
1.1.1.15 root 217: static const uint32 baseaddr = 0xe88000;
1.1 root 218:
219: public:
220: MFPDevice();
1.1.1.14 root 221: ~MFPDevice() override;
1.1 root 222:
1.1.1.13 root 223: bool Init() override;
1.1.1.11 root 224: void ResetHard(bool poweron) override;
1.1 root 225:
1.1.1.6 root 226: // 割り込みアクノリッジ
1.1.1.14 root 227: busdata InterruptAcknowledge();
1.1.1.6 root 228:
1.1.1.11 root 229: // HSync 入力
230: void SetHSync(bool hsync);
231:
1.1 root 232: // VDisp 入力
233: void SetVDisp(bool vdisp);
234:
1.1.1.12 root 235: // 電源ボタン状態入力
236: void SetPowSW(bool powsw);
237:
238: // ALARM 信号入力
239: void SetAlarmOut(bool alarm);
240:
1.1.1.3 root 241: // KEY CTRL 状態を設定する
242: void SetKeyCtrl(bool ctrl);
243:
1.1.1.8 root 244: // キーボードからの送信が可能なら true を返す。
245: bool RxIsReady() const;
1.1.1.3 root 246:
247: // キーボードからデータを受信
248: void Rx(uint32 data);
1.1.1.2 root 249:
1.1.1.3 root 250: protected:
251: // BusIO インタフェース
252: static const uint32 NPORT = 0x20;
1.1.1.15 root 253: busdata ReadPort(uint32 offset);
254: busdata WritePort(uint32 offset, uint32 data);
255: busdata PeekPort(uint32 offset);
256: bool PokePort(uint32 offset, uint32 data);
1.1.1.3 root 257:
258: private:
1.1.1.18 root 259: void SetIER(uint16 data);
1.1 root 260: void SetTCR(int ch, uint32 data);
1.1.1.2 root 261: uint8 GetTDR(int ch) const;
1.1 root 262: void SetTDR(int ch, uint32 data);
1.1.1.18 root 263: void RestartTimerEvent(int ch);
264: void StopTimerEvent(int ch);
265: bool IsTimerIntrEnable(int ch) const;
1.1 root 266:
267: // GPIP の信号状態をセットする
268: void SetGPIP(int num, bool val);
269:
1.1.1.3 root 270: void SetUCR(uint32 data);
271: void SetRSR(uint32 data);
272: void SetUDR(uint32 data);
273:
1.1.1.8 root 274: // RSR::BF ビットの状態を変える
275: void SetBF();
276: void ClearBF();
277: // MFP の RR 線の状態を返す
278: bool IsRR() const;
279:
1.1.1.3 root 280: // イベントコールバック
1.1.1.19! root 281: void TimerCallback(Event *);
! 282: void KeyCallback(Event *);
1.1 root 283:
1.1.1.6 root 284: // 必要なら割り込みを上げる
285: void SetInterrupt(uint ch);
286:
287: // 割り込み信号線の状態を変える
288: void ChangeInterrupt();
289:
1.1.1.9 root 290: DECLARE_MONITOR_CALLBACK(MonitorUpdate);
291:
1.1 root 292: struct MFP mfp {};
1.1.1.19! root 293: std::array<Event *, 4> event {};
! 294: Event *key_event {};
1.1.1.9 root 295:
1.1.1.18 root 296: // 各タイマーが刻んでいる時刻 (時間軸)
297: std::array<uint64, 4> stime {};
298:
299: // 各タイマーの周期
300: std::array<uint64, 4> rt_period {};
301:
302: // タイマーを実時間に追従する場合は true。
303: bool sync_rt {};
304:
1.1.1.16 root 305: Monitor *monitor {};
1.1.1.3 root 306:
1.1.1.13 root 307: InterruptDevice *interrupt {};
1.1.1.18 root 308: Syncer *syncer {};
1.1.1.13 root 309: X68030Keyboard *keyboard {};
310:
1.1.1.19! root 311: static const busdata wait;
1.1 root 312: static const char *intrname[];
313: static const char *gpipname[];
1.1.1.18 root 314: static const uint64 prescale_ns[8];
1.1 root 315: static const char *prescale_str[8];
1.1.1.15 root 316: static const uint timer_vector[4];
317: static const char *regname[MFP::RegMax];
1.1 root 318: };
319:
1.1.1.13 root 320: static inline MFPDevice *GetMFPDevice() {
321: return Object::GetObject<MFPDevice>(OBJ_MFP);
322: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.