Annotation of nono/vm/iodevstream.cpp, revision 1.1

1.1     ! root        1: //
        !             2: // nono
        !             3: // Copyright (C) 2024 nono project
        !             4: // Licensed under nono-license.txt
        !             5: //
        !             6: 
        !             7: #include "iodevstream.h"
        !             8: #include "bus.h"
        !             9: #include "mainbus.h"
        !            10: #include "mainram.h"
        !            11: 
        !            12: // デストラクタ
        !            13: IODeviceStream::~IODeviceStream()
        !            14: {
        !            15: }
        !            16: 
        !            17: // 現在位置から size バイト分読み込んでポインタを進める。
        !            18: // size は busaddr::Size* する。
        !            19: busdata
        !            20: IODeviceStream::ReadN(busaddr size)
        !            21: {
        !            22:        busaddr addr = busaddr(offset) | size | BusAddr::SRead;
        !            23:        busdata data;
        !            24: 
        !            25:        do {
        !            26:                busdata bd = dev->Read(addr);
        !            27:                if (__predict_false(bd.IsBusErr())) {
        !            28:                        return bd;
        !            29:                }
        !            30:                data |= MainbusDevice::DYNAMIC_BUS_SIZING_R(addr, bd);
        !            31:        } while (addr.GetSize() != 0);
        !            32: 
        !            33:        offset += size.GetSize();
        !            34:        data |= busdata(size.Get());
        !            35:        return data;
        !            36: }
        !            37: 
        !            38: // 現在位置から data を書き出してポインタを進める。
        !            39: // size は busaddr::Size* を指定する。
        !            40: busdata
        !            41: IODeviceStream::WriteN(busaddr size, uint32 data)
        !            42: {
        !            43:        busaddr addr = busaddr(offset) | size | BusAddr::SWrite;
        !            44:        do {
        !            45:                busdata r = dev->Write(addr, data);
        !            46:                if (__predict_false(r.IsBusErr())) {
        !            47:                        return r;
        !            48:                }
        !            49:                MainbusDevice::DYNAMIC_BUS_SIZING_W(addr, data, r);
        !            50:        } while (addr.GetSize() != 0);
        !            51: 
        !            52:        offset += size.GetSize();
        !            53:        return 0;
        !            54: }
        !            55: 
        !            56: // 現在位置以降にホストの src から len バイトを書き出してポインタを進める。
        !            57: void
        !            58: IODeviceStream::WriteMem(const void *src, uint len)
        !            59: {
        !            60:        auto mainram = dynamic_cast<MainRAMDevice *>(dev);
        !            61:        if (mainram) {
        !            62:                mainram->WriteMem(offset, src, len);
        !            63:                offset += len;
        !            64:        } else {
        !            65:                const uint8 *s = (const uint8 *)src;
        !            66:                for (int i = 0; i < len; i++) {
        !            67:                        Write1(*s++);
        !            68:                }
        !            69:        }
        !            70: }

unix.superglobalmegacorp.com

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