--- nono/vm/xiospace.cpp 2026/04/29 17:04:42 1.1.1.4 +++ 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" @@ -11,8 +15,9 @@ #include "dmac.h" #include "fdc.h" #include "gvram.h" -#include "ioctlr.h" #include "mfp.h" +#include "opm.h" +#include "pedec.h" #include "pio.h" #include "pluto.h" #include "printer.h" @@ -26,36 +31,22 @@ #include "sysport.h" #include "tvram.h" #include "videoctlr.h" -#include "vm.h" -#include // -// X68030 のメイン空間 ($000000-$FFFFFF) 担当。 -// - -// デバイス -static std::unique_ptr areaset; -static std::unique_ptr fdc; -static std::unique_ptr pluto; -static std::unique_ptr ppi; -static std::unique_ptr printer; -static std::unique_ptr sprite; -static std::unique_ptr sysport; - // 1つの 8KB ブロックを複数のデバイスで共有する場合 -class MuxDevice - : public IODevice +// +class MuxDevice : public IODevice { using inherited = IODevice; public: MuxDevice(); - virtual ~MuxDevice(); + virtual ~MuxDevice() override; - virtual uint64 Read8(uint32 addr); - virtual uint64 Read16(uint32 addr); - virtual uint64 Write8(uint32 addr, uint32 data); - virtual uint64 Write16(uint32 addr, uint32 data); - virtual uint64 Peek8(uint32 addr); + uint64 Read8(uint32 addr) override; + uint64 Read16(uint32 addr) override; + uint64 Write8(uint32 addr, uint32 data) override; + uint64 Write16(uint32 addr, uint32 data) override; + uint64 Peek8(uint32 addr) override; IODevice *SearchDevice(uint32 addr) const; @@ -64,11 +55,13 @@ class MuxDevice std::vector devlist; }; +// コンストラクタ MuxDevice::MuxDevice() + : inherited("MuxDevice") { - logname = "none"; } +// デストラクタ MuxDevice::~MuxDevice() { } @@ -78,11 +71,9 @@ MuxDevice::~MuxDevice() void MuxDevice::AddDevice(IODevice *dev) { - if (dev->devlen == 0) { - printf("MuxDevice::AddDevice: '%s' devlen not set!\n", - dev->devname.c_str()); - exit(1); - } + assertmsg(dev->devlen != 0, "MuxDevice::AddDevice '%s'", + dev->GetName().c_str()); + devlist.push_back(dev); } @@ -148,72 +139,79 @@ MuxDevice::Peek8(uint32 addr) } +// +// X68030 のメイン空間担当 +// + +// グローバル参照用 +XIOSpaceDevice *gXIOSpace; + // コンストラクタ XIOSpaceDevice::XIOSpaceDevice() + : inherited("IOSpace") { - logname = "xiospace"; - devname = "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(areaset, AreaSetDevice()); - ADD_DEVICE(gCGROM, CGROMDevice()); - ADD_DEVICE(gCRTC, BusIO_W()); - ADD_DEVICE(gDMAC, BusIO_B()); - ADD_DEVICE(fdc, BusIO_EB()); - ADD_DEVICE(gGVRAM, GVRAMDevice()); - ADD_DEVICE(gIOCtlr, BusIO_EB()); - ADD_DEVICE(gIPLROM1, IPLROM1Device()); - ADD_DEVICE(gIPLROM2, IPLROM2Device()); - ADD_DEVICE(gMFP, BusIO_EB()); - ADD_DEVICE(pluto, PlutoDevice()); - ADD_DEVICE(ppi, BusIO_EB()); - ADD_DEVICE(printer, 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(sprite, SpriteDevice()); - ADD_DEVICE(sysport, BusIO_FB()); - ADD_DEVICE(gTVRAM, TVRAMDevice()); - ADD_DEVICE(gVideoCtlr, BusIO_W()); + 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 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 に差し替える。 - IODevice *buserr = gVM->GetBusErrDevice(); + // BusErr に差し替える。 for (auto&& d : table) { if (d == nullptr) { - d = buserr; + 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"); } else { - printf("%s\n", table[i]->devname.c_str()); + printf("%s\n", table[i]->GetName().c_str()); } } } @@ -226,16 +224,10 @@ XIOSpaceDevice::Init() void XIOSpaceDevice::AddDevice(IODevice *dev) { - if (dev->devaddr == 0) { - printf("XIOSpaceDevice:AddDevice: '%s' devaddr not set!\n", - dev->devname.c_str()); - exit(1); - } - if (dev->devlen == 0) { - printf("XIOSpaceDevice:AddDevice: '%s' devlen not set!\n", - dev->devname.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++) { @@ -310,3 +302,31 @@ XIOSpaceDevice::Peek8(uint32 addr) IODevice *d = SearchDevice(addr); return d->Peek8(addr); } + +// ブートページを切り替える。 +// (VM_X68030::SwitchBootPage() の下請け) +void +XIOSpaceDevice::SwitchBootPage(bool isrom) +{ + IODevice *ram; + IODevice *rom; + + if (isrom) { + // 0x000000 からの 64KB ( 8エントリ)、 + // 0xfe0000 からの 128KB (16エントリ) のどちらも IPLROM0 が担当する。 + ram = gIPLROM0; + rom = gIPLROM0; + } else { + // 0x000000 からの 64KB ( 8エントリ) に RAM を見せる。 + // 0xfe0000 からの 128KB (16エントリ) に IPLROM1 を見せる。 + ram = gRAM; + rom = gIPLROM1; + } + + for (int i = 0; i < 8; i++) { + table[i] = ram; + } + for (int i = 0; i < 16; i++) { + table[table.size() - 16 + i] = rom; + } +}