|
|
1.1 ! root 1: // ! 2: // nono ! 3: // Copyright (C) 2023 nono project ! 4: // Licensed under nono-license.txt ! 5: // ! 6: ! 7: // ! 8: // X68030 勝手に拡張メモリ ! 9: // ! 10: // 拡張メモリは TS-6BE16 互換か 060turbo 互換のいずれか。 ! 11: // TS-6BE16 互換だと $0100'0000 〜 $01ff'ffff の 16MB。 ! 12: // 060turbo 互換だと $1000'0000 〜 $17ff'ffff の 128MB、 ! 13: // $1000'0000 〜 $1fff'ffff の 256MB。 ! 14: // ! 15: ! 16: // 拡張 RAM はロングワード単位でホストバイトオーダ配置なので、 ! 17: // バイトアクセス、ワードアクセス時は HLB(), HLW() マクロを使用のこと。 ! 18: ! 19: #include "extram.h" ! 20: #include "config.h" ! 21: ! 22: // コンストラクタ ! 23: ExtRAMDevice::ExtRAMDevice() ! 24: : inherited(OBJ_EXTRAM) ! 25: { ! 26: } ! 27: ! 28: // デストラクタ ! 29: ExtRAMDevice::~ExtRAMDevice() ! 30: { ! 31: } ! 32: ! 33: // 初期化 ! 34: bool ! 35: ExtRAMDevice::Init() ! 36: { ! 37: if (inherited::Init() == false) { ! 38: return false; ! 39: } ! 40: ! 41: const ConfigItem& item = gConfig->Find("extram-size"); ! 42: uint32 extram_size_MB = item.AsInt(); ! 43: if (extram_size_MB <= 0) { ! 44: return true; ! 45: } ! 46: switch (extram_size_MB) { ! 47: case 16: ! 48: ram_addr = 0x01'000000; ! 49: break; ! 50: case 128: ! 51: case 256: ! 52: ram_addr = 0x10'000000; ! 53: break; ! 54: default: ! 55: item.Err("Valid size is 16, 128, and 256 for now"); ! 56: return false; ! 57: } ! 58: ! 59: ram_size = extram_size_MB * 1024 * 1024; ! 60: ram.reset(new uint8[ram_size]); ! 61: ! 62: return true; ! 63: } ! 64: ! 65: // 電源オン/リセット ! 66: void ! 67: ExtRAMDevice::ResetHard(bool poweron) ! 68: { ! 69: if (poweron) { ! 70: // ノイズで埋めたいがとりあえず。 ! 71: memset(&ram[0], 0, ram_size); ! 72: } ! 73: } ! 74: ! 75: inline uint32 ! 76: ExtRAMDevice::Decoder(uint32 addr) const ! 77: { ! 78: return (addr - ram_addr); ! 79: } ! 80: ! 81: uint64 ! 82: ExtRAMDevice::Read8(uint32 addr) ! 83: { ! 84: uint32 offset = Decoder(addr); ! 85: uint32 data = ram[HLB(offset)]; ! 86: putlog(4, "$%08x.B -> $%02x", addr, data); ! 87: return data; ! 88: } ! 89: ! 90: uint64 ! 91: ExtRAMDevice::Read16(uint32 addr) ! 92: { ! 93: uint32 offset = Decoder(addr); ! 94: uint32 data = *(uint16 *)&ram[HLW(offset)]; ! 95: putlog(4, "$%08x.W -> $%04x", addr, data); ! 96: return data; ! 97: } ! 98: ! 99: uint64 ! 100: ExtRAMDevice::Read32(uint32 addr) ! 101: { ! 102: uint32 offset = Decoder(addr); ! 103: uint32 data = *(uint32 *)&ram[offset]; ! 104: putlog(4, "$%08x.L -> $%08x", addr, data); ! 105: return data; ! 106: } ! 107: ! 108: uint64 ! 109: ExtRAMDevice::Write8(uint32 addr, uint32 data) ! 110: { ! 111: uint32 offset = Decoder(addr); ! 112: ram[HLB(offset)] = data; ! 113: putlog(3, "$%08x.B <- $%02x", addr, data); ! 114: return 0; ! 115: } ! 116: ! 117: uint64 ! 118: ExtRAMDevice::Write16(uint32 addr, uint32 data) ! 119: { ! 120: uint32 offset = Decoder(addr); ! 121: *(uint16 *)&ram[HLW(offset)] = data; ! 122: putlog(3, "$%08x.W <- $%04x", addr, data); ! 123: return 0; ! 124: } ! 125: ! 126: uint64 ! 127: ExtRAMDevice::Write32(uint32 addr, uint32 data) ! 128: { ! 129: uint32 offset = Decoder(addr); ! 130: *(uint32 *)&ram[offset] = data; ! 131: putlog(3, "$%08x.L <- $%08x", addr, data); ! 132: return 0; ! 133: } ! 134: ! 135: uint64 ! 136: ExtRAMDevice::Peek8(uint32 addr) ! 137: { ! 138: uint32 offset = Decoder(addr); ! 139: return ram[HLB(offset)]; ! 140: } ! 141: ! 142: uint64 ! 143: ExtRAMDevice::Poke8(uint32 addr, uint32 data) ! 144: { ! 145: if ((int32)data >= 0) { ! 146: uint32 offset = Decoder(addr); ! 147: ram[HLB(offset)] = data; ! 148: } ! 149: return 0; ! 150: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.