Added Read/Write function to MC
This commit is contained in:
1 parent
0be1f139ef
commit
8cf9e2c5f5
20 files changed
+256
-9
No files matched your search
@@ -1,4 +1,85 @@
|
||||
using System;
|
||||
|
||||
namespace CPUSimulation
|
||||
{
|
||||
|
||||
public class Bit
|
||||
{
|
||||
bool _value;
|
||||
public Bit(bool value = false)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
public bool GetValue()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
public class Byte
|
||||
{
|
||||
Bit[] _bits;
|
||||
public Byte(Bit[] bits)
|
||||
{
|
||||
if (bits.Length != 8)
|
||||
{
|
||||
throw new ArgumentException("A byte must consist of exactly 8 bits.");
|
||||
}
|
||||
_bits = bits;
|
||||
}
|
||||
|
||||
public Bit[] GetBits()
|
||||
{
|
||||
return _bits;
|
||||
}
|
||||
}
|
||||
|
||||
public class MemoryBank
|
||||
{
|
||||
Byte[] _bytes;
|
||||
public MemoryBank(Byte[] bytes)
|
||||
{
|
||||
_bytes = bytes;
|
||||
}
|
||||
|
||||
public Byte Read(byte address)
|
||||
{
|
||||
return _bytes[address];
|
||||
}
|
||||
|
||||
public void Write(byte address, Byte data)
|
||||
{
|
||||
_bytes[address] = data;
|
||||
}
|
||||
}
|
||||
|
||||
public class Word
|
||||
{
|
||||
Byte[] _bytes;
|
||||
public Word(Byte[] bytes)
|
||||
{
|
||||
_bytes = bytes;
|
||||
}
|
||||
|
||||
public int GetByteCount()
|
||||
{
|
||||
return _bytes.Length;
|
||||
}
|
||||
|
||||
public Byte[] GetBytes()
|
||||
{
|
||||
return _bytes;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
string wordString = "";
|
||||
foreach (Byte b in _bytes)
|
||||
{
|
||||
foreach (Bit bit in b.GetBits())
|
||||
{
|
||||
wordString += bit.GetValue() ? "1" : "0";
|
||||
}
|
||||
}
|
||||
return wordString;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user