Annotation of nono/vm/xiospace.cpp, revision 1.1.1.8

1.1       root        1: //
                      2: // nono
1.1.1.3   root        3: // Copyright (C) 2020 nono project
                      4: // Licensed under nono-license.txt
1.1       root        5: //
                      6: 
1.1.1.3   root        7: #include "xiospace.h"
1.1       root        8: #include "areaset.h"
1.1.1.2   root        9: #include "busio.h"
1.1       root       10: #include "crtc.h"
                     11: #include "dmac.h"
                     12: #include "fdc.h"
                     13: #include "gvram.h"
                     14: #include "mfp.h"
1.1.1.5   root       15: #include "opm.h"
                     16: #include "pedec.h"
1.1.1.2   root       17: #include "pio.h"
1.1.1.3   root       18: #include "pluto.h"
1.1       root       19: #include "printer.h"
                     20: #include "ram.h"
1.1.1.2   root       21: #include "romimg_x68k.h"
1.1       root       22: #include "rp5c15.h"
                     23: #include "scc.h"
                     24: #include "spc.h"
                     25: #include "sprite.h"
                     26: #include "sram.h"
                     27: #include "sysport.h"
                     28: #include "tvram.h"
1.1.1.3   root       29: #include "videoctlr.h"
1.1       root       30: #include "vm.h"
1.1.1.3   root       31: #include <typeinfo>
1.1       root       32: 
                     33: //
                     34: // X68030 のメイン空間 ($000000-$FFFFFF) 担当。
                     35: //
                     36: 
                     37: // 1つの 8KB ブロックを複数のデバイスで共有する場合
1.1.1.8 ! root       38: class MuxDevice : public IODevice
1.1       root       39: {
1.1.1.3   root       40:        using inherited = IODevice;
1.1       root       41:  public:
                     42:        MuxDevice();
1.1.1.5   root       43:        virtual ~MuxDevice() override;
1.1       root       44: 
1.1.1.5   root       45:        uint64 Read8(uint32 addr) override;
                     46:        uint64 Read16(uint32 addr) override;
                     47:        uint64 Write8(uint32 addr, uint32 data) override;
                     48:        uint64 Write16(uint32 addr, uint32 data) override;
                     49:        uint64 Peek8(uint32 addr) override;
1.1       root       50: 
1.1.1.2   root       51:        IODevice *SearchDevice(uint32 addr) const;
1.1       root       52: 
                     53:        void AddDevice(IODevice *dev);
                     54: 
                     55:        std::vector<IODevice*> devlist;
                     56: };
                     57: 
                     58: MuxDevice::MuxDevice()
1.1.1.8 ! root       59:        : inherited("MuxDevice")
1.1       root       60: {
                     61: }
                     62: 
                     63: MuxDevice::~MuxDevice()
                     64: {
                     65: }
                     66: 
1.1.1.3   root       67: // デバイスを追加する。
                     68: // ここに追加するデバイスは dev->devlen を指定すること。
1.1       root       69: void
                     70: MuxDevice::AddDevice(IODevice *dev)
                     71: {
                     72:        if (dev->devlen == 0) {
1.1.1.3   root       73:                printf("MuxDevice::AddDevice: '%s' devlen not set!\n",
1.1.1.8 ! root       74:                        dev->GetName().c_str());
1.1       root       75:                exit(1);
                     76:        }
                     77:        devlist.push_back(dev);
                     78: }
                     79: 
                     80: IODevice *
1.1.1.2   root       81: MuxDevice::SearchDevice(uint32 addr) const
1.1       root       82: {
                     83:        for (const auto& d : devlist) {
                     84:                if (d->devaddr <= addr && addr < d->devaddr + d->devlen) {
                     85:                        return d;
                     86:                }
                     87:        }
                     88:        return nullptr;
                     89: }
                     90: 
                     91: uint64
                     92: MuxDevice::Read8(uint32 addr)
                     93: {
                     94:        IODevice *d = SearchDevice(addr);
                     95:        if (d == nullptr) {
                     96:                return (uint64)-1;
                     97:        }
                     98:        return d->Read8(addr);
                     99: }
                    100: 
                    101: uint64
                    102: MuxDevice::Read16(uint32 addr)
                    103: {
                    104:        IODevice *d = SearchDevice(addr);
                    105:        if (d == nullptr) {
                    106:                return (uint64)-1;
                    107:        }
                    108:        return d->Read16(addr);
                    109: }
                    110: 
                    111: uint64
                    112: MuxDevice::Write8(uint32 addr, uint32 data)
                    113: {
                    114:        IODevice *d = SearchDevice(addr);
                    115:        if (d == nullptr) {
                    116:                return (uint64)-1;
                    117:        }
                    118:        return d->Write8(addr, data);
                    119: }
                    120: 
                    121: uint64
                    122: MuxDevice::Write16(uint32 addr, uint32 data)
                    123: {
                    124:        IODevice *d = SearchDevice(addr);
                    125:        if (d == nullptr) {
                    126:                return (uint64)-1;
                    127:        }
                    128:        return d->Write16(addr, data);
                    129: }
                    130: 
                    131: uint64
                    132: MuxDevice::Peek8(uint32 addr)
                    133: {
                    134:        IODevice *d = SearchDevice(addr);
                    135:        if (d == nullptr) {
                    136:                return (uint64)-1;
                    137:        }
                    138:        return d->Peek8(addr);
                    139: }
                    140: 
                    141: 
1.1.1.6   root      142: std::unique_ptr<XIOSpaceDevice> gXIOSpace;
                    143: 
1.1       root      144: // コンストラクタ
                    145: XIOSpaceDevice::XIOSpaceDevice()
1.1.1.8 ! root      146:        : inherited("IOSpace")
1.1       root      147: {
                    148: #define ADD_DEVICE(varname, clsname)   do {    \
1.1.1.2   root      149:        varname.reset(new clsname);     \
                    150:        AddDevice(varname.get());       \
1.1       root      151: } while (0)
                    152: 
                    153:        // デバイスクラス作成 (順序に注意)
1.1.1.6   root      154:        ADD_DEVICE(gAreaSet, AreaSetDevice());
1.1.1.4   root      155:        ADD_DEVICE(gCGROM, CGROMDevice());
1.1.1.3   root      156:        ADD_DEVICE(gCRTC, BusIO_W<CRTCDevice>());
                    157:        ADD_DEVICE(gDMAC, BusIO_B<DMACDevice>());
1.1.1.5   root      158:        ADD_DEVICE(gFDC, BusIO_EB<FDCDevice>());
1.1       root      159:        ADD_DEVICE(gGVRAM, GVRAMDevice());
1.1.1.5   root      160:        ADD_DEVICE(gPEDEC, BusIO_EB<PEDECDevice>());
1.1.1.4   root      161:        ADD_DEVICE(gIPLROM1, IPLROM1Device());
                    162:        ADD_DEVICE(gIPLROM2, IPLROM2Device());
1.1.1.3   root      163:        ADD_DEVICE(gMFP, BusIO_EB<MFPDevice>());
1.1.1.6   root      164:        ADD_DEVICE(gPluto, PlutoDevice());
                    165:        ADD_DEVICE(gPPI, BusIO_EB<PPIDevice>());
                    166:        ADD_DEVICE(gPrinter, PrinterDevice());
1.1.1.3   root      167:        ADD_DEVICE(gRTC, BusIO_EB<RP5C15Device>());
                    168:        ADD_DEVICE(gSCC, BusIO_EB<SCCDevice>());
1.1.1.4   root      169:        ADD_DEVICE(gSRAM, SRAMDevice());                                // Required by SPC
1.1.1.2   root      170:        ADD_DEVICE(gSPC, BusIO_X68kSPC<SPCDevice>());
1.1.1.6   root      171:        ADD_DEVICE(gSprite, SpriteDevice());
                    172:        ADD_DEVICE(gSysport, BusIO_FB<SysportDevice>());
1.1       root      173:        ADD_DEVICE(gTVRAM, TVRAMDevice());
1.1.1.3   root      174:        ADD_DEVICE(gVideoCtlr, BusIO_W<VideoCtlrDevice>());
1.1.1.5   root      175:        ADD_DEVICE(gOPM, BusIO_EB<OPMDevice>());
1.1.1.4   root      176: }
                    177: 
                    178: // デストラクタ
                    179: XIOSpaceDevice::~XIOSpaceDevice()
                    180: {
                    181: }
                    182: 
                    183: bool
                    184: XIOSpaceDevice::Init()
                    185: {
                    186:        // RAM のみ RamDevice::Init() で ram_size が決定してから行う。
1.1.1.6   root      187:        int ram_size = gRAM->GetSize();
1.1.1.4   root      188:        for (int i = 0; i < ram_size / 8192; i++) {
                    189:                table[i] = gRAM.get();
                    190:        }
                    191: 
                    192:        // 必要なデバイスは全部埋めたので、この時点で nullptr なエントリを
1.1.1.7   root      193:        // BusErr に差し替える。
1.1.1.4   root      194:        for (auto&& d : table) {
                    195:                if (d == nullptr) {
1.1.1.7   root      196:                        d = gBusErr.get();
1.1.1.4   root      197:                }
                    198:        }
1.1       root      199: 
                    200:        // デバッグ表示
                    201:        if (0) {
                    202:                for (int i = 0; i < 512; i++) {
                    203:                        printf("[%3d] $%06x ", i, 0xc00000 + i * 8192);
1.1.1.4   root      204:                        assert(table[i]);
                    205:                        if (dynamic_cast<MuxDevice*>(table[i])) {
1.1       root      206:                                printf("MuxDevice\n");
1.1.1.4   root      207:                        } else {
1.1.1.8 ! root      208:                                printf("%s\n", table[i]->GetName().c_str());
1.1       root      209:                        }
                    210:                }
                    211:        }
                    212: 
1.1.1.4   root      213:        return true;
1.1       root      214: }
                    215: 
                    216: // デバイステーブルに dev を追加する。
1.1.1.3   root      217: // ここに追加するデバイスは dev->devlen を指定すること。
1.1       root      218: void
                    219: XIOSpaceDevice::AddDevice(IODevice *dev)
                    220: {
                    221:        if (dev->devaddr == 0) {
1.1.1.3   root      222:                printf("XIOSpaceDevice:AddDevice: '%s' devaddr not set!\n",
1.1.1.8 ! root      223:                        dev->GetName().c_str());
1.1       root      224:                exit(1);
                    225:        }
                    226:        if (dev->devlen == 0) {
1.1.1.3   root      227:                printf("XIOSpaceDevice:AddDevice: '%s' devlen not set!\n",
1.1.1.8 ! root      228:                        dev->GetName().c_str());
1.1       root      229:                exit(1);
                    230:        }
                    231: 
                    232:        int idx = dev->devaddr / 8192;
                    233:        for (int i = idx; i < idx + (dev->devlen + 8191) /  8192; i++) {
                    234:                if (table[i] == nullptr) {
                    235:                        table[i] = dev;
                    236:                } else {
1.1.1.4   root      237:                        MuxDevice *mux = dynamic_cast<MuxDevice*>(table[i]);
                    238:                        if (mux) {
                    239:                                mux->AddDevice(dev);
                    240:                        } else {
                    241:                                MuxDevice *muxdev = new MuxDevice();
                    242:                                muxdev->AddDevice(table[i]);
                    243:                                muxdev->AddDevice(dev);
                    244:                                table[i] = muxdev;
                    245:                        }
1.1       root      246:                }
                    247:        }
                    248: }
                    249: 
                    250: uint64
                    251: XIOSpaceDevice::Read8(uint32 addr)
                    252: {
                    253:        addr &= 0x00ffffff;
                    254:        IODevice *d = SearchDevice(addr);
                    255:        return d->Read8(addr);
                    256: }
                    257: 
                    258: uint64
                    259: XIOSpaceDevice::Read16(uint32 addr)
                    260: {
                    261:        addr &= 0x00ffffff;
                    262:        IODevice *d = SearchDevice(addr);
                    263:        return d->Read16(addr);
                    264: }
                    265: 
                    266: uint64
                    267: XIOSpaceDevice::Read32(uint32 addr)
                    268: {
                    269:        addr &= 0x00ffffff;
                    270:        IODevice *d = SearchDevice(addr);
                    271:        return d->Read32(addr);
                    272: }
                    273: 
                    274: uint64
                    275: XIOSpaceDevice::Write8(uint32 addr, uint32 data)
                    276: {
                    277:        addr &= 0x00ffffff;
                    278:        IODevice *d = SearchDevice(addr);
                    279:        return d->Write8(addr, data);
                    280: }
                    281: 
                    282: uint64
                    283: XIOSpaceDevice::Write16(uint32 addr, uint32 data)
                    284: {
                    285:        addr &= 0x00ffffff;
                    286:        IODevice *d = SearchDevice(addr);
                    287:        return d->Write16(addr, data);
                    288: }
                    289: 
                    290: uint64
                    291: XIOSpaceDevice::Write32(uint32 addr, uint32 data)
                    292: {
                    293:        addr &= 0x00ffffff;
                    294:        IODevice *d = SearchDevice(addr);
                    295:        return d->Write32(addr, data);
                    296: }
                    297: 
                    298: uint64
                    299: XIOSpaceDevice::Peek8(uint32 addr)
                    300: {
                    301:        addr &= 0x00ffffff;
                    302:        IODevice *d = SearchDevice(addr);
                    303:        return d->Peek8(addr);
                    304: }
1.1.1.7   root      305: 
                    306: // ブートページを切り替える。
                    307: // (VM_X68030::SwitchBootPage() の下請け)
                    308: void
                    309: XIOSpaceDevice::SwitchBootPage(bool isrom)
                    310: {
                    311:        IODevice *ram;
                    312:        IODevice *rom;
                    313: 
                    314:        if (isrom) {
                    315:                // 0x000000 からの  64KB ( 8エントリ)、
                    316:                // 0xfe0000 からの 128KB (16エントリ) のどちらも IPLROM0 が担当する。
                    317:                ram = gIPLROM0.get();
                    318:                rom = ram;
                    319:        } else {
                    320:                // 0x000000 からの  64KB ( 8エントリ) に RAM を見せる。
                    321:                // 0xfe0000 からの 128KB (16エントリ) に IPLROM1 を見せる。
                    322:                ram = gRAM.get();
                    323:                rom = gIPLROM1.get();
                    324:        }
                    325: 
                    326:        for (int i = 0; i < 8; i++) {
                    327:                table[i] = ram;
                    328:        }
                    329:        for (int i = 0; i < 16; i++) {
                    330:                table[table.size() - 16 + i] = rom;
                    331:        }
                    332: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.