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