|
|
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:
7: //
8: // GVRAM
9: //
1.1.1.6 root 10:
1.1 root 11: // GVRAM はワード単位でホストバイトオーダ配置なので、
12: // バイトアクセス時は HB() マクロを使用のこと。
13:
1.1.1.6 root 14: #include "gvram.h"
15: #include "videoctlr.h"
16:
1.1.1.8 root 17: // InsideOut p.135
18: static const busdata wait = busdata::Wait(9 * 40_nsec);
19:
1.1.1.6 root 20: // コンストラクタ
1.1 root 21: GVRAMDevice::GVRAMDevice()
1.1.1.7 root 22: : inherited(OBJ_GVRAM)
1.1 root 23: {
24: }
25:
1.1.1.6 root 26: // デストラクタ
1.1 root 27: GVRAMDevice::~GVRAMDevice()
28: {
29: }
30:
1.1.1.10! root 31: // 初期化
! 32: bool
! 33: GVRAMDevice::Init()
! 34: {
! 35: uint devlen = 0x20'0000; // XXX とりあえず
! 36: mem.reset(new(std::nothrow) uint8[devlen]);
! 37: if ((bool)mem == false) {
! 38: warnx("Cannot allocate %u bytes at %s", devlen, __method__);
! 39: return false;
! 40: }
! 41:
! 42: return true;
! 43: }
! 44:
1.1.1.9 root 45: inline uint32
46: GVRAMDevice::Decoder(uint32 addr) const
1.1 root 47: {
1.1.1.9 root 48: return addr - baseaddr;
1.1 root 49: }
50:
1.1.1.8 root 51: busdata
1.1.1.9 root 52: GVRAMDevice::Read(busaddr addr)
1.1 root 53: {
1.1.1.9 root 54: uint32 offset = Decoder(addr.Addr());
1.1.1.8 root 55: busdata data;
1.1.1.9 root 56:
57: data = *(uint16 *)&mem[offset & ~1U];
1.1.1.8 root 58: data |= wait;
1.1.1.9 root 59: data |= BusData::Size2;
1.1.1.8 root 60: return data;
1.1 root 61: }
62:
1.1.1.8 root 63: busdata
1.1.1.9 root 64: GVRAMDevice::Write(busaddr addr, uint32 data)
1.1 root 65: {
1.1.1.9 root 66: uint32 offset = Decoder(addr.Addr());
67: uint32 reqsize = addr.GetSize();
68: uint32 datasize = std::min(2 - (offset & 1U), reqsize);
69: data >>= (reqsize - datasize) * 8;
70:
71: if (datasize == 1) {
72: mem[HB(offset)] = data;
73: } else {
74: *(uint16 *)&mem[offset] = data;
75: }
76:
77: busdata r = wait;
78: r |= busdata::Size(datasize);
79: return r;
1.1 root 80: }
81:
1.1.1.8 root 82: busdata
1.1.1.9 root 83: GVRAMDevice::Peek1(uint32 addr)
1.1 root 84: {
1.1.1.9 root 85: uint32 offset = Decoder(addr);
86: return mem[HB(offset)];
1.1 root 87: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.