|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2020 [email protected]
4: //
5:
6: #include "aout.h"
7: #include "bt454.h"
8: #include "mainapp.h"
9: #include "memorystream.h"
10: #include "romemu_luna88k.h"
11: #include "ram.h"
12: #include "spc.h"
13:
14: // コンストラクタ
15: Luna88kPROMEmuDevice::Luna88kPROMEmuDevice()
16: {
17: devaddr = baseaddr;
18: mask = 1024 - 1; // サイズは適当
19: mem = new uint8 [mask + 1];
20: }
21:
22: // デストラクタ
23: Luna88kPROMEmuDevice::~Luna88kPROMEmuDevice()
24: {
25: if (mem) {
26: delete[] mem;
27: }
28: }
29:
30: bool
31: Luna88kPROMEmuDevice::Init()
32: {
33: MemoryStreamBE ms(mem);
34:
35: // リセットベクタは本来2ワードだけだが他のベクタは使わないので
36: // 直接コードを書く。
37: uint32 hi = ROMIO_IPL >> 16;
38: uint32 lo = ROMIO_IPL & 0xffff;
39: ms.Write32(0x5c400000 | hi); // or.u r2, r0, (ROMIO_IPL >> 16)
40: ms.Write32(0x58420000 | lo); // or r2, r2, (ROMIO_IPL & 0xffff)
41: ms.Write32(0xf4221400); // ld r1, r2, r0
42: ms.Write32(0xf400c001); // jmp r1
43:
44: return true;
45: }
46:
47: void
48: Luna88kPROMEmuDevice::ResetHard()
49: {
50: ipl_done = false;
51: }
52:
53: // アドレスデコーダ
54: inline uint64
55: Luna88kPROMEmuDevice::Decoder(uint32 addr) const
56: {
57: return addr - baseaddr;
58: }
59:
60: uint64
61: Luna88kPROMEmuDevice::Read32(uint32 addr)
62: {
63: uint64 offset = Decoder(addr);
64:
65: // (ロング)ワードアクセスでだけ謎の I/O 空間が見える
66: switch (offset) {
67: case ROMIO_IPL - baseaddr:
68: if (!ipl_done)
69: return IPL();
70: break;
71: default:
72: break;
73: }
74:
75: return inherited::Read32(addr);
76: }
77:
78: // 起動時の処理を行う。
79: // 成功すればエントリポイント、失敗すれば 0 を返す。
80: uint32
81: Luna88kPROMEmuDevice::IPL()
82: {
83: uint32 entry = 0;
84:
85: ipl_done = true;
86:
87: // ベクタテーブルを rte で埋めておく
88: for (int i = 0; i < 512; i++) {
89: gRAM->Write32(i * 8, 0xf400fc00 /* rte */);
90: }
91:
92: // ROM の機能テーブル
93: // 0x00001100 からあるようだ
94: // 0x0000110c GETC()
95: // 0x00001110 PUTC(c)
96: // 0x00001114 ビットマッププレーンの有効状態が入っている。
97: // bit0: plane0 有効
98: // bit1..7: plane1..7 有効
99: gRAM->Write32(0x0000110c, 0x00001300);
100: gRAM->Write32(0x00001110, 0x00001400);
101: gRAM->Write32(0x00001114, 0x00000001);
102:
103: // ROM GETC エミュレータ
104: gRAM->Write32(0x00001300, 0xfc000c00); // internal inst getc
105: gRAM->Write32(0x00001304, 0xf400c001); // jmp r1
106:
107: // ROM PUTC エミュレータ
108: gRAM->Write32(0x00001400, 0xfc001000); // internal inst putc
109: gRAM->Write32(0x00001404, 0xf400c001); // jmp r1
110:
111: // 初期パレット
112: gBT454->Write8(0, 14 << 4); // select palette
113: gBT454->Write8(1, 15 << 4); // R=15
114: gBT454->Write8(1, 15 << 4); // G=15
115: gBT454->Write8(1, 15 << 4); // B=15
116:
117: // SCSI
118: // BDID の書き込みによってホストデバイスがバスにアタッチされる構造なので。
119: gSPC->Write8(SPC::BDID, 7);
120:
121: if (gMainApp.host_file) {
122: // ホストのファイルを読み込んでエントリポイントアドレスを
123: // この Read アクセスの読み出し値として返す。
124: entry = gRAM->LoadFile(gMainApp.host_file, AOUT_MID_M88K);
125: }
126:
127: return entry;
128: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.