mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 17:04:42 -04:00
added a test for the ProgramMemoryLoader
This commit is contained in:
parent
d3921fa888
commit
368cb2de27
@ -1279,7 +1279,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
modelModifier.preInit(model);
|
||||
else {
|
||||
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();
|
||||
@ -1651,7 +1651,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
@Override
|
||||
public void start(File romHex) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
runModelState.enter(true, new ProgramMemoryRomLoader(romHex));
|
||||
runModelState.enter(true, new ProgramMemoryLoader(romHex));
|
||||
circuitComponent.repaintNeeded();
|
||||
});
|
||||
}
|
||||
@ -1659,7 +1659,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
@Override
|
||||
public void debug(File romHex) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
runModelState.enter(false, new ProgramMemoryRomLoader(romHex));
|
||||
runModelState.enter(false, new ProgramMemoryLoader(romHex));
|
||||
circuitComponent.repaintNeeded();
|
||||
if (model != null)
|
||||
showMeasurementDialog(ModelEvent.STEP);
|
||||
|
@ -19,7 +19,7 @@ import java.util.List;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
@ -27,7 +27,7 @@ public class ProgramMemoryRomLoader implements ModelModifier {
|
||||
*
|
||||
* @param romHex the file to load
|
||||
*/
|
||||
ProgramMemoryRomLoader(File romHex) {
|
||||
ProgramMemoryLoader(File romHex) {
|
||||
this.romHex = romHex;
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
96
src/test/resources/dig/testProgLoader.dig
Normal file
96
src/test/resources/dig/testProgLoader.dig
Normal 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>
|
4
src/test/resources/dig/testProgLoader.hex
Normal file
4
src/test/resources/dig/testProgLoader.hex
Normal file
@ -0,0 +1,4 @@
|
||||
v2.0 raw
|
||||
55
|
||||
AA
|
||||
|
Loading…
x
Reference in New Issue
Block a user