Counters are able to act as program counters via the remote interface, closes #426

This commit is contained in:
hneemann 2020-03-15 22:21:54 +01:00
parent c2c8eafaf3
commit a814f678b4
6 changed files with 60 additions and 17 deletions

View File

@ -3,6 +3,7 @@ Release Notes
Head, planned as v0.25
- move the "lib" folder from the "examples" folder to the root folder.
- Reordering of the cells in the K-Map
- Counters are able to act as program counters via the remote interface.
- 74193 was added
v0.24, released on 1. Feb. 2020

View File

@ -14,7 +14,7 @@ import static de.neemann.digital.core.element.PinInfo.input;
/**
* A simple counter.
*/
public class Counter extends Node implements Element {
public class Counter extends Node implements Element, ProgramCounter {
/**
* The counters {@link ElementTypeDescription}
@ -25,13 +25,15 @@ public class Counter extends Node implements Element {
.addAttribute(Keys.BITS)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.VALUE_IS_PROBE);
.addAttribute(Keys.VALUE_IS_PROBE)
.addAttribute(Keys.IS_PROGRAM_COUNTER);
private final ObservableValue out;
private final ObservableValue ovf;
private final long maxValue;
private final boolean probe;
private final String label;
private final boolean isProgramCounter;
private ObservableValue clockIn;
private ObservableValue clrIn;
private ObservableValue enable;
@ -52,6 +54,7 @@ public class Counter extends Node implements Element {
maxValue = Bits.mask(bits);
probe = attributes.get(Keys.VALUE_IS_PROBE);
label = attributes.getLabel();
isProgramCounter = attributes.get(Keys.IS_PROGRAM_COUNTER);
}
@Override
@ -92,7 +95,6 @@ public class Counter extends Node implements Element {
return ovs(out, ovf);
}
@Override
public void registerNodes(Model model) {
super.registerNodes(model);
@ -105,4 +107,13 @@ public class Counter extends Node implements Element {
}));
}
@Override
public boolean isProgramCounter() {
return isProgramCounter;
}
@Override
public long getProgramCounter() {
return counter;
}
}

View File

@ -17,7 +17,7 @@ import static de.neemann.digital.core.element.PinInfo.input;
/**
* A simple counter.
*/
public class CounterPreset extends Node implements Element {
public class CounterPreset extends Node implements Element, ProgramCounter {
/**
* The counters {@link ElementTypeDescription}
@ -35,7 +35,8 @@ public class CounterPreset extends Node implements Element {
.addAttribute(Keys.MAX_VALUE)
.addAttribute(Keys.INVERTER_CONFIG)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.VALUE_IS_PROBE);
.addAttribute(Keys.VALUE_IS_PROBE)
.addAttribute(Keys.IS_PROGRAM_COUNTER);
private final ObservableValue out;
private final ObservableValue ovf;
@ -43,6 +44,7 @@ public class CounterPreset extends Node implements Element {
private final boolean probe;
private final String label;
private final int bits;
private final boolean isProgramCounter;
private ObservableValue clockIn;
private ObservableValue clrIn;
private ObservableValue enable;
@ -72,6 +74,7 @@ public class CounterPreset extends Node implements Element {
probe = attributes.get(Keys.VALUE_IS_PROBE);
label = attributes.getLabel();
isProgramCounter = attributes.get(Keys.IS_PROGRAM_COUNTER);
}
@Override
@ -145,4 +148,13 @@ public class CounterPreset extends Node implements Element {
}));
}
@Override
public boolean isProgramCounter() {
return isProgramCounter;
}
@Override
public long getProgramCounter() {
return counter;
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2020 Helmut Neemann.
* Use of this source code is governed by the GPL v3 license
* that can be found in the LICENSE file.
*/
package de.neemann.digital.core.memory;
/**
* This interface is implemented by all components which are able to act as a program counter.
*/
public interface ProgramCounter {
/**
* @return true if this component is used as the program counter
*/
boolean isProgramCounter();
/**
* @return the value of the program counter
*/
long getProgramCounter();
}

View File

@ -17,7 +17,7 @@ import static de.neemann.digital.core.element.PinInfo.input;
/**
* A simple register.
*/
public class Register extends Node implements Element, Countable {
public class Register extends Node implements Element, Countable, ProgramCounter {
/**
* The registers {@link ElementTypeDescription}
@ -92,17 +92,13 @@ public class Register extends Node implements Element, Countable {
}));
}
/**
* @return true if this register is the program counter
*/
@Override
public boolean isProgramCounter() {
return isProgramCounter;
}
/**
* @return the value of this register
*/
public long getValue() {
@Override
public long getProgramCounter() {
return value;
}

View File

@ -15,7 +15,7 @@ import de.neemann.digital.core.element.ElementAttributes;
import de.neemann.digital.core.element.Keys;
import de.neemann.digital.core.io.Button;
import de.neemann.digital.core.io.*;
import de.neemann.digital.core.memory.Register;
import de.neemann.digital.core.memory.ProgramCounter;
import de.neemann.digital.core.stats.Statistics;
import de.neemann.digital.core.wiring.AsyncSeq;
import de.neemann.digital.core.wiring.Clock;
@ -1777,9 +1777,9 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
private long address;
private void getProgramROMAddress(Model model) {
List<Register> roms = model.findNode(Register.class, Register::isProgramCounter);
if (roms.size() == 1)
address = roms.get(0).getValue();
List<Node> programCounters = model.findNode(n -> n instanceof ProgramCounter && ((ProgramCounter) n).isProgramCounter());
if (programCounters.size() == 1)
address = ((ProgramCounter) programCounters.get(0)).getProgramCounter();
else
address = -1;
}