A few small consistency updates:

1) Drop Get/SetPagedByte in favour of normal BusRead/Write
2) Tidy some "using" statements
3) More "expression body" usage, if possible
4) Use field initialisation, rather than construction, if possible
5) Correct IntelProcessor register set/get methods (there were remnants of "copy pasta" code)

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon
2019-02-03 20:29:52 +00:00
parent 0ca57d8641
commit d4a35c402c
10 changed files with 50 additions and 92 deletions
+4 -4
View File
@@ -37,8 +37,8 @@
protected override ushort GetWordPaged(byte page, byte offset)
{
var high = GetBytePaged(page, offset);
var low = GetBytePaged(page, (byte)(offset + 1));
var high = BusRead(offset, page);
var low = BusRead((byte)(offset + 1), page);
return MakeWord(low, high);
}
@@ -64,8 +64,8 @@
protected override void SetWordPaged(byte page, byte offset, ushort value)
{
SetBytePaged(page, offset, HighByte(value));
SetBytePaged(page, (byte)(offset + 1), LowByte(value));
BusWrite(offset, page, HighByte(value));
BusWrite((byte)(offset + 1), page, LowByte(value));
}
}
}
+3 -3
View File
@@ -1,7 +1,7 @@
using System;
namespace EightBit
namespace EightBit
{
using System;
[Flags]
public enum Bits
{
+5 -23
View File
@@ -13,17 +13,8 @@
public event EventHandler<EventArgs> ReadingByte;
public event EventHandler<EventArgs> ReadByte;
public byte Data
{
get { return data; }
set { data = value; }
}
public ushort Address
{
get { return address; }
set { address = value; }
}
public byte Data { get => data; set => data = value; }
public ushort Address { get => address; set => address = value; }
public abstract MemoryMapping Mapping(ushort absolute);
@@ -49,10 +40,7 @@
return Read();
}
public byte Read(byte low, byte high)
{
return Read(Chip.MakeWord(low, high));
}
public byte Read(byte low, byte high) => Read(Chip.MakeWord(low, high));
public void Write()
{
@@ -73,10 +61,7 @@
Write(value);
}
public void Write(byte low, byte high, byte value)
{
Write(Chip.MakeWord(low, high), value);
}
public void Write(byte low, byte high, byte value) => Write(Chip.MakeWord(low, high), value);
public virtual void RaisePOWER() {}
public virtual void LowerPOWER() {}
@@ -103,10 +88,7 @@
protected ref byte Reference() => ref Reference(Address);
protected ref byte Reference(byte low, byte high)
{
return ref Reference(Chip.MakeWord(low, high));
}
protected ref byte Reference(byte low, byte high) => ref Reference(Chip.MakeWord(low, high));
//[[nodiscard]] static std::map<uint16_t, std::vector<uint8_t>> parseHexFile(std::string path);
//void loadHexFile(std::string path);
+1 -1
View File
@@ -13,7 +13,7 @@
public event EventHandler<EventArgs> LoweringPOWER;
public event EventHandler<EventArgs> LoweredPOWER;
public ref PinLevel POWER() { return ref powerLine; }
public ref PinLevel POWER() => ref powerLine;
public bool Powered => POWER().Raised();
+4 -6
View File
@@ -4,13 +4,11 @@
public sealed class InputOutput
{
private byte[] input;
private byte[] output;
private byte[] input = new byte[0x100];
private byte[] output = new byte[0x100];
public InputOutput()
{
input = new byte[0x100];
output = new byte[0x100];
}
public event EventHandler<PortEventArgs> ReadingPort;
@@ -19,8 +17,8 @@
public event EventHandler<PortEventArgs> WritingPort;
public event EventHandler<PortEventArgs> WrittenPort;
byte Read(byte port) { return ReadInputPort(port); }
void Write(byte port, byte value) { WriteOutputPort(port, value); }
byte Read(byte port) => ReadInputPort(port);
void Write(byte port, byte value) => WriteOutputPort(port, value);
byte ReadInputPort(byte port)
{
+10 -11
View File
@@ -4,7 +4,7 @@
public abstract class IntelProcessor : LittleEndianProcessor
{
private readonly IntelOpCodeDecoded[] decodedOpCodes;
private readonly IntelOpCodeDecoded[] decodedOpCodes = new IntelOpCodeDecoded[0x100];
private ushort sp;
private ushort memptr;
@@ -13,7 +13,6 @@
protected IntelProcessor(Bus bus)
: base(bus)
{
decodedOpCodes = new IntelOpCodeDecoded[0x100];
sp = (ushort)Mask.Mask16;
memptr = (ushort)Mask.Mask16;
@@ -26,7 +25,7 @@
public event EventHandler<EventArgs> LoweringHALT;
public event EventHandler<EventArgs> LoweredHALT;
public ref PinLevel HALT() { return ref haltLine; }
public ref PinLevel HALT() => ref haltLine;
protected bool Halted => HALT().Lowered();
@@ -34,20 +33,20 @@
public ushort MEMPTR { get => memptr; set => memptr = value; }
public abstract ushort AF { get; set; }
public byte A { get { return HighByte(AF); } set { AF = (ushort)(LowerPart(AF) | PromoteByte(value)); } }
public byte F { get { return LowByte(AF); } set { AF = (ushort)(HigherPart(AF) | value); } }
public byte A { get => HighByte(AF); set => AF = (ushort)(LowerPart(AF) | PromoteByte(value)); }
public byte F { get => LowByte(AF); set => AF = (ushort)(HigherPart(AF) | value); }
public abstract ushort BC { get; set; }
public byte B { get { return HighByte(AF); } set { BC = (ushort)(LowerPart(BC) | PromoteByte(value)); } }
public byte C { get { return LowByte(AF); } set { BC = (ushort)(HigherPart(BC) | value); } }
public byte B { get => HighByte(AF); set => BC = (ushort)(LowerPart(BC) | PromoteByte(value)); }
public byte C { get => LowByte(AF); set => BC = (ushort)(HigherPart(BC) | value); }
public abstract ushort DE { get; set; }
public byte D { get { return HighByte(AF); } set { DE = (ushort)(LowerPart(DE) | PromoteByte(value)); } }
public byte E { get { return LowByte(AF); } set { DE = (ushort)(HigherPart(DE) | value); } }
public byte D { get => HighByte(DE); set => DE = (ushort)(LowerPart(DE) | PromoteByte(value)); }
public byte E { get => LowByte(DE); set => DE = (ushort)(HigherPart(DE) | value); }
public abstract ushort HL { get; set; }
public byte H { get { return HighByte(AF); } set { HL = (ushort)(LowerPart(AF) | PromoteByte(value)); } }
public byte L { get { return LowByte(AF); } set { HL = (ushort)(HigherPart(AF) | value); } }
public byte H { get => HighByte(HL); set => HL = (ushort)(LowerPart(HL) | PromoteByte(value)); }
public byte L { get => LowByte(HL); set { HL = (ushort)(HigherPart(HL) | value); } }
public override void RaisePOWER()
{
+4 -4
View File
@@ -37,8 +37,8 @@
protected override ushort GetWordPaged(byte page, byte offset)
{
var low = GetBytePaged(page, offset);
var high = GetBytePaged(page, (byte)(offset + 1));
var low = BusRead(offset, page);
var high = BusRead((byte)(offset + 1), page);
return MakeWord(low, high);
}
@@ -64,8 +64,8 @@
protected override void SetWordPaged(byte page, byte offset, ushort value)
{
SetBytePaged(page, offset, LowByte(value));
SetBytePaged(page, (byte)(offset + 1), HighByte(value));
BusWrite(offset, page, LowByte(value));
BusWrite((byte)(offset + 1), page, HighByte(value));
}
}
}
+6 -26
View File
@@ -31,8 +31,8 @@
protected byte OpCode { get => opcode; set => opcode = value; }
public Bus Bus { get => bus; set => bus = value; }
public ref PinLevel RESET() { return ref resetLine; }
public ref PinLevel INT() { return ref intLine; }
public ref PinLevel RESET() => ref resetLine;
public ref PinLevel INT() => ref intLine;
public abstract int Step();
public abstract int Execute();
@@ -101,10 +101,7 @@
#region BusWrite
protected void BusWrite(byte low, byte high, byte data)
{
BusWrite(MakeWord(low, high), data);
}
protected void BusWrite(byte low, byte high, byte data) => BusWrite(MakeWord(low, high), data);
protected void BusWrite(ushort address, byte data)
{
@@ -124,10 +121,7 @@
#region BusRead
protected byte BusRead(byte low, byte high)
{
return BusRead(MakeWord(low, high));
}
protected byte BusRead(byte low, byte high) => BusRead(MakeWord(low, high));
protected byte BusRead(ushort address)
{
@@ -139,14 +133,6 @@
#endregion
#region Paged reader/writer wrappers
protected byte GetBytePaged(byte page, byte offset) => BusRead(offset, page);
protected void SetBytePaged(byte page, byte offset, byte value) => BusWrite(offset, page, value);
#endregion
protected byte FetchByte() => BusRead(PC++);
protected abstract ushort GetWord();
@@ -175,10 +161,7 @@
SetWord(value);
}
protected void Jump(ushort destination)
{
PC = destination;
}
protected void Jump(ushort destination) => PC = destination;
protected void Call(ushort destination)
{
@@ -186,9 +169,6 @@
Jump(destination);
}
protected virtual void Return()
{
Jump(PopWord());
}
protected virtual void Return() => Jump(PopWord());
}
}