added a test for the ProgramMemoryLoader

This commit is contained in:
hneemann 2018-07-31 21:55:34 +02:00
parent d3921fa888
commit 368cb2de27
5 changed files with 138 additions and 5 deletions

View File

@ -1279,7 +1279,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
modelModifier.preInit(model); modelModifier.preInit(model);
else { else {
if (settings.get(Keys.PRELOAD_PROGRAM)) if (settings.get(Keys.PRELOAD_PROGRAM))
new ProgramMemoryRomLoader(settings.get(Keys.PROGRAM_TO_PRELOAD)).preInit(model); new ProgramMemoryLoader(settings.get(Keys.PROGRAM_TO_PRELOAD)).preInit(model);
} }
model.init(); model.init();
@ -1651,7 +1651,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
@Override @Override
public void start(File romHex) { public void start(File romHex) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
runModelState.enter(true, new ProgramMemoryRomLoader(romHex)); runModelState.enter(true, new ProgramMemoryLoader(romHex));
circuitComponent.repaintNeeded(); circuitComponent.repaintNeeded();
}); });
} }
@ -1659,7 +1659,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
@Override @Override
public void debug(File romHex) { public void debug(File romHex) {
SwingUtilities.invokeLater(() -> { SwingUtilities.invokeLater(() -> {
runModelState.enter(false, new ProgramMemoryRomLoader(romHex)); runModelState.enter(false, new ProgramMemoryLoader(romHex));
circuitComponent.repaintNeeded(); circuitComponent.repaintNeeded();
if (model != null) if (model != null)
showMeasurementDialog(ModelEvent.STEP); showMeasurementDialog(ModelEvent.STEP);

View File

@ -19,7 +19,7 @@ import java.util.List;
/** /**
* A Modifier that loads a given rom file to the program memory of the model. * A Modifier that loads a given rom file to the program memory of the model.
*/ */
public class ProgramMemoryRomLoader implements ModelModifier { public class ProgramMemoryLoader implements ModelModifier {
private final File romHex; private final File romHex;
/** /**
@ -27,7 +27,7 @@ public class ProgramMemoryRomLoader implements ModelModifier {
* *
* @param romHex the file to load * @param romHex the file to load
*/ */
ProgramMemoryRomLoader(File romHex) { ProgramMemoryLoader(File romHex) {
this.romHex = romHex; this.romHex = romHex;
} }

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2016 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.gui;
import de.neemann.digital.core.Model;
import de.neemann.digital.core.memory.RAMDualPort;
import de.neemann.digital.integration.Resources;
import de.neemann.digital.integration.ToBreakRunner;
import junit.framework.TestCase;
import java.io.File;
import java.util.List;
public class ProgramMemoryLoaderTest extends TestCase {
public void testSimple() throws Exception {
ToBreakRunner runner = new ToBreakRunner("dig/testProgLoader.dig", false);
Model model = runner.getModel();
File romHex = new File(Resources.getRoot(), "dig/testProgLoader.hex");
new ProgramMemoryLoader(romHex).preInit(model);
model.init();
List<RAMDualPort> ramList = model.findNode(RAMDualPort.class);
assertEquals(1, ramList.size());
RAMDualPort ram = ramList.get(0);
assertEquals(0x55, ram.getMemory().getDataWord(0));
assertEquals(0xAA, ram.getMemory().getDataWord(1));
}
}

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<circuit>
<version>1</version>
<attributes/>
<visualElements>
<visualElement>
<elementName>RAMDualPort</elementName>
<elementAttributes>
<entry>
<string>AddrBits</string>
<int>8</int>
</entry>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
<entry>
<string>isProgramMemory</string>
<boolean>true</boolean>
</entry>
</elementAttributes>
<pos x="420" y="220"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
</elementAttributes>
<pos x="380" y="220"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
</elementAttributes>
<pos x="340" y="240"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes/>
<pos x="380" y="260"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes/>
<pos x="340" y="280"/>
</visualElement>
<visualElement>
<elementName>In</elementName>
<elementAttributes/>
<pos x="380" y="300"/>
</visualElement>
<visualElement>
<elementName>Out</elementName>
<elementAttributes>
<entry>
<string>Bits</string>
<int>8</int>
</entry>
</elementAttributes>
<pos x="520" y="260"/>
</visualElement>
</visualElements>
<wires>
<wire>
<p1 x="340" y="240"/>
<p2 x="420" y="240"/>
</wire>
<wire>
<p1 x="380" y="260"/>
<p2 x="420" y="260"/>
</wire>
<wire>
<p1 x="480" y="260"/>
<p2 x="520" y="260"/>
</wire>
<wire>
<p1 x="340" y="280"/>
<p2 x="420" y="280"/>
</wire>
<wire>
<p1 x="380" y="220"/>
<p2 x="420" y="220"/>
</wire>
<wire>
<p1 x="380" y="300"/>
<p2 x="420" y="300"/>
</wire>
</wires>
</circuit>

View File

@ -0,0 +1,4 @@
v2.0 raw
55
AA