mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-03-31 04:30:58 +00:00
Simplfy access to Z80 registers
This commit is contained in:
parent
1321a909d0
commit
d80f340081
@ -18,7 +18,7 @@ namespace EightBit
|
||||
|
||||
public event EventHandler<EventArgs>? ReadByte;
|
||||
|
||||
public byte Data { get => this.data; set => this.data = value; }
|
||||
public ref byte Data => ref this.data;
|
||||
|
||||
public Register16 Address { get; } = new();
|
||||
|
||||
|
@ -38,27 +38,27 @@ namespace EightBit
|
||||
|
||||
public abstract Register16 AF { get; }
|
||||
|
||||
public byte A { get => this.AF.High; set => this.AF.High = value; }
|
||||
public ref byte A => ref this.AF.High;
|
||||
|
||||
public byte F { get => this.AF.Low; set => this.AF.Low = value; }
|
||||
public ref byte F => ref this.AF.Low;
|
||||
|
||||
public abstract Register16 BC { get; }
|
||||
|
||||
public byte B { get => this.BC.High; set => this.BC.High = value; }
|
||||
public ref byte B => ref this.BC.High;
|
||||
|
||||
public byte C { get => this.BC.Low; set => this.BC.Low = value; }
|
||||
public ref byte C => ref this.BC.Low;
|
||||
|
||||
public abstract Register16 DE { get; }
|
||||
|
||||
public byte D { get => this.DE.High; set => this.DE.High = value; }
|
||||
public ref byte D => ref this.DE.High;
|
||||
|
||||
public byte E { get => this.DE.Low; set => this.DE.Low = value; }
|
||||
public ref byte E => ref this.DE.Low;
|
||||
|
||||
public abstract Register16 HL { get; }
|
||||
|
||||
public byte H { get => this.HL.High; set => this.HL.High = value; }
|
||||
public ref byte H => ref this.HL.High;
|
||||
|
||||
public byte L { get => this.HL.Low; set => this.HL.Low = value; }
|
||||
public ref byte L => ref this.HL.Low;
|
||||
|
||||
public ref PinLevel HALT => ref this.haltLine;
|
||||
|
||||
|
@ -12,26 +12,25 @@ namespace M6502.Test
|
||||
|
||||
public bool Profile { get; set; } = true;
|
||||
|
||||
public bool BreakOnKeyRead { get; } = true;
|
||||
|
||||
|
||||
// Sudoku
|
||||
//public string Program { get; } = "sudoku.65b";
|
||||
//public string Symbols { get; } = "sudoku.dbg";
|
||||
//public Register16 InputAddress { get; } = new Register16(0xe000);
|
||||
//public Register16 OutputAddress { get; } = new Register16(0xe001);
|
||||
//public Register16 LoadAddress { get; } = new Register16(0xf000);
|
||||
//public Register16 StartAddress { get; } = new Register16(0xf000);
|
||||
//public bool AllowKeyRead { get; } = false;
|
||||
public string Program { get; } = "sudoku.65b";
|
||||
public string Symbols { get; } = "sudoku.dbg";
|
||||
public Register16 InputAddress { get; } = new Register16(0xe000);
|
||||
public Register16 OutputAddress { get; } = new Register16(0xe001);
|
||||
public Register16 LoadAddress { get; } = new Register16(0xf000);
|
||||
public Register16 StartAddress { get; } = new Register16(0xf000);
|
||||
public bool AllowKeyRead { get; } = false;
|
||||
public bool BreakOnKeyRead { get; } = false;
|
||||
|
||||
// Klaus
|
||||
public string Program { get; } = "6502_functional_test.bin";
|
||||
public string Symbols { get; } = "";
|
||||
public Register16 InputAddress { get; } = new Register16(0xf004);
|
||||
public Register16 OutputAddress { get; } = new Register16(0xf001);
|
||||
public Register16 LoadAddress { get; } = new Register16(0x400);
|
||||
public Register16 StartAddress { get; } = new Register16(0x400);
|
||||
public bool AllowKeyRead { get; } = true;
|
||||
//public string Program { get; } = "6502_functional_test.bin";
|
||||
//public string Symbols { get; } = "6502_functional_test.dbg";
|
||||
//public Register16 InputAddress { get; } = new Register16(0xf004);
|
||||
//public Register16 OutputAddress { get; } = new Register16(0xf001);
|
||||
//public Register16 LoadAddress { get; } = new Register16(0x0);
|
||||
//public Register16 StartAddress { get; } = new Register16(0x400);
|
||||
//public bool AllowKeyRead { get; } = true;
|
||||
//public bool BreakOnKeyRead { get; } = true;
|
||||
|
||||
public int PollingTickInterval { get; } = 10000000;
|
||||
|
||||
|
84
Z80/Z80.cs
84
Z80/Z80.cs
@ -646,80 +646,66 @@ namespace EightBit
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(rp)),
|
||||
};
|
||||
|
||||
private byte R(int r) => r switch
|
||||
{
|
||||
0 => this.B,
|
||||
1 => this.C,
|
||||
2 => this.D,
|
||||
3 => this.E,
|
||||
4 => this.HL2().High,
|
||||
5 => this.HL2().Low,
|
||||
6 => this.MemoryRead(this.displaced ? this.DisplacedAddress : this.HL),
|
||||
7 => this.A,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(r)),
|
||||
};
|
||||
|
||||
private void R(int r, byte value)
|
||||
private ref byte R(int r, AccessLevel access = AccessLevel.ReadOnly)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0:
|
||||
this.B = value;
|
||||
break;
|
||||
return ref this.B;
|
||||
case 1:
|
||||
this.C = value;
|
||||
break;
|
||||
return ref this.C;
|
||||
case 2:
|
||||
this.D = value;
|
||||
break;
|
||||
return ref this.D;
|
||||
case 3:
|
||||
this.E = value;
|
||||
break;
|
||||
return ref this.E;
|
||||
case 4:
|
||||
this.HL2().High = value;
|
||||
break;
|
||||
return ref this.HL2().High;
|
||||
case 5:
|
||||
this.HL2().Low = value;
|
||||
break;
|
||||
return ref this.HL2().Low;
|
||||
case 6:
|
||||
this.MemoryWrite(this.displaced ? this.DisplacedAddress : this.HL, value);
|
||||
break;
|
||||
this.Bus.Address.Assign(this.displaced ? this.DisplacedAddress : this.HL);
|
||||
if (access == AccessLevel.ReadOnly)
|
||||
{
|
||||
MemoryRead();
|
||||
}
|
||||
// Will need a post-MemoryWrite
|
||||
return ref this.Bus.Data;
|
||||
case 7:
|
||||
this.A = value;
|
||||
break;
|
||||
return ref this.A;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(r));
|
||||
}
|
||||
}
|
||||
|
||||
private void R2(int r, byte value)
|
||||
private void R(int r, byte value)
|
||||
{
|
||||
R(r, AccessLevel.WriteOnly) = value;
|
||||
if (r == 6)
|
||||
this.MemoryWrite();
|
||||
}
|
||||
|
||||
private ref byte R2(int r)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0:
|
||||
this.B = value;
|
||||
break;
|
||||
return ref this.B;
|
||||
case 1:
|
||||
this.C = value;
|
||||
break;
|
||||
return ref this.C;
|
||||
case 2:
|
||||
this.D = value;
|
||||
break;
|
||||
return ref this.D;
|
||||
case 3:
|
||||
this.E = value;
|
||||
break;
|
||||
return ref this.E;
|
||||
case 4:
|
||||
this.H = value;
|
||||
break;
|
||||
return ref this.H;
|
||||
case 5:
|
||||
this.L = value;
|
||||
break;
|
||||
return ref this.L;
|
||||
case 6:
|
||||
this.MemoryWrite(this.HL, value);
|
||||
break;
|
||||
// N.B. Write not possible, when r == 6
|
||||
MemoryRead(this.HL);
|
||||
return ref this.Bus.Data;
|
||||
case 7:
|
||||
this.A = value;
|
||||
break;
|
||||
return ref this.A;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(r));
|
||||
}
|
||||
@ -782,7 +768,7 @@ namespace EightBit
|
||||
this.MemoryWrite(operand);
|
||||
if (!memoryZ)
|
||||
{
|
||||
this.R2(z, operand);
|
||||
this.R2(z) = operand;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -809,7 +795,7 @@ namespace EightBit
|
||||
this.ReadPort();
|
||||
if (y != 6)
|
||||
{
|
||||
this.R(y, this.Bus.Data); // IN r[y],(C)
|
||||
this.R(y, AccessLevel.WriteOnly) = this.Bus.Data; // IN r[y],(C)
|
||||
}
|
||||
|
||||
this.F = AdjustSZPXY(this.F, this.Bus.Data);
|
||||
|
Loading…
x
Reference in New Issue
Block a user