--- nono/vm/romemu_x68k.cpp 2026/04/29 17:05:14 1.1 +++ nono/vm/romemu_x68k.cpp 2026/04/29 17:05:17 1.1.1.2 @@ -9,11 +9,10 @@ // #include "romemu_x68k.h" -#include "bus.h" +#include "mainbus.h" +#include "mainram.h" #include "memorystream.h" -#include "m68030core.h" #include "mpu680x0.h" -#include "ram.h" #include "romimg_x68k.h" #include "scsidev.h" #include "spc.h" @@ -21,10 +20,9 @@ // コンストラクタ ROM30EmuDevice::ROM30EmuDevice() - : inherited("IPLROM2") + : inherited(OBJ_IPLROM2) { - devaddr = baseaddr; - devlen = 0x020000; + uint devlen = 0x020000; mask = devlen - 1; imagebuf.reset(new uint8 [devlen]); @@ -35,18 +33,18 @@ ROM30EmuDevice::ROM30EmuDevice() // デストラクタ ROM30EmuDevice::~ROM30EmuDevice() { - gIPLROM2 = NULL; } +// 初期化 bool ROM30EmuDevice::Init() { - // 親クラス if (inherited::Init() == false) { return false; } - cpu = gMPU680x0->GetCPU(); + mainbus = GetMainbusDevice(); + spc = GetSPCDevice(); MemoryStreamBE ms(imagebuf.get()); // fc0000.L 〜 fc001c.L: SCSI ブートアドレス @@ -102,7 +100,7 @@ uint64 ROM30EmuDevice::Read32(uint32 addr) { // IPLROM2 領域からのロングワードアクセスでだけ謎の I/O 空間が見える。 - if ((gMPU->GetPaddr() & 0xfffe0000) == baseaddr) { + if ((mpu->GetPaddr() & 0xfffe0000) == baseaddr) { switch (addr) { case ROMIO_SCSI: return SCSIIOCS(); @@ -123,15 +121,21 @@ ROM30EmuDevice::Read32(uint32 addr) uint32 ROM30EmuDevice::SCSIBoot() const { + auto mainram = GetMainRAMDevice(); + auto sram = GetSRAMDevice(); + + auto mpu680x0 = dynamic_cast(mpu); + m68kreg& reg = mpu680x0->reg; + // SRAM の ROM 起動アドレスから SCSI ID を取得。 - uint32 romaddr = gSRAM->GetROMAddr(); + uint32 romaddr = sram->GetROMAddr(); if ((romaddr & 0xffff00) != 0xfc0000) { return 0; } int id = (romaddr & 0x1f) >> 2; // ターゲットディスク - SCSITarget *target = gSPC->GetTarget(id); + SCSITarget *target = spc->GetTarget(id); if (target == NULL) { putlog(1, "%s: SCSI ID %d not found", __func__, id); return 0; @@ -183,15 +187,15 @@ ROM30EmuDevice::SCSIBoot() const } // メモリの 0x2000 番地に置く for (int i = 0; i < blocksize; i++) { - gRAM->Write8(0x2000 + i, block[i]); + mainram->Write8(0x2000 + i, block[i]); } // D4 にはこの時の SCSI ID が置いてある(のが見えている) - RegD(4) = id; + reg.D[4] = id; // XXX D2 は最後に _S_READ を発行した LBA を指しているようだ。 // なので +1 ブロックの LBA になる。 - RegD(2) = blocksize / sectsize; + reg.D[2] = blocksize / sectsize; // 成功したのでジャンプ先アドレスを返す putlog(1, "%s succeeded", __func__); @@ -202,8 +206,10 @@ ROM30EmuDevice::SCSIBoot() const uint32 ROM30EmuDevice::SCSIIOCS() { - uint32 scsicall = RegD(1); + auto mpu680x0 = dynamic_cast(mpu); + m68kreg& reg = mpu680x0->reg; + uint32 scsicall = reg.D[1]; switch (scsicall) { case 0x20: // _S_INQUIRY return SCSI_S_INQUIRY(scsicall); @@ -228,12 +234,14 @@ ROM30EmuDevice::SCSIIOCS() } #define PRE \ - uint32 d4 = RegD(4); \ + auto mpu680x0 = dynamic_cast(mpu); \ + m68kreg& reg = mpu680x0->reg; \ + uint32 d4 = reg.D[4]; \ uint32 id = d4 & 0x0000ffff; \ uint32 lun = (d4 >> 16) & 0x0000ffff; \ std::string scsiname = GetSCSICallName(scsicall); \ /* ターゲットディスク */ \ - SCSITarget *target = gSPC->GetTarget(id); \ + SCSITarget *target = spc->GetTarget(id); \ if (target == NULL) { \ putlog(1, "%s ID%d not found", scsiname.c_str(), id); \ return -1; \ @@ -254,8 +262,8 @@ ROM30EmuDevice::SCSI_S_INQUIRY(uint32 sc { PRE; - uint32 a1 = RegA(1); - uint32 reqlen = RegD(3); + uint32 a1 = reg.A[1]; + uint32 reqlen = reg.D[3]; putlog(1, "%s a1=$%06x", loghdr.c_str(), a1); std::vector cmdseq(6); cmdseq[0] = SCSI::Command::Inquiry; @@ -274,7 +282,7 @@ ROM30EmuDevice::SCSI_S_INQUIRY(uint32 sc // アロケーションサイズ(reqlen)と結果(cmd->buf)の小さい方まで転送 int len = std::min((int)reqlen, (int)res.size()); for (int i = 0; i < len; i++) { - int64 r = vm_phys_write_8(a1++, res[i]); + int64 r = mainbus->Write8(a1++, res[i]); if (r < 0) { return -1; } @@ -287,10 +295,10 @@ ROM30EmuDevice::SCSI_S_READEXT(uint32 sc { PRE; - uint32 a1 = RegA(1); - uint32 lba = RegD(2); - uint32 blkcount = RegD(3); - uint32 blkshift = RegD(5); + uint32 a1 = reg.A[1]; + uint32 lba = reg.D[2]; + uint32 blkcount = reg.D[3]; + uint32 blkshift = reg.D[5]; uint32 blkbytes = 0x100 << blkshift; uint32 bytes = blkcount * blkbytes; @@ -329,7 +337,7 @@ ROM30EmuDevice::SCSI_S_READEXT(uint32 sc } for (int i = 0; i < bytes; i++) { - int64 r = vm_phys_write_8(a1++, res[i]); + int64 r = mainbus->Write8(a1++, res[i]); if (r < 0) { return -1; } @@ -351,7 +359,7 @@ ROM30EmuDevice::SCSI_S_READCAP(uint32 sc { PRE; - uint32 a1 = RegA(1); + uint32 a1 = reg.A[1]; putlog(1, "%s a1=$%06x", loghdr.c_str(), a1); std::vector cmdseq(10); cmdseq[0] = SCSI::Command::ReadCapacity; @@ -368,7 +376,7 @@ ROM30EmuDevice::SCSI_S_READCAP(uint32 sc const std::vector& res = cmd->buf; assert(res.size() == 8); for (auto data : res) { - int64 r = vm_phys_write_8(a1++, data); + int64 r = mainbus->Write8(a1++, data); if (r < 0) { return -1; }