--- nono/vm/romemu_luna.h 2026/04/29 17:04:53 1.1.1.8 +++ nono/vm/romemu_luna.h 2026/04/29 17:05:10 1.1.1.12 @@ -4,13 +4,17 @@ // Licensed under nono-license.txt // +// +// LUNA シリーズの ROM エミュレーション共通部分 +// + #pragma once -#include "device.h" +#include "rom.h" -class LunaPROMEmuDevice : public IODevice +class LunaPROMEmuDevice : public ROMDevice { - using inherited = IODevice; + using inherited = ROMDevice; protected: // このデバイス先頭アドレス @@ -23,6 +27,15 @@ class LunaPROMEmuDevice : public IODevic static const uint32 ROMIO_CLOSE = (ROMIO_BASE + 8); static const uint32 ROMIO_ENTRY = (ROMIO_BASE + 12); + // 文字コード + // 概ね ASCII だが制御コード部分は必要な文字だけを適当に割り当てる。 + static const char BS = 0x08; + static const char LF = 0x0a; + static const char UP = 0x1c; + static const char LEFT = 0x1d; + static const char RIGHT = 0x1e; + static const char DOWN = 0x1f; + // ブート情報格納用 struct bootinfo_t { int dkunit {}; @@ -35,32 +48,31 @@ class LunaPROMEmuDevice : public IODevic virtual ~LunaPROMEmuDevice() override; bool Init() override; - void ResetHard() override; - uint64 Read8(uint32 addr) override; - uint64 Read16(uint32 addr) override; uint64 Read32(uint32 addr) override; - uint64 Write8(uint32 addr, uint32 data) override; - uint64 Write16(uint32 addr, uint32 data) override; - uint64 Write32(uint32 addr, uint32 data) override; - uint64 Peek8(uint32 addr) override; protected: virtual uint32 ROM_Init() = 0; virtual uint32 ROM_Entry() = 0; virtual void ROM_Close(); + virtual void GetChar(char); virtual void Command() = 0; void InitDevice(); - void InitScreen(const char *machine_name); - void ConsoleUpdate(); - uint32 LoadHostFile(); - uint32 LoadGuestFile(const bootinfo_t&); + void InitScreen(); + void PrintTitle(const char *machine_name); + void ClearPrompt(); + void Putc(uint ch); + void Print(const std::string& s); + void Print(const char *fmt, ...) __printflike(2, 3); - std::unique_ptr romdata {}; + // NVRAM + uint8 CalcNVRAMCsum() const; + void WriteNVRAMCsum(); + bool VerifyNVRAM() const; - // 内蔵 ROM 使用後はアクセスできないようにするため - bool is_closed {}; + uint32 LoadHostFile(); + uint32 LoadGuestFile(const bootinfo_t&); // エラーメッセージの受け渡し用 // 基本的にエラーが起きた時だけ更新するので、ここにエラーメッセージを @@ -68,15 +80,28 @@ class LunaPROMEmuDevice : public IODevic // 関数から戻ったら empty() かどうか確認する、errno みたいな使い方。 std::string errmsg {}; - // ROM モニタ用コンソール画面 - TextConsole text {}; - // 入力バッファ std::string inputbuf {}; // 現在のプロンプト文字列 std::string prompt {}; + // デフォルトプロンプト。 + const std::string default_prompt = ">"; + + // プロンプトのある行(最上行が 0) + int prompt_y {}; + + // カーソル位置(入力バッファ先頭が0) + int inputpos {}; + + int screen_w {}; // テキスト桁数 + int screen_h {}; // テキスト行数 + int cursor_x {}; // カーソル位置(桁) + int cursor_y {}; // カーソル位置(行) + int origin_px {}; // テキスト画面の左上 X 座標(ピクセル) + int origin_py {}; // テキスト画面の左上 Y 座標(ピクセル) + // NVRAM // 本来他デバイスはすべてグローバル参照できるのだが、LUNA の NVRAM は // RTC と兼用になっていて、RTCDevice *gRTC として見えるので @@ -84,15 +109,9 @@ class LunaPROMEmuDevice : public IODevic MK48T02Device *nvram {}; private: - uint64 Decoder(uint32 addr) const; - - // ROM->RAM 切り替え用フラグ。true なら ROM モード - bool isrom {}; - // キー入力 void ROM_Keyin(); - int inputpos {}; // カーソル位置 bool is_shift {}; // SHIFT キー押し下げ中 int mousecnt {}; // マウス入力をスキップするためのカウンタ