|
|
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: {
1.1.1.2 ! root 22: busaddr ba = busaddr(addr) | size | BusAddr::SRead;
1.1 root 23: busdata data;
24:
25: do {
1.1.1.2 ! root 26: busdata bd = dev->Read(ba);
1.1 root 27: if (__predict_false(bd.IsBusErr())) {
28: return bd;
29: }
1.1.1.2 ! root 30: data |= MainbusDevice::DYNAMIC_BUS_SIZING_R(ba, bd);
! 31: } while (ba.GetSize() != 0);
1.1 root 32:
1.1.1.2 ! root 33: addr += size.GetSize();
1.1 root 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: {
1.1.1.2 ! root 43: busaddr ba = busaddr(addr) | size | BusAddr::SWrite;
1.1 root 44: do {
1.1.1.2 ! root 45: busdata r = dev->Write(ba, data);
1.1 root 46: if (__predict_false(r.IsBusErr())) {
47: return r;
48: }
1.1.1.2 ! root 49: MainbusDevice::DYNAMIC_BUS_SIZING_W(ba, data, r);
! 50: } while (ba.GetSize() != 0);
1.1 root 51:
1.1.1.2 ! root 52: addr += size.GetSize();
1.1 root 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) {
1.1.1.2 ! root 62: mainram->WriteMem(addr, src, len);
! 63: addr += len;
1.1 root 64: } else {
65: const uint8 *s = (const uint8 *)src;
66: for (int i = 0; i < len; i++) {
67: Write1(*s++);
68: }
69: }
70: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.