From e1c90dbe01ee886dd23942ef6c004b2d312dac12 Mon Sep 17 00:00:00 2001 From: Josh Dersch Date: Mon, 9 Nov 2015 17:36:26 -0800 Subject: [PATCH] Fixed bug in carry flag on SUB operations; SUBLZ X,X now works correctly. Alto now appears to boot successfully. Skeleton of Display hardware added. --- Contralto/AltoSystem.cs | 7 +++- Contralto/CPU/ALU.cs | 6 +-- Contralto/CPU/CPU.cs | 1 + Contralto/CPU/MicroInstruction.cs | 16 ++++++++ Contralto/CPU/Shifter.cs | 5 +++ Contralto/CPU/Tasks/DisplayHorizontalTask.cs | 42 ++++++++++++++++++++ Contralto/CPU/Tasks/DisplayWordTask.cs | 42 ++++++++++++++++++++ Contralto/CPU/Tasks/EmulatorTask.cs | 5 ++- Contralto/CPU/Tasks/Task.cs | 17 ++++++-- Contralto/Contralto.csproj | 3 ++ Contralto/Display/DisplayController.cs | 41 +++++++++++++++++++ Contralto/IO/DiskController.cs | 4 +- Contralto/Memory/Memory.cs | 6 ++- 13 files changed, 182 insertions(+), 13 deletions(-) create mode 100644 Contralto/CPU/Tasks/DisplayHorizontalTask.cs create mode 100644 Contralto/CPU/Tasks/DisplayWordTask.cs create mode 100644 Contralto/Display/DisplayController.cs diff --git a/Contralto/AltoSystem.cs b/Contralto/AltoSystem.cs index c64c037..89a8779 100644 --- a/Contralto/AltoSystem.cs +++ b/Contralto/AltoSystem.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Contralto.CPU; using Contralto.IO; using Contralto.Memory; +using Contralto.Display; namespace Contralto { @@ -23,6 +24,7 @@ namespace Contralto _mem = new Memory.Memory(); _keyboard = new Keyboard(); _diskController = new DiskController(this); + _displayController = new DisplayController(this); // Attach memory-mapped devices to the bus _memBus.AddDevice(_mem); @@ -32,7 +34,8 @@ namespace Contralto _clockableDevices = new List(); _clockableDevices.Add(_memBus); _clockableDevices.Add(_diskController); - _clockableDevices.Add(_cpu); + _clockableDevices.Add(_displayController); + _clockableDevices.Add(_cpu); Reset(); } @@ -45,6 +48,7 @@ namespace Contralto ALU.Reset(); Shifter.Reset(); _diskController.Reset(); + _displayController.Reset(); } public void SingleStep() @@ -85,6 +89,7 @@ namespace Contralto private Contralto.Memory.Memory _mem; private Keyboard _keyboard; private DiskController _diskController; + private DisplayController _displayController; private List _clockableDevices; } diff --git a/Contralto/CPU/ALU.cs b/Contralto/CPU/ALU.cs index 1714fb5..6b0125a 100644 --- a/Contralto/CPU/ALU.cs +++ b/Contralto/CPU/ALU.cs @@ -72,7 +72,7 @@ namespace Contralto.CPU // addition (1s complement), a carry out means borrow; thus, // a carry is generated when there is no underflow and no carry // is generated when there is underflow." - _carry = (r <= 0) ? 0 : 1; + _carry = (r < 0) ? 0 : 1; break; case AluFunction.BusPlusT: @@ -82,12 +82,12 @@ namespace Contralto.CPU case AluFunction.BusMinusT: r = bus - t; - _carry = (r <= 0) ? 0 : 1; + _carry = (r < 0) ? 0 : 1; break; case AluFunction.BusMinusTMinus1: r = bus - t - 1; - _carry = (r <= 0) ? 0 : 1; + _carry = (r < 0) ? 0 : 1; break; case AluFunction.BusPlusTPlus1: diff --git a/Contralto/CPU/CPU.cs b/Contralto/CPU/CPU.cs index 6966b28..c85efb6 100644 --- a/Contralto/CPU/CPU.cs +++ b/Contralto/CPU/CPU.cs @@ -31,6 +31,7 @@ namespace Contralto.CPU _tasks[(int)TaskType.Emulator] = new EmulatorTask(this); _tasks[(int)TaskType.DiskSector] = new DiskTask(this, true); _tasks[(int)TaskType.DiskWord] = new DiskTask(this, false); + _tasks[(int)TaskType.DisplayWord] = new DisplayWordTask(this); Reset(); } diff --git a/Contralto/CPU/MicroInstruction.cs b/Contralto/CPU/MicroInstruction.cs index a584f2b..3bfea08 100644 --- a/Contralto/CPU/MicroInstruction.cs +++ b/Contralto/CPU/MicroInstruction.cs @@ -135,6 +135,22 @@ namespace Contralto.CPU ReadKDATA = 4, } + enum DisplayWordF2 + { + LoadDDR = 8, + } + + enum DisplayHorizontalF2 + { + EVENFIELD = 8, + SETMODE = 9, + } + + enum DisplayVerticalF2 + { + EVENFIELD = 8, + } + public class MicroInstruction { public MicroInstruction(UInt32 code) diff --git a/Contralto/CPU/Shifter.cs b/Contralto/CPU/Shifter.cs index 3046717..ce51cf5 100644 --- a/Contralto/CPU/Shifter.cs +++ b/Contralto/CPU/Shifter.cs @@ -143,6 +143,11 @@ namespace Contralto.CPU // "...and places the low order bit of T into the high order bit position // of the shifter output on right shifts." _output |= (ushort)((t & 0x1) << 15); + + if (_count != 1) + { + throw new NotImplementedException("magic LCY 8 not implemented yet."); + } } else if (_dns) { diff --git a/Contralto/CPU/Tasks/DisplayHorizontalTask.cs b/Contralto/CPU/Tasks/DisplayHorizontalTask.cs new file mode 100644 index 0000000..543d77a --- /dev/null +++ b/Contralto/CPU/Tasks/DisplayHorizontalTask.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Contralto.Memory; + +namespace Contralto.CPU +{ + public partial class AltoCPU + { + /// + /// DisplayWordTask provides functionality for the DWT task + /// + private class DisplayHorizontalTask : Task + { + public DisplayHorizontalTask(AltoCPU cpu) : base(cpu) + { + _taskType = TaskType.DisplayHorizontal; + + // The Wakeup signal is always true for the Emulator task. + _wakeup = false; + } + + protected override void ExecuteSpecialFunction2(MicroInstruction instruction) + { + DisplayWordF2 ef2 = (DisplayWordF2)instruction.F2; + switch (ef2) + { + case DisplayWordF2.LoadDDR: + + break; + + default: + throw new InvalidOperationException(String.Format("Unhandled display word F2 {0}.", ef2)); + break; + } + } + } + } +} diff --git a/Contralto/CPU/Tasks/DisplayWordTask.cs b/Contralto/CPU/Tasks/DisplayWordTask.cs new file mode 100644 index 0000000..8f1768d --- /dev/null +++ b/Contralto/CPU/Tasks/DisplayWordTask.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Contralto.Memory; + +namespace Contralto.CPU +{ + public partial class AltoCPU + { + /// + /// DisplayWordTask provides functionality for the DWT task + /// + private class DisplayWordTask : Task + { + public DisplayWordTask(AltoCPU cpu) : base(cpu) + { + _taskType = TaskType.DisplayWord; + + // The Wakeup signal is always true for the Emulator task. + _wakeup = false; + } + + protected override void ExecuteSpecialFunction2(MicroInstruction instruction) + { + DisplayWordF2 ef2 = (DisplayWordF2)instruction.F2; + switch (ef2) + { + case DisplayWordF2.LoadDDR: + + break; + + default: + throw new InvalidOperationException(String.Format("Unhandled display word F2 {0}.", ef2)); + break; + } + } + } + } +} diff --git a/Contralto/CPU/Tasks/EmulatorTask.cs b/Contralto/CPU/Tasks/EmulatorTask.cs index 0646eba..fd562dd 100644 --- a/Contralto/CPU/Tasks/EmulatorTask.cs +++ b/Contralto/CPU/Tasks/EmulatorTask.cs @@ -76,8 +76,9 @@ namespace Contralto.CPU break; case EmulatorF1.STARTF: - // Dispatch function to I/O based on contents of AC0... (TBD: what are these?) - throw new NotImplementedException(); + // Dispatch function to Ethernet I/O based on contents of AC0... (TBD: what are these?) + // For now do nothing, since we have no Ethernet implemented + //throw new NotImplementedException(); break; case EmulatorF1.SWMODE: diff --git a/Contralto/CPU/Tasks/Task.cs b/Contralto/CPU/Tasks/Task.cs index 74d9d0a..35d3145 100644 --- a/Contralto/CPU/Tasks/Task.cs +++ b/Contralto/CPU/Tasks/Task.cs @@ -409,8 +409,16 @@ namespace Contralto.CPU return nextTask; } - protected abstract ushort GetBusSource(int bs); - protected abstract void ExecuteSpecialFunction1(MicroInstruction instruction); + protected virtual ushort GetBusSource(int bs) + { + // Nothing by default. + return 0; + } + + protected virtual void ExecuteSpecialFunction1(MicroInstruction instruction) + { + // Nothing by default + } /// /// Used to allow Task-specific F2s that need to modify RSELECT to do so. @@ -421,7 +429,10 @@ namespace Contralto.CPU // Nothing by default. } - protected abstract void ExecuteSpecialFunction2(MicroInstruction instruction); + protected virtual void ExecuteSpecialFunction2(MicroInstruction instruction) + { + // Nothing by default. + } protected virtual void ExecuteSpecialFunction2Late(MicroInstruction instruction) { diff --git a/Contralto/Contralto.csproj b/Contralto/Contralto.csproj index faacf86..99f9a4c 100644 --- a/Contralto/Contralto.csproj +++ b/Contralto/Contralto.csproj @@ -48,6 +48,8 @@ + + @@ -61,6 +63,7 @@ Debugger.cs + diff --git a/Contralto/Display/DisplayController.cs b/Contralto/Display/DisplayController.cs new file mode 100644 index 0000000..12d9df9 --- /dev/null +++ b/Contralto/Display/DisplayController.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Contralto.Logging; + +namespace Contralto.Display +{ + /// + /// DisplayController implements hardware controlling the virtual electron beam + /// as it scans across the screen. It implements the logic of the display's sync generator + /// and wakes up the DVT and DHT tasks as necessary during a display field. + /// + public class DisplayController : IClockable + { + public DisplayController(AltoSystem system) + { + _system = system; + Reset(); + } + + public void Reset() + { + _evenField = true; + } + + public void Clock() + { + // TODO: Move the electron beam appropriately and wake up the display tasks + // as necessary. + } + + + bool _evenField; + + + private AltoSystem _system; + } +} diff --git a/Contralto/IO/DiskController.cs b/Contralto/IO/DiskController.cs index 60e5fe5..804d851 100644 --- a/Contralto/IO/DiskController.cs +++ b/Contralto/IO/DiskController.cs @@ -368,7 +368,7 @@ namespace Contralto.IO // And figure out how long this will take. _seekClocks = CalculateSeekTime(); _elapsedSeekTime = 0.0; - + Log.Write(LogComponent.DiskController, "Seek to {0} from {1} commencing. Will take {2} clocks.", _destCylinder, _cylinder, _seekClocks); } } @@ -384,7 +384,7 @@ namespace Contralto.IO // double seekTimeMsec = 15.0 + 8.6 * Math.Sqrt(dt); - return seekTimeMsec / AltoSystem.ClockInterval; + return (seekTimeMsec / AltoSystem.ClockInterval) / 100; // div 100 to make things faster for now } /// diff --git a/Contralto/Memory/Memory.cs b/Contralto/Memory/Memory.cs index 7f2bdc0..6434663 100644 --- a/Contralto/Memory/Memory.cs +++ b/Contralto/Memory/Memory.cs @@ -34,10 +34,11 @@ namespace Contralto.Memory address += 0x10000 * GetBankNumber(task, extendedMemory); ushort data = _mem[address]; + /* if (extendedMemory) { Log.Write(LogComponent.Memory, "extended memory read from {0} - {1}", Conversion.ToOctal(address), Conversion.ToOctal(data)); - } + } */ return data; } @@ -59,10 +60,11 @@ namespace Contralto.Memory address += 0x10000 * GetBankNumber(task, extendedMemory); _mem[address] = data; + /* if (extendedMemory) { Log.Write(LogComponent.Memory, "extended memory write to {0} of {1}", Conversion.ToOctal(address), Conversion.ToOctal(data)); - } + } */ } }