Skip to content

Commit

Permalink
allowed to save ROM data
Browse files Browse the repository at this point in the history
  • Loading branch information
hneemann committed Feb 3, 2017
1 parent 1106b33 commit 27ed3d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/main/java/de/neemann/digital/core/memory/DataField.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ public DataField(Reader reader) throws IOException {
}
}

/**
* Save the stored data
*
* @param file file to store the data to
* @throws IOException IOException
*/
public void saveTo(File file) throws IOException {
DataField df = getMinimized();
try (BufferedWriter w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) {
w.write("v2.0 raw");
w.newLine();
for (long l : df.getData()) {
w.write(Long.toHexString(l));
w.newLine();
}
}
}

/**
* Sets all stored data to null!
* Is not called during simulation! Is only called during editing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import de.neemann.digital.core.io.IntFormat;
import de.neemann.digital.core.memory.DataField;
import de.neemann.digital.core.memory.ROM;
import de.neemann.digital.testing.TestData;
import de.neemann.digital.gui.components.testing.TestDataEditor;
import de.neemann.digital.gui.sync.NoSync;
import de.neemann.digital.lang.Lang;
import de.neemann.digital.testing.TestData;
import de.neemann.gui.ErrorMessage;
import de.neemann.gui.StringUtils;
import de.neemann.gui.ToolTipAction;
Expand Down Expand Up @@ -305,6 +305,22 @@ public void actionPerformed(ActionEvent e) {
.setToolTip(Lang.get("btn_reload_tt"))
.createJButton()
);
panel.add(new ToolTipAction(Lang.get("btn_save")) {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
fc.setSelectedFile(attr.getFile(ROM.LAST_DATA_FILE_KEY));
fc.setFileFilter(new FileNameExtensionFilter("hex", "hex"));
if (fc.showSaveDialog(panel) == JFileChooser.APPROVE_OPTION) {
attr.setFile(ROM.LAST_DATA_FILE_KEY, fc.getSelectedFile());
try {
data.saveTo(fc.getSelectedFile());
} catch (IOException e1) {
new ErrorMessage(Lang.get("msg_errorWritingFile")).addCause(e1).show(panel);
}
}
}
}.createJButton());
return panel;
}

Expand Down

0 comments on commit 27ed3d9

Please sign in to comment.