--- nono/vm/xiospace.cpp 2026/04/29 17:04:28 1.1.1.1 +++ nono/vm/xiospace.cpp 2026/04/29 17:04:36 1.1.1.3 @@ -1,20 +1,23 @@ // // nono -// Copyright (C) 2018 isaki@NetBSD.org +// Copyright (C) 2020 nono project +// Licensed under nono-license.txt // -#include +#include "xiospace.h" #include "areaset.h" +#include "busio.h" #include "crtc.h" #include "dmac.h" #include "fdc.h" #include "gvram.h" -#include "iocon.h" +#include "ioctlr.h" #include "mfp.h" +#include "pio.h" #include "pluto.h" -#include "ppi.h" #include "printer.h" #include "ram.h" +#include "romimg_x68k.h" #include "rp5c15.h" #include "scc.h" #include "spc.h" @@ -22,35 +25,31 @@ #include "sram.h" #include "sysport.h" #include "tvram.h" -#include "vicon.h" +#include "videoctlr.h" #include "vm.h" -#include "x68krom.h" -#include "xiospace.h" +#include // // X68030 のメイン空間 ($000000-$FFFFFF) 担当。 // // デバイス -AreaSetDevice *areaset; -CGROMDevice *cgrom; -CRTCDevice *crtc; -DMACDevice *dmac; -FDCDevice *fdc; -IPLROM1Device *iplrom1; -IPLROM2Device *iplrom2; -PlutoDevice *pluto; -PPIDevice *ppi; -PrinterDevice *printer; -SCCDevice *scc; -SpriteDevice *sprite; -SysportDevice *sysport; +static std::unique_ptr areaset; +static std::unique_ptr cgrom; +static std::unique_ptr fdc; +static std::unique_ptr iplrom1; +static std::unique_ptr iplrom2; +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 { - typedef IODevice inherited; + using inherited = IODevice; public: MuxDevice(); virtual ~MuxDevice(); @@ -61,7 +60,7 @@ class MuxDevice virtual uint64 Write16(uint32 addr, uint32 data); virtual uint64 Peek8(uint32 addr); - IODevice *SearchDevice(uint32 addr); + IODevice *SearchDevice(uint32 addr) const; void AddDevice(IODevice *dev); @@ -77,20 +76,21 @@ MuxDevice::~MuxDevice() { } -// デバイスを追加します。 -// ここに追加するデバイスは dev->devlen の指定が必須です。 +// デバイスを追加する。 +// ここに追加するデバイスは dev->devlen を指定すること。 void MuxDevice::AddDevice(IODevice *dev) { if (dev->devlen == 0) { - printf("MuxDevice::AddDevice: '%s' devlen not set!\n", dev->devname); + printf("MuxDevice::AddDevice: '%s' devlen not set!\n", + dev->devname.c_str()); exit(1); } devlist.push_back(dev); } IODevice * -MuxDevice::SearchDevice(uint32 addr) +MuxDevice::SearchDevice(uint32 addr) const { for (const auto& d : devlist) { if (d->devaddr <= addr && addr < d->devaddr + d->devlen) { @@ -162,36 +162,36 @@ XIOSpaceDevice::XIOSpaceDevice() // 場合や上位8ビットに値が入っていて 24bit にミラーされたアドレスへの // アクセスになる場合はここを通る。 for (int i = 0; i < ram_size / 8192; i++) { - table[i] = gRAM; + table[i] = gRAM.get(); } #define ADD_DEVICE(varname, clsname) do { \ - varname = new clsname; \ - AddDevice(static_cast(varname)); \ + varname.reset(new clsname); \ + AddDevice(varname.get()); \ } while (0) // デバイスクラス作成 (順序に注意) ADD_DEVICE(areaset, AreaSetDevice()); ADD_DEVICE(cgrom, CGROMDevice()); - ADD_DEVICE(crtc, CRTCDevice()); - ADD_DEVICE(dmac, DMACDevice()); - ADD_DEVICE(fdc, FDCDevice()); + ADD_DEVICE(gCRTC, BusIO_W()); + ADD_DEVICE(gDMAC, BusIO_B()); + ADD_DEVICE(fdc, BusIO_EB()); ADD_DEVICE(gGVRAM, GVRAMDevice()); - ADD_DEVICE(gIOCon, IOConDevice()); + ADD_DEVICE(gIOCtlr, BusIO_EB()); ADD_DEVICE(iplrom1, IPLROM1Device()); ADD_DEVICE(iplrom2, IPLROM2Device()); - ADD_DEVICE(gMFP, MFPDevice()); + ADD_DEVICE(gMFP, BusIO_EB()); ADD_DEVICE(pluto, PlutoDevice()); - ADD_DEVICE(ppi, PPIDevice()); + ADD_DEVICE(ppi, BusIO_EB()); ADD_DEVICE(printer, PrinterDevice()); - ADD_DEVICE(gRTC, RP5C15Device()); - ADD_DEVICE(scc, SCCDevice()); - ADD_DEVICE(gSPC, SPCDevice(0xe96000)); + ADD_DEVICE(gRTC, BusIO_EB()); + ADD_DEVICE(gSCC, BusIO_EB()); + ADD_DEVICE(gSPC, BusIO_X68kSPC()); ADD_DEVICE(sprite, SpriteDevice()); ADD_DEVICE(gSRAM, SRAMDevice()); - ADD_DEVICE(sysport, SysportDevice()); + ADD_DEVICE(sysport, BusIO_FB()); ADD_DEVICE(gTVRAM, TVRAMDevice()); - ADD_DEVICE(gVicon, ViconDevice()); + ADD_DEVICE(gVideoCtlr, BusIO_W()); // デバッグ表示 if (0) { @@ -202,7 +202,7 @@ XIOSpaceDevice::XIOSpaceDevice() } else if (dynamic_cast(table[i])) { printf("MuxDevice\n"); } else if (dynamic_cast(table[i])) { - printf("%s\n", table[i]->devname); + printf("%s\n", table[i]->devname.c_str()); } } } @@ -214,16 +214,18 @@ XIOSpaceDevice::~XIOSpaceDevice() } // デバイステーブルに dev を追加する。 -// ここに追加するデバイスは dev->devlen の指定が必須です。 +// ここに追加するデバイスは dev->devlen を指定すること。 void XIOSpaceDevice::AddDevice(IODevice *dev) { if (dev->devaddr == 0) { - printf("XIOSpaceDevice:AddDevice: '%s' devaddr not set!\n", dev->devname); + 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); + printf("XIOSpaceDevice:AddDevice: '%s' devlen not set!\n", + dev->devname.c_str()); exit(1); }