|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // メインバス (X68030)
9: //
10:
11: // IODevice
12: // +-- MainbusBaseDevice (InitMainbus() と FC アクセスを持つ)
13: // | +-- MainbusDevice (これがメインバス、システムに1つ)
14: // | | +-- Mainbus24Device (上位8ビットがテーブルで表せるメインバス)
15: // | | | +-- LunaMainbus
16: // | | | | +-- Luna1Mainbus
17: // | | | | +-- Luna88kMainbus
18: // | | | +-- NewsMainbus
19: // | | | +-- Virt68kMainbus
20: // | | |
21: // | | | +-------------+
22: // | | +--| X68kMainbus |(上位8ビットが IODevice で表せないため)
23: // | | +-------------+
24: // | |
25: // | +-- X68kIODevice (FC を受け取るため)
26: // |
27: // +-- XPbusDevice
28:
29: #include "mainbus_x68k.h"
30: #include "bankram.h"
31: #include "extram.h"
32: #include "interrupt.h"
33: #include "mainapp.h"
1.1.1.3 root 34: #include "monitor.h"
1.1 root 35: #include "x68kio.h"
36:
37: // コンストラクタ
38: X68kMainbus::X68kMainbus()
39: : inherited(OBJ_MAINBUS)
40: {
41: // デバイス
42: NEWDV(Interrupt, new X68030Interrupt());
43: NEWDV(X68kIO, new X68kIODevice());
44: NEWDV(ExtRAM, new ExtRAMDevice());
45:
46: // デバイスの割り当ては Init() で行っている。
47:
1.1.1.3 root 48: monitor = gMonitorManager->Regist(ID_MONITOR_MAINBUS, this);
49: monitor->func = ToMonitorCallback(&X68kMainbus::MonitorUpdate);
50: monitor->SetSize(75, 33);
1.1 root 51:
1.1.1.3 root 52: accstat_monitor->func =
1.1 root 53: ToMonitorCallback(&X68kMainbus::MonitorUpdateAccStat);
1.1.1.3 root 54: accstat_monitor->SetSize(80, 2 + 32 + 3);
1.1 root 55: }
56:
57: // デストラクタ
58: X68kMainbus::~X68kMainbus()
59: {
60: }
61:
62: // 初期化
63: bool
64: X68kMainbus::Init()
65: {
66: if (inherited::Init() == false) {
67: return false;
68: }
69:
70: for (int i = 0; i < bankram.size(); i++) {
71: bankram[i] = gMainApp.FindObject<BankRAMDevice>(OBJ_BANKRAM(i));
72: }
73:
74: return true;
75: }
76:
77: // メインバスの初期化
78: bool
79: X68kMainbus::InitMainbus()
80: {
1.1.1.2 root 81: int extstart;
82: int extsize;
83:
1.1 root 84: // 拡張メモリはサイズが確定した後のここで配置。
85: extsize = pExtRAM->GetSizeMB();
86:
87: // 上位8ビット全域を一旦全部内蔵空間にしてから
88: std::fill(is_intio.begin(), is_intio.end(), true);
89:
90: if (extsize == 16) {
91: // TS-6BE16 互換 (16MB) なら $01 の 16MB。
92: extstart = 16;
93: is_intio[1] = false;
94: } else {
95: // 060turbo 互換なら $10 から。
96: extstart = 256;
97: for (int i = 0x10, end = i + (extsize / 16); i < end; i++) {
98: is_intio[i] = false;
99: }
100: }
101:
102: // 親子構造になっている。
103: if (pX68kIO->InitMainbus() == false) {
104: return false;
105: }
106:
1.1.1.2 root 107: // アクセス統計のデバイスがある領域。
108: accstat_avail[0] = 0x80;
109: for (int i = extstart / 16; i < (extstart + extsize) / 16; i++) {
110: accstat_avail[i / 8] |= 0x80U >> (i % 8);
111: }
112:
1.1 root 113: return true;
114: }
115:
116: // リセットについて。
117: //
118: // PWRRESET
119: // 電源オン ----------+--> VIPS
120: // (7505) +--> VideoCtlr
121: // +--> OSCIAN2
122: // |
123: // | +------+
124: // +-->| |
125: // 本体 SWRESET | YUKI |
126: // リセット ------------->| |
127: // スイッチ +------+
128: // | IPLRESET
129: // |
130: // +--> FPU
131: // |
132: // ▽
133: // RESET |
134: // |<-> MPU (68030)
135: // +--> PPI (8255)
136: // +--> SPC (MB89352)
137: // +--> ADPCM (MSM6258)
138: // +--> FDC (uPD72065B)
139: // +--> MFP (MC68901)
140: // |
141: // | +-------+
142: // +-->| PEDEC |
143: // | +-------+
144: // | |
145: // | +-- OPMIC -----> OPM(YM2151)
146: // | +-- SCCRD/WR --> SCC(Z8530)
147: // |
148: // | EXRESET
149: // +---|>-----------> 外部バス
150: // ▽
151: // SYSRESET |
152: // |<-> SAKI ---+
153: // | | BEC0,BEC1
154: // +--> DMAC <--+
155: // +--> CYNTHIA
156: // リセットされない?
157: // o CACHY
158:
159: // MPU の RESET 命令によるリセット
160: void
161: X68kMainbus::ResetByMPU()
162: {
163: std::vector<int> ids {
164: OBJ_ADPCM,
165: OBJ_BANKRAM0,
166: OBJ_BANKRAM1,
167: OBJ_DMAC,
168: OBJ_ETHERNET0,
169: OBJ_ETHERNET1,
170: OBJ_FDC,
171: OBJ_MFP,
172: OBJ_OPM,
173: OBJ_PEDEC,
174: OBJ_PLUTO,
175: OBJ_PPI,
176: OBJ_MPSCC,
177: OBJ_SPC,
178: OBJ_WINDRV,
179: };
180: for (auto id : ids) {
181: auto dev = gMainApp.FindObject<IODevice>(id);
182: if (dev) {
183: dev->ResetHard(false);
184: }
185: }
186: }
187:
188: inline bool
189: X68kMainbus::IsIntio(uint32 addr) const
190: {
191: return is_intio[(addr >> 24) & 0xff];
192: }
193:
1.1.1.2 root 194: // 内蔵 16MB 分で折り返す
195: #define ACCSTAT_INTIO(pa) \
196: (((pa) >> AccStat::SHIFT) & ((1U << (24 - AccStat::SHIFT)) - 1))
1.1 root 197:
198: busdata
1.1.1.2 root 199: X68kMainbus::Read(busaddr addr)
1.1 root 200: {
1.1.1.2 root 201: uint32 pa = addr.Addr();
202: if (IsIntio(pa)) {
203: // 内蔵 16MB を 2MB 単位で
204: accstat_read[ACCSTAT_INTIO(pa)] = AccStat::READ;
205: return pX68kIO->Read(addr);
206: } else {
207: // 拡張メモリのアドレスは折り返しは起きない
208: accstat_read[pa >> AccStat::SHIFT] = AccStat::READ;
209: return pExtRAM->Read(addr);
210: }
1.1 root 211: }
212:
213: busdata
1.1.1.2 root 214: X68kMainbus::Write(busaddr addr, uint32 data)
1.1 root 215: {
1.1.1.2 root 216: uint32 pa = addr.Addr();
217: if (IsIntio(pa)) {
218: // 内蔵 16MB を 2MB 単位で
219: accstat_write[ACCSTAT_INTIO(pa)] = AccStat::WRITE;
220: return pX68kIO->Write(addr, data);
221: } else { \
222: // 拡張メモリのアドレスは折り返しは起きない
223: accstat_write[pa >> AccStat::SHIFT] = AccStat::WRITE;
224: return pExtRAM->Write(addr, data);
225: }
1.1 root 226: }
227:
228: busdata
1.1.1.2 root 229: X68kMainbus::Peek1(uint32 addr)
1.1 root 230: {
231: if (IsIntio(addr)) {
1.1.1.2 root 232: return pX68kIO->Peek1(addr);
1.1 root 233: } else {
1.1.1.2 root 234: return pExtRAM->Peek1(addr);
1.1 root 235: }
236: }
237:
238: bool
1.1.1.2 root 239: X68kMainbus::Poke1(uint32 addr, uint32 data)
1.1 root 240: {
241: if (IsIntio(addr)) {
1.1.1.2 root 242: return pX68kIO->Poke1(addr, data);
1.1 root 243: } else {
1.1.1.2 root 244: return pExtRAM->Poke1(addr, data);
1.1 root 245: }
246: }
247:
248: void
249: X68kMainbus::MonitorUpdate(Monitor *, TextScreen& screen)
250: {
251: screen.Clear();
252:
253: // 012345678901234567890
254: // $0000'0000: 1234567
255:
256: for (int i = 0; i < 8; i++) {
257: screen.Print(12 + i * 8, 0, "+$0%x", i);
258: }
259:
260: auto xioname = FormatDevName(pX68kIO.get()).first;
261: auto extname = FormatDevName(pExtRAM.get()).first;
262:
263: int idx = 0;
264: for (int i = 0; i < is_intio.size() / 8; i++) {
265: screen.Print(0, i + 1, "$%02x00'0000:", idx);
266: for (int j = 0; j < 8; j++) {
267: screen.Print(12 + j * 8, i + 1, "%s",
268: (is_intio[idx] ? xioname : extname).c_str());
269: idx++;
270: }
271: }
272: }
273:
274: void
1.1.1.2 root 275: X68kMainbus::MonitorUpdateAccStat(Monitor *monitor_, TextScreen& screen)
1.1 root 276: {
1.1.1.2 root 277: // メインバス空間は親クラス側の処理そのまま。
278: inherited::MonitorUpdateAccStat(monitor_, screen);
1.1 root 279:
1.1.1.2 root 280: // バンクメモリ側の情報取得。
1.1 root 281: for (int n = 0; n < bankram.size(); n++) {
282: if (bankram[n]) {
1.1.1.2 root 283: bankram[n]->FetchAccStat(&accbank[n * AccStat::BANKLEN]);
1.1 root 284: }
285: }
286:
1.1.1.2 root 287: // バンクメモリ側の描画。
288: for (int n = 0; n < bankram.size(); n++) {
289: int y = 35 + n;
290: screen.Print(0, y, "BankMem #%u:", n);
1.1 root 291: if (bankram[n]) {
1.1.1.2 root 292: for (int i = 0; i < AccStat::BANKLEN; i++) {
293: uint op = accbank[n * AccStat::BANKLEN + i] & 3;
1.1 root 294: uint8 ch = ".RWA"[op];
1.1.1.2 root 295: screen.Putc(12 + i, y, ch);
1.1 root 296: }
297: }
298: }
299: }
300:
301: // ブートページを切り替える。
302: void
303: X68kMainbus::SwitchBootPage(bool isrom)
304: {
305: // X68030 ではすべて X68kIO が担当している
306: pX68kIO->SwitchBootPage(isrom);
307: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.