|
|
1.1 root 1: //
2: // nono
1.1.1.2 root 3: // Copyright (C) 2020 nono project
4: // Licensed under nono-license.txt
1.1 root 5: //
6:
1.1.1.12 root 7: //
8: // LUNA シリーズの ROM エミュレーション共通部分
9: //
10:
1.1 root 11: #pragma once
12:
1.1.1.15! root 13: #include "romemu.h"
1.1 root 14:
1.1.1.13 root 15: class BT45xDevice;
1.1.1.15! root 16: class LanceDevice;
1.1.1.13 root 17: class LunafbDevice;
18: class MainRAMDevice;
19: class MK48T02Device;
20: class SIODevice;
21: class SPCDevice;
22:
1.1.1.15! root 23: class LunaPROMEmuDevice : public ROMEmuDevice
1.1 root 24: {
1.1.1.15! root 25: using inherited = ROMEmuDevice;
1.1 root 26:
1.1.1.7 root 27: protected:
1.1 root 28: // このデバイス先頭アドレス
29: static const uint32 baseaddr = 0x41000000;
30:
31: // 謎の I/O 空間
1.1.1.2 root 32: static const uint32 ROMIO_BASE = 0x41010000;
1.1.1.14 root 33: static const uint32 ROMIO_INIT = (ROMIO_BASE + 0x00);
34: static const uint32 ROMIO_LOAD = (ROMIO_BASE + 0x04);
35: static const uint32 ROMIO_KEYIN = (ROMIO_BASE + 0x08);
36: static const uint32 ROMIO_CLOSE = (ROMIO_BASE + 0x0c);
37: static const uint32 ROMIO_ENTRY = (ROMIO_BASE + 0x10);
38: static const uint32 ROMIO_AP1 = (ROMIO_BASE + 0x14);
39: static const uint32 ROMIO_AP2 = (ROMIO_BASE + 0x18);
40: static const uint32 ROMIO_CLKCNT = (ROMIO_BASE + 0x1c);
1.1 root 41:
1.1.1.9 root 42: // 文字コード
43: // 概ね ASCII だが制御コード部分は必要な文字だけを適当に割り当てる。
44: static const char BS = 0x08;
45: static const char LF = 0x0a;
1.1.1.14 root 46: static const char CR = 0x0d;
1.1.1.9 root 47: static const char UP = 0x1c;
48: static const char LEFT = 0x1d;
49: static const char RIGHT = 0x1e;
50: static const char DOWN = 0x1f;
51:
1.1.1.7 root 52: // ブート情報格納用
53: struct bootinfo_t {
54: int dkunit {};
55: int dkpart {};
56: std::string dkfile {};
57: };
58:
1.1 root 59: public:
60: LunaPROMEmuDevice();
1.1.1.14 root 61: ~LunaPROMEmuDevice() override;
1.1 root 62:
1.1.1.2 root 63: bool Init() override;
1.1 root 64:
1.1.1.7 root 65: protected:
1.1.1.15! root 66: uint64 ReadROMIO(busaddr addr) override;
! 67: bool WriteROMIO(busaddr addr, uint32 data) override;
! 68:
! 69: void ROM_Init();
1.1.1.14 root 70: virtual void ROM_InitMD() = 0;
71: uint32 ROM_Load();
72: uint32 ROM_Entry();
1.1.1.7 root 73: virtual void ROM_Close();
1.1.1.14 root 74: void ROM_AP1();
75: void ROM_AP2();
76: virtual uint32 LoadFile(const std::string& fname) = 0;
1.1.1.13 root 77: virtual void ProcessChar(char);
1.1.1.7 root 78: virtual void Command() = 0;
1.1 root 79:
1.1.1.12 root 80: void InitScreen();
1.1.1.14 root 81: void InitPalette();
82: void PrintTitle();
1.1.1.9 root 83: void ClearPrompt();
1.1.1.13 root 84: int Getc();
1.1.1.12 root 85: void Putc(uint ch);
86: void Print(const std::string& s);
87: void Print(const char *fmt, ...) __printflike(2, 3);
1.1.1.9 root 88:
89: // NVRAM
1.1.1.14 root 90: virtual bool InitNVRAM() = 0;
91: virtual void GetNVRAM(bootinfo_t&) = 0;
1.1.1.9 root 92: uint8 CalcNVRAMCsum() const;
93: void WriteNVRAMCsum();
94: bool VerifyNVRAM() const;
95:
1.1 root 96: uint32 LoadHostFile();
1.1.1.7 root 97: uint32 LoadGuestFile(const bootinfo_t&);
1.1.1.2 root 98:
1.1.1.14 root 99: // 読み込んだプログラムのエントリポイント。
100: // エントリポイントがセットされていない時は -1。
101: uint32 entrypoint {};
102:
103: // エントリポイントに実行を移す時には true。
104: // LUNA-I は 'x' コマンドを実行したら。
105: // LUNA-88K では 'b'/'bh' コマンドで。
106: bool execute {};
107:
108: // 機種名 (タイトル表示用)
109: const char *machine_name {};
110:
1.1 root 111: // エラーメッセージの受け渡し用
112: // 基本的にエラーが起きた時だけ更新するので、ここにエラーメッセージを
113: // 返す可能性がある関数をコールする前に呼び出し側が clear() しておき、
114: // 関数から戻ったら empty() かどうか確認する、errno みたいな使い方。
1.1.1.4 root 115: std::string errmsg {};
1.1 root 116:
117: // 入力バッファ
118: std::string inputbuf {};
119:
1.1.1.7 root 120: // 現在のプロンプト文字列
121: std::string prompt {};
1.1 root 122:
1.1.1.11 root 123: // デフォルトプロンプト。
124: const std::string default_prompt = ">";
125:
1.1.1.9 root 126: // プロンプトのある行(最上行が 0)
127: int prompt_y {};
128:
129: // カーソル位置(入力バッファ先頭が0)
130: int inputpos {};
131:
1.1.1.12 root 132: int screen_w {}; // テキスト桁数
133: int screen_h {}; // テキスト行数
134: int cursor_x {}; // カーソル位置(桁)
135: int cursor_y {}; // カーソル位置(行)
1.1.1.14 root 136: bool cursor_on {}; // カーソル表示
137: bool bold {};
1.1.1.12 root 138: int origin_px {}; // テキスト画面の左上 X 座標(ピクセル)
139: int origin_py {}; // テキスト画面の左上 Y 座標(ピクセル)
140:
1.1.1.13 root 141: BT45xDevice *bt45x {};
1.1.1.15! root 142: LanceDevice *lance {};
1.1.1.13 root 143: LunafbDevice *lunafb {};
144: MainRAMDevice *mainram {};
1.1.1.4 root 145: MK48T02Device *nvram {};
1.1.1.13 root 146: SIODevice *sio {};
147: SPCDevice *spc {};
1.1 root 148:
1.1.1.7 root 149: private:
150: // キー入力
151: void ROM_Keyin();
152:
153: bool is_shift {}; // SHIFT キー押し下げ中
154: int mousecnt {}; // マウス入力をスキップするためのカウンタ
155:
1.1.1.14 root 156: uint32 clkcnt {}; // クロック割り込みカウンタ
157:
1.1 root 158: // LUNA キーコード -> ASCII 変換テーブル
159: static const uint8 lunakey2asciitable[128];
160: static const uint8 lunakey2shifttable[128];
161: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.