From 47a2ee4b2b655bb2d95a7e492137946d8f189095 Mon Sep 17 00:00:00 2001 From: Josh Dersch Date: Wed, 11 Nov 2015 16:34:44 -0800 Subject: [PATCH] Implemented temporary "fake" display controller which renders Alto DCBs to the screen, bypassing the display microcode. Alto is booting! Rough keyboard implementation. --- Contralto/AltoSystem.cs | 9 + Contralto/CPU/CPU.cs | 16 +- Contralto/CPU/MicroInstruction.cs | 6 + Contralto/CPU/Tasks/CursorTask.cs | 18 +- Contralto/CPU/Tasks/DisplayHorizontalTask.cs | 8 +- Contralto/CPU/Tasks/DisplayVerticalTask.cs | 8 +- Contralto/CPU/Tasks/DisplayWordTask.cs | 7 +- Contralto/Contralto.csproj | 1 + Contralto/Debugger.Designer.cs | 183 ++++++++++--------- Contralto/Debugger.cs | 101 +++++++++- Contralto/Display/DisplayController.cs | 81 ++++---- Contralto/Display/FakeDisplayController.cs | 164 +++++++++++++++++ Contralto/IO/DiskController.cs | 96 ++++++---- Contralto/IO/Keyboard.cs | 180 +++++++++++++++++- Contralto/Memory/MemoryBus.cs | 11 +- 15 files changed, 690 insertions(+), 199 deletions(-) create mode 100644 Contralto/Display/FakeDisplayController.cs diff --git a/Contralto/AltoSystem.cs b/Contralto/AltoSystem.cs index 1226e06..a87b36f 100644 --- a/Contralto/AltoSystem.cs +++ b/Contralto/AltoSystem.cs @@ -25,6 +25,7 @@ namespace Contralto _keyboard = new Keyboard(); _diskController = new DiskController(this); _displayController = new DisplayController(this); + _fakeDisplayController = new FakeDisplayController(this); // Attach memory-mapped devices to the bus _memBus.AddDevice(_mem); @@ -35,6 +36,7 @@ namespace Contralto _clockableDevices.Add(_memBus); _clockableDevices.Add(_diskController); _clockableDevices.Add(_displayController); + _clockableDevices.Add(_fakeDisplayController); _clockableDevices.Add(_cpu); Reset(); @@ -60,6 +62,7 @@ namespace Contralto public void AttachDisplay(Debugger d) { _displayController.AttachDisplay(d); + _fakeDisplayController.AttachDisplay(d); } public void SingleStep() @@ -91,6 +94,11 @@ namespace Contralto get { return _displayController; } } + public Keyboard Keyboard + { + get { return _keyboard; } + } + /// /// Time (in msec) for one system clock /// @@ -106,6 +114,7 @@ namespace Contralto private Keyboard _keyboard; private DiskController _diskController; private DisplayController _displayController; + private FakeDisplayController _fakeDisplayController; private List _clockableDevices; } diff --git a/Contralto/CPU/CPU.cs b/Contralto/CPU/CPU.cs index 70b1da1..51705bd 100644 --- a/Contralto/CPU/CPU.cs +++ b/Contralto/CPU/CPU.cs @@ -33,8 +33,8 @@ namespace Contralto.CPU _tasks[(int)TaskType.DiskWord] = new DiskTask(this, false); //_tasks[(int)TaskType.DisplayWord] = new DisplayWordTask(this); //_tasks[(int)TaskType.DisplayHorizontal] = new DisplayHorizontalTask(this); - //_tasks[(int)TaskType.DisplayVertical] = new DisplayVerticalTask(this); - //_tasks[(int)TaskType.Cursor] = new CursorTask(this); + _tasks[(int)TaskType.DisplayVertical] = new DisplayVerticalTask(this); + _tasks[(int)TaskType.Cursor] = new CursorTask(this); _tasks[(int)TaskType.MemoryRefresh] = new MemoryRefreshTask(this); Reset(); @@ -43,14 +43,14 @@ namespace Contralto.CPU public void Hack() { _tasks[(int)TaskType.DisplayWord] = new DisplayWordTask(this); - _tasks[(int)TaskType.DisplayHorizontal] = new DisplayHorizontalTask(this); - _tasks[(int)TaskType.DisplayVertical] = new DisplayVerticalTask(this); - _tasks[(int)TaskType.Cursor] = new CursorTask(this); + //_tasks[(int)TaskType.DisplayHorizontal] = new DisplayHorizontalTask(this); + //_tasks[(int)TaskType.DisplayVertical] = new DisplayVerticalTask(this); + //_tasks[(int)TaskType.Cursor] = new CursorTask(this); _tasks[(int)TaskType.DisplayWord].Reset(); - _tasks[(int)TaskType.DisplayHorizontal].Reset(); - _tasks[(int)TaskType.DisplayVertical].Reset(); - _tasks[(int)TaskType.Cursor].Reset(); + //_tasks[(int)TaskType.DisplayHorizontal].Reset(); + //_tasks[(int)TaskType.DisplayVertical].Reset(); + //_tasks[(int)TaskType.Cursor].Reset(); } public Task[] Tasks diff --git a/Contralto/CPU/MicroInstruction.cs b/Contralto/CPU/MicroInstruction.cs index 3bfea08..0e98985 100644 --- a/Contralto/CPU/MicroInstruction.cs +++ b/Contralto/CPU/MicroInstruction.cs @@ -151,6 +151,12 @@ namespace Contralto.CPU EVENFIELD = 8, } + enum CursorF2 + { + LoadXPREG = 8, + LoadCSR = 9, + } + public class MicroInstruction { public MicroInstruction(UInt32 code) diff --git a/Contralto/CPU/Tasks/CursorTask.cs b/Contralto/CPU/Tasks/CursorTask.cs index b5bcae7..c7e6f16 100644 --- a/Contralto/CPU/Tasks/CursorTask.cs +++ b/Contralto/CPU/Tasks/CursorTask.cs @@ -4,8 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Contralto.Memory; - namespace Contralto.CPU { public partial class AltoCPU @@ -17,23 +15,25 @@ namespace Contralto.CPU { public CursorTask(AltoCPU cpu) : base(cpu) { - _taskType = TaskType.DisplayWord; - - // The Wakeup signal is always true for the Emulator task. + _taskType = TaskType.Cursor; _wakeup = false; } protected override void ExecuteSpecialFunction2(MicroInstruction instruction) { - DisplayWordF2 ef2 = (DisplayWordF2)instruction.F2; - switch (ef2) + CursorF2 cf2 = (CursorF2)instruction.F2; + switch (cf2) { - case DisplayWordF2.LoadDDR: + case CursorF2.LoadXPREG: + // TODO: load cursor X-position register from bus + break; + case CursorF2.LoadCSR: + // TODO: load cursor shift register from bus break; default: - throw new InvalidOperationException(String.Format("Unhandled display word F2 {0}.", ef2)); + throw new InvalidOperationException(String.Format("Unhandled cursor F2 {0}.", cf2)); break; } } diff --git a/Contralto/CPU/Tasks/DisplayHorizontalTask.cs b/Contralto/CPU/Tasks/DisplayHorizontalTask.cs index 4905a32..4c5059f 100644 --- a/Contralto/CPU/Tasks/DisplayHorizontalTask.cs +++ b/Contralto/CPU/Tasks/DisplayHorizontalTask.cs @@ -4,8 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Contralto.Memory; - namespace Contralto.CPU { public partial class AltoCPU @@ -23,8 +21,8 @@ namespace Contralto.CPU protected override void ExecuteSpecialFunction2(MicroInstruction instruction) { - DisplayHorizontalF2 ef2 = (DisplayHorizontalF2)instruction.F2; - switch (ef2) + DisplayHorizontalF2 dh2 = (DisplayHorizontalF2)instruction.F2; + switch (dh2) { case DisplayHorizontalF2.EVENFIELD: _nextModifier |= (ushort)(_cpu._system.DisplayController.EVENFIELD ? 1 : 0); @@ -35,7 +33,7 @@ namespace Contralto.CPU break; default: - throw new InvalidOperationException(String.Format("Unhandled display word F2 {0}.", ef2)); + throw new InvalidOperationException(String.Format("Unhandled display word F2 {0}.", dh2)); break; } } diff --git a/Contralto/CPU/Tasks/DisplayVerticalTask.cs b/Contralto/CPU/Tasks/DisplayVerticalTask.cs index 5c48279..07a6c3b 100644 --- a/Contralto/CPU/Tasks/DisplayVerticalTask.cs +++ b/Contralto/CPU/Tasks/DisplayVerticalTask.cs @@ -4,8 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Contralto.Memory; - namespace Contralto.CPU { public partial class AltoCPU @@ -31,15 +29,15 @@ namespace Contralto.CPU protected override void ExecuteSpecialFunction2(MicroInstruction instruction) { - DisplayVerticalF2 ef2 = (DisplayVerticalF2)instruction.F2; - switch (ef2) + DisplayVerticalF2 dv2 = (DisplayVerticalF2)instruction.F2; + switch (dv2) { case DisplayVerticalF2.EVENFIELD: _nextModifier |= (ushort)(_cpu._system.DisplayController.EVENFIELD ? 1 : 0); break; default: - throw new InvalidOperationException(String.Format("Unhandled display vertical F2 {0}.", ef2)); + throw new InvalidOperationException(String.Format("Unhandled display vertical F2 {0}.", dv2)); break; } } diff --git a/Contralto/CPU/Tasks/DisplayWordTask.cs b/Contralto/CPU/Tasks/DisplayWordTask.cs index d2bf2b0..326edfb 100644 --- a/Contralto/CPU/Tasks/DisplayWordTask.cs +++ b/Contralto/CPU/Tasks/DisplayWordTask.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -using Contralto.Memory; namespace Contralto.CPU { @@ -23,15 +22,15 @@ namespace Contralto.CPU protected override void ExecuteSpecialFunction2(MicroInstruction instruction) { - DisplayWordF2 ef2 = (DisplayWordF2)instruction.F2; - switch (ef2) + DisplayWordF2 dw2 = (DisplayWordF2)instruction.F2; + switch (dw2) { case DisplayWordF2.LoadDDR: _cpu._system.DisplayController.LoadDDR(_busData); break; default: - throw new InvalidOperationException(String.Format("Unhandled display word F2 {0}.", ef2)); + throw new InvalidOperationException(String.Format("Unhandled display word F2 {0}.", dw2)); break; } } diff --git a/Contralto/Contralto.csproj b/Contralto/Contralto.csproj index 7e61926..3acd376 100644 --- a/Contralto/Contralto.csproj +++ b/Contralto/Contralto.csproj @@ -66,6 +66,7 @@ Debugger.cs + diff --git a/Contralto/Debugger.Designer.cs b/Contralto/Debugger.Designer.cs index ba51e8c..74e68b0 100644 --- a/Contralto/Debugger.Designer.cs +++ b/Contralto/Debugger.Designer.cs @@ -28,21 +28,21 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle16 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle20 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle17 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle18 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle19 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle21 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle22 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle23 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle24 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle25 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle26 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle27 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle28 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle29 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle30 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle31 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle35 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle32 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle33 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle34 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle36 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle37 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle38 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle39 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle40 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle41 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle42 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle43 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle44 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle45 = new System.Windows.Forms.DataGridViewCellStyle(); this.Microcode = new System.Windows.Forms.GroupBox(); this.label2 = new System.Windows.Forms.Label(); this.JumpToAddress = new System.Windows.Forms.TextBox(); @@ -130,6 +130,7 @@ this.JumpToAddress.Name = "JumpToAddress"; this.JumpToAddress.Size = new System.Drawing.Size(48, 20); this.JumpToAddress.TabIndex = 12; + this.JumpToAddress.TabStop = false; this.JumpToAddress.KeyDown += new System.Windows.Forms.KeyEventHandler(this.OnJumpAddressKeyDown); // // _sourceViewer @@ -138,8 +139,8 @@ this._sourceViewer.AllowUserToDeleteRows = false; this._sourceViewer.AllowUserToResizeColumns = false; this._sourceViewer.AllowUserToResizeRows = false; - dataGridViewCellStyle16.BackColor = System.Drawing.Color.Silver; - this._sourceViewer.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle16; + dataGridViewCellStyle31.BackColor = System.Drawing.Color.Silver; + this._sourceViewer.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle31; this._sourceViewer.CellBorderStyle = System.Windows.Forms.DataGridViewCellBorderStyle.SingleVertical; this._sourceViewer.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this._sourceViewer.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { @@ -152,14 +153,14 @@ this._sourceViewer.Name = "_sourceViewer"; this._sourceViewer.ReadOnly = true; this._sourceViewer.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single; - dataGridViewCellStyle20.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle20.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle20.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle20.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle20.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle20.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle20.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this._sourceViewer.RowHeadersDefaultCellStyle = dataGridViewCellStyle20; + dataGridViewCellStyle35.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle35.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle35.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle35.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle35.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle35.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle35.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this._sourceViewer.RowHeadersDefaultCellStyle = dataGridViewCellStyle35; this._sourceViewer.RowHeadersVisible = false; this._sourceViewer.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.DisableResizing; this._sourceViewer.RowTemplate.Height = 18; @@ -169,6 +170,7 @@ this._sourceViewer.ShowRowErrors = false; this._sourceViewer.Size = new System.Drawing.Size(584, 571); this._sourceViewer.TabIndex = 1; + this._sourceViewer.TabStop = false; this._sourceViewer.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.SourceViewCellClick); // // Breakpoint @@ -187,9 +189,9 @@ // T // this.T.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; - dataGridViewCellStyle17.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle17.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.T.DefaultCellStyle = dataGridViewCellStyle17; + dataGridViewCellStyle32.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle32.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.T.DefaultCellStyle = dataGridViewCellStyle32; this.T.HeaderText = "T"; this.T.Name = "T"; this.T.ReadOnly = true; @@ -200,8 +202,8 @@ // Addr // this.Addr.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.AllCellsExceptHeader; - dataGridViewCellStyle18.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Addr.DefaultCellStyle = dataGridViewCellStyle18; + dataGridViewCellStyle33.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Addr.DefaultCellStyle = dataGridViewCellStyle33; this.Addr.HeaderText = "Addr"; this.Addr.Name = "Addr"; this.Addr.ReadOnly = true; @@ -212,8 +214,8 @@ // Source // this.Source.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; - dataGridViewCellStyle19.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.Source.DefaultCellStyle = dataGridViewCellStyle19; + dataGridViewCellStyle34.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.Source.DefaultCellStyle = dataGridViewCellStyle34; this.Source.HeaderText = "Source Code"; this.Source.Name = "Source"; this.Source.ReadOnly = true; @@ -236,21 +238,21 @@ this._registerData.AllowUserToDeleteRows = false; this._registerData.AllowUserToResizeColumns = false; this._registerData.AllowUserToResizeRows = false; - dataGridViewCellStyle21.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); - this._registerData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle21; + dataGridViewCellStyle36.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); + this._registerData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle36; this._registerData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this._registerData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.RegNum, this.R, this.S}); - dataGridViewCellStyle22.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle22.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle22.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle22.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle22.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle22.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle22.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this._registerData.DefaultCellStyle = dataGridViewCellStyle22; + dataGridViewCellStyle37.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle37.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle37.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle37.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle37.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle37.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle37.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this._registerData.DefaultCellStyle = dataGridViewCellStyle37; this._registerData.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this._registerData.Location = new System.Drawing.Point(7, 19); this._registerData.MultiSelect = false; @@ -267,6 +269,7 @@ this._registerData.ShowRowErrors = false; this._registerData.Size = new System.Drawing.Size(123, 600); this._registerData.TabIndex = 0; + this._registerData.TabStop = false; // // RegNum // @@ -303,6 +306,7 @@ this.StepButton.Name = "StepButton"; this.StepButton.Size = new System.Drawing.Size(44, 23); this.StepButton.TabIndex = 3; + this.StepButton.TabStop = false; this.StepButton.Text = "Step"; this.StepButton.UseVisualStyleBackColor = true; this.StepButton.Click += new System.EventHandler(this.OnStepButtonClicked); @@ -313,6 +317,7 @@ this.AutoStep.Name = "AutoStep"; this.AutoStep.Size = new System.Drawing.Size(47, 23); this.AutoStep.TabIndex = 4; + this.AutoStep.TabStop = false; this.AutoStep.Text = "Auto"; this.AutoStep.UseVisualStyleBackColor = true; this.AutoStep.Click += new System.EventHandler(this.OnAutoStepButtonClicked); @@ -323,6 +328,7 @@ this.RunButton.Name = "RunButton"; this.RunButton.Size = new System.Drawing.Size(41, 23); this.RunButton.TabIndex = 5; + this.RunButton.TabStop = false; this.RunButton.Text = "Run"; this.RunButton.UseVisualStyleBackColor = true; this.RunButton.Click += new System.EventHandler(this.RunButton_Click); @@ -333,6 +339,7 @@ this.StopButton.Name = "StopButton"; this.StopButton.Size = new System.Drawing.Size(43, 23); this.StopButton.TabIndex = 6; + this.StopButton.TabStop = false; this.StopButton.Text = "Stop"; this.StopButton.UseVisualStyleBackColor = true; this.StopButton.Click += new System.EventHandler(this.OnStopButtonClicked); @@ -351,21 +358,21 @@ // this._taskData.AllowUserToAddRows = false; this._taskData.AllowUserToDeleteRows = false; - dataGridViewCellStyle23.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); - this._taskData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle23; + dataGridViewCellStyle38.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); + this._taskData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle38; this._taskData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this._taskData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.TaskName, this.TaskState, this.TaskPC}); - dataGridViewCellStyle24.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle24.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle24.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle24.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle24.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle24.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle24.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this._taskData.DefaultCellStyle = dataGridViewCellStyle24; + dataGridViewCellStyle39.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle39.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle39.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle39.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle39.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle39.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle39.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this._taskData.DefaultCellStyle = dataGridViewCellStyle39; this._taskData.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this._taskData.Location = new System.Drawing.Point(7, 19); this._taskData.MultiSelect = false; @@ -381,6 +388,7 @@ this._taskData.ShowRowErrors = false; this._taskData.Size = new System.Drawing.Size(123, 319); this._taskData.TabIndex = 0; + this._taskData.TabStop = false; // // TaskName // @@ -421,20 +429,20 @@ // this._otherRegs.AllowUserToAddRows = false; this._otherRegs.AllowUserToDeleteRows = false; - dataGridViewCellStyle25.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); - this._otherRegs.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle25; + dataGridViewCellStyle40.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); + this._otherRegs.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle40; this._otherRegs.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this._otherRegs.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Reg, this.RegValue}); - dataGridViewCellStyle26.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle26.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle26.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle26.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle26.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle26.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle26.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this._otherRegs.DefaultCellStyle = dataGridViewCellStyle26; + dataGridViewCellStyle41.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle41.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle41.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle41.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle41.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle41.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle41.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this._otherRegs.DefaultCellStyle = dataGridViewCellStyle41; this._otherRegs.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this._otherRegs.Location = new System.Drawing.Point(7, 19); this._otherRegs.MultiSelect = false; @@ -487,8 +495,8 @@ this._memoryData.AllowUserToAddRows = false; this._memoryData.AllowUserToDeleteRows = false; this._memoryData.AllowUserToResizeRows = false; - dataGridViewCellStyle27.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); - this._memoryData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle27; + dataGridViewCellStyle42.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); + this._memoryData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle42; this._memoryData.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText; this._memoryData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this._memoryData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { @@ -496,14 +504,14 @@ this.Address, this.Data, this.Disassembly}); - dataGridViewCellStyle28.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle28.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle28.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle28.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle28.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle28.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle28.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this._memoryData.DefaultCellStyle = dataGridViewCellStyle28; + dataGridViewCellStyle43.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle43.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle43.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle43.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle43.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle43.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle43.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this._memoryData.DefaultCellStyle = dataGridViewCellStyle43; this._memoryData.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this._memoryData.Location = new System.Drawing.Point(6, 19); this._memoryData.MultiSelect = false; @@ -520,6 +528,7 @@ this._memoryData.ShowRowErrors = false; this._memoryData.Size = new System.Drawing.Size(279, 273); this._memoryData.TabIndex = 0; + this._memoryData.TabStop = false; this._memoryData.VirtualMode = true; this._memoryData.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.MemoryViewCellClick); this._memoryData.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnMemoryCellValueNeeded); @@ -556,20 +565,20 @@ // this._diskData.AllowUserToAddRows = false; this._diskData.AllowUserToDeleteRows = false; - dataGridViewCellStyle29.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); - this._diskData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle29; + dataGridViewCellStyle44.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(224)))), ((int)(((byte)(224)))), ((int)(((byte)(224))))); + this._diskData.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle44; this._diskData.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this._diskData.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridViewTextBoxColumn1, this.dataGridViewTextBoxColumn2}); - dataGridViewCellStyle30.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle30.BackColor = System.Drawing.SystemColors.Window; - dataGridViewCellStyle30.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - dataGridViewCellStyle30.ForeColor = System.Drawing.SystemColors.ControlText; - dataGridViewCellStyle30.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle30.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle30.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this._diskData.DefaultCellStyle = dataGridViewCellStyle30; + dataGridViewCellStyle45.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle45.BackColor = System.Drawing.SystemColors.Window; + dataGridViewCellStyle45.Font = new System.Drawing.Font("Consolas", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + dataGridViewCellStyle45.ForeColor = System.Drawing.SystemColors.ControlText; + dataGridViewCellStyle45.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle45.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle45.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this._diskData.DefaultCellStyle = dataGridViewCellStyle45; this._diskData.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this._diskData.Location = new System.Drawing.Point(6, 19); this._diskData.MultiSelect = false; @@ -585,6 +594,7 @@ this._diskData.ShowRowErrors = false; this._diskData.Size = new System.Drawing.Size(147, 273); this._diskData.TabIndex = 1; + this._diskData.TabStop = false; // // dataGridViewTextBoxColumn1 // @@ -609,6 +619,7 @@ this.ResetButton.Name = "ResetButton"; this.ResetButton.Size = new System.Drawing.Size(57, 23); this.ResetButton.TabIndex = 12; + this.ResetButton.TabStop = false; this.ResetButton.Text = "Reset"; this.ResetButton.UseVisualStyleBackColor = true; this.ResetButton.Click += new System.EventHandler(this.ResetButton_Click); @@ -619,6 +630,7 @@ this.RunToNextTaskButton.Name = "RunToNextTaskButton"; this.RunToNextTaskButton.Size = new System.Drawing.Size(51, 23); this.RunToNextTaskButton.TabIndex = 13; + this.RunToNextTaskButton.TabStop = false; this.RunToNextTaskButton.Text = "Run T"; this.RunToNextTaskButton.UseVisualStyleBackColor = true; this.RunToNextTaskButton.Click += new System.EventHandler(this.RunToNextTaskButton_Click); @@ -629,6 +641,7 @@ this.NovaStep.Name = "NovaStep"; this.NovaStep.Size = new System.Drawing.Size(66, 23); this.NovaStep.TabIndex = 14; + this.NovaStep.TabStop = false; this.NovaStep.Text = "Nova Step"; this.NovaStep.UseVisualStyleBackColor = true; this.NovaStep.Click += new System.EventHandler(this.NovaStep_Click); @@ -694,6 +707,7 @@ this.DisplayBox.Size = new System.Drawing.Size(606, 808); this.DisplayBox.TabIndex = 0; this.DisplayBox.TabStop = false; + this.DisplayBox.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.DisplayBox_PreviewKeyDown); // // button1 // @@ -701,6 +715,7 @@ this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; + this.button1.TabStop = false; this.button1.Text = "HACK"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); @@ -727,9 +742,13 @@ this.Controls.Add(this.StepButton); this.Controls.Add(this.groupBox1); this.Controls.Add(this.Microcode); + this.KeyPreview = true; this.Name = "Debugger"; this.Text = "Debugger"; this.Load += new System.EventHandler(this.Debugger_Load); + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Debugger_KeyDown); + this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Debugger_KeyUp); + this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.Debugger_PreviewKeyDown); this.Microcode.ResumeLayout(false); this.Microcode.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this._sourceViewer)).EndInit(); diff --git a/Contralto/Debugger.cs b/Contralto/Debugger.cs index e8bf5a2..8be6d98 100644 --- a/Contralto/Debugger.cs +++ b/Contralto/Debugger.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using Contralto.CPU; using System.Threading; using System.Drawing.Imaging; +using Contralto.IO; namespace Contralto { @@ -27,7 +28,8 @@ namespace Contralto InitializeComponent(); InitControls(); - RefreshUI(); + InitKeymap(); + RefreshUI(); } public void LoadSourceCode(string path) @@ -773,6 +775,98 @@ namespace Contralto } + // Hacky initial implementation of keyboard input. + private void Debugger_KeyDown(object sender, KeyEventArgs e) + { + e.SuppressKeyPress = true; + if (_keyMap.ContainsKey(e.KeyCode)) + { + _system.Keyboard.KeyDown(_keyMap[e.KeyCode]); + } + } + + private void DisplayBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) + { + + } + + private void Debugger_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) + { + if (_keyMap.ContainsKey(e.KeyCode)) + { + _system.Keyboard.KeyDown(_keyMap[e.KeyCode]); + } + } + + private void Debugger_KeyUp(object sender, KeyEventArgs e) + { + if (_keyMap.ContainsKey(e.KeyCode)) + { + _system.Keyboard.KeyUp(_keyMap[e.KeyCode]); + } + + e.SuppressKeyPress = true; + } + + private void InitKeymap() + { + _keyMap = new Dictionary(); + + _keyMap.Add(Keys.A, AltoKey.A); + _keyMap.Add(Keys.B, AltoKey.B); + _keyMap.Add(Keys.C, AltoKey.C); + _keyMap.Add(Keys.D, AltoKey.D); + _keyMap.Add(Keys.E, AltoKey.E); + _keyMap.Add(Keys.F, AltoKey.F); + _keyMap.Add(Keys.G, AltoKey.G); + _keyMap.Add(Keys.H, AltoKey.H); + _keyMap.Add(Keys.I, AltoKey.I); + _keyMap.Add(Keys.J, AltoKey.J); + _keyMap.Add(Keys.K, AltoKey.K); + _keyMap.Add(Keys.L, AltoKey.L); + _keyMap.Add(Keys.M, AltoKey.M); + _keyMap.Add(Keys.N, AltoKey.N); + _keyMap.Add(Keys.O, AltoKey.O); + _keyMap.Add(Keys.P, AltoKey.P); + _keyMap.Add(Keys.Q, AltoKey.Q); + _keyMap.Add(Keys.R, AltoKey.R); + _keyMap.Add(Keys.S, AltoKey.S); + _keyMap.Add(Keys.T, AltoKey.T); + _keyMap.Add(Keys.U, AltoKey.U); + _keyMap.Add(Keys.V, AltoKey.V); + _keyMap.Add(Keys.W, AltoKey.W); + _keyMap.Add(Keys.X, AltoKey.X); + _keyMap.Add(Keys.Y, AltoKey.Y); + _keyMap.Add(Keys.Z, AltoKey.Z); + _keyMap.Add(Keys.D0, AltoKey.D0); + _keyMap.Add(Keys.D1, AltoKey.D1); + _keyMap.Add(Keys.D2, AltoKey.D2); + _keyMap.Add(Keys.D3, AltoKey.D3); + _keyMap.Add(Keys.D4, AltoKey.D4); + _keyMap.Add(Keys.D5, AltoKey.D5); + _keyMap.Add(Keys.D6, AltoKey.D6); + _keyMap.Add(Keys.D7, AltoKey.D7); + _keyMap.Add(Keys.D8, AltoKey.D8); + _keyMap.Add(Keys.D9, AltoKey.D9); + _keyMap.Add(Keys.Space, AltoKey.Space); + _keyMap.Add(Keys.OemPeriod, AltoKey.Period); + _keyMap.Add(Keys.Oemcomma, AltoKey.Comma); + _keyMap.Add(Keys.OemQuotes, AltoKey.Quote); + _keyMap.Add(Keys.OemBackslash, AltoKey.BSlash); + _keyMap.Add(Keys.OemQuestion, AltoKey.FSlash); + _keyMap.Add(Keys.Oemplus, AltoKey.Plus); + _keyMap.Add(Keys.OemMinus, AltoKey.Minus); + _keyMap.Add(Keys.Escape, AltoKey.ESC); + _keyMap.Add(Keys.Delete, AltoKey.DEL); + _keyMap.Add(Keys.Left, AltoKey.Arrow); + _keyMap.Add(Keys.LShiftKey, AltoKey.LShift); + _keyMap.Add(Keys.RShiftKey, AltoKey.RShift); + _keyMap.Add(Keys.ControlKey, AltoKey.CTRL); + + + } + + private enum ExecutionType { None = 0, @@ -821,9 +915,14 @@ namespace Contralto private Bitmap _displayBuffer; private Rectangle _displayRect = new Rectangle(0, 0, 608, 808); + // Keyboard mapping from windows vkeys to Alto keys + private Dictionary _keyMap; + private void button1_Click(object sender, EventArgs e) { _system.CPU.Hack(); } + + } } diff --git a/Contralto/Display/DisplayController.cs b/Contralto/Display/DisplayController.cs index cd3d671..c7340cb 100644 --- a/Contralto/Display/DisplayController.cs +++ b/Contralto/Display/DisplayController.cs @@ -84,6 +84,28 @@ namespace Contralto.Display _clocks++; _totalClocks++; + // + // "If the DWT has not executed a BLOCK, if DHT is not blocked, and if the + // buffer is not full, DWT wakeups are generated." + // + if (_dataBuffer.Count < 16 && + !_system.CPU.IsBlocked(TaskType.DisplayHorizontal) && + !_dwtBlocked) + { + //Console.WriteLine("DWT wakeup, {0}", _dataBuffer.Count); + _system.CPU.WakeupTask(TaskType.DisplayWord); + } + else + { + // We can't take any words right now, remove Wakeup from + // the DWT. + if (_dataBuffer.Count >= 16) + { + //Log.Write(LogComponent.Display, "buffer full, blocking DWT."); + } + _system.CPU.BlockTask(TaskType.DisplayWord); + } + switch (_state) { case DisplayState.VerticalBlank: @@ -98,44 +120,17 @@ namespace Contralto.Display // Wake up DVT, DHT _dwtBlocked = false; - _dhtBlocked = false; - _system.CPU.WakeupTask(TaskType.DisplayVertical); + _dhtBlocked = false; _system.CPU.WakeupTask(TaskType.DisplayHorizontal); - _system.CPU.BlockTask(TaskType.DisplayWord); - - // Run MRT - _system.CPU.WakeupTask(TaskType.MemoryRefresh); - - // TODO: clear DWT, DHT block flip-flop - _state = DisplayState.VisibleScanline; + _system.CPU.BlockTask(TaskType.DisplayWord); + + _state = DisplayState.HorizontalBlank; //Console.WriteLine("Frame"); } break; - case DisplayState.VisibleScanline: - // - // "If the DWT has not executed a BLOCK, if DHT is not blocked, and if the - // buffer is not full, DWT wakeups are generated." - // - if (_dataBuffer.Count < 16 && - !_system.CPU.IsBlocked(TaskType.DisplayHorizontal) && - !_dwtBlocked) - { - //Console.WriteLine("DWT wakeup, {0}", _dataBuffer.Count); - _system.CPU.WakeupTask(TaskType.DisplayWord); - } - else - { - // We can't take any words right now, remove Wakeup from - // the DWT. - if (_dataBuffer.Count >= 16) - { - //Log.Write(LogComponent.Display, "buffer full, blocking DWT."); - } - _system.CPU.BlockTask(TaskType.DisplayWord); - } - + case DisplayState.VisibleScanline: // // A scanline is 38 words wide; we clock in each word // from the buffer (if present). @@ -151,7 +146,7 @@ namespace Contralto.Display displayWord = _dataBuffer.Dequeue(); } - _display.DrawDisplayWord(_scanline, _word, displayWord); + //_display.DrawDisplayWord(_scanline, _word, displayWord); _word++; if (_word > 37) @@ -165,7 +160,7 @@ namespace Contralto.Display break; case DisplayState.HorizontalBlank: - // Kill time until end of HBlank + // Kill time until end of HBlank if (_clocks > _horizontalBlankClocks) { _clocks -= _horizontalBlankClocks; @@ -180,11 +175,14 @@ namespace Contralto.Display _state = DisplayState.VerticalBlank; _evenField = !_evenField; - _system.CPU.BlockTask(TaskType.DisplayVertical); + // Wakeup DVT + _system.CPU.WakeupTask(TaskType.DisplayVertical); + + // Block DHT _system.CPU.BlockTask(TaskType.DisplayHorizontal); _system.CPU.BlockTask(TaskType.DisplayWord); - _display.RefreshAltoDisplay(); + //_display.RefreshAltoDisplay(); _frames++; //Log.Write(LogComponent.Display, "Display field completed. {0} total clocks elapsed.", _totalClocks); @@ -192,7 +190,10 @@ namespace Contralto.Display } else { - _state = DisplayState.VisibleScanline; + _state = DisplayState.VisibleScanline; + + // Run MRT + _system.CPU.WakeupTask(TaskType.MemoryRefresh); } } break; @@ -248,9 +249,9 @@ namespace Contralto.Display // Timing constants // 38uS per scanline; 4uS for hblank. // ~35 scanlines for vblank (1330uS) - private const double _wordClocks = (34.0 / 38.0) / 0.17; // uSec to clocks - private const double _horizontalBlankClocks = 4.0 / 0.17; - private const double _verticalBlankClocks = 1333.0 / 0.17; + private const double _wordClocks = (34.0 / 38.0) / 0.017; // uSec to clocks + private const double _horizontalBlankClocks = 4.0 / 0.017; + private const double _verticalBlankClocks = 1333.0 / 0.017; } diff --git a/Contralto/Display/FakeDisplayController.cs b/Contralto/Display/FakeDisplayController.cs new file mode 100644 index 0000000..bebc790 --- /dev/null +++ b/Contralto/Display/FakeDisplayController.cs @@ -0,0 +1,164 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Contralto.Logging; +using Contralto.CPU; + +namespace Contralto.Display +{ + /// + /// FakeDisplayController draws the display without the aid of the + /// display microcode tasks (i.e. it cheats). It reads the displaylist + /// starting at DASTART and renders the display from there. + /// + public class FakeDisplayController : IClockable + { + public FakeDisplayController(AltoSystem system) + { + _system = system; + Reset(); + } + + public void AttachDisplay(Debugger display) + { + _display = display; + } + + public void Reset() + { + + } + + public void Clock() + { + _clocks++; + + if (_clocks > _frameClocks) + { + _clocks -= _frameClocks; + + RenderDisplay(); + _display.RefreshAltoDisplay(); + } + } + + private void RenderDisplay() + { + // pick up DASTART; if zero we render a blank screen. + ushort daStart = _system.MemoryBus.DebugReadWord(0x110); + + if (daStart == 0) + { + for (int scanline = 0; scanline < 808; scanline++) + { + for (int word = 0; word < 38; word++) + { + _display.DrawDisplayWord(scanline, word, 0xffff); + } + } + + _display.RefreshAltoDisplay(); + return; + } + + DCB dcb = GetNextDCB(daStart); + int dcbScanline = 0; + + for (int scanline = 0; scanline < 808; scanline++) + { + int wordOffset = 0; + + // fill in HTAB + for(int htab = 0;htab> 8; + dcb.nWrds = (mode & 0xff); + + dcb.startAddress = _system.MemoryBus.DebugReadWord((ushort)(address + 2)); + dcb.scanlineCount = _system.MemoryBus.DebugReadWord((ushort)(address + 3)) * 2; + + return dcb; + } + + + private struct DCB + { + public ushort daNext; + public bool lowRes; + public bool whiteOnBlack; + public int hTab; + public int nWrds; + public ushort startAddress; + public int scanlineCount; + } + + private double _clocks; + + private AltoSystem _system; + private Debugger _display; + + // Timing constants + // 38uS per scanline; 4uS for hblank. + // ~35 scanlines for vblank (1330uS) + private const double _scanlineClocks = 38.0 / 0.017; + private const double _frameClocks = _scanlineClocks * 850; // approx. + } +} diff --git a/Contralto/IO/DiskController.cs b/Contralto/IO/DiskController.cs index a760426..af9b6c6 100644 --- a/Contralto/IO/DiskController.cs +++ b/Contralto/IO/DiskController.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Contralto.Memory; using System.IO; using Contralto.Logging; +using Contralto.CPU; namespace Contralto.IO { @@ -36,7 +37,8 @@ namespace Contralto.IO public ushort KDATA { get - { + { + _debugRead = false; return _kDataRead; } set @@ -235,10 +237,7 @@ namespace Contralto.IO _sector = (_sector + 1) % 12; - _kStat = (ushort)((_kStat & 0x0fff) | (_sector << 12)); - - // TODO: seclate semantics. Looks like if the sector task was BLOCKed when a new sector is signaled - // then the seclate flag is set. + _kStat = (ushort)((_kStat & 0x0fff) | (_sector << 12)); // Reset internal state machine for sector data _sectorWordIndex = 0; @@ -254,6 +253,12 @@ namespace Contralto.IO { Log.Write(LogType.Verbose, LogComponent.DiskController, "Waking up sector task for C/H/S {0}/{1}/{2}", _cylinder, _head, _sector); _system.CPU.WakeupTask(CPU.TaskType.DiskSector); + + // Reset SECLATE + _seclateClocks = 0; + _seclate = false; + _seclateEnable = true; + _kStat &= 0xffef; } } @@ -293,12 +298,35 @@ namespace Contralto.IO // SpinDisk(); + // Deal with SECLATE semantics: If the Disk Sector task wakes up and runs before + // we hit the trigger time, then _seclate remains false. + // Otherwise, when the trigger time is hit _seclate is raised until + // the beginning of the next sector. + if (_system.CPU.CurrentTask.Priority == (int)TaskType.DiskSector) + { + // Sector task is running; clear enable for seclate signal + _seclateEnable = false; + } + + if (_seclateEnable) + { + _seclateClocks++; + + if (_seclateClocks > _seclateDuration) + { + _seclate = true; + _kStat |= 0x0010; // TODO: move to constant field! + //Log.Write(LogComponent.DiskSectorTask, "SECLATE for sector {0} at sector time {1}", _sector, _elapsedSectorTime); + _seclateEnable = false; + } + } + // // Update the WDINIT signal; this is based on WDALLOW (!_wdInhib) which sets WDINIT (this is done // in KCOM way above). // WDINIT is reset when BLOCK (a BLOCK F1 is being executed) and WDTSKACT (the disk word task is running) are 1. // - if (_system.CPU.CurrentTask.Priority == (int)CPU.TaskType.DiskWord && + if (_system.CPU.CurrentTask.Priority == (int)TaskType.DiskWord && _system.CPU.CurrentTask.BLOCK) { _wdInit = false; @@ -433,22 +461,28 @@ namespace Contralto.IO // If the word task is enabled AND the write ("crystal") clock is enabled // then we will wake up the word task now. // - if (!_wdInhib && !_bClkSource) + if (!_seclate && !_wdInhib && !_bClkSource) { bWakeup = true; - } + } // // If the clock is enabled OR the WFFO bit is set (go ahead and run the bit clock) - // then we will wake up the word task and read in the data if transfers are not - // inhibited. TODO: this should only happen on reads. + // and we weren't late reading this sector, then we will wake up the word task + // and read in the data if transfers are not inhibited. TODO: this should only happen on reads. // - if (_wffo || _diskBitCounterEnable) + if (!_seclate && (_wffo || _diskBitCounterEnable)) { if (!_xferOff) { + if (_debugRead) + { + Console.WriteLine("--- missed word {0}({1}) ---", _sectorWordIndex, _kDataRead); + } + Log.Write(LogType.Verbose, LogComponent.DiskWordTask, "Sector {0} Word {1} read into KDATA", _sector, Conversion.ToOctal(diskWord)); _kDataRead = diskWord; + _debugRead = _sectorData[_sectorWordIndex].Type == CellType.Data; } if (!_wdInhib) @@ -471,12 +505,12 @@ namespace Contralto.IO if (bWakeup) { Log.Write(LogType.Verbose, LogComponent.DiskWordTask, "Word task awoken for word {0}.", _sectorWordIndex); - _system.CPU.WakeupTask(CPU.TaskType.DiskWord); + _system.CPU.WakeupTask(TaskType.DiskWord); } // Last, move to the next word. _sectorWordIndex++; - } + } } private void LoadSector() @@ -486,29 +520,7 @@ namespace Contralto.IO // Note that this data is packed in in REVERSE ORDER because that's // how it gets written out and it's how the Alto expects it to be read back in. // - DiabloDiskSector sector = _pack.GetSector(_cylinder, _head, _sector); - - // debugging - /* - if (_cylinder >= 32) - { - Console.WriteLine("loading in C/H/S {0}/{1}/{2}", _cylinder, _head, _sector); - for(int i=0;i /// Currently just a stub indicating that no keys are being pressed. /// @@ -17,14 +96,19 @@ namespace Contralto.IO { public Keyboard() { - + InitMap(); + Reset(); + } + + public void Reset() + { + _keyWords = new ushort[4]; } public ushort Read(int address, TaskType task, bool extendedMemoryReference) - { - // TODO: implement; return nothing pressed for any address now. - Log.Write(LogComponent.Keyboard, "Keyboard read; unimplemented."); - return 0xffff; + { + // keyboard word is inverted + return (ushort)~_keyWords[address - 0xfe1c]; // TODO: move to constant. } public void Load(int address, ushort data, TaskType task, bool extendedMemoryReference) @@ -32,14 +116,100 @@ namespace Contralto.IO // nothing } + public void KeyDown(AltoKey key) + { + AltoKeyBit bits = _keyMap[key]; + _keyWords[bits.Word] |= _keyMap[key].Bitmask; + } + + public void KeyUp(AltoKey key) + { + AltoKeyBit bits = _keyMap[key]; + _keyWords[bits.Word] &= (ushort)~_keyMap[key].Bitmask; + } + public MemoryRange[] Addresses { get { return _addresses; } } + private readonly MemoryRange[] _addresses = { new MemoryRange(0xfe1c, 0xfe1f), // 177034-177037 }; + + private void InitMap() + { + _keyMap = new Dictionary(); + _keyMap.Add(AltoKey.D5, new AltoKeyBit(0, 0x8000)); + _keyMap.Add(AltoKey.D4, new AltoKeyBit(0, 0x4000)); + _keyMap.Add(AltoKey.D6, new AltoKeyBit(0, 0x2000)); + _keyMap.Add(AltoKey.E, new AltoKeyBit(0, 0x1000)); + _keyMap.Add(AltoKey.D7, new AltoKeyBit(0, 0x0800)); + _keyMap.Add(AltoKey.D, new AltoKeyBit(0, 0x0400)); + _keyMap.Add(AltoKey.U, new AltoKeyBit(0, 0x0200)); + _keyMap.Add(AltoKey.V, new AltoKeyBit(0, 0x0100)); + _keyMap.Add(AltoKey.D0, new AltoKeyBit(0, 0x0080)); + _keyMap.Add(AltoKey.K, new AltoKeyBit(0, 0x0040)); + _keyMap.Add(AltoKey.Minus, new AltoKeyBit(0, 0x0020)); + _keyMap.Add(AltoKey.P, new AltoKeyBit(0, 0x0010)); + _keyMap.Add(AltoKey.FSlash, new AltoKeyBit(0, 0x0008)); + _keyMap.Add(AltoKey.BSlash, new AltoKeyBit(0, 0x0004)); + _keyMap.Add(AltoKey.LF, new AltoKeyBit(0, 0x0002)); + _keyMap.Add(AltoKey.BS, new AltoKeyBit(0, 0x0001)); + + _keyMap.Add(AltoKey.D3, new AltoKeyBit(1, 0x8000)); + _keyMap.Add(AltoKey.D2, new AltoKeyBit(1, 0x4000)); + _keyMap.Add(AltoKey.W, new AltoKeyBit(1, 0x2000)); + _keyMap.Add(AltoKey.Q, new AltoKeyBit(1, 0x1000)); + _keyMap.Add(AltoKey.S, new AltoKeyBit(1, 0x0800)); + _keyMap.Add(AltoKey.A, new AltoKeyBit(1, 0x0400)); + _keyMap.Add(AltoKey.D9, new AltoKeyBit(1, 0x0200)); + _keyMap.Add(AltoKey.I, new AltoKeyBit(1, 0x0100)); + _keyMap.Add(AltoKey.X, new AltoKeyBit(1, 0x0080)); + _keyMap.Add(AltoKey.O, new AltoKeyBit(1, 0x0040)); + _keyMap.Add(AltoKey.L, new AltoKeyBit(1, 0x0020)); + _keyMap.Add(AltoKey.Comma, new AltoKeyBit(1, 0x0010)); + _keyMap.Add(AltoKey.Quote, new AltoKeyBit(1, 0x0008)); + _keyMap.Add(AltoKey.RBracket, new AltoKeyBit(1, 0x0004)); + _keyMap.Add(AltoKey.BlankMiddle, new AltoKeyBit(1, 0x0002)); + _keyMap.Add(AltoKey.BlankTop, new AltoKeyBit(1, 0x0001)); + + _keyMap.Add(AltoKey.D1, new AltoKeyBit(2, 0x8000)); + _keyMap.Add(AltoKey.ESC, new AltoKeyBit(2, 0x4000)); + _keyMap.Add(AltoKey.TAB, new AltoKeyBit(2, 0x2000)); + _keyMap.Add(AltoKey.F, new AltoKeyBit(2, 0x1000)); + _keyMap.Add(AltoKey.CTRL, new AltoKeyBit(2, 0x0800)); + _keyMap.Add(AltoKey.C, new AltoKeyBit(2, 0x0400)); + _keyMap.Add(AltoKey.J, new AltoKeyBit(2, 0x0200)); + _keyMap.Add(AltoKey.B, new AltoKeyBit(2, 0x0100)); + _keyMap.Add(AltoKey.Z, new AltoKeyBit(2, 0x0080)); + _keyMap.Add(AltoKey.LShift, new AltoKeyBit(2, 0x0040)); + _keyMap.Add(AltoKey.Period, new AltoKeyBit(2, 0x0020)); + _keyMap.Add(AltoKey.Semicolon, new AltoKeyBit(2, 0x0010)); + _keyMap.Add(AltoKey.Return, new AltoKeyBit(2, 0x0008)); + _keyMap.Add(AltoKey.Arrow, new AltoKeyBit(2, 0x0004)); + _keyMap.Add(AltoKey.DEL, new AltoKeyBit(2, 0x0002)); + + _keyMap.Add(AltoKey.R, new AltoKeyBit(3, 0x8000)); + _keyMap.Add(AltoKey.T, new AltoKeyBit(3, 0x4000)); + _keyMap.Add(AltoKey.G, new AltoKeyBit(3, 0x2000)); + _keyMap.Add(AltoKey.Y, new AltoKeyBit(3, 0x1000)); + _keyMap.Add(AltoKey.H, new AltoKeyBit(3, 0x0800)); + _keyMap.Add(AltoKey.D8, new AltoKeyBit(3, 0x0400)); + _keyMap.Add(AltoKey.N, new AltoKeyBit(3, 0x0200)); + _keyMap.Add(AltoKey.M, new AltoKeyBit(3, 0x0100)); + _keyMap.Add(AltoKey.Lock, new AltoKeyBit(3, 0x0080)); + _keyMap.Add(AltoKey.Space, new AltoKeyBit(3, 0x0040)); + _keyMap.Add(AltoKey.LBracket, new AltoKeyBit(3, 0x0020)); + _keyMap.Add(AltoKey.Plus, new AltoKeyBit(3, 0x0010)); + _keyMap.Add(AltoKey.RShift, new AltoKeyBit(3, 0x0008)); + _keyMap.Add(AltoKey.BlankBottom, new AltoKeyBit(3, 0x0004)); + } + + private ushort[] _keyWords; + + private Dictionary _keyMap; } } diff --git a/Contralto/Memory/MemoryBus.cs b/Contralto/Memory/MemoryBus.cs index 931603b..e370d78 100644 --- a/Contralto/Memory/MemoryBus.cs +++ b/Contralto/Memory/MemoryBus.cs @@ -87,6 +87,13 @@ namespace Contralto.Memory return ReadFromBus(address, TaskType.Emulator, false); } + public ushort DebugReadWord(TaskType task, ushort address) + { + // TODO: allow debug reads from any bank. + // probably add special debug calls to IMemoryMappedDevice iface. + return ReadFromBus(address, task, false); + } + public void Clock() { _memoryCycle++; @@ -267,7 +274,7 @@ namespace Contralto.Memory else { //throw new NotImplementedException(String.Format("Read from unimplemented memory-mapped I/O device at {0}.", OctalHelpers.ToOctal(address))); - Console.WriteLine("Read from unimplemented memory-mapped I/O device at {0}.", Conversion.ToOctal(address)); + //Console.WriteLine("Read from unimplemented memory-mapped I/O device at {0}.", Conversion.ToOctal(address)); return 0; } } @@ -289,7 +296,7 @@ namespace Contralto.Memory else { // throw new NotImplementedException(String.Format("Write to unimplemented memory-mapped I/O device at {0}.", OctalHelpers.ToOctal(address))); - Console.WriteLine("Write to unimplemented memory-mapped I/O device at {0}.", Conversion.ToOctal(address)); + //Console.WriteLine("Write to unimplemented memory-mapped I/O device at {0}.", Conversion.ToOctal(address)); } }