File:  [Isaki's NoNo m68k/m88k emulator] / nono / vm / zram.cpp
Revision 1.1.1.5 (vendor branch): download - view: text, annotated - select for diffs
Wed Apr 29 17:05:10 2026 UTC (2 months, 3 weeks ago) by root
Branches: MAIN, Isaki
CVS tags: v016, v015, HEAD
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];
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.