Prefer to use events directly, rather than through "On" methods

This commit is contained in:
Adrian Conlon
2025-03-29 11:31:47 +00:00
parent 87abbaa75e
commit b461eb97d6
9 changed files with 92 additions and 108 deletions

View File

@@ -42,9 +42,9 @@ namespace EightBit
public byte Read()
{
this.OnReadingByte();
this.ReadingByte?.Invoke(this, EventArgs.Empty);
var returned = this.Data = this.Reference();
this.OnReadByte();
ReadByte?.Invoke(this, EventArgs.Empty);
return returned;
}
@@ -67,9 +67,9 @@ namespace EightBit
public void Write()
{
this.OnWritingByte();
this.WritingByte?.Invoke(this, EventArgs.Empty);
this.Reference() = this.Data;
this.OnWrittenByte();
this.WrittenByte?.Invoke(this, EventArgs.Empty);
}
public void Write(byte value)
@@ -106,14 +106,6 @@ namespace EightBit
public abstract void Initialize();
protected virtual void OnWritingByte() => WritingByte?.Invoke(this, EventArgs.Empty);
protected virtual void OnWrittenByte() => WrittenByte?.Invoke(this, EventArgs.Empty);
protected virtual void OnReadingByte() => ReadingByte?.Invoke(this, EventArgs.Empty);
protected virtual void OnReadByte() => ReadByte?.Invoke(this, EventArgs.Empty);
protected ref byte Reference(ushort absolute)
{
var mapped = this.Mapping(absolute);

View File

@@ -25,11 +25,9 @@ namespace EightBit
public void Tick()
{
++this.Cycles;
this.OnTicked();
Ticked?.Invoke(this, EventArgs.Empty);
}
protected virtual void OnTicked() => Ticked?.Invoke(this, EventArgs.Empty);
protected void ResetCycles() => this.Cycles = 0;
}
}

View File

@@ -138,22 +138,6 @@ namespace EightBit
}
}
protected virtual void OnRaisingRESET() => RaisingRESET?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedRESET() => RaisedRESET?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweringRESET() => LoweringRESET?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredRESET() => LoweredRESET?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisingINT() => RaisingINT?.Invoke(this, EventArgs.Empty);
protected virtual void OnRaisedINT() => RaisedINT?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweringINT() => LoweringINT?.Invoke(this, EventArgs.Empty);
protected virtual void OnLoweredINT() => LoweredINT?.Invoke(this, EventArgs.Empty);
protected virtual void HandleRESET() => this.RaiseRESET();
protected virtual void HandleINT() => this.RaiseINT();

View File

@@ -42,6 +42,7 @@ namespace LR35902
this.IO = new IoRegisters(this);
this.CPU = new LR35902(this);
this.CPU.MachineTicked += this.CPU_MachineTicked;
this.WrittenByte += this.Bus_WrittenByte;
}
public LR35902 CPU { get; }
@@ -173,10 +174,8 @@ namespace LR35902
return new MemoryMapping(this.highInternalRam, 0xff80, 0xffff, AccessLevel.ReadWrite);
}
protected override void OnWrittenByte()
private void Bus_WrittenByte(object? sender, EventArgs e)
{
base.OnWrittenByte();
var address = this.Address.Word;
var value = this.Data;

View File

@@ -287,70 +287,73 @@ namespace LR35902
private void Bus_WrittenByte(object? sender, EventArgs e)
{
var address = this.bus.Address.Word;
var value = this.bus.Data;
var port = (ushort)(address - BASE);
switch (port)
var page = this.bus.Address.High;
var port = this.bus.Address.Low;
var io = (page == BasePage) && (port < 0x80);
if (io)
{
case P1:
this.scanP14 = (value & (byte)Bits.Bit4) == 0;
this.scanP15 = (value & (byte)Bits.Bit5) == 0;
break;
var value = this.bus.Data;
switch (port)
{
case P1:
this.scanP14 = (value & (byte)Bits.Bit4) == 0;
this.scanP15 = (value & (byte)Bits.Bit5) == 0;
break;
case SB: // R/W
case SC: // R/W
break;
case SB: // R/W
case SC: // R/W
break;
case DIV: // R/W
this.Poke(port, 0);
this.timerCounter = this.divCounter.Word = 0;
break;
case TIMA: // R/W
break;
case TMA: // R/W
break;
case TAC: // R/W
timerRate = this.TimerClockTicks;
break;
case DIV: // R/W
this.Poke(port, 0);
this.timerCounter = this.divCounter.Word = 0;
break;
case TIMA: // R/W
break;
case TMA: // R/W
break;
case TAC: // R/W
timerRate = this.TimerClockTicks;
break;
case IF: // R/W
break;
case IF: // R/W
break;
case LCDC:
case STAT:
case SCY:
case SCX:
break;
case DMA:
this.dmaAddress.Word = Chip.PromoteByte(value);
this.dmaTransferActive = true;
break;
case LY: // R/O
this.Poke(port, 0);
break;
case BGP:
case OBP0:
case OBP1:
case WY:
case WX:
break;
case LCDC:
case STAT:
case SCY:
case SCX:
break;
case DMA:
this.dmaAddress.Word = Chip.PromoteByte(value);
this.dmaTransferActive = true;
break;
case LY: // R/O
this.Poke(port, 0);
break;
case BGP:
case OBP0:
case OBP1:
case WY:
case WX:
break;
case BOOT_DISABLE:
this.BootRomDisabled = value != 0;
break;
default:
break;
case BOOT_DISABLE:
this.BootRomDisabled = value != 0;
break;
default:
break;
}
}
}
private void Bus_ReadingByte(object? sender, EventArgs e)
{
var address = this.bus.Address.Word;
var io = address >= BASE && address < 0xff80;
var page = this.bus.Address.High;
var port = this.bus.Address.Low;
var io = (page == BasePage) && (port < 0x80);
if (io)
{
var port = (ushort)(address - BASE);
switch (port)
{
// Port/Mode Registers

View File

@@ -32,13 +32,10 @@ namespace LR35902.BlarggTest
private void Board_WrittenByte(object? sender, System.EventArgs e)
{
switch (this.Address.Word)
EightBit.Register16 serial = new(IoRegisters.SB, IoRegisters.BasePage);
if (this.Address == serial)
{
case IoRegisters.BASE + IoRegisters.SB:
System.Console.Out.Write(Convert.ToChar(this.Data));
break;
default:
break;
System.Console.Out.Write(Convert.ToChar(this.Data));
}
}

View File

@@ -6,8 +6,16 @@ namespace M6502
{
using EightBit;
public class WDC65C02(Bus bus) : Core(bus)
public class WDC65C02 : Core
{
public WDC65C02(Bus bus)
: base(bus)
{
this.LoweredRESET += this.WDC65C02_LoweredRESET;
this.LoweredINT += this.WDC65C02_LoweredINT;
}
private bool _stopped;
private bool _waiting;
@@ -171,15 +179,13 @@ namespace M6502
}
}
protected override void OnLoweredRESET()
private void WDC65C02_LoweredRESET(object? sender, EventArgs e)
{
base.OnLoweredRESET();
this.Stopped = this.Waiting = false;
}
protected override void OnLoweredINT()
private void WDC65C02_LoweredINT(object? sender, EventArgs e)
{
base.OnLoweredINT();
this.Waiting = false;
}

View File

@@ -48,6 +48,7 @@ namespace EightBit
public MC6809(Bus bus)
: base(bus)
{
this.RaisedPOWER += this.MC6809_RaisedPOWER;
}
public event EventHandler<EventArgs> RaisingNMI;
@@ -342,12 +343,11 @@ namespace EightBit
}
}
protected override void OnRaisedPOWER()
private void MC6809_RaisedPOWER(object? sender, EventArgs e)
{
this.LowerBA();
this.LowerBS();
this.LowerRW();
base.OnRaisedPOWER();
}
protected override void HandleRESET()

View File

@@ -46,6 +46,13 @@ namespace EightBit
// *** Data bit is "don't care" in 7-bit plus parity modes
public sealed class MC6850 : ClockedChip
{
public MC6850()
{
this.RaisedPOWER += this.MC6850_RaisedPOWER;
this.Ticked += this.MC6850_Ticked;
}
private PinLevel rxdataLine = PinLevel.Low;
private PinLevel txdataLine = PinLevel.Low;
@@ -88,17 +95,17 @@ namespace EightBit
private StartupCondition startup = StartupCondition.WarmStart;
public event EventHandler<EventArgs> Accessing;
public event EventHandler<EventArgs>? Accessing;
public event EventHandler<EventArgs> Accessed;
public event EventHandler<EventArgs>? Accessed;
public event EventHandler<EventArgs> Transmitting;
public event EventHandler<EventArgs>? Transmitting;
public event EventHandler<EventArgs> Transmitted;
public event EventHandler<EventArgs>? Transmitted;
public event EventHandler<EventArgs> Receiving;
public event EventHandler<EventArgs>? Receiving;
public event EventHandler<EventArgs> Received;
public event EventHandler<EventArgs>? Received;
[Flags]
public enum ControlRegister
@@ -377,15 +384,13 @@ namespace EightBit
return returned;
}
protected override void OnRaisedPOWER()
private void MC6850_RaisedPOWER(object? sender, EventArgs e)
{
this.startup = StartupCondition.ColdStart;
base.OnRaisedPOWER();
}
protected override void OnTicked()
private void MC6850_Ticked(object? sender, EventArgs e)
{
base.OnTicked();
this.Step();
}