added auto load function to ROM

This commit is contained in:
hneemann 2016-06-17 17:02:36 +02:00
parent 1981818ed4
commit 2f40085148
7 changed files with 45 additions and 24 deletions

View File

@ -40,7 +40,7 @@ public interface Element {
/**
* Is called after registerNodes is called on all Elements.
*/
default void init(Model model) {
default void init(Model model) throws NodeException {
}
}

View File

@ -151,6 +151,12 @@ public final class Keys {
public static final Key<Boolean> SHOW_LISTING
= new Key<>("showList", false);
/**
* flag to enable the ROMs auto load function
*/
public static final Key<Boolean> AUTO_RELOAD_ROM
= new Key<>("autoReload", false);
/**
* flag to show the data table window
*/

View File

@ -8,6 +8,7 @@ import de.neemann.digital.core.element.Keys;
import de.neemann.digital.lang.Lang;
import java.io.File;
import java.io.IOException;
import static de.neemann.digital.core.element.PinInfo.input;
@ -32,15 +33,17 @@ public class ROM extends Node implements Element {
.addAttribute(Keys.BITS)
.addAttribute(Keys.ADDR_BITS)
.addAttribute(Keys.LABEL)
.addAttribute(Keys.SHOW_LISTING)
.addAttribute(Keys.DATA);
.addAttribute(Keys.DATA)
.addAttribute(Keys.AUTO_RELOAD_ROM)
.addAttribute(Keys.SHOW_LISTING);
private final DataField data;
private DataField data;
private final ObservableValue output;
private final int addrBits;
private final boolean showList;
private final File listFile;
private final File hexFile;
private final Observable romObservable = new Observable();
private final boolean autoLoad;
private ObservableValue addrIn;
private ObservableValue selIn;
private int addr;
@ -58,10 +61,11 @@ public class ROM extends Node implements Element {
data = attr.get(Keys.DATA);
addrBits = attr.get(Keys.ADDR_BITS);
showList = attr.get(Keys.SHOW_LISTING);
if (showList) {
listFile = attr.getFile(LAST_DATA_FILE_KEY);
autoLoad = attr.get(Keys.AUTO_RELOAD_ROM);
if (showList || autoLoad) {
hexFile = attr.getFile(LAST_DATA_FILE_KEY);
} else
listFile = null;
hexFile = null;
}
@Override
@ -102,15 +106,26 @@ public class ROM extends Node implements Element {
*
* @return the file
*/
public File getListFile() {
return listFile;
public File getHexFile() {
return hexFile;
}
@Override
public void init(Model model) throws NodeException {
if (autoLoad) {
try {
data = new DataField(hexFile);
} catch (IOException e) {
throw new NodeException(e.getMessage(), this, null);
}
}
}
/**
* @return true if there is a listing to show
*/
public boolean showListing() {
return showList && listFile != null;
return showList && hexFile != null;
}
/**

View File

@ -64,7 +64,6 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
ATTR_LIST.add(Keys.SHOW_DATA_TABLE);
ATTR_LIST.add(Keys.SHOW_DATA_GRAPH);
ATTR_LIST.add(Keys.SHOW_DATA_GRAPH_MICRO);
ATTR_LIST.add(Keys.SHOW_LISTING);
}
private static final String MESSAGE = Lang.get("message");
@ -648,17 +647,14 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
if (settings.get(Keys.SHOW_DATA_GRAPH_MICRO))
windowPosManager.register("datasetMicro", new DataSetDialog(this, model, true, ordering)).setVisible(true);
if (settings.get(Keys.SHOW_LISTING)) {
int i = 0;
for (ROM rom : model.findNode(ROM.class))
if (rom.showListing())
try {
windowPosManager.register("rom" + (i++), new ROMListingDialog(this, rom)).setVisible(true);
} catch (IOException e) {
new ErrorMessage(Lang.get("msg_errorReadingListing_N0", rom.getListFile().toString())).addCause(e).show(this);
}
}
int i = 0;
for (ROM rom : model.findNode(ROM.class))
if (rom.showListing())
try {
windowPosManager.register("rom" + (i++), new ROMListingDialog(this, rom)).setVisible(true);
} catch (IOException e) {
new ErrorMessage(Lang.get("msg_errorReadingListing_N0", rom.getHexFile().toString())).addCause(e).show(this);
}
model.init();

View File

@ -39,7 +39,7 @@ public class ROMListingDialog extends JDialog implements Observer {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
File filename = rom.getListFile();
File filename = rom.getHexFile();
String name = filename.getName();
int p = name.lastIndexOf('.');
if (p >= 0) {

View File

@ -183,6 +183,8 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen.</string>
<string name="key_Value">Wert</string>
<string name="key_Width">Breite</string>
<string name="key_Width_tt">Breite des Symbols wenn diese Schaltung in eine andere eingefügt wird.</string>
<string name="key_autoReload">Bei jedem Start neu Laden.</string>
<string name="key_autoReload_tt">Lädt das HEX-File bei jedem Modelstart neu.</string>
<string name="key_flipSelPos">Tausche Position des Selectors</string>
<string name="key_intFormat">Zahlenformat</string>
<string name="key_intFormat_ascii">ASCII</string>

View File

@ -183,6 +183,8 @@ To analyse you can run the circuit in single gate step mode.</string>
<string name="key_Value">Value</string>
<string name="key_Width">Width</string>
<string name="key_Width_tt">With of symbol if this circuit is used in an element ins an other circuit.</string>
<string name="key_autoReload">Reload at model start</string>
<string name="key_autoReload_tt">Reloads the hex file every time the model is started.</string>
<string name="key_flipSelPos">Flip selector position</string>
<string name="key_intFormat">Number Format</string>
<string name="key_intFormat_ascii">ascii</string>