Fixed a bug in Am2900; created dlatch8/80; relayouted some components
[Mograsim.git] / net.mograsim.machine / src / net / mograsim / machine / mi / MicroInstructionMemoryParser.java
index b5117a7..d049e37 100644 (file)
@@ -28,29 +28,35 @@ public class MicroInstructionMemoryParser
 
                long minAddr = def.getMinimalAddress();
                long maxAddr = def.getMaximalAddress();
-               
+
                String line;
                long i = minAddr;
                try
                {
                        for (; i <= maxAddr && input.ready() && !"".equals((line = input.readLine())); i++)
-                               memory.setCell(i, parse(miDef, line));
-               } catch (IOException e)
+                       {
+                               long iFinal = i;
+                               memory.setCell(i, parse(() -> memory.notifyObservers(iFinal), miDef, line));
+                       }
+               }
+               catch (IOException e)
                {
                        e.printStackTrace();
                }
-               
-               for(; i <= maxAddr; i++)
-                       memory.setCell(i, miDef.createDefaultInstruction());
+
+               for (; i <= maxAddr; i++)
+               {
+                       long iFinal = i;
+                       memory.setCell(i, miDef.createDefaultInstruction(() -> memory.notifyObservers(iFinal)));
+               }
        }
-       
-       public static MicroInstruction parse(MicroInstructionDefinition definition, String toParse)
+
+       public static MicroInstruction parse(Runnable updateCallback, MicroInstructionDefinition definition, String toParse)
        {
                int size = definition.size();
                String[] strings = toParse.split(",");
                if (size != strings.length)
-                       throw new MicroInstructionMemoryParseException(
-                                       "String does not match definition! The number of parameters does not match.");
+                       throw new MicroInstructionMemoryParseException("String does not match definition! The number of parameters does not match.");
                MicroInstructionParameter[] params = new MicroInstructionParameter[size];
                ParameterClassification[] classes = definition.getParameterClassifications();
                try
@@ -59,8 +65,9 @@ public class MicroInstructionMemoryParser
                        {
                                params[i] = classes[i].parse(strings[i]);
                        }
-                       return new StandardMicroInstruction(params);
-               } catch (Exception e)
+                       return new StandardMicroInstruction(updateCallback, params);
+               }
+               catch (Exception e)
                {
                        throw new MicroInstructionMemoryParseException(e.getCause());
                }