From 9ee888ed68ac16d0ef55ec1c2249aa6e76a49b1d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20H=C3=B6gstedt?= <marin.hogstedt@hotmail.com>
Date: Tue, 11 Jun 2024 10:28:29 +0200
Subject: [PATCH] the first step back is now fixed, alhough the code is shit
 and i dont know why this this solution is a solution

---
 src/simudator/core/processor.py    |  4 ++++
 src/simudator/processor/mia/mia.py | 14 +++++++++-----
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/simudator/core/processor.py b/src/simudator/core/processor.py
index 543e578..6e76bb2 100644
--- a/src/simudator/core/processor.py
+++ b/src/simudator/core/processor.py
@@ -253,9 +253,13 @@ class Processor:
 
         try:
             module_states = self.module_history[cycle_index]
+            print(cycle_index)
         except IndexError:
+            print(cycle_index)
+            print(321)
             raise IndexError
 
+
         for module_name, module_state in module_states.items():
             self.modules[module_name].set_state(module_state)
 
diff --git a/src/simudator/processor/mia/mia.py b/src/simudator/processor/mia/mia.py
index 632248c..22fcefb 100644
--- a/src/simudator/processor/mia/mia.py
+++ b/src/simudator/processor/mia/mia.py
@@ -294,21 +294,22 @@ class MIA_CPU(Processor):
             self.new_instruction = True
             self.current_instruction = self.get_current_instrution()
             self.assembly_cycles.append(self.get_clock())
-            self.finished_assembly_instructions += 1
         else:
             self.new_instruction = False
 
     def get_current_instrution(self) -> str:
-        """Returns a string containing the label for the current instruction.
+        """
+        Returns a string containing the label for the current instruction.
 
-        If the label doesnt exist, the string is empty."""
+        If the label doesnt exist, the string is empty.
+        """
         ir = self.get_module("IR")
         op_code = ir.op
         return self.get_module("K1").get_label(int(op_code))
 
     def run_asm_instruction(self, num_instructions = 1) -> None:
         """
-        Runs assembler instructions on Mia 'num_instructions' times.
+        Runs 'num_instructions' assembler instructions on Mia.
 
         Default argument is one, but it is possible to specify any number of instructions.
         """
@@ -336,15 +337,18 @@ class MIA_CPU(Processor):
 
         index = len(self.assembly_cycles)
         index -= num_instructions
+        index -= 1
 
         # We cant undo more instructions than we have performed.
         if index < 0:
             raise IndexError
 
         clockcycle = self.assembly_cycles[index]
-        self.assembly_cycles = self.assembly_cycles[:index]
 
+        print("Cycle: ", clockcycle)
+        print("Steps : ", num_instructions)
         self.load_cycle(clockcycle)
+        self.assembly_cycles = self.assembly_cycles[:index+1]
 
 
     def should_halt(self) -> bool:
-- 
GitLab