-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNvRamDevice.cs
More file actions
48 lines (42 loc) · 1.34 KB
/
NvRamDevice.cs
File metadata and controls
48 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
namespace ProcessorEmulator.Emulation
{
public class NvRamDevice : IBusDevice
{
public uint StartAddress { get; }
public uint Size { get; }
private readonly byte[] _memory;
public NvRamDevice(uint startAddress, uint size)
{
StartAddress = startAddress;
Size = size;
_memory = new byte[size];
}
public uint Read32(uint offset)
{
if (offset + 4 > Size) return 0;
return (uint)(_memory[offset] |
(_memory[offset + 1] << 8) |
(_memory[offset + 2] << 16) |
(_memory[offset + 3] << 24));
}
public void Write32(uint offset, uint value)
{
if (offset + 4 > Size) return;
_memory[offset] = (byte)(value & 0xFF);
_memory[offset + 1] = (byte)((value >> 8) & 0xFF);
_memory[offset + 2] = (byte)((value >> 16) & 0xFF);
_memory[offset + 3] = (byte)((value >> 24) & 0xFF);
}
public byte Read8(uint offset)
{
if (offset >= Size) return 0;
return _memory[offset];
}
public void Write8(uint offset, byte value)
{
if (offset >= Size) return;
_memory[offset] = value;
}
}
}