mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2024-06-02 16:41:33 +00:00
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:
parent
0ca57d8641
commit
d4a35c402c
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
|
||||
namespace EightBit
|
||||
namespace EightBit
|
||||
{
|
||||
using System;
|
||||
|
||||
[Flags]
|
||||
public enum Bits
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,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)
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@
|
|||
case 0x25: A = AndR(A, AM_ZeroPage()); break; // AND (zero page)
|
||||
case 0x26: BusReadModifyWrite(ROL(AM_ZeroPage())); break; // ROL (zero page)
|
||||
case 0x27: RLA(AM_ZeroPage()); break; // *RLA (zero page)
|
||||
case 0x28: BusRead(); GetBytePaged(1, S); PLP(); break; // PLP (implied)
|
||||
case 0x28: BusRead(); BusRead(S, 1); PLP(); break; // PLP (implied)
|
||||
case 0x29: A = AndR(A, AM_Immediate()); break; // AND (immediate)
|
||||
case 0x2a: BusRead(); A = ROL(A); break; // ROL A (implied)
|
||||
case 0x2b: ANC(AM_Immediate()); break; // *ANC (immediate)
|
||||
|
@ -281,7 +281,7 @@
|
|||
case 0x65: A = ADC(A, AM_ZeroPage()); break; // ADC (zero page)
|
||||
case 0x66: BusReadModifyWrite(ROR(AM_ZeroPage())); break; // ROR (zero page)
|
||||
case 0x67: RRA(AM_ZeroPage()); break; // *RRA (zero page)
|
||||
case 0x68: BusRead(); GetBytePaged(1, S); A = Through(Pop()); break; // PLA (implied)
|
||||
case 0x68: BusRead(); BusRead(S, 1); A = Through(Pop()); break; // PLA (implied)
|
||||
case 0x69: A = ADC(A, AM_Immediate()); break; // ADC (immediate)
|
||||
case 0x6a: BusRead(); A = ROR(A); break; // ROR A (implied)
|
||||
case 0x6b: ARR(AM_Immediate()); break; // *ARR (immediate)
|
||||
|
@ -472,9 +472,9 @@
|
|||
return Cycles;
|
||||
}
|
||||
|
||||
protected override byte Pop() => GetBytePaged(1, ++S);
|
||||
protected override byte Pop() => BusRead(++S, 1);
|
||||
|
||||
protected override void Push(byte value) => SetBytePaged(1, S--, value);
|
||||
protected override void Push(byte value) => BusWrite(S--, 1, value);
|
||||
|
||||
protected override sealed void HandleRESET()
|
||||
{
|
||||
|
@ -608,7 +608,7 @@
|
|||
var crossed = Address_AbsoluteX();
|
||||
var address = crossed.Item1;
|
||||
var page = crossed.Item2;
|
||||
var possible = GetBytePaged(page, LowByte(address));
|
||||
var possible = BusRead(LowByte(address), page);
|
||||
if ((behaviour == PageCrossingBehavior.AlwaysReadTwice) || (page != HighByte(address)))
|
||||
possible = BusRead(address);
|
||||
return possible;
|
||||
|
@ -619,7 +619,7 @@
|
|||
var crossed = Address_AbsoluteY();
|
||||
var address = crossed.Item1;
|
||||
var page = crossed.Item2;
|
||||
var possible = GetBytePaged(page, LowByte(address));
|
||||
var possible = BusRead(LowByte(address), page);
|
||||
if (page != HighByte(address))
|
||||
possible = BusRead(address);
|
||||
return possible;
|
||||
|
@ -636,7 +636,7 @@
|
|||
var crossed = Address_IndirectIndexedY();
|
||||
var address = crossed.Item1;
|
||||
var page = crossed.Item2;
|
||||
var possible = GetBytePaged(page, LowByte(address));
|
||||
var possible = BusRead(LowByte(address), page);
|
||||
if (page != HighByte(address))
|
||||
possible = BusRead(address);
|
||||
return possible;
|
||||
|
@ -803,7 +803,7 @@
|
|||
private void JSR()
|
||||
{
|
||||
var low = FetchByte();
|
||||
GetBytePaged(1, S); // dummy read
|
||||
BusRead(S, 1); // dummy read
|
||||
PushWord(PC);
|
||||
PC = MakeWord(low, FetchByte());
|
||||
}
|
||||
|
@ -838,14 +838,14 @@
|
|||
|
||||
private void RTI()
|
||||
{
|
||||
GetBytePaged(1, S); // dummy read
|
||||
BusRead(S, 1); // dummy read
|
||||
PLP();
|
||||
Return();
|
||||
}
|
||||
|
||||
private void RTS()
|
||||
{
|
||||
GetBytePaged(1, S); // dummy read
|
||||
BusRead(S, 1); // dummy read
|
||||
Return();
|
||||
FetchByte();
|
||||
}
|
||||
|
@ -921,7 +921,7 @@
|
|||
var crossed = Address_AbsoluteX();
|
||||
var address = crossed.Item1;
|
||||
var page = crossed.Item2;
|
||||
GetBytePaged(page, LowByte(address));
|
||||
BusRead(LowByte(address), page);
|
||||
BusWrite(address, A);
|
||||
}
|
||||
|
||||
|
@ -930,7 +930,7 @@
|
|||
var crossed = Address_AbsoluteY();
|
||||
var address = crossed.Item1;
|
||||
var page = crossed.Item2;
|
||||
GetBytePaged(page, LowByte(address));
|
||||
BusRead(LowByte(address), page);
|
||||
BusWrite(address, A);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,8 +56,7 @@
|
|||
CPU.ExecutedInstruction += CPU_ExecutedInstruction;
|
||||
|
||||
Poke(0x00, 0x4c);
|
||||
Poke(0x01, Chip.LowByte(configuration.StartAddress));
|
||||
Poke(0x02, Chip.HighByte(configuration.StartAddress));
|
||||
cpu.PokeWord(0x01, configuration.StartAddress);
|
||||
}
|
||||
|
||||
private void CPU_ExecutedInstruction(object sender, System.EventArgs e)
|
||||
|
|
Loading…
Reference in New Issue
Block a user