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