Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAP2! #201

Merged
merged 22 commits into from
Jan 21, 2021
Merged

SAP2! #201

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions SAP1EMU.Assembler/InstructionValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static bool IsValidInstruction(string instruction, InstructionSet iset)
}
try
{
return !string.IsNullOrEmpty(iset.instructions.Find(x => x.OpCode.ToLower().Equals(instruction.ToLower())).OpCode);
return !string.IsNullOrEmpty(iset.Instructions.Find(x => x.OpCode.ToLower().Equals(instruction.ToLower())).OpCode);
}
catch (NullReferenceException)
{
Expand All @@ -28,7 +28,7 @@ public static string GetUpperNibble(string instruction, InstructionSet iset)
{
return "0000";
}
return iset.instructions.Find(x => x.OpCode.ToLower().Equals(instruction.ToLower())).BinCode;
return iset.Instructions.Find(x => x.OpCode.ToLower().Equals(instruction.ToLower())).BinCode;
}
}
}
2 changes: 1 addition & 1 deletion SAP1EMU.Engine/EngineProc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void Run()
// Log the Instruction
if (TState == 4)
{
string iname = InstructionSet.instructions.Find(x => x.BinCode.Equals(ireg.ToString())).OpCode;
string iname = InstructionSet.Instructions.Find(x => x.BinCode.Equals(ireg.ToString())).OpCode;
int operandVal = Convert.ToInt32(ireg.ToString_Frame_Use().Substring(4, 4), 2);
string hexOperand = "0x" + operandVal.ToString("X");
// Log.Information($"SAP1Emu: Instruction: {iname}, Operand: {hexOperand}");
Expand Down
54 changes: 48 additions & 6 deletions SAP1EMU.GUI/Controllers/AssemblerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
using Microsoft.AspNetCore.Mvc;

using SAP1EMU.Assembler;
using SAP1EMU.Lib;
using SAP2_Assembler = SAP1EMU.SAP2.Assembler;

using SAP1_Lib = SAP1EMU.Lib;
using SAP2_Lib = SAP1EMU.SAP2.Lib;

using System;
using System.Collections.Generic;
Expand All @@ -16,33 +19,62 @@ namespace SAP1EMU.GUI.Controllers
public class AssemblerController : ControllerBase
{
/// <summary>
/// Gets a list of supported instruction sets
/// Gets a list of supported instruction sets for the specified emulator
/// </summary>
/// <returns>A list of instruction sets</returns>
/// <response code="200">Returns the list</response>
/// <response code="500">List not found. Contact Network Admin</response>
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpGet("supported_sets")]
public ActionResult<IEnumerable<string>> Get()
public IActionResult GetSupportedSets([FromQuery] string emulator)
{
try
{
if (emulator.Equals("SAP1"))
{
return Ok(SAP1_Lib.OpCodeLoader.GetISetNames());
}
else if (emulator.Equals("SAP2"))
{
return Ok(SAP2_Lib.OpCodeLoader.GetISetNames());
}

//Not a set we have trigger that catch block below
throw new Exception();

}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
}

[HttpGet("supported_emulators")]
public IActionResult GetEmulators()
{
try
{
return Ok(OpCodeLoader.GetISetNames());
return Ok(new List<string>() { "SAP1", "SAP2" });

}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e.Message);
}
}


public class AssemblePacket
{
[Required]
public List<string> CodeList { get; set; }

[Required]
public string SetName { get; set; }

[Required]
public string Emulator { get; set; }
}

/// <summary>
Expand All @@ -57,11 +89,21 @@ public class AssemblePacket
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
[HttpPost]
public ActionResult Post([FromBody] AssemblePacket assemblePacket)
public IActionResult Post([FromBody] AssemblePacket assemblePacket)
{
try
{
return Ok(Assemble.Parse(assemblePacket.CodeList, assemblePacket.SetName));
if(assemblePacket.Emulator.Equals("SAP1"))
{
return Ok(Assemble.Parse(assemblePacket.CodeList, assemblePacket.SetName));
}
else if (assemblePacket.Emulator.Equals("SAP2"))
{
return Ok(SAP2_Assembler.Assemble.Parse(assemblePacket.CodeList, assemblePacket.SetName));
}

//Not a set we have trigger that catch block below
throw new Exception();
}
catch (ParseException pe)
{
Expand Down
15 changes: 13 additions & 2 deletions SAP1EMU.GUI/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
using Microsoft.Extensions.Logging;

using SAP1EMU.GUI.Models;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;

namespace SAP1EMU.GUI.Controllers
{
[ApiExplorerSettings(IgnoreApi = true)]
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
Expand All @@ -30,6 +29,18 @@ public IActionResult About()

[HttpGet]
public IActionResult Emulator()
{
return View("EmulatorPicker");
}

[Route("/Emulator/SAP1")]
public IActionResult SAP1()
{
return View();
}

[Route("/Emulator/SAP2")]
public IActionResult SAP2()
{
return View();
}
Expand Down
20 changes: 15 additions & 5 deletions SAP1EMU.GUI/Controllers/SAP2Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
using SAP1EMU.GUI.Hubs;
using SAP1EMU.GUI.Models;
using SAP1EMU.SAP2.Assembler;

using SAP1EMU.SAP2.Lib;
using System;
using System.Linq;

using System.Collections.Generic;
using SAP1EMU.SAP2.Engine;

namespace SAP1EMU.GUI.Controllers
{
Expand All @@ -19,11 +20,13 @@ public class SAP2Controller : Controller
{
private Sap1EmuContext _sap1EmuContext { get; set; }
private readonly IHubContext<EmulatorHub> _hubContext;
private readonly IDecoder _decoder;

public SAP2Controller(Sap1EmuContext sap1EmuContext, IHubContext<EmulatorHub> hubContext)
public SAP2Controller(Sap1EmuContext sap1EmuContext, IHubContext<EmulatorHub> hubContext, IDecoder decoder)
{
_sap1EmuContext = sap1EmuContext;
_hubContext = hubContext;
_decoder = decoder;
}


Expand Down Expand Up @@ -56,7 +59,8 @@ public IActionResult StartEmulation([FromBody] SAP2CodePacket sap2CodePacket)
SAP2BinaryPacket sap2BinaryPacket = new SAP2BinaryPacket()
{
EmulationID = sap2CodePacket.EmulationID,
Code = Assemble.Parse((System.Collections.Generic.List<string>)sap2CodePacket.Code)
Code = Assemble.Parse((List<string>)sap2CodePacket.Code),
SetName = sap2CodePacket.SetName
};

// Save Binary
Expand All @@ -65,7 +69,13 @@ public IActionResult StartEmulation([FromBody] SAP2CodePacket sap2CodePacket)
_sap1EmuContext.SaveChangesAsync(); // Might have to switch to sync

// RunEmulatorAsync
return Ok();
RAMProgram rmp = new RAMProgram((List<string>)sap2CodePacket.Code);

EngineProc engine = new EngineProc();
engine.Init(rmp, _decoder, sap2BinaryPacket.SetName);
engine.Run();

return Ok(engine.FrameStack());
}

[HttpPost("ResumeEmulation")]
Expand Down
6 changes: 3 additions & 3 deletions SAP1EMU.GUI/InstructionSets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"SetName": "SAP1Emu",
"SetDescription": "The full intruction set for the SAP1Emu Project.",
"instructions": [
"Instructions": [
{
"OpCode": "LDA",
"BinCode": "0000",
Expand Down Expand Up @@ -152,7 +152,7 @@
{
"SetName": "Malvino",
"SetDescription": "The instruction set outlined in Digital Computer Electronics by Malvino & Brown.\nThe SAP1Emu Set is a superset of the Malvino Set.",
"instructions": [
"Instructions": [
{
"OpCode": "LDA",
"BinCode": "0000",
Expand Down Expand Up @@ -218,7 +218,7 @@
{
"SetName": "BenEater",
"SetDescription": "The instruction set outlined by Ben Eater.",
"instructions": [
"Instructions": [
{
"OpCode": "NOP",
"BinCode": "0000",
Expand Down
1 change: 1 addition & 0 deletions SAP1EMU.GUI/Models/SAP2BinaryPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class SAP2BinaryPacket
public int Id { get; set; }
public Guid EmulationID { get; set; }
public IEnumerable<string> Code { get; set; }
public string SetName { get; set; }
}
}
1 change: 1 addition & 0 deletions SAP1EMU.GUI/Models/SAP2CodePacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public class SAP2CodePacket
public int Id { get; set; }
public Guid EmulationID { get; set; }
public IEnumerable<string> Code { get; set; }
public string SetName { get; set; }
}
}
6 changes: 6 additions & 0 deletions SAP1EMU.GUI/SAP1EMU.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
<ProjectReference Include="..\SAP1EMU.Engine\SAP1EMU.Engine.csproj" />
<ProjectReference Include="..\SAP1EMU.Lib\SAP1EMU.Lib.csproj" />
<ProjectReference Include="..\SAP1EMU.SAP2.Assembler\SAP1EMU.SAP2.Assembler.csproj" />
<ProjectReference Include="..\SAP1EMU.SAP2.Lib\SAP1EMU.SAP2.Lib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
<ProjectReference Include="..\SAP1EMU.SAP2.Engine\SAP1EMU.SAP2.Engine.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
Expand Down
Loading