import net.mograsim.logic.model.serializing.IdentifyParams;
import net.mograsim.logic.model.serializing.JSONSerializable;
import net.mograsim.logic.model.snippets.HighLevelStateHandler;
+import net.mograsim.logic.model.snippets.highlevelstatehandlers.DefaultHighLevelStateHandler;
/**
* The base class for all model components.<br>
this.pinAddedListeners = new ArrayList<>();
this.pinRemovedListeners = new ArrayList<>();
+ this.highLevelStateHandler = new DefaultHighLevelStateHandler();
+
if (callInit)
init();
}
*
* @author Daniel Kirschten
*/
- public Object getHighLevelState(String stateID)
+ public final Object getHighLevelState(String stateID)
{
return highLevelStateHandler.getHighLevelState(stateID);
}
*
* @author Daniel Kirschten
*/
- public void setHighLevelState(String stateID, Object newState)
+ public final void setHighLevelState(String stateID, Object newState)
{
highLevelStateHandler.setHighLevelState(stateID, newState);
}
import net.mograsim.logic.model.modeladapter.componentadapters.ClockAdapter;
import net.mograsim.logic.model.serializing.IdentifyParams;
import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
import net.mograsim.logic.model.util.JsonHandler;
import net.mograsim.preferences.Preferences;
this.outputPin = new Pin(model, this, "", 1, PinUsage.OUTPUT, oc.newX(width, height / 2), oc.newY(width, height / 2));
addPin(outputPin);
+ setHighLevelStateHandler(new HighLevelStateHandler()
+ {
+ @Override
+ public Object getHighLevelState(String stateID)
+ {
+ switch (stateID)
+ {
+ case "out":
+ if (clock != null)
+ return clock.getOut().getInputValues();
+ return null;
+ default:
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+ }
+
+ @Override
+ public void setHighLevelState(String stateID, Object newState)
+ {
+ switch (stateID)
+ {
+ case "out":
+ throw new UnsupportedOperationException("cannot set state of clock");
+ default:
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+ }
+
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+
+ @Override
+ public Object getParamsForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+ });
+
init();
}
return clock != null;
}
- @Override
- public Object getHighLevelState(String stateID)
- {
- switch (stateID)
- {
- case "out":
- if (clock != null)
- return clock.getOut().getInputValues();
- return null;
- default:
- return super.getHighLevelState(stateID);
- }
- }
-
- @Override
- public void setHighLevelState(String stateID, Object newState)
- {
- switch (stateID)
- {
- case "out":
- throw new UnsupportedOperationException("cannot set state of clock");
- default:
- super.setHighLevelState(stateID, newState);
- }
- }
-
public CoreClock getClock()
{
return clock;
import net.mograsim.logic.model.modeladapter.componentadapters.ManualSwitchAdapter;
import net.mograsim.logic.model.serializing.IdentifyParams;
import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
import net.mograsim.preferences.Preferences;
public class ModelManualSwitch extends ModelComponent
setSize(width, height);
addPin(this.outputPin = new Pin(model, this, "", logicWidth, PinUsage.OUTPUT, width, height / 2));
+ setHighLevelStateHandler(new HighLevelStateHandler()
+ {
+ @Override
+ public Object getHighLevelState(String stateID)
+ {
+ switch (stateID)
+ {
+ case "out":
+ if (manualSwitch != null)
+ return manualSwitch.getValues();
+ return null;
+ default:
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+ }
+
+ @Override
+ public void setHighLevelState(String stateID, Object newState)
+ {
+ switch (stateID)
+ {
+ case "out":
+ if (manualSwitch != null)
+ manualSwitch.setState((BitVector) newState);
+ break;
+ default:
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+ }
+
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+
+ @Override
+ public Object getParamsForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+ });
+
init();
}
return manualSwitch != null;
}
- @Override
- public Object getHighLevelState(String stateID)
- {
- switch (stateID)
- {
- case "out":
- if (manualSwitch != null)
- return manualSwitch.getValues();
- return null;
- default:
- return super.getHighLevelState(stateID);
- }
- }
-
- @Override
- public void setHighLevelState(String stateID, Object newState)
- {
- switch (stateID)
- {
- case "out":
- if (manualSwitch != null)
- manualSwitch.setState((BitVector) newState);
- break;
- default:
- super.setHighLevelState(stateID, newState);
- break;
- }
- }
-
@Override
public boolean clicked(double x, double y)
{
import net.mograsim.logic.model.model.wires.Pin;
import net.mograsim.logic.model.model.wires.PinUsage;
import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
import net.mograsim.machine.ModelMemory;
import net.mograsim.machine.mi.MicroInstructionMemory;
import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
addPin(dataPin = new Pin(model, this, "D", definition.getMicroInstructionDefinition().sizeInBits(), PinUsage.OUTPUT, getWidth(),
50));
+ setHighLevelStateHandler(new HighLevelStateHandler()
+ {
+ @Override
+ public Object getHighLevelState(String stateID)
+ {
+ if (stateID.equals("memory_binding"))
+ return memory.getMemory();
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+
+ @Override
+ public void setHighLevelState(String stateID, Object newState)
+ {
+ if (stateID.equals("memory_binding"))
+ memory.setMemory((MicroInstructionMemory) newState);
+ else
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+
+ @Override
+ public Object getParamsForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+ });
+
init();
}
this.memory = memory;
}
- @Override
- public void setHighLevelState(String stateID, Object newState)
- {
- if (stateID.equals("memory_binding"))
- memory.setMemory((MicroInstructionMemory) newState);
- else
- super.setHighLevelState(stateID, newState);
- }
-
- @Override
- public Object getHighLevelState(String stateID)
- {
- if (stateID.equals("memory_binding"))
- return memory.getMemory();
- return super.getHighLevelState(stateID);
- }
-
static
{
LogicCoreAdapter.addComponentAdapter(new MicroInstructionMemoryAdapter());
import net.mograsim.logic.model.model.wires.Pin;
import net.mograsim.logic.model.model.wires.PinUsage;
import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
+import net.mograsim.logic.model.serializing.IdentifyParams;
+import net.mograsim.logic.model.snippets.HighLevelStateHandler;
import net.mograsim.machine.MainMemory;
import net.mograsim.machine.MainMemoryDefinition;
import net.mograsim.machine.ModelMemory;
addPin(dataPin = new Pin(model, this, "D", definition.getCellWidth(), PinUsage.TRISTATE, getWidth(), 50));
addPin(rWPin = new Pin(model, this, "RW", 1, PinUsage.INPUT, getWidth(), 70));
+ setHighLevelStateHandler(new HighLevelStateHandler()
+ {
+ @Override
+ public Object getHighLevelState(String stateID)
+ {
+ if (stateID.equals("memory_binding"))
+ return memory.getMemory();
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+
+ @Override
+ public void setHighLevelState(String stateID, Object newState)
+ {
+ if (stateID.equals("memory_binding"))
+ memory.setMemory((MainMemory) newState);
+ else
+ throw new IllegalArgumentException("No high level state with ID " + stateID);
+ }
+
+ @Override
+ public String getIDForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+
+ @Override
+ public Object getParamsForSerializing(IdentifyParams idParams)
+ {
+ return null;
+ }
+ });
+
init();
}
return memory;
}
- @Override
- public void setHighLevelState(String stateID, Object newState)
- {
- if (stateID.equals("memory_binding"))
- memory.setMemory((MainMemory) newState);
- else
- super.setHighLevelState(stateID, newState);
- }
-
- @Override
- public Object getHighLevelState(String stateID)
- {
- if (stateID.equals("memory_binding"))
- return memory.getMemory();
- return super.getHighLevelState(stateID);
- }
-
static
{
LogicCoreAdapter.addComponentAdapter(new WordAddressableMemoryAdapter());