From 894cb257ada6b6ab904c173233668284533eb478 Mon Sep 17 00:00:00 2001 From: Chris Anders Date: Sun, 27 Oct 2024 11:04:49 +0100 Subject: [PATCH] feat: Add Stack BusActivations --- src/MimaSim/MimaSim/MIMA/Components/Stack.cs | 14 +++++++++++++- src/MimaSim/MimaSim/MIMA/ErrorCodes.cs | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/MimaSim/MimaSim/MIMA/Components/Stack.cs b/src/MimaSim/MimaSim/MIMA/Components/Stack.cs index 6bd6d01..2a8b03e 100644 --- a/src/MimaSim/MimaSim/MIMA/Components/Stack.cs +++ b/src/MimaSim/MimaSim/MIMA/Components/Stack.cs @@ -1,4 +1,6 @@ -namespace MimaSim.MIMA.Components; +using MimaSim.Core; + +namespace MimaSim.MIMA.Components; public class Stack(CPU cpu) { @@ -9,10 +11,18 @@ public void Push() var sp = cpu.ControlUnit.SP.GetValue(); var value = cpu.Accumulator.GetValue(); + if (sp < 0) + { + cpu.ControlUnit.SetError(ErrorCodes.StackOverflow); + return; + } + Data[sp] = value; sp--; cpu.ControlUnit.SP.SetValue(sp); + + BusRegistry.Activate("cu->stack"); } public void Pop() @@ -24,5 +34,7 @@ public void Pop() sp++; cpu.ControlUnit.SP.SetValue(sp); + + BusRegistry.Activate("cu->stack"); } } \ No newline at end of file diff --git a/src/MimaSim/MimaSim/MIMA/ErrorCodes.cs b/src/MimaSim/MimaSim/MIMA/ErrorCodes.cs index 301098f..0086426 100644 --- a/src/MimaSim/MimaSim/MIMA/ErrorCodes.cs +++ b/src/MimaSim/MimaSim/MIMA/ErrorCodes.cs @@ -3,5 +3,6 @@ public enum ErrorCodes { Unknown, - SysCallNotFound = 0x01, + SysCallNotFound, + StackOverflow } \ No newline at end of file