--- nono/vm/scsidev.h 2026/04/29 17:04:59 1.1.1.10 +++ nono/vm/scsidev.h 2026/04/29 17:05:25 1.1.1.16 @@ -4,13 +4,9 @@ // Licensed under nono-license.txt // -// SCSI デバイス共通部分 - -#pragma once - -#include "diskimage.h" -#include "scsibus.h" -#include "scsicmd.h" +// +// SCSI デバイス +// // IODevice (SPCDevice の親になるため) // | @@ -24,6 +20,14 @@ // v v // SPCDevice SCSIDisk (各デバイス、各ターゲット固有部分) +#pragma once + +#include "diskimage.h" +#include "message.h" +#include "monitor.h" +#include "scsibus.h" +#include "scsicmd.h" + // // SCSI デバイスとしての共通部分。 // これ自体は IODevice ではないが SCSI ホストアダプタがこれを継承するため。 @@ -32,8 +36,8 @@ class SCSIDevice : public IODevice { using inherited = IODevice; public: - SCSIDevice(const std::string& objname_); - virtual ~SCSIDevice() override; + SCSIDevice(int objid_); + ~SCSIDevice() override; // バスに接続 (SCSIBus::Attach から呼ばれる) void Attach(SCSIBus *bus_, int id) { @@ -125,8 +129,8 @@ class SCSIHostDevice : public SCSIDevice { using inherited = SCSIDevice; public: - SCSIHostDevice(const std::string& objname_); - virtual ~SCSIHostDevice() override; + SCSIHostDevice(int objid_); + ~SCSIHostDevice() override; bool Create() override; bool Init() override; @@ -146,7 +150,7 @@ class SCSIHostDevice : public SCSIDevice } // SCSIBus を取得 (UI からインジケータ表示用) - std::shared_ptr GetSCSIBus() const { return scsibus; } + SCSIBus *GetSCSIBus() const { return scsibus.get(); } protected: DECLARE_MONITOR_CALLBACK(MonitorUpdateDevs); @@ -184,7 +188,7 @@ class SCSIHostDevice : public SCSIDevice // ID0 ||<----> bus |<----------+ // || +----------+ own // - std::shared_ptr scsibus {}; + std::unique_ptr scsibus {}; std::unique_ptr target[8] {}; // 接続中のデバイス(イニシエータ含む)を ID 順に並べたリスト (モニタ用) @@ -201,10 +205,10 @@ class SCSITarget : public SCSIDevice { using inherited = SCSIDevice; public: - SCSITarget(const std::string& objname_, SCSIHostDevice *h, int id); - virtual ~SCSITarget() override; + SCSITarget(SCSIHostDevice *h, int id); + ~SCSITarget() override; - bool PowerOn() override; + void ResetHard(bool poweron) override; // Inquiry データを返す (Cmd から呼ばれる) virtual bool Inquiry(std::vector& buf, int lun) = 0; @@ -212,6 +216,9 @@ class SCSITarget : public SCSIDevice // 現在のコマンド列を返す (モニタ用) std::vector GetCmdSeq() const { return cmdseq; } + // コマンドを選択する (ROM30 エミュレーション用) + SCSICmd *SelectCommand(const std::vector& cmdseq_); + // 論理ブロック長 uint32 GetBlocksize() const { return blocksize; } void SetBlocksize(uint32 val) { blocksize = val; } @@ -247,19 +254,20 @@ class SCSITarget : public SCSIDevice void TransferAckCB() override; protected: + // SCSI コマンドのディスパッチャ + virtual void DispatchCmd(); + // ホスト SCSIHostDevice *host {}; // コマンド std::vector cmdseq {}; + // このコマンドの長さ。 // cmdseq の1バイト目で決まるやつのことで、受信目標バイト数。 // 今何バイト受信しているかは cmdseq.size()。 int cmdlen {}; - // SCSI コマンドのディスパッチャ - virtual void DispatchCmd(); - // 現在実行中の SCSI コマンド std::unique_ptr cmd {}; @@ -297,10 +305,10 @@ class SCSIDisk : public SCSITarget public: SCSIDisk(SCSIHostDevice *h, int id, SCSI::DevType type); - virtual ~SCSIDisk() override; + ~SCSIDisk() override; bool Init() override; - bool PowerOn() override; + void ResetHard(bool poweron) override; void DispatchCmd() override; bool Inquiry(std::vector& buf, int lun) override; @@ -339,6 +347,8 @@ class SCSIDisk : public SCSITarget // メディアの書き込みモードを返す RW GetWriteMode() const { return write_mode; } + // メディアの書き込みモードを文字列で返す (モニタ用) + const char *GetWriteModeStr() const; // メディア(ディスク)イメージを開く/閉じる。(同一スレッドから呼ぶこと) bool LoadDisk(const std::string& path_); @@ -372,8 +382,8 @@ class SCSIDisk : public SCSITarget void MediaChanged() const; // メディア挿入/排出コールバック - void LoadCallback(Event&); - void UnloadCallback(Event&); + void LoadMessage(MessageID, uint32); + void UnloadMessage(MessageID, uint32); // イメージファイルのフルパス std::string pathname {}; @@ -381,7 +391,7 @@ class SCSIDisk : public SCSITarget std::string new_pathname {}; // イメージファイル - std::unique_ptr image {}; + DiskImage image {}; bool removable_device {}; // リムーバブルデバイスなら true bool writeable_device {}; // 書き込み可能なデバイスなら true @@ -396,8 +406,4 @@ class SCSIDisk : public SCSITarget bool medium_removal_prevented {}; uint64 seektime {}; - - // UI からの指示を受け取るイベント - // (リムーバブルデバイスでのみ作成するので、ポインタ) - Event *event {}; };