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