|
|
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: // 3ポート共有 RAM
9: //
10:
1.1.1.5 ! root 11: // ZRAM はバイト配置とする。
! 12:
! 13: #include "zram.h"
! 14:
! 15: // グローバル参照用
! 16: ZRAMDevice *gZRAM;
1.1 root 17:
1.1.1.5 ! root 18: // コンストラクタ
1.1 root 19: ZRAMDevice::ZRAMDevice()
1.1.1.4 root 20: : inherited("ZRAM")
1.1 root 21: {
22: devaddr = 0x71000000;
23: devlen = 128 * 1024;
24:
1.1.1.2 root 25: ram.reset(new uint8[devlen]);
1.1 root 26: }
27:
1.1.1.5 ! root 28: // デストラクタ
1.1 root 29: ZRAMDevice::~ZRAMDevice()
30: {
1.1.1.5 ! root 31: gZRAM = NULL;
1.1 root 32: }
33:
1.1.1.2 root 34: // アドレスデコーダ
35: inline uint64
36: ZRAMDevice::Decoder(uint32 addr) const
37: {
38: // たぶん 128KB で折り返しイメージが見えるはず。要確認。
39: return addr % devlen;
40: }
1.1 root 41:
42: uint64
43: ZRAMDevice::Read8(uint32 addr)
44: {
1.1.1.2 root 45: uint32 offset = Decoder(addr);
1.1.1.5 ! root 46: uint32 data = ram[offset];
1.1 root 47: return data;
48: }
49:
50: uint64
51: ZRAMDevice::Read16(uint32 addr)
52: {
1.1.1.2 root 53: uint32 offset = Decoder(addr);
1.1.1.5 ! root 54: uint32 data;
! 55: data = (uint32)ram[offset + 0] << 8;
! 56: data |= (uint32)ram[offset + 1];
1.1 root 57: return data;
58: }
59:
60: uint64
61: ZRAMDevice::Read32(uint32 addr)
62: {
1.1.1.2 root 63: uint32 offset = Decoder(addr);
1.1.1.5 ! root 64: uint32 data;
! 65: data = (uint32)ram[offset + 0] << 24;
! 66: data |= (uint32)ram[offset + 1] << 16;
! 67: data |= (uint32)ram[offset + 2] << 8;
! 68: data |= (uint32)ram[offset + 3];
1.1 root 69: return data;
70: }
71:
72: uint64
73: ZRAMDevice::Write8(uint32 addr, uint32 data)
74: {
1.1.1.5 ! root 75: putlog(3, "$%08x.B <- $%02x", addr, data);
1.1 root 76:
1.1.1.2 root 77: uint32 offset = Decoder(addr);
1.1.1.5 ! root 78: ram[offset] = data;
1.1 root 79: return 0;
80: }
81:
82: uint64
83: ZRAMDevice::Write16(uint32 addr, uint32 data)
84: {
1.1.1.5 ! root 85: putlog(3, "$%08x.W <- $%04x", addr, data);
1.1 root 86:
1.1.1.2 root 87: uint32 offset = Decoder(addr);
1.1.1.5 ! root 88: ram[offset + 0] = (data >> 8) & 0xff;
! 89: ram[offset + 1] = data & 0xff;
1.1 root 90: return 0;
91: }
92:
93: uint64
94: ZRAMDevice::Write32(uint32 addr, uint32 data)
95: {
1.1.1.5 ! root 96: putlog(3, "$%08x.L <- $%08x", addr, data);
1.1 root 97:
1.1.1.2 root 98: uint32 offset = Decoder(addr);
1.1.1.5 ! root 99: ram[offset + 0] = data >> 24;
! 100: ram[offset + 1] = (data >> 16) & 0xff;
! 101: ram[offset + 2] = (data >> 8) & 0xff;
! 102: ram[offset + 3] = data & 0xff;
1.1 root 103: return 0;
104: }
105:
106: uint64
107: ZRAMDevice::Peek8(uint32 addr)
108: {
1.1.1.2 root 109: uint32 offset = Decoder(addr);
1.1.1.5 ! root 110: return ram[offset];
1.1 root 111: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.