Skip to content

Commit

Permalink
Merge branch 'refactoring' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jnosek committed Jul 11, 2020
2 parents 193613e + c210794 commit 59716e0
Show file tree
Hide file tree
Showing 67 changed files with 447 additions and 435 deletions.
1 change: 1 addition & 0 deletions AGC.dev/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Apollo.Virtual.AGC;
using Apollo.Virtual.AGC.Math;
using System;

namespace AGC.dev
Expand Down
2 changes: 2 additions & 0 deletions AGC/AGC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>Apollo.Virtual.AGC</RootNamespace>
<AssemblyName>AGC</AssemblyName>
</PropertyGroup>

</Project>
1 change: 0 additions & 1 deletion AGC/Computer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class Computer
{
public MemoryMap Memory;

public Processor CPU;

public Computer()
Expand Down
17 changes: 0 additions & 17 deletions AGC/ExtraCodeInstructionSet.cs

This file was deleted.

24 changes: 24 additions & 0 deletions AGC/ExtraInstructions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Apollo.Virtual.AGC.Instructions;

namespace Apollo.Virtual.AGC
{
static class ExtraInstructions
{
public static InstructionList Build(Processor cpu) =>
new InstructionList(new IInstruction[]
{
new BranchZeroToFixed(cpu),
new QuarterCodeInstructionList(new IQuarterCodeInstruction[] {
new Augment(cpu),
new Diminish(cpu)
}),
new QuarterCodeInstructionList(new IQuarterCodeInstruction[] {
new DoubleClearAndAdd(cpu)
}),
new QuarterCodeInstructionList(new IQuarterCodeInstruction[] {
new DoubleClearAndSubtract(cpu)
}),
new BranchZeroOrMinusToFixed(cpu)
});
}
}
21 changes: 0 additions & 21 deletions AGC/InstructionSet.cs

This file was deleted.

15 changes: 10 additions & 5 deletions AGC/Instructions/Add.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@
/// </summary>
class Add : IInstruction
{
public Processor CPU { get; set; }
public Add(Processor cpu)
{
this.cpu = cpu;
}

private readonly Processor cpu;

public ushort Code { get { return 0x06; } }
public ushort Code => 0x6;

public void Execute(ushort K)
{
var value = CPU.Memory[K];
var value = cpu.Memory[K];

// value in K is re-written
// we do this first for the case of the DOUBLE instruction,
// where K is the A register
CPU.Memory[K] = value;
cpu.Memory[K] = value;

CPU.A.Add(value);
cpu.A.Add(value);
}
}
}
17 changes: 10 additions & 7 deletions AGC/Instructions/AddToStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@
///
/// Adds the accumulator to an eraseable memory location and vice versa
/// </summary>
class AddToStorage : IInstruction
class AddToStorage : IQuarterCodeInstruction
{
public ushort Code
public AddToStorage(Processor cpu)
{
get { return 0x03; }
this.cpu = cpu;
}

public Processor CPU { get; set; }
private readonly Processor cpu;

public ushort Code => 0x2;
public ushort QuarterCode => 0x3;

public void Execute(ushort K)
{
var value = CPU.Memory[K];
CPU.A.Add(value);
var value = cpu.Memory[K];
cpu.A.Add(value);

CPU.Memory[K] = CPU.A.Read();
cpu.Memory[K] = cpu.A.Read();
}
}
}
21 changes: 13 additions & 8 deletions AGC/Instructions/Augment.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
namespace Apollo.Virtual.AGC.Instructions
using Apollo.Virtual.AGC.Math;

namespace Apollo.Virtual.AGC.Instructions
{
/// <summary>
/// AUG - EX 0010 10
/// Increments a positive value in erasable memory by 1
/// Or decrements a negative value in erasable memory by -1
/// </summary>
class Augment: IInstruction
class Augment: IQuarterCodeInstruction
{
public ushort Code
public Augment(Processor cpu)
{
get { return 0x02; }
this.cpu = cpu;
}

public Processor CPU { get; set; }
private readonly Processor cpu;

public ushort Code => 0x2;
public ushort QuarterCode => 0x2;

public void Execute(ushort K)
{
var value = CPU.Memory[K];
var value = cpu.Memory[K];

// if negative
if(value.IsNegative)
{
CPU.Memory[K] = value + OnesCompliment.NegativeOne;
cpu.Memory[K] = value + OnesCompliment.NegativeOne;
}
// if positive
else
{
CPU.Memory[K] = value + OnesCompliment.PositiveOne;
cpu.Memory[K] = value + OnesCompliment.PositiveOne;
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions AGC/Instructions/BranchZeroOrMinusToFixed.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Apollo.Virtual.AGC.Instructions
using Apollo.Virtual.AGC.Math;

namespace Apollo.Virtual.AGC.Instructions
{
/// <summary>
/// BZMF - EX 0110
Expand All @@ -7,20 +9,22 @@
/// </summary>
class BranchZeroOrMinusToFixed : IInstruction
{
public ushort Code
public BranchZeroOrMinusToFixed(Processor cpu)
{
get { return 0x06; }
this.cpu = cpu;
}

public Processor CPU { get; set; }
private readonly Processor cpu;

public ushort Code => 0x6;

public void Execute(ushort K)
{
var value = CPU.A.Read();
var value = cpu.A.Read();

// if +0 or negative, jump
if (value == 0 || (value & 0x8000) > 0)
CPU.Z.Write(new OnesCompliment(K));
cpu.Z.Write(new OnesCompliment(K));
}
}
}
18 changes: 11 additions & 7 deletions AGC/Instructions/BranchZeroToFixed.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Apollo.Virtual.AGC.Instructions
using Apollo.Virtual.AGC.Math;

namespace Apollo.Virtual.AGC.Instructions
{
/// <summary>
/// BZF - EX 0001
Expand All @@ -7,24 +9,26 @@
/// </summary>
class BranchZeroToFixed : IInstruction
{
public ushort Code
public BranchZeroToFixed(Processor cpu)
{
get { return 0x01; }
this.cpu = cpu;
}

public Processor CPU { get; set; }
private readonly Processor cpu;

public ushort Code => 0x1;

public void Execute(ushort K)
{
// if in overflow, no jump
if(CPU.A.IsOverflow)
if(cpu.A.IsOverflow)
return;

var value = CPU.A.Read();
var value = cpu.A.Read();

// if +0 or -0, then jump
if (value == 0 || value == OnesCompliment.NegativeZero)
CPU.Z.Write(new OnesCompliment(K));
cpu.Z.Write(new OnesCompliment(K));
}
}
}
14 changes: 8 additions & 6 deletions AGC/Instructions/ClearAndAdd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,24 @@
/// </summary>
class ClearAndAdd : IInstruction
{
public ushort Code
public ClearAndAdd(Processor cpu)
{
get { return 0x3; }
this.cpu = cpu;
}

public Processor CPU { get; set; }
private readonly Processor cpu;

public ushort Code => 0x3;

public void Execute(ushort K)
{
var value = CPU.Memory[K];
var value = cpu.Memory[K];

// set value in accumulator
CPU.A.Write(value);
cpu.A.Write(value);

// value in K is re-written
CPU.Memory[K] = value;
cpu.Memory[K] = value;
}
}
}
16 changes: 9 additions & 7 deletions AGC/Instructions/ClearAndSubtract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,26 @@
/// </summary>
class ClearAndSubtract : IInstruction
{
public ushort Code
public ClearAndSubtract(Processor cpu)
{
get { return 0x4; }
this.cpu = cpu;
}

public Processor CPU { get; set; }
private readonly Processor cpu;

public ushort Code => 0x4;

public void Execute(ushort K)
{
var value = CPU.Memory[K];
var value = cpu.Memory[K];

// write the compliment to the accumulator
CPU.A.Write(~value);
cpu.A.Write(~value);

// if not the A register, re-write value to K
if (K != CPU.A.Address)
if (K != cpu.A.Address)
{
CPU.Memory[K] = value;
cpu.Memory[K] = value;
}
}
}
Expand Down
Loading

0 comments on commit 59716e0

Please sign in to comment.