|
|
nono 0.3.0
//
// nono
// Copyright (C) 2020 nono project
// Licensed under nono-license.txt
//
//
// 3ポート共有 RAM
//
// ZRAM はバイト配置とする。
#include "zram.h"
// グローバル参照用
ZRAMDevice *gZRAM;
// コンストラクタ
ZRAMDevice::ZRAMDevice()
: inherited("ZRAM")
{
devaddr = 0x71000000;
devlen = 128 * 1024;
ram.reset(new uint8[devlen]);
}
// デストラクタ
ZRAMDevice::~ZRAMDevice()
{
gZRAM = NULL;
}
// アドレスデコーダ
inline uint64
ZRAMDevice::Decoder(uint32 addr) const
{
// たぶん 128KB で折り返しイメージが見えるはず。要確認。
return addr % devlen;
}
uint64
ZRAMDevice::Read8(uint32 addr)
{
uint32 offset = Decoder(addr);
uint32 data = ram[offset];
return data;
}
uint64
ZRAMDevice::Read16(uint32 addr)
{
uint32 offset = Decoder(addr);
uint32 data;
data = (uint32)ram[offset + 0] << 8;
data |= (uint32)ram[offset + 1];
return data;
}
uint64
ZRAMDevice::Read32(uint32 addr)
{
uint32 offset = Decoder(addr);
uint32 data;
data = (uint32)ram[offset + 0] << 24;
data |= (uint32)ram[offset + 1] << 16;
data |= (uint32)ram[offset + 2] << 8;
data |= (uint32)ram[offset + 3];
return data;
}
uint64
ZRAMDevice::Write8(uint32 addr, uint32 data)
{
putlog(3, "$%08x.B <- $%02x", addr, data);
uint32 offset = Decoder(addr);
ram[offset] = data;
return 0;
}
uint64
ZRAMDevice::Write16(uint32 addr, uint32 data)
{
putlog(3, "$%08x.W <- $%04x", addr, data);
uint32 offset = Decoder(addr);
ram[offset + 0] = (data >> 8) & 0xff;
ram[offset + 1] = data & 0xff;
return 0;
}
uint64
ZRAMDevice::Write32(uint32 addr, uint32 data)
{
putlog(3, "$%08x.L <- $%08x", addr, data);
uint32 offset = Decoder(addr);
ram[offset + 0] = data >> 24;
ram[offset + 1] = (data >> 16) & 0xff;
ram[offset + 2] = (data >> 8) & 0xff;
ram[offset + 3] = data & 0xff;
return 0;
}
uint64
ZRAMDevice::Peek8(uint32 addr)
{
uint32 offset = Decoder(addr);
return ram[offset];
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.