From 9e73fb84982f00f90a497daae29c80511b0e4fd1 Mon Sep 17 00:00:00 2001 From: Mikael Fredriksson Date: Fri, 21 Feb 2020 11:20:04 +0100 Subject: [PATCH] Emulator can now load BIN format paper tapes, run and dump tty output to console. --- Emulator/Options.cs | 6 ++++ Emulator/Program.cs | 75 ++++++++++++++++++++++++++++++++++----------- Emulator/TINT.cs | 24 --------------- 3 files changed, 63 insertions(+), 42 deletions(-) delete mode 100644 Emulator/TINT.cs diff --git a/Emulator/Options.cs b/Emulator/Options.cs index 6833fa0..ad92bd7 100644 --- a/Emulator/Options.cs +++ b/Emulator/Options.cs @@ -13,9 +13,15 @@ public class Options [Option(Required = false, HelpText = "PAL assembly file")] public string Assemble { get; set; } + [Option(Required = false, HelpText = "load bin format paper tape")] + public string Load { get; set; } + [Option(Required = false, Default = false, HelpText = "run the assembled file")] public bool Run { get; set; } + [Option(Required = false, Default = false, HelpText = "dump tty output to console")] + public bool TTY { get; set; } + [Option(Required = false, Default = 200, HelpText = "starting address")] public int StartingAddress { get; set; } diff --git a/Emulator/Program.cs b/Emulator/Program.cs index bb3123a..4399827 100644 --- a/Emulator/Program.cs +++ b/Emulator/Program.cs @@ -1,7 +1,9 @@ using CommandLine; using Serilog; using Serilog.Core; +using System; using System.IO; +using System.Net.Http; using System.Threading; namespace Core8 @@ -10,6 +12,8 @@ public static class Program { private static LoggingLevelSwitch loggingLevel = new LoggingLevelSwitch(Serilog.Events.LogEventLevel.Information); + private static PDP pdp; + public static void Main(string[] args) { Log.Logger = new LoggerConfiguration() @@ -21,24 +25,56 @@ public static void Main(string[] args) Parser.Default.ParseArguments(args) .WithParsed(o => { + pdp = new PDP(); + if (o.TINT) { - TINT.Play(); + TINT(); } else if (!string.IsNullOrWhiteSpace(o.Assemble)) { - Assemble(o.PALBART, o.Assemble, o.Run, o.StartingAddress, o.DumpMemory); + if (TryAssemble(o.PALBART, o.Assemble, out var binary) && o.Run) + { + o.Load = binary; + } + } + + if (!string.IsNullOrWhiteSpace(o.Load)) + { + Load(o.Load); + + if (o.Run) + { + Run(o.StartingAddress, o.DumpMemory); + } + } + + if (o.TTY) + { + Console.WriteLine(pdp.CPU.Teletype.Printout); } }); + } + + private static void TINT() + { + pdp.Clear(); + using var httpClient = new HttpClient(); + pdp.LoadPaperTape(httpClient.GetByteArrayAsync(@"https://github.com/PontusPih/TINT8/releases/download/v0.1.0-alpha/tint.bin").Result); + + pdp.Clear(); + + Run(200, false); } - private static void Assemble(string palbart, string file, bool run, int startingAddress, bool dumpMemory) + + private static bool TryAssemble(string palbart, string file, out string binary) { var assembler = new Assembler(palbart); - var assembled = assembler.TryAssemble(file, out var binary); + var assembled = assembler.TryAssemble(file, out binary); if (!assembled) { @@ -47,27 +83,30 @@ private static void Assemble(string palbart, string file, bool run, int starting else { Log.Information($"Assembled: {file} -> {binary}"); + } - if (run) - { - var pdp = new PDP(); + return assembled; + } - pdp.LoadPaperTape(File.ReadAllBytes(binary)); + private static void Run(int startingAddress, bool dumpMemory) + { + pdp.Load8(startingAddress); - pdp.Load8(startingAddress); + if (dumpMemory) + { + pdp.DumpMemory(); + } - if (dumpMemory) - { - pdp.DumpMemory(); - } + //pdp.CPU.Debug(true); - pdp.CPU.Debug(true); + pdp.Continue(waitForHalt: true); - pdp.Continue(waitForHalt: true); + Thread.Sleep(1000); + } - Thread.Sleep(1000); - } - } + private static void Load(string binFile) + { + pdp.LoadPaperTape(File.ReadAllBytes(binFile)); } } } diff --git a/Emulator/TINT.cs b/Emulator/TINT.cs deleted file mode 100644 index d833e51..0000000 --- a/Emulator/TINT.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Net.Http; - -namespace Core8 -{ - public static class TINT - { - public static void Play() - { - var pdp = new PDP(); - - pdp.Clear(); - - using var httpClient = new HttpClient(); - - pdp.LoadPaperTape(httpClient.GetByteArrayAsync(@"https://github.com/PontusPih/TINT8/releases/download/v0.1.0-alpha/tint.bin").Result); - - pdp.Clear(); - - pdp.Load8(0200); - - pdp.Continue(waitForHalt: true); - } - } -}