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