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