Skip to content

Commit

Permalink
Emulator can now load BIN format paper tapes, run and dump tty output…
Browse files Browse the repository at this point in the history
… to console.
  • Loading branch information
sictransit committed Feb 21, 2020
1 parent 3e39ea4 commit 9e73fb8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 42 deletions.
6 changes: 6 additions & 0 deletions Emulator/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
75 changes: 57 additions & 18 deletions Emulator/Program.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -21,24 +25,56 @@ public static void Main(string[] args)
Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>(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)
{
Expand All @@ -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));
}
}
}
24 changes: 0 additions & 24 deletions Emulator/TINT.cs

This file was deleted.

0 comments on commit 9e73fb8

Please sign in to comment.