mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2026-10-24 14:05:42 +00:00
Some simplifications
This commit is contained in:
1 parent
284158247b
commit
53e33b9eef
4 files changed
+31
-62
No files matched your search
+2
-29
@@ -163,37 +163,16 @@ namespace EightBit
|
||||
|
||||
protected void OnWrittenMemory() => this.WrittenMemory?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
protected void MemoryWrite(byte low, byte high)
|
||||
{
|
||||
this.Bus.Address.Assign(low, high);
|
||||
this.MemoryWrite();
|
||||
}
|
||||
|
||||
protected void MemoryWrite(byte low, byte high, byte data)
|
||||
{
|
||||
this.Bus.Address.Assign(low, high);
|
||||
this.Bus.Data = data;
|
||||
this.MemoryWrite();
|
||||
}
|
||||
|
||||
protected void MemoryWrite(ushort address, byte data)
|
||||
{
|
||||
this.Bus.Address.Word = address;
|
||||
this.Bus.Data = data;
|
||||
this.MemoryWrite();
|
||||
this.MemoryWrite(data);
|
||||
}
|
||||
|
||||
protected void MemoryWrite(Register16 address, byte data)
|
||||
{
|
||||
this.Bus.Address.Assign(address);
|
||||
this.Bus.Data = data;
|
||||
this.MemoryWrite();
|
||||
}
|
||||
|
||||
protected void MemoryWrite(Register16 address)
|
||||
{
|
||||
this.Bus.Address.Assign(address);
|
||||
this.MemoryWrite();
|
||||
this.MemoryWrite(data);
|
||||
}
|
||||
|
||||
protected void MemoryWrite(byte data)
|
||||
@@ -212,12 +191,6 @@ namespace EightBit
|
||||
return this.MemoryRead();
|
||||
}
|
||||
|
||||
protected byte MemoryRead(ushort address)
|
||||
{
|
||||
this.Bus.Address.Word = address;
|
||||
return this.MemoryRead();
|
||||
}
|
||||
|
||||
protected byte MemoryRead(Register16 address)
|
||||
{
|
||||
this.Bus.Address.Assign(address);
|
||||
|
||||
+5
-13
@@ -628,7 +628,7 @@ namespace Intel8080
|
||||
|
||||
private byte Increment(byte operand)
|
||||
{
|
||||
var result = ++operand;
|
||||
var result = operand; ++result;
|
||||
AdjustSZP(result);
|
||||
ClearBit(StatusBits.AC, LowNibble(result));
|
||||
return result;
|
||||
@@ -636,7 +636,7 @@ namespace Intel8080
|
||||
|
||||
private byte Decrement(byte operand)
|
||||
{
|
||||
var result = --operand;
|
||||
var result = operand; --result;
|
||||
AdjustSZP(result);
|
||||
SetBit(StatusBits.AC, LowNibble(result) != (byte)Mask.Four);
|
||||
return result;
|
||||
@@ -657,12 +657,8 @@ namespace Intel8080
|
||||
|
||||
protected sealed override void CallConditional(bool condition)
|
||||
{
|
||||
this.FetchInto(this.MEMPTR);
|
||||
if (condition)
|
||||
{
|
||||
this.Call();
|
||||
}
|
||||
else
|
||||
base.CallConditional(condition);
|
||||
if (!condition)
|
||||
{
|
||||
this.Tick();
|
||||
}
|
||||
@@ -670,12 +666,8 @@ namespace Intel8080
|
||||
|
||||
protected sealed override void ReturnConditionalFlag(int flag)
|
||||
{
|
||||
var condition = this.ConvertCondition(flag);
|
||||
this.Tick();
|
||||
if (condition)
|
||||
{
|
||||
this.Return();
|
||||
}
|
||||
base.ReturnConditionalFlag(flag);
|
||||
}
|
||||
|
||||
private Register16 Add(Register16 operand, Register16 value)
|
||||
|
||||
+14
-8
@@ -5,6 +5,7 @@
|
||||
namespace LR35902
|
||||
{
|
||||
using EightBit;
|
||||
using System.Diagnostics;
|
||||
|
||||
public sealed class LR35902 : IntelProcessor
|
||||
{
|
||||
@@ -336,29 +337,34 @@ namespace LR35902
|
||||
|
||||
private void Start() => this.Stopped = false;
|
||||
|
||||
private void MemoryUpdate(int ticks)
|
||||
private void MemoryUpdate(int ticks = 1)
|
||||
{
|
||||
Debug.Assert(ticks > 0, "Ticks must be greater than zero");
|
||||
this.OnWritingMemory();
|
||||
this.LowerMWR();
|
||||
this.LowerWR();
|
||||
base.MemoryWrite();
|
||||
this.TickMachine(ticks);
|
||||
this.RaiseWR();
|
||||
this.RaiseMWR();
|
||||
this.OnWrittenMemory();
|
||||
}
|
||||
|
||||
protected override void MemoryWrite()
|
||||
{
|
||||
this.MemoryUpdate(1);
|
||||
this.MemoryUpdate();
|
||||
}
|
||||
|
||||
protected override byte MemoryRead()
|
||||
{
|
||||
this.OnReadingMemory();
|
||||
this.LowerMWR();
|
||||
this.LowerRD();
|
||||
_ = base.MemoryRead();
|
||||
this.TickMachine();
|
||||
this.RaiseRD();
|
||||
this.RaiseMWR();
|
||||
this.OnReadMemory();
|
||||
return this.Bus.Data;
|
||||
}
|
||||
|
||||
@@ -863,7 +869,7 @@ namespace LR35902
|
||||
break;
|
||||
case 1: // CB prefix
|
||||
this._prefixCB = true;
|
||||
this.Execute(this.FetchByte());
|
||||
this.Execute(this.FetchInstruction());
|
||||
break;
|
||||
case 6: // DI
|
||||
this.DisableInterrupts();
|
||||
@@ -1063,9 +1069,9 @@ namespace LR35902
|
||||
|
||||
private byte RL(byte operand)
|
||||
{
|
||||
this.F = ClearBit(this.F, StatusBits.NF | StatusBits.HC | StatusBits.ZF);
|
||||
this.ClearBit(StatusBits.NF | StatusBits.HC | StatusBits.ZF);
|
||||
var carry = this.Carry();
|
||||
this.F = SetBit(this.F, StatusBits.CF, operand & (byte)Bits.Bit7);
|
||||
this.SetBit(StatusBits.CF, operand & (byte)Bits.Bit7);
|
||||
return (byte)((operand << 1) | (carry >> 4)); // CF at Bit4
|
||||
}
|
||||
|
||||
@@ -1146,13 +1152,13 @@ namespace LR35902
|
||||
this.SetBit(StatusBits.CF, this.Carry() != 0 || (updated & (int)Bits.Bit8) != 0);
|
||||
this.A = LowByte(updated);
|
||||
|
||||
this.F = AdjustZero(this.F, this.A);
|
||||
this.AdjustZero(this.A);
|
||||
}
|
||||
|
||||
protected override void CPL()
|
||||
{
|
||||
base.CPL();
|
||||
this.F = SetBit(this.F, StatusBits.HC | StatusBits.NF);
|
||||
this.SetBit(StatusBits.HC | StatusBits.NF);
|
||||
}
|
||||
|
||||
private void SCF()
|
||||
@@ -1164,7 +1170,7 @@ namespace LR35902
|
||||
private void CCF()
|
||||
{
|
||||
this.ClearBit(StatusBits.NF | StatusBits.HC);
|
||||
this.ClearBit(StatusBits.CF, this.F & (byte)StatusBits.CF);
|
||||
this.ClearBit(StatusBits.CF, this.Carry());
|
||||
}
|
||||
|
||||
private void RetI()
|
||||
|
||||
+10
-12
@@ -1643,19 +1643,21 @@ namespace Z80
|
||||
private byte Increment(byte operand)
|
||||
{
|
||||
this.ClearBit(StatusBits.NF);
|
||||
this.AdjustSZXY(++operand);
|
||||
this.SetBit(StatusBits.VF, operand == (byte)Bits.Bit7);
|
||||
this.ClearBit(StatusBits.HC, LowNibble(operand));
|
||||
return operand;
|
||||
var result = operand; ++result;
|
||||
this.AdjustSZXY(result);
|
||||
this.SetBit(StatusBits.VF, result == (byte)Bits.Bit7);
|
||||
this.ClearBit(StatusBits.HC, LowNibble(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
private byte Decrement(byte operand)
|
||||
{
|
||||
this.SetBit(StatusBits.NF);
|
||||
this.ClearBit(StatusBits.HC, LowNibble(operand));
|
||||
this.AdjustSZXY(--operand);
|
||||
this.SetBit(StatusBits.VF, operand == (byte)Mask.Seven);
|
||||
return operand;
|
||||
var result = operand; --result;
|
||||
this.AdjustSZXY(result);
|
||||
this.SetBit(StatusBits.VF, result == (byte)Mask.Seven);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void RetN()
|
||||
@@ -1681,12 +1683,8 @@ namespace Z80
|
||||
|
||||
protected sealed override void ReturnConditionalFlag(int flag)
|
||||
{
|
||||
var condition = this.ConvertCondition(flag);
|
||||
this.Tick();
|
||||
if (condition)
|
||||
{
|
||||
this.Return();
|
||||
}
|
||||
base.ReturnConditionalFlag(flag);
|
||||
}
|
||||
|
||||
private Register16 SBC(Register16 operand, Register16 value)
|
||||
|
||||
Reference in new issue
Block a user