From e62b66dd08ca445d1f7e5b802a503ad3ec83b2df Mon Sep 17 00:00:00 2001 From: Melodi <62381002+Melodi17@users.noreply.github.com> Date: Fri, 8 Aug 2025 23:57:26 +1000 Subject: added branching to compiler and comment generation --- Emulator/Chip/Q1Cpu.cs | 12 ++++-------- Emulator/Chip/Q1CpuInstructions.cs | 40 +++++++++++++++++--------------------- Emulator/Chip/RamDevice.cs | 6 +++--- 3 files changed, 25 insertions(+), 33 deletions(-) (limited to 'Emulator/Chip') diff --git a/Emulator/Chip/Q1Cpu.cs b/Emulator/Chip/Q1Cpu.cs index d1fcf7a..16489e4 100644 --- a/Emulator/Chip/Q1Cpu.cs +++ b/Emulator/Chip/Q1Cpu.cs @@ -5,10 +5,6 @@ using Assembler; public partial class Q1Cpu { - public const u16 StackStart = 0x2FFF; - public const u16 StackLength = 16 * 2; // 16 16-bit values - public const u16 ProgramStart = 0x1FFF; - public Random Random; public u16 AX = 0; // Accumulator register @@ -35,10 +31,10 @@ public partial class Q1Cpu this.V = new u16[16]; - this.SP = Q1Cpu.StackStart; + this.SP = Q1Layout.StackStart; this.PushStack(0xFFFF); - this.PC = Q1Cpu.ProgramStart; + this.PC = Q1Layout.ProgramStart; } public void Clock() @@ -88,7 +84,7 @@ public partial class Q1Cpu private void PushStack(u16 value) { - if (this.SP + 2 >= Q1Cpu.StackStart + Q1Cpu.StackLength) + if (this.SP + 2 >= Q1Layout.StackStart + Q1Layout.StackLength) throw new InvalidOperationException("Stack overflow"); this.Bus.WriteWord(this.SP, value); @@ -97,7 +93,7 @@ public partial class Q1Cpu private u16 PopStack() { - if (this.SP - 2 < Q1Cpu.StackStart) + if (this.SP - 2 < Q1Layout.StackStart) throw new InvalidOperationException("Stack underflow"); this.SP -= 2; diff --git a/Emulator/Chip/Q1CpuInstructions.cs b/Emulator/Chip/Q1CpuInstructions.cs index 2da8969..72d78e5 100644 --- a/Emulator/Chip/Q1CpuInstructions.cs +++ b/Emulator/Chip/Q1CpuInstructions.cs @@ -14,8 +14,10 @@ public partial class Q1Cpu { 0x04, ["NOP", "POP", "NOP", "NOP"] }, { 0x10, ["INV", "INV", "NOP", "AND"] }, - { 0x11, ["SHL", "SHL", "NOP", "OR"] }, - { 0x12, ["SHR", "SHR", "NOP", "XOR"] }, + { 0x11, ["NOP", "NOP", "NOP", "OR"] }, + { 0x12, ["NOP", "NOP", "NOP", "XOR"] }, + { 0x13, ["NOP", "NOP", "NOP", "SHL"] }, + { 0x14, ["NOP", "NOP", "NOP", "SHR"] }, { 0x20, ["NOT", "NOT", "NOP", "CMP"] }, { 0x21, ["NOP", "NOP", "NOP", "LT"] }, @@ -40,8 +42,10 @@ public partial class Q1Cpu { 0x04, (this.Instruction_NOP, this.Instruction_POP, this.Instruction_NOP, this.Instruction_NOP) }, { 0x10, (this.Instruction_INV_DX, this.Instruction_INV, this.Instruction_NOP, this.Instruction_AND) }, - { 0x11, (this.Instruction_SHL_DX, this.Instruction_SHL, this.Instruction_NOP, this.Instruction_OR) }, - { 0x12, (this.Instruction_SHR_DX, this.Instruction_SHR, this.Instruction_NOP, this.Instruction_XOR) }, + { 0x11, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_OR) }, + { 0x12, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_XOR) }, + { 0x13, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_SHL) }, + { 0x14, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_SHR) }, { 0x20, (this.Instruction_NOT_LX, this.Instruction_NOT, this.Instruction_NOP, this.Instruction_CMP) }, { 0x21, (this.Instruction_NOP, this.Instruction_NOP, this.Instruction_NOP, this.Instruction_LT) }, @@ -118,27 +122,19 @@ public partial class Q1Cpu { this.AX = (u16) (this.AX - 1); } - private void Instruction_SHL(u8 obj) + private void Instruction_SHL(u8 m1, u8 m2) { - var address = this.Address(obj); - u16 value = address.read(); - u16 result = (u16) (value << 1); - address.write(result); - } - private void Instruction_SHR(u8 obj) - { - var address = this.Address(obj); - u16 value = address.read(); - u16 result = (u16) (value >> 1); - address.write(result); - } - private void Instruction_SHL_DX() - { - this.DX = (u16) (this.DX << 1); + u16 v1 = this.Address(m1).read(); + u16 v2 = this.Address(m1).read(); + u16 shifted = (u16) (v1 << v2); + this.DX = shifted; } - private void Instruction_SHR_DX() + private void Instruction_SHR(u8 m1, u8 m2) { - this.DX = (u16) (this.DX >> 1); + u16 v1 = this.Address(m1).read(); + u16 v2 = this.Address(m1).read(); + u16 shifted = (u16) (v1 >> v2); + this.DX = shifted; } private void Instruction_XOR(u8 m1, u8 m2) { diff --git a/Emulator/Chip/RamDevice.cs b/Emulator/Chip/RamDevice.cs index 8d5b051..a40713a 100644 --- a/Emulator/Chip/RamDevice.cs +++ b/Emulator/Chip/RamDevice.cs @@ -6,14 +6,14 @@ public class RamDevice : BusDevice public RamDevice(u16 start, u16 size) : base(start, (u16) (start + size)) { - this.Memory = new u8[size]; + this.Memory = new u8[size]; } - + public override void Reset() { this.Memory = new u8[this.AddressableEnd - this.AddressableStart]; } - + public override void Clock() { // No clocking needed for RAM -- cgit v1.3.1