|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2023 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: // ! 8: // Nereid バンクメモリ ! 9: // ! 10: ! 11: // バンクメモリはロングワード単位でホストバイトオーダ配置なので、 ! 12: // バイトアクセス、ワードアクセス時は HLB(), HLW() マクロを使用のこと。 ! 13: ! 14: #include "bankram.h" ! 15: #include "config.h" ! 16: ! 17: // コンストラクタ ! 18: BankRAMDevice::BankRAMDevice(int objid_, int ram_size_MB) ! 19: : inherited(objid_) ! 20: { ! 21: // ram_size_MB は正数のみ。負数は親側で処理する。 ! 22: assert(ram_size_MB >= 0); ! 23: ! 24: ram_size = ram_size_MB * 1024 * 1024; ! 25: // 初期化は Init() で行う ! 26: } ! 27: ! 28: // デストラクタ ! 29: BankRAMDevice::~BankRAMDevice() ! 30: { ! 31: } ! 32: ! 33: // 初期化 ! 34: bool ! 35: BankRAMDevice::Init() ! 36: { ! 37: if (inherited::Init() == false) { ! 38: return false; ! 39: } ! 40: ! 41: ram.reset(new uint8[ram_size]); ! 42: ! 43: return true; ! 44: } ! 45: ! 46: // 電源オン/リセット ! 47: void ! 48: BankRAMDevice::ResetHard(bool poweron) ! 49: { ! 50: if (poweron) { ! 51: // ノイズで埋めたいがとりあえず。 ! 52: memset(&ram[0], 0, ram_size); ! 53: } ! 54: ! 55: // リセットでクリアされる。 ! 56: SetPage(0); ! 57: } ! 58: ! 59: inline uint32 ! 60: BankRAMDevice::Decoder(uint32 addr) const ! 61: { ! 62: return pageaddr + (addr & 0xffff); ! 63: } ! 64: ! 65: uint64 ! 66: BankRAMDevice::Read8(uint32 addr) ! 67: { ! 68: uint32 offset = Decoder(addr); ! 69: uint32 data = ram[HLB(offset)]; ! 70: putlog(4, "$%08x.B -> $%02x", addr, data); ! 71: return data; ! 72: } ! 73: ! 74: uint64 ! 75: BankRAMDevice::Read16(uint32 addr) ! 76: { ! 77: uint32 offset = Decoder(addr); ! 78: uint32 data = *(uint16 *)&ram[HLW(offset)]; ! 79: putlog(4, "$%08x.W -> $%04x", addr, data); ! 80: return data; ! 81: } ! 82: ! 83: uint64 ! 84: BankRAMDevice::Read32(uint32 addr) ! 85: { ! 86: uint32 offset = Decoder(addr); ! 87: uint32 data = *(uint32 *)&ram[offset]; ! 88: putlog(4, "$%08x.L -> $%08x", addr, data); ! 89: return data; ! 90: } ! 91: ! 92: uint64 ! 93: BankRAMDevice::Write8(uint32 addr, uint32 data) ! 94: { ! 95: uint32 offset = Decoder(addr); ! 96: ram[HLB(offset)] = data; ! 97: putlog(3, "$%08x.B <- $%02x", addr, data); ! 98: return 0; ! 99: } ! 100: ! 101: uint64 ! 102: BankRAMDevice::Write16(uint32 addr, uint32 data) ! 103: { ! 104: uint32 offset = Decoder(addr); ! 105: *(uint16 *)&ram[HLW(offset)] = data; ! 106: putlog(3, "$%08x.W <- $%04x", addr, data); ! 107: return 0; ! 108: } ! 109: ! 110: uint64 ! 111: BankRAMDevice::Write32(uint32 addr, uint32 data) ! 112: { ! 113: uint32 offset = Decoder(addr); ! 114: *(uint32 *)&ram[offset] = data; ! 115: putlog(3, "$%08x.L <- $%08x", addr, data); ! 116: return 0; ! 117: } ! 118: ! 119: uint64 ! 120: BankRAMDevice::Peek8(uint32 addr) ! 121: { ! 122: uint32 offset = Decoder(addr); ! 123: return ram[HLB(offset)]; ! 124: } ! 125: ! 126: uint64 ! 127: BankRAMDevice::Poke8(uint32 addr, uint32 data) ! 128: { ! 129: if ((int32)data >= 0) { ! 130: uint32 offset = Decoder(addr); ! 131: ram[HLB(offset)] = data; ! 132: } ! 133: return 0; ! 134: } ! 135: ! 136: void ! 137: BankRAMDevice::SetPage(uint32 page_) ! 138: { ! 139: page = page_; ! 140: // XXX 4MB の時の折返し確認 ! 141: pageaddr = (page << 16) & (ram_size - 1); ! 142: ! 143: putlog(2, "Page <- $%02x", page); ! 144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.