--- nono/vm/romemu_luna.h 2026/04/29 17:04:55 1.1.1.9 +++ 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: // このデバイス先頭アドレス @@ -44,15 +48,8 @@ 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; @@ -62,9 +59,12 @@ class LunaPROMEmuDevice : public IODevic virtual void Command() = 0; void InitDevice(); - void InitScreen(const char *machine_name); + void InitScreen(); + void PrintTitle(const char *machine_name); void ClearPrompt(); - void ConsoleUpdate(); + void Putc(uint ch); + void Print(const std::string& s); + void Print(const char *fmt, ...) __printflike(2, 3); // NVRAM uint8 CalcNVRAMCsum() const; @@ -74,29 +74,34 @@ class LunaPROMEmuDevice : public IODevic uint32 LoadHostFile(); uint32 LoadGuestFile(const bootinfo_t&); - std::unique_ptr romdata {}; - // エラーメッセージの受け渡し用 // 基本的にエラーが起きた時だけ更新するので、ここにエラーメッセージを // 返す可能性がある関数をコールする前に呼び出し側が clear() しておき、 // 関数から戻ったら empty() かどうか確認する、errno みたいな使い方。 std::string errmsg {}; - // ROM モニタ用コンソール画面 - TextScreen 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 として見えるので @@ -104,11 +109,6 @@ class LunaPROMEmuDevice : public IODevic MK48T02Device *nvram {}; private: - uint64 Decoder(uint32 addr) const; - - // ROM->RAM 切り替え用フラグ。true なら ROM モード - bool isrom {}; - // キー入力 void ROM_Keyin();