The listener is now only called on the rising edge of the clock cycle.
Fixed a stupid bug in innerHighlight, creating Optionals of potential
null values with of()
"compName": "WireCrossPoint#43",
"pinName": ""
},
- "name": "unnamedWire#163",
+ "name": "wire_mpm_address",
"path": [
{
"x": 205.0,
package net.mograsim.logic.model.am2900.machine;
+import java.util.HashSet;
+import java.util.Set;
+
import net.mograsim.logic.core.components.CoreClock;
import net.mograsim.logic.core.timeline.Timeline;
import net.mograsim.logic.core.types.BitVector;
private AssignableMainMemory mainMemory;
private AssignableMicroInstructionMemory instMemory;
private CoreClock clock;
+ private long activeInstructionAddress;
+
+ private final Set<ActiveMicroInstructionChangedListener> amicListeners;
public Am2900Machine(LogicModelModifiable model, Am2900MachineDefinition am2900MachineDefinition)
{
this.logicModel = model;
this.am2900 = IndirectModelComponentCreator.createComponent(logicModel,
"resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json", "Am2900");
+ this.amicListeners = new HashSet<>();
+
CoreModelParameters params = new CoreModelParameters();
params.gateProcessTime = 50;
params.wireTravelTime = 10;
am2900.setHighLevelState("ram.memory_binding", mainMemory);
am2900.setHighLevelState("mpm.memory_binding", instMemory);
clock = logicModel.getComponentBySubmodelPath("Am2900.Clock#0", ModelClock.class).getClock();
+ clock.registerObserver(c ->
+ {
+ if (clock.isOn())
+ {
+ long oldAddress = activeInstructionAddress;
+ activeInstructionAddress = getCurrentMicroInstructionAddress();
+ notifyActiveMicroInstructionChangedListeners(oldAddress, activeInstructionAddress);
+ }
+ });
}
@Override
{
return instMemory;
}
+
+ @Override
+ public long getActiveMicroInstructionAddress()
+ {
+ return activeInstructionAddress;
+ }
+
+ private long getCurrentMicroInstructionAddress()
+ {
+ // TODO: replace with highlevelstate
+ BitVector vector = logicModel.getWireBySubmodelPath("Am2900.wire_mpm_address").getWireValues();
+ return vector.isBinary() ? vector.getUnsignedValueLong() : -1;
+ }
+
+ @Override
+ public void addActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener listener)
+ {
+ amicListeners.add(listener);
+ }
+
+ @Override
+ public void removeActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener listener)
+ {
+ amicListeners.remove(listener);
+ }
+
+ private void notifyActiveMicroInstructionChangedListeners(long oldAddress, long newAddress)
+ {
+ amicListeners.forEach(l -> l.instructionChanged(oldAddress, newAddress));
+ }
}
\ No newline at end of file
AssignableMainMemory getMainMemory();
AssignableMicroInstructionMemory getMicroInstructionMemory();
+
+ void addActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener listener);
+
+ void removeActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener listener);
+
+ long getActiveMicroInstructionAddress();
+
+ public interface ActiveMicroInstructionChangedListener
+ {
+ public void instructionChanged(long oldAddress, long newAddress);
+ }
}
\ No newline at end of file
import java.util.Set;
import net.mograsim.machine.Memory.MemoryCellModifiedListener;
-import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener;
-public class AssignableMicroInstructionMemory
- implements MicroInstructionMemory, MemoryCellModifiedListener, ActiveMicroInstructionChangedListener
+public class AssignableMicroInstructionMemory implements MicroInstructionMemory, MemoryCellModifiedListener
{
private Set<MemoryCellModifiedListener> observers = new HashSet<>();
- private Set<ActiveMicroInstructionChangedListener> activeInstructionListeners = new HashSet<>();
+
private Set<MIMemoryReassignedListener> reassignmentListeners = new HashSet<>();
private MicroInstructionMemory real = null;
observers.remove(ob);
}
- @Override
- public void registerActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob)
- {
- activeInstructionListeners.add(ob);
- }
-
- @Override
- public void deregisterActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob)
- {
- activeInstructionListeners.remove(ob);
- }
-
private void notifyMemoryChanged(long address)
{
observers.forEach(o -> o.update(address));
}
- private void notifyActiveInstructionChanged(long address)
- {
- activeInstructionListeners.forEach(o -> o.activeMicroInstructionChanged(address));
- }
-
@Override
public MicroInstructionMemoryDefinition getDefinition()
{
notifyMemoryChanged(address);
}
- @Override
- public void setActiveInstruction(long address)
- {
- real.setActiveInstruction(address);
- }
-
- @Override
- public void activeMicroInstructionChanged(long address)
- {
- notifyActiveInstructionChanged(address);
- }
-
public void registerMemoryReassignedListener(MIMemoryReassignedListener listener)
{
reassignmentListeners.add(listener);
{
@Override
public MicroInstructionMemoryDefinition getDefinition();
-
- public void registerActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob);
-
- public void deregisterActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob);
-
- public void setActiveInstruction(long address);
-
- public static interface ActiveMicroInstructionChangedListener
- {
- public void activeMicroInstructionChanged(long address);
- }
}
package net.mograsim.machine.mi;
import java.util.HashSet;
-import java.util.Set;
import net.mograsim.machine.standard.memory.MemoryException;
private MicroInstruction[] data;
private MicroInstructionMemoryDefinition definition;
private HashSet<MemoryCellModifiedListener> observers = new HashSet<>();
- private Set<ActiveMicroInstructionChangedListener> activeInstructionListeners = new HashSet<>();
- private long activeInstruction = -1;
public StandardMicroInstructionMemory(MicroInstructionMemoryDefinition definition)
{
observers.remove(ob);
}
- @Override
- public void registerActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob)
- {
- activeInstructionListeners.add(ob);
- }
-
- @Override
- public void deregisterActiveMicroInstructionChangedListener(ActiveMicroInstructionChangedListener ob)
- {
- activeInstructionListeners.remove(ob);
- }
-
private void notifyMemoryChanged(long address)
{
observers.forEach(ob -> ob.update(address));
}
- private void notifyActiveInstructionChanged(long address)
- {
- activeInstructionListeners.forEach(o -> o.activeMicroInstructionChanged(address));
- }
-
@Override
public MicroInstructionMemoryDefinition getDefinition()
{
return definition;
}
-
- @Override
- public void setActiveInstruction(long address)
- {
- if (address != activeInstruction)
- {
- activeInstruction = address;
- notifyActiveInstructionChanged(address);
- }
- }
-
}
return e -> data.feedSignals(Bit.U.toVector(data.width()));// TODO don't always feed U, but decide to feed X or U.
long addressed = address.getValues().getUnsignedValueLong();
BitVector storedData = memory.getCell(addressed).toBitVector();
- memory.setActiveInstruction(addressed);
return e -> data.feedSignals(storedData);
}
}
\ No newline at end of file
canvasParent.layout();
+ // update preview
+ ((ActiveInstructionPreviewContentProvider) instPreview.getTableViewer().getContentProvider()).setMachine(machine);
+
// initialize executer
exec = new LogicExecuter(machine.getTimeline());
updateSpeedFactorFromInput(simSpeedInput.getValue());
{
instPreview = new InstructionTable(parent, new DisplaySettings(), getSite().getWorkbenchWindow().getWorkbench().getThemeManager());
instPreview.getTableViewer().getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
- instPreview.setContentProvider(new ActiveInstructionPreviewContentProvider(instPreview.getTableViewer()));
+ ActiveInstructionPreviewContentProvider cProv;
+ instPreview.setContentProvider(cProv = new ActiveInstructionPreviewContentProvider(instPreview.getTableViewer()));
+ cProv.setMachine(machine);
}
private static void setPauseText(Button pauseButton, boolean hovered)
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
+import net.mograsim.machine.Machine;
+import net.mograsim.machine.Machine.ActiveMicroInstructionChangedListener;
import net.mograsim.machine.mi.MicroInstructionMemory;
-import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener;
+import net.mograsim.plugin.util.SingleSWTRequest;
-public class ActiveInstructionPreviewContentProvider implements InstructionTableContentProvider, ActiveMicroInstructionChangedListener
+public class ActiveInstructionPreviewContentProvider implements InstructionTableContentProvider
{
private TableViewer viewer;
private MicroInstructionMemory memory;
private InstructionTableRow activeRow;
+ private Machine machine;
+ private SingleSWTRequest requester = new SingleSWTRequest();
+
+ private ActiveMicroInstructionChangedListener instChanged = (oldAddress, newAddress) ->
+ {
+ activeRow = new InstructionTableRow(Long.max(0, newAddress), memory);
+ requester.request(() -> updateElement(0));
+ };
public ActiveInstructionPreviewContentProvider(TableViewer viewer)
{
viewer.setItemCount(1);
}
- @Override
- public void activeMicroInstructionChanged(long address)
- {
- this.activeRow = new InstructionTableRow(address, memory);
- viewer.refresh();
- }
-
@Override
public void update(long address)
{
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput)
{
- if (oldInput != null)
- ((MicroInstructionMemory) oldInput).deregisterActiveMicroInstructionChangedListener(this);
-
memory = (MicroInstructionMemory) newInput;
- if (memory != null)
+ }
+
+ public void setMachine(Machine newMachine)
+ {
+ if (machine != null)
+ machine.removeActiveMicroInstructionChangedListener(instChanged);
+
+ machine = newMachine;
+ if (machine != null)
{
- activeMicroInstructionChanged(0);
- memory.registerActiveMicroInstructionChangedListener(this);
+ instChanged.instructionChanged(-1, 0);
+ machine.addActiveMicroInstructionChangedListener(instChanged);
}
}
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;
+import net.mograsim.machine.Machine.ActiveMicroInstructionChangedListener;
import net.mograsim.machine.Memory.MemoryCellModifiedListener;
import net.mograsim.machine.mi.AssignableMicroInstructionMemory.MIMemoryReassignedListener;
import net.mograsim.machine.mi.MicroInstructionMemory;
-import net.mograsim.machine.mi.MicroInstructionMemory.ActiveMicroInstructionChangedListener;
import net.mograsim.machine.mi.MicroInstructionMemoryParseException;
import net.mograsim.machine.mi.MicroInstructionMemoryParser;
import net.mograsim.plugin.nature.MachineContext;
table.refresh();
};
- private ActiveMicroInstructionChangedListener activeInstructionChangedListener = address -> highlight(
- (int) (address - memory.getDefinition().getMinimalAddress()));
+ private ActiveMicroInstructionChangedListener instChangeListener = (oldAddress, newAddress) ->
+ {
+ highlight((int) (newAddress - memory.getDefinition().getMinimalAddress()));
+ };
private MIMemoryReassignedListener reassignedListener = newAssignee ->
{
m.getMicroInstructionMemory().registerMemoryReassignedListener(reassignedListener);
context.addActiveMachineListener(activeMachineListener);
m.getMicroInstructionMemory().bind(memory);
+ m.addActiveMicroInstructionChangedListener(instChangeListener);
}));
}
if (this.memory != null)
{
this.memory.deregisterCellModifiedListener(cellModifiedListener);
- this.memory.deregisterActiveMicroInstructionChangedListener(activeInstructionChangedListener);
}
this.memory = memory;
if (memory != null)
{
this.memory.registerCellModifiedListener(cellModifiedListener);
- this.memory.registerActiveMicroInstructionChangedListener(activeInstructionChangedListener);
}
if (table != null)
table.bindMicroInstructionMemory(memory);
@Override
public void dispose()
{
- memory.deregisterActiveMicroInstructionChangedListener(activeInstructionChangedListener);
memory.deregisterCellModifiedListener(cellModifiedListener);
- context.getActiveMachine().ifPresent(m -> m.getMicroInstructionMemory().deregisterMemoryReassignedListener(reassignedListener));
+ context.getActiveMachine().ifPresent(m ->
+ {
+ m.removeActiveMicroInstructionChangedListener(instChangeListener);
+ m.getMicroInstructionMemory().deregisterMemoryReassignedListener(reassignedListener);
+ });
context.removeActiveMachineListener(activeMachineListener);
super.dispose();
}
package net.mograsim.plugin.tables.mi;
import java.util.Optional;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Table;
import net.mograsim.plugin.tables.LazyTableViewer;
+import net.mograsim.plugin.util.SingleSWTRequest;
public class RowHighlighter
{
- private int highlighted = -1, toHighlight;
+ private int highlighted = -1;
private LazyTableViewer viewer;
- private AtomicBoolean waiting = new AtomicBoolean();
private ColorProvider cProv;
+ private SingleSWTRequest requester = new SingleSWTRequest();
public RowHighlighter(LazyTableViewer viewer, ColorProvider cProv)
{
public void highlight(int row)
{
- synchronized (waiting)
+ requester.request(() ->
{
- toHighlight = row;
- if (!waiting.get())
- {
- waiting.set(true);
- Display.getDefault().asyncExec(() ->
- {
- synchronized (waiting)
- {
- waiting.set(false);
- if (!viewer.getTable().isDisposed())
- innerHighlight(toHighlight);
- }
- });
- }
- }
+ if (!viewer.getTable().isDisposed())
+ innerHighlight(row);
+ });
}
private void innerHighlight(int row)
{
table.showItem(table.getItem(Math.min(table.getItemCount(), row + 2)));
table.showItem(table.getItem(row));
- Optional.of(table.getItem(row).getData()).ifPresent(d -> viewer.update(d, null));
+ Optional.ofNullable(table.getItem(row).getData()).ifPresent(d -> viewer.update(d, null));
}
if (highlighted != -1)
- Optional.of(table.getItem(highlighted).getData()).ifPresent(d -> viewer.update(d, null));
+ Optional.ofNullable(table.getItem(highlighted).getData()).ifPresent(d -> viewer.update(d, null));
highlighted = row;
}
}
--- /dev/null
+package net.mograsim.plugin.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.eclipse.swt.widgets.Display;
+
+public class SingleSWTRequest
+{
+ private AtomicBoolean waiting = new AtomicBoolean();
+
+ public void request(Runnable request)
+ {
+ synchronized (waiting)
+ {
+ if (!waiting.get())
+ {
+ waiting.set(true);
+ Display.getDefault().asyncExec(() ->
+ {
+ synchronized (waiting)
+ {
+ waiting.set(false);
+ request.run();
+ }
+ });
+ }
+ }
+ }
+}