Moved execution code to Execute() method

btnStep_Click and btn_Start uses same functionality, moved execution code to an independent function to reduce line duplication
This commit is contained in:
Ferit Yiğit BALABAN
2021-10-30 04:58:00 +03:00
parent 7c227a0a49
commit 587ab5d0c4
+8 -3
View File
@@ -166,9 +166,14 @@ namespace processor
{ {
} }
private string Status = "Stopped"; private CpuStatus _status = CpuStatus.Stopped;
private void btnStep_Click(object sender, EventArgs e) private void btnStep_Click(object sender, EventArgs e)
{
}
private void Execute()
{ {
if (ReadInstRegister()[0] is 12) // Do not run method if instruction is 0xC - halt opcode if (ReadInstRegister()[0] is 12) // Do not run method if instruction is 0xC - halt opcode
{ {
@@ -178,10 +183,10 @@ namespace processor
} }
int counter = ReadCounter(); int counter = ReadCounter();
if (Status is "Running") // This check is useful to determine if the execution has just started or was already running if (_status is CpuStatus.Running) // This check is useful to determine if the execution has just started or was already running
SetCounter(counter + 2); SetCounter(counter + 2);
else SetCounter(counter); else SetCounter(counter);
Status = "Running"; _status = CpuStatus.Running;
int[] fields = ReadInstRegister(); int[] fields = ReadInstRegister();
ResolveOpcode(fields[0], fields[1], fields[2], fields[3]); ResolveOpcode(fields[0], fields[1], fields[2], fields[3]);