mirror of
https://github.com/MoleskiCoder/EightBitNet.git
synced 2025-02-21 00:29:07 +00:00
Optimise Board events
This commit is contained in:
parent
38c4c2972c
commit
a9020ef0f0
@ -17,13 +17,15 @@ namespace M6502.Test
|
|||||||
private readonly Profiler profiler;
|
private readonly Profiler profiler;
|
||||||
private readonly MemoryMapping mapping;
|
private readonly MemoryMapping mapping;
|
||||||
|
|
||||||
private ushort oldPC;
|
private readonly Register16 oldPC = new((ushort)Mask.Sixteen);
|
||||||
private int cyclesPolled;
|
private int cyclesPolled;
|
||||||
|
|
||||||
private char key;
|
private char key;
|
||||||
private bool keyHandled;
|
private bool keyHandled;
|
||||||
private bool keyAvailable;
|
private bool keyAvailable;
|
||||||
|
|
||||||
|
private bool inputting = false;
|
||||||
|
|
||||||
public Board(Configuration configuration)
|
public Board(Configuration configuration)
|
||||||
{
|
{
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
@ -33,8 +35,6 @@ namespace M6502.Test
|
|||||||
this.disassembler = new Disassembler(this, this.CPU, this.symbols);
|
this.disassembler = new Disassembler(this, this.CPU, this.symbols);
|
||||||
this.mapping = new MemoryMapping(this.ram, 0x0000, (ushort)Mask.Sixteen, AccessLevel.ReadWrite);
|
this.mapping = new MemoryMapping(this.ram, 0x0000, (ushort)Mask.Sixteen, AccessLevel.ReadWrite);
|
||||||
|
|
||||||
this.oldPC = (ushort)Mask.Sixteen;
|
|
||||||
|
|
||||||
this.symbols.Parse(string.IsNullOrEmpty(this.configuration.Symbols) ? string.Empty : this.configuration.RomDirectory + "/" + this.configuration.Symbols);
|
this.symbols.Parse(string.IsNullOrEmpty(this.configuration.Symbols) ? string.Empty : this.configuration.RomDirectory + "/" + this.configuration.Symbols);
|
||||||
|
|
||||||
this.profiler = new Profiler(this.CPU, this.disassembler, this.symbols, this.configuration.Profile);
|
this.profiler = new Profiler(this.CPU, this.disassembler, this.symbols, this.configuration.Profile);
|
||||||
@ -77,18 +77,13 @@ namespace M6502.Test
|
|||||||
if (this.configuration.AllowKeyRead)
|
if (this.configuration.AllowKeyRead)
|
||||||
{
|
{
|
||||||
this.CPU.ExecutedInstruction += this.CPU_ExecutedInstruction_Polling;
|
this.CPU.ExecutedInstruction += this.CPU_ExecutedInstruction_Polling;
|
||||||
}
|
|
||||||
|
|
||||||
this.CPU.ExecutedInstruction += this.CPU_ExecutedInstruction;
|
|
||||||
|
|
||||||
this.WrittenByte += this.Bus_WrittenByte;
|
|
||||||
|
|
||||||
if (this.configuration.AllowKeyRead)
|
|
||||||
{
|
|
||||||
this.ReadingByte += this.Bus_ReadingByte;
|
this.ReadingByte += this.Bus_ReadingByte;
|
||||||
this.ReadByte += this.Bus_ReadByte;
|
this.ReadByte += this.Bus_ReadByte;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.CPU.ExecutedInstruction += this.CPU_ExecutedInstruction;
|
||||||
|
this.WrittenByte += this.Bus_WrittenByte;
|
||||||
|
|
||||||
if (this.configuration.Profile)
|
if (this.configuration.Profile)
|
||||||
{
|
{
|
||||||
this.profiler.StartingOutput += this.Profiler_StartingOutput;
|
this.profiler.StartingOutput += this.Profiler_StartingOutput;
|
||||||
@ -109,13 +104,12 @@ namespace M6502.Test
|
|||||||
|
|
||||||
private void Bus_ReadingByte(object? sender, EventArgs e)
|
private void Bus_ReadingByte(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var address = this.Address;
|
this.inputting = this.Address == this.configuration.InputAddress;
|
||||||
if (address == this.configuration.InputAddress)
|
if (this.inputting && this.keyAvailable && !this.keyHandled)
|
||||||
{
|
{
|
||||||
var ready = this.keyAvailable && !this.keyHandled;
|
if (this.Peek(this.Address) == 0)
|
||||||
if (ready && (this.Peek(address) == 0))
|
|
||||||
{
|
{
|
||||||
this.Poke(address, (byte)this.key);
|
this.Poke(this.Address, (byte)this.key);
|
||||||
this.keyHandled = true;
|
this.keyHandled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,8 +117,7 @@ namespace M6502.Test
|
|||||||
|
|
||||||
private void Bus_ReadByte(object? sender, EventArgs e)
|
private void Bus_ReadByte(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var address = this.Address;
|
if (this.inputting)
|
||||||
if (address == this.configuration.InputAddress)
|
|
||||||
{
|
{
|
||||||
if (this.configuration.BreakOnKeyRead)
|
if (this.configuration.BreakOnKeyRead)
|
||||||
{
|
{
|
||||||
@ -134,7 +127,7 @@ namespace M6502.Test
|
|||||||
{
|
{
|
||||||
if (this.keyHandled)
|
if (this.keyHandled)
|
||||||
{
|
{
|
||||||
this.Poke(address, 0);
|
this.Poke(this.Address, 0);
|
||||||
this.keyAvailable = false;
|
this.keyAvailable = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -152,10 +145,10 @@ namespace M6502.Test
|
|||||||
|
|
||||||
private void CPU_ExecutedInstruction(object? sender, EventArgs e)
|
private void CPU_ExecutedInstruction(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var pc = this.CPU.PC.Word;
|
if (this.oldPC != this.CPU.PC)
|
||||||
if (this.oldPC != pc)
|
|
||||||
{
|
{
|
||||||
this.oldPC = pc;
|
this.oldPC.Low = this.CPU.PC.Low;
|
||||||
|
this.oldPC.High = this.CPU.PC.High;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user