mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 15:26:52 -04:00
format is provided to the data editor
This commit is contained in:
parent
28243c332d
commit
0b1467ec1f
@ -90,6 +90,24 @@ public enum IntFormat {
|
||||
}
|
||||
}
|
||||
|
||||
public int strLen(int bits) {
|
||||
switch (this) {
|
||||
case dec:
|
||||
return (int) Math.ceil(Math.log10(1L<<bits));
|
||||
case decSigned:
|
||||
return (int) Math.ceil(Math.log10(1L<<(bits-1)))+1;
|
||||
case hex:
|
||||
return (bits-1)/4+3;
|
||||
case bin:
|
||||
return bits+2;
|
||||
case oct:
|
||||
return (bits-1)/3+3;
|
||||
case ascii:
|
||||
return 3;
|
||||
default:
|
||||
return (bits-1)/4+3;
|
||||
}
|
||||
}
|
||||
|
||||
private static final char[] DIGITS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
|
||||
|
@ -31,6 +31,7 @@ public class EEPROM extends Node implements Element, RAMInterface, ROMInterface
|
||||
.addAttribute(Keys.BITS)
|
||||
.addAttribute(Keys.ADDR_BITS)
|
||||
.addAttribute(Keys.LABEL)
|
||||
.addAttribute(Keys.INT_FORMAT)
|
||||
.addAttribute(Keys.IS_PROGRAM_MEMORY)
|
||||
.addAttribute(Keys.INVERTER_CONFIG)
|
||||
.addAttribute(Keys.DATA);
|
||||
@ -42,6 +43,7 @@ public class EEPROM extends Node implements Element, RAMInterface, ROMInterface
|
||||
private final String label;
|
||||
private final ObservableValue dataOut;
|
||||
private final boolean isProgramMemory;
|
||||
private final IntFormat intFormat;
|
||||
private DataField memory;
|
||||
private ObservableValue addrIn;
|
||||
private ObservableValue csIn;
|
||||
@ -74,6 +76,7 @@ public class EEPROM extends Node implements Element, RAMInterface, ROMInterface
|
||||
.setPinDescription(DESCRIPTION)
|
||||
.setBidirectional();
|
||||
isProgramMemory = attr.get(Keys.IS_PROGRAM_MEMORY);
|
||||
intFormat = attr.get(Keys.INT_FORMAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -122,6 +125,11 @@ public class EEPROM extends Node implements Element, RAMInterface, ROMInterface
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntFormat getIntFormat() {
|
||||
return intFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObservableValues getOutputs() {
|
||||
return dataOut.asList();
|
||||
|
@ -30,10 +30,12 @@ public class RAMDualPort extends Node implements Element, RAMInterface {
|
||||
.addAttribute(Keys.ROTATE)
|
||||
.addAttribute(Keys.BITS)
|
||||
.addAttribute(Keys.ADDR_BITS)
|
||||
.addAttribute(Keys.INT_FORMAT)
|
||||
.addAttribute(Keys.IS_PROGRAM_MEMORY)
|
||||
.addAttribute(Keys.LABEL);
|
||||
|
||||
private DataField memory;
|
||||
private final IntFormat intFormat;
|
||||
private final ObservableValue output;
|
||||
private final int addrBits;
|
||||
private final int bits;
|
||||
@ -63,6 +65,7 @@ public class RAMDualPort extends Node implements Element, RAMInterface {
|
||||
memory = createDataField(attr, size);
|
||||
label = attr.getLabel();
|
||||
isProgramMemory = attr.get(Keys.IS_PROGRAM_MEMORY);
|
||||
intFormat = attr.get(Keys.INT_FORMAT);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,6 +184,11 @@ public class RAMDualPort extends Node implements Element, RAMInterface {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntFormat getIntFormat() {
|
||||
return intFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the used memory field
|
||||
*
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package de.neemann.digital.core.memory;
|
||||
|
||||
import de.neemann.digital.core.IntFormat;
|
||||
import de.neemann.digital.core.stats.Countable;
|
||||
|
||||
/**
|
||||
@ -25,4 +26,8 @@ public interface RAMInterface extends ProgramMemory, Countable {
|
||||
* @return the addr bits
|
||||
*/
|
||||
int getAddrBits();
|
||||
|
||||
default IntFormat getIntFormat() {
|
||||
return IntFormat.hex;
|
||||
}
|
||||
}
|
||||
|
@ -38,10 +38,12 @@ public class ROM extends Node implements Element, ROMInterface, ProgramMemory {
|
||||
.addAttribute(Keys.ADDR_BITS)
|
||||
.addAttribute(Keys.LABEL)
|
||||
.addAttribute(Keys.DATA)
|
||||
.addAttribute(Keys.INT_FORMAT)
|
||||
.addAttribute(Keys.IS_PROGRAM_MEMORY)
|
||||
.addAttribute(Keys.AUTO_RELOAD_ROM);
|
||||
|
||||
private DataField data;
|
||||
private final IntFormat intFormat;
|
||||
private final ObservableValue output;
|
||||
private final int addrBits;
|
||||
private final int dataBits;
|
||||
@ -73,6 +75,7 @@ public class ROM extends Node implements Element, ROMInterface, ProgramMemory {
|
||||
hexFile = attr.getFile(LAST_DATA_FILE_KEY);
|
||||
} else
|
||||
hexFile = null;
|
||||
intFormat = attr.get(Keys.INT_FORMAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,6 +143,11 @@ public class ROM extends Node implements Element, ROMInterface, ProgramMemory {
|
||||
return addrBits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IntFormat getIntFormat() {
|
||||
return intFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDataBits() {
|
||||
return dataBits;
|
||||
|
@ -5,6 +5,7 @@
|
||||
*/
|
||||
package de.neemann.digital.core.memory.rom;
|
||||
|
||||
import de.neemann.digital.core.IntFormat;
|
||||
import de.neemann.digital.core.memory.DataField;
|
||||
import de.neemann.digital.core.stats.Countable;
|
||||
|
||||
@ -34,4 +35,5 @@ public interface ROMInterface extends Countable {
|
||||
*/
|
||||
int getAddrBits();
|
||||
|
||||
IntFormat getIntFormat();
|
||||
}
|
||||
|
@ -71,8 +71,9 @@ public class RAMShape extends GenericShape {
|
||||
@Override
|
||||
public boolean clicked(CircuitComponent cc, Point pos, IOState ioState, Element element, SyncAccess modelSync) {
|
||||
if (element instanceof RAMInterface) {
|
||||
DataField dataField = ((RAMInterface) element).getMemory();
|
||||
DataEditor dataEditor = new DataEditor(cc, dataField, dataBits, addrBits, true, modelSync);
|
||||
RAMInterface ram = (RAMInterface) element;
|
||||
DataField dataField = ram.getMemory();
|
||||
DataEditor dataEditor = new DataEditor(cc, dataField, dataBits, addrBits, true, modelSync, ram.getIntFormat());
|
||||
dataEditor.showDialog(dialogTitle, model);
|
||||
}
|
||||
return false;
|
||||
|
@ -5,10 +5,7 @@
|
||||
*/
|
||||
package de.neemann.digital.gui.components;
|
||||
|
||||
import de.neemann.digital.core.Bits;
|
||||
import de.neemann.digital.core.Model;
|
||||
import de.neemann.digital.core.ModelEvent;
|
||||
import de.neemann.digital.core.SyncAccess;
|
||||
import de.neemann.digital.core.*;
|
||||
import de.neemann.digital.core.memory.DataField;
|
||||
import de.neemann.digital.core.memory.importer.Importer;
|
||||
import de.neemann.digital.gui.SaveAsHelper;
|
||||
@ -53,7 +50,7 @@ public class DataEditor extends JDialog {
|
||||
* @param modelIsRunning true if model is running
|
||||
* @param modelSync used to access the running model
|
||||
*/
|
||||
public DataEditor(Component parent, DataField dataField, int dataBits, int addrBits, boolean modelIsRunning, SyncAccess modelSync) {
|
||||
public DataEditor(Component parent, DataField dataField, int dataBits, int addrBits, boolean modelIsRunning, SyncAccess modelSync, IntFormat intFormat) {
|
||||
super(SwingUtilities.windowForComponent(parent), Lang.get("key_Data"), modelIsRunning ? ModalityType.MODELESS : ModalityType.APPLICATION_MODAL);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
|
@ -606,7 +606,7 @@ public final class EditorFactory {
|
||||
getAttributeDialog().storeEditedValues();
|
||||
int dataBits = attr.get(Keys.BITS);
|
||||
int addrBits = getAddrBits(attr);
|
||||
DataEditor de = new DataEditor(panel, data, dataBits, addrBits, false, SyncAccess.NOSYNC);
|
||||
DataEditor de = new DataEditor(panel, data, dataBits, addrBits, false, SyncAccess.NOSYNC, attr.get(Keys.INT_FORMAT));
|
||||
de.setFileName(attr.getFile(ROM.LAST_DATA_FILE_KEY));
|
||||
if (de.showDialog()) {
|
||||
DataField mod = de.getModifiedDataField();
|
||||
|
@ -88,7 +88,7 @@ public class ProbeDialog extends JDialog implements ModelStateObserverTyped {
|
||||
ram.getDataBits(),
|
||||
ram.getAddrBits(),
|
||||
true,
|
||||
model).showDialog(ram.getLabel(), model);
|
||||
model, ram.getIntFormat()).showDialog(ram.getLabel(), model);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ public class ROMEditorDialog extends JDialog {
|
||||
}
|
||||
|
||||
public boolean edit(ROMEditorDialog romEditorDialog) {
|
||||
DataEditor de = new DataEditor(romEditorDialog, data, ri.getDataBits(), ri.getAddrBits(), false, SyncAccess.NOSYNC);
|
||||
DataEditor de = new DataEditor(romEditorDialog, data, ri.getDataBits(), ri.getAddrBits(), false, SyncAccess.NOSYNC, ri.getIntFormat());
|
||||
if (de.showDialog()) {
|
||||
data = de.getModifiedDataField();
|
||||
return true;
|
||||
|
@ -86,4 +86,34 @@ public class IntFormatTest extends TestCase {
|
||||
assertTrue(format.name() + ":" + val + " != " + conv, val.isEqual(conv));
|
||||
}
|
||||
}
|
||||
|
||||
public void testStrLen() {
|
||||
assertEquals(6,IntFormat.hex.strLen(16));
|
||||
assertEquals(6,IntFormat.hex.strLen(15));
|
||||
assertEquals(6,IntFormat.hex.strLen(14));
|
||||
assertEquals(6,IntFormat.hex.strLen(13));
|
||||
assertEquals(5,IntFormat.hex.strLen(12));
|
||||
|
||||
assertEquals(18,IntFormat.bin.strLen(16));
|
||||
assertEquals(17,IntFormat.bin.strLen(15));
|
||||
assertEquals(16,IntFormat.bin.strLen(14));
|
||||
|
||||
assertEquals(3,IntFormat.dec.strLen(8));
|
||||
assertEquals(3,IntFormat.dec.strLen(9));
|
||||
assertEquals(4,IntFormat.dec.strLen(10));
|
||||
|
||||
assertEquals(4,IntFormat.decSigned.strLen(8));
|
||||
assertEquals(4,IntFormat.decSigned.strLen(9));
|
||||
assertEquals(4,IntFormat.decSigned.strLen(10));
|
||||
assertEquals(5,IntFormat.decSigned.strLen(11));
|
||||
|
||||
assertEquals(4,IntFormat.oct.strLen(4));
|
||||
assertEquals(4,IntFormat.oct.strLen(5));
|
||||
assertEquals(4,IntFormat.oct.strLen(6));
|
||||
assertEquals(5,IntFormat.oct.strLen(7));
|
||||
assertEquals(5,IntFormat.oct.strLen(8));
|
||||
assertEquals(5,IntFormat.oct.strLen(9));
|
||||
assertEquals(6,IntFormat.oct.strLen(10));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user