diff --git a/imlac/DisplayProcessor.cs b/imlac/DisplayProcessor.cs index 3904fc1..77130e0 100644 --- a/imlac/DisplayProcessor.cs +++ b/imlac/DisplayProcessor.cs @@ -45,8 +45,8 @@ namespace imlac { _system = system; _mem = _system.Memory; - _instructionCache = new DisplayInstruction[Memory.Size]; _dtStack = new Stack(8); + InitializeCache(); } public void Reset() @@ -156,6 +156,11 @@ namespace imlac get { return _dpcEntry; } } + public void InitializeCache() + { + _instructionCache = new DisplayInstruction[Memory.Size]; + } + public void InvalidateCache(ushort address) { _instructionCache[address & Memory.SizeMask] = null; diff --git a/imlac/IO/TTY.cs b/imlac/IO/TTY.cs index 51f12f0..9792bd3 100644 --- a/imlac/IO/TTY.cs +++ b/imlac/IO/TTY.cs @@ -166,7 +166,7 @@ namespace imlac.IO private byte _txData; private int _clocks; - private readonly int _dataClocks = 100; + private readonly int _dataClocks = 250; private ISerialDataChannel _dataChannel; diff --git a/imlac/Memory.cs b/imlac/Memory.cs index f694642..6e3b572 100644 --- a/imlac/Memory.cs +++ b/imlac/Memory.cs @@ -15,15 +15,39 @@ along with sImlac. If not, see . */ +using System; + namespace imlac { - // TODO: make memory size configurable. public class Memory { public Memory(ImlacSystem system) - { - _mem = new ushort[Size]; + { _system = system; + SetMemorySize(0x2000); + } + + public void SetMemorySize(ushort size) + { + if (size != 0x1000 && size != 0x2000 && size != 0x4000) + { + throw new InvalidOperationException("Size must be 4k, 8k, or 16k."); + } + + _size = size; + _sizeMask = (ushort)(size - 1); + + _mem = new ushort[Size]; + + if (_system.Processor != null) + { + _system.Processor.InitializeCache(); + } + + if (_system.DisplayProcessor != null) + { + _system.DisplayProcessor.InitializeCache(); + } } public ushort Fetch(ushort address) @@ -44,13 +68,16 @@ namespace imlac public static ushort Size { - get { return 0x4000; } + get { return _size; } } public static ushort SizeMask { - get { return 0x3fff; } - } + get { return _sizeMask; } + } + + private static ushort _size; + private static ushort _sizeMask; private ushort[] _mem; private ImlacSystem _system; diff --git a/imlac/Processor.cs b/imlac/Processor.cs index 44f3fdf..394b434 100644 --- a/imlac/Processor.cs +++ b/imlac/Processor.cs @@ -43,11 +43,11 @@ namespace imlac { _system = system; _mem = _system.Memory; - _instructionCache = new Instruction[Memory.Size]; _iotDispatch = new IIOTDevice[0x200]; // 9 bits of IOT instructions Reset(); + InitializeCache(); } public void Reset() @@ -119,6 +119,11 @@ namespace imlac return GetCachedInstruction(address).Disassemble(address); } + public void InitializeCache() + { + _instructionCache = new Instruction[Memory.Size]; + } + public void InvalidateCache(ushort address) { _instructionCache[address & Memory.SizeMask] = null; @@ -578,7 +583,7 @@ namespace imlac } private ushort GetEffectiveAddress(ushort baseAddress) - { + { return (ushort)((_pc & (Memory.SizeMask & 0xf800)) | (baseAddress & 0x07ff)); } diff --git a/imlac/System.cs b/imlac/System.cs index e4dc9ad..ca72443 100644 --- a/imlac/System.cs +++ b/imlac/System.cs @@ -254,6 +254,29 @@ namespace imlac return SystemExecutionState.Debugging; } + [DebuggerFunction("set memory size 4kw", "Sets memory size to 4KW")] + private SystemExecutionState SetMemorySize4kw() + { + _memory.SetMemorySize(0x1000); + return SystemExecutionState.Debugging; + } + + + [DebuggerFunction("set memory size 8kw", "Sets memory size to 8KW")] + private SystemExecutionState SetMemorySize8kw() + { + _memory.SetMemorySize(0x2000); + return SystemExecutionState.Debugging; + } + + + [DebuggerFunction("set memory size 16kw", "Sets memory size to 16KW")] + private SystemExecutionState SetMemorySize16kw() + { + _memory.SetMemorySize(0x4000); + return SystemExecutionState.Debugging; + } + [DebuggerFunction("set logging", "Sets the logging configuration", "")] private SystemExecutionState SetLogging(LogType value) {