--- nono/vm/xiospace.cpp 2026/04/29 17:04:56 1.1.1.8 +++ nono/vm/xiospace.cpp 2026/04/29 17:05:10 1.1.1.10 @@ -4,6 +4,10 @@ // Licensed under nono-license.txt // +// +// X68030 のメイン空間 ($000000-$FFFFFF) 担当 +// + #include "xiospace.h" #include "areaset.h" #include "busio.h" @@ -27,14 +31,10 @@ #include "sysport.h" #include "tvram.h" #include "videoctlr.h" -#include "vm.h" -#include // -// X68030 のメイン空間 ($000000-$FFFFFF) 担当。 -// - // 1つの 8KB ブロックを複数のデバイスで共有する場合 +// class MuxDevice : public IODevice { using inherited = IODevice; @@ -55,11 +55,13 @@ class MuxDevice : public IODevice std::vector devlist; }; +// コンストラクタ MuxDevice::MuxDevice() : inherited("MuxDevice") { } +// デストラクタ MuxDevice::~MuxDevice() { } @@ -69,11 +71,9 @@ MuxDevice::~MuxDevice() void MuxDevice::AddDevice(IODevice *dev) { - if (dev->devlen == 0) { - printf("MuxDevice::AddDevice: '%s' devlen not set!\n", - dev->GetName().c_str()); - exit(1); - } + assertmsg(dev->devlen != 0, "MuxDevice::AddDevice '%s'", + dev->GetName().c_str()); + devlist.push_back(dev); } @@ -139,45 +139,51 @@ MuxDevice::Peek8(uint32 addr) } -std::unique_ptr gXIOSpace; +// +// X68030 のメイン空間担当 +// + +// グローバル参照用 +XIOSpaceDevice *gXIOSpace; // コンストラクタ XIOSpaceDevice::XIOSpaceDevice() : inherited("IOSpace") { -#define ADD_DEVICE(varname, clsname) do { \ - varname.reset(new clsname); \ - AddDevice(varname.get()); \ +#define ADD_DEVICE(NAME, NEW_CTOR) do { \ + NEWDV(NAME, NEW_CTOR); \ + AddDevice(dynamic_cast(__CONCAT(p,NAME).get())); \ } while (0) // デバイスクラス作成 (順序に注意) - ADD_DEVICE(gAreaSet, AreaSetDevice()); - ADD_DEVICE(gCGROM, CGROMDevice()); - ADD_DEVICE(gCRTC, BusIO_W()); - ADD_DEVICE(gDMAC, BusIO_B()); - ADD_DEVICE(gFDC, BusIO_EB()); - ADD_DEVICE(gGVRAM, GVRAMDevice()); - ADD_DEVICE(gPEDEC, BusIO_EB()); - ADD_DEVICE(gIPLROM1, IPLROM1Device()); - ADD_DEVICE(gIPLROM2, IPLROM2Device()); - ADD_DEVICE(gMFP, BusIO_EB()); - ADD_DEVICE(gPluto, PlutoDevice()); - ADD_DEVICE(gPPI, BusIO_EB()); - ADD_DEVICE(gPrinter, PrinterDevice()); - ADD_DEVICE(gRTC, BusIO_EB()); - ADD_DEVICE(gSCC, BusIO_EB()); - ADD_DEVICE(gSRAM, SRAMDevice()); // Required by SPC - ADD_DEVICE(gSPC, BusIO_X68kSPC()); - ADD_DEVICE(gSprite, SpriteDevice()); - ADD_DEVICE(gSysport, BusIO_FB()); - ADD_DEVICE(gTVRAM, TVRAMDevice()); - ADD_DEVICE(gVideoCtlr, BusIO_W()); - ADD_DEVICE(gOPM, BusIO_EB()); + ADD_DEVICE(AreaSet, new AreaSetDevice()); + ADD_DEVICE(CGROM, new CGROMDevice()); + ADD_DEVICE(CRTC, new BusIO_W()); + ADD_DEVICE(DMAC, new BusIO_B()); + ADD_DEVICE(FDC, new BusIO_EB()); + ADD_DEVICE(GVRAM, new GVRAMDevice()); + ADD_DEVICE(PEDEC, new BusIO_EB()); + ADD_DEVICE(IPLROM1, new IPLROM1Device()); + ADD_DEVICE(IPLROM2, new IPLROM2Device()); + ADD_DEVICE(MFP, new BusIO_EB()); + ADD_DEVICE(PlaneVRAM, new TVRAMDevice()); + ADD_DEVICE(Pluto, new PlutoDevice()); + ADD_DEVICE(PPI, new BusIO_EB()); + ADD_DEVICE(Printer, new PrinterDevice()); + ADD_DEVICE(RTC, new BusIO_EB()); + ADD_DEVICE(SCC, new BusIO_EB()); + ADD_DEVICE(SRAM, new SRAMDevice()); // Required by SPC + ADD_DEVICE(SPC, new BusIO_X68kSPC()); + ADD_DEVICE(Sprite, new SpriteDevice()); + ADD_DEVICE(Sysport, new BusIO_FB()); + ADD_DEVICE(VideoCtlr, new BusIO_W()); + ADD_DEVICE(OPM, new BusIO_EB()); } // デストラクタ XIOSpaceDevice::~XIOSpaceDevice() { + gXIOSpace = NULL; } bool @@ -186,21 +192,21 @@ XIOSpaceDevice::Init() // RAM のみ RamDevice::Init() で ram_size が決定してから行う。 int ram_size = gRAM->GetSize(); for (int i = 0; i < ram_size / 8192; i++) { - table[i] = gRAM.get(); + table[i] = gRAM; } // 必要なデバイスは全部埋めたので、この時点で nullptr なエントリを // BusErr に差し替える。 for (auto&& d : table) { if (d == nullptr) { - d = gBusErr.get(); + d = gBusErr; } } // デバッグ表示 if (0) { - for (int i = 0; i < 512; i++) { - printf("[%3d] $%06x ", i, 0xc00000 + i * 8192); + for (int i = 1536; i < table.size(); i++) { + printf("[%3d] $%06x ", i, i * 8192); assert(table[i]); if (dynamic_cast(table[i])) { printf("MuxDevice\n"); @@ -218,16 +224,10 @@ XIOSpaceDevice::Init() void XIOSpaceDevice::AddDevice(IODevice *dev) { - if (dev->devaddr == 0) { - printf("XIOSpaceDevice:AddDevice: '%s' devaddr not set!\n", - dev->GetName().c_str()); - exit(1); - } - if (dev->devlen == 0) { - printf("XIOSpaceDevice:AddDevice: '%s' devlen not set!\n", - dev->GetName().c_str()); - exit(1); - } + assertmsg(dev->devaddr != 0, "XIOSpaceDevice:AddDevice '%s'", + dev->GetName().c_str()); + assertmsg(dev->devlen != 0, "XIOSpaceDevice:AddDevice '%s'", + dev->GetName().c_str()); int idx = dev->devaddr / 8192; for (int i = idx; i < idx + (dev->devlen + 8191) / 8192; i++) { @@ -314,13 +314,13 @@ XIOSpaceDevice::SwitchBootPage(bool isro if (isrom) { // 0x000000 からの 64KB ( 8エントリ)、 // 0xfe0000 からの 128KB (16エントリ) のどちらも IPLROM0 が担当する。 - ram = gIPLROM0.get(); - rom = ram; + ram = gIPLROM0; + rom = gIPLROM0; } else { // 0x000000 からの 64KB ( 8エントリ) に RAM を見せる。 // 0xfe0000 からの 128KB (16エントリ) に IPLROM1 を見せる。 - ram = gRAM.get(); - rom = gIPLROM1.get(); + ram = gRAM; + rom = gIPLROM1; } for (int i = 0; i < 8; i++) {