added getDoubleValue to data source and fixed windows to handle double values

git-svn-id: https://mspsim.svn.sourceforge.net/svnroot/mspsim/mspsim@299 23d1a52b-0c3c-0410-b72d-8f29ab48fe35
This commit is contained in:
joxe 2008-09-04 19:11:51 +00:00
parent 4df60061f4
commit 91c5fd7d35
10 changed files with 46 additions and 18 deletions

View File

@ -60,7 +60,7 @@ public abstract class AbstractWindowDataHandler implements WindowDataHandler {
public abstract void setProperty(int index, String param, String[] args);
public int atoi(String data, int defaultValue) {
public static int atoi(String data, int defaultValue) {
try {
return Integer.parseInt(data);
} catch (NumberFormatException e) {
@ -68,4 +68,11 @@ public abstract class AbstractWindowDataHandler implements WindowDataHandler {
}
}
public static double atod(String data, double defaultValue) {
try {
return Double.parseDouble(data);
} catch (NumberFormatException e) {
return defaultValue;
}
}
}

View File

@ -610,9 +610,6 @@ public class Timer extends IOUnit {
}
}
// System.out.println("UpdateCounter: C1: " + counter + " C2:" + ctr);
if (DEBUG) {
System.out.println(getName() + ": Updating counter cycctr: " + cycctr + " divider: " + divider + " mode:" + mode + " => " + counter);
}

View File

@ -126,7 +126,7 @@ public class LineChart extends JFreeWindowDataHandler {
addSeries();
}
for (int i = 0; i < parts.length; i++) {
dataset.getSeries(i).add(point, atoi(parts[i], 0));
dataset.getSeries(i).add(point, atod(parts[i], 0));
}
point++;
panel.repaint();

View File

@ -64,7 +64,7 @@ public class LineSampleChart extends JFreeWindowDataHandler {
String parts[] = line.trim().split(" ");
dataSeries.clear();
for (int i = 0; i < parts.length; i++) {
dataSeries.add(i, atoi(parts[i], 0));
dataSeries.add(i, atod(parts[i], 0));
}
panel.repaint();
}

View File

@ -103,13 +103,7 @@ public abstract class GenericNode extends Chip implements Runnable {
IHexReader reader = new IHexReader();
reader.readFile(memory, firmwareFile = args[0]);
} else {
elf = ELF.readELF(firmwareFile = args[0]);
elf.loadPrograms(memory);
MapTable map = elf.getMap();
cpu.getDisAsm().setMap(map);
cpu.setMap(map);
registry.registerComponent("elf", elf);
registry.registerComponent("mapTable", map);
loadFirmware(args[0], memory);
}
cpu.reset();
@ -160,6 +154,17 @@ public abstract class GenericNode extends Chip implements Runnable {
}
}
public void loadFirmware(String name, int[] memory) throws IOException {
stop();
elf = ELF.readELF(firmwareFile = name);
elf.loadPrograms(memory);
MapTable map = elf.getMap();
cpu.getDisAsm().setMap(map);
cpu.setMap(map);
registry.registerComponent("elf", elf);
registry.registerComponent("mapTable", map);
}
// A step that will break out of breakpoints!
public void step(int nr) {
if (!cpu.isRunning()) {

View File

@ -39,5 +39,6 @@
package se.sics.mspsim.util;
public interface DataSource {
public double getDoubleValue();
public int getValue();
}

View File

@ -44,6 +44,7 @@ public interface MultiDataSource {
public int getModeMax();
public double getDoubleValue(int mode);
public int getValue(int mode);
}

View File

@ -137,7 +137,7 @@ public class OperatingModeStatistics {
}
// returns percentage since last call...
public int getValue() {
public double getDoubleValue() {
long diff = cpu.cycles - lastCycles;
if (diff == 0) return 0;
long val = entry.getValue(mode, cpu.cycles);
@ -147,7 +147,11 @@ public class OperatingModeStatistics {
if (operation == OP_INVERT) {
return (int) (100 - 100 * valDiff / diff);
}
return (int) (100 * valDiff / diff);
return (100.0 * valDiff / diff);
}
public int getValue() {
return (int) getDoubleValue();
}
}
@ -171,6 +175,10 @@ public class OperatingModeStatistics {
// returns percentage since last call...
public int getValue(int mode) {
return (int) getDoubleValue(mode);
}
public double getDoubleValue(int mode) {
long diff = cpu.cycles - lastCycles[mode];
if (diff == 0) return 0;
@ -178,7 +186,7 @@ public class OperatingModeStatistics {
long valDiff = (val - lastValue[mode]);
lastValue[mode] = val;
lastCycles[mode] = cpu.cycles;
return (int) (100 * valDiff / diff);
return (100.0 * valDiff / diff);
}
}

View File

@ -20,6 +20,9 @@ public class StackMonitor implements CPUMonitor {
stackMax = stack;
return tmp;
}
public double getDoubleValue() {
return getValue();
}
};
private DataSource minDataSource = new DataSource() {
@ -28,12 +31,18 @@ public class StackMonitor implements CPUMonitor {
stackMin = stack;
return tmp;
}
public double getDoubleValue() {
return getValue();
}
};
private DataSource dataSource = new DataSource() {
public int getValue() {
return stack;
}
public double getDoubleValue() {
return getValue();
}
};
public StackMonitor(MSP430 cpu) {

View File

@ -139,10 +139,10 @@ public class StatCommands implements CommandBundle {
MultiDataSource ds = (MultiDataSource) s;
for (int k = 0, m = ds.getModeMax(); k <= m; k++) {
if (k > 0) out.print(' ');
out.print(ds.getValue(k));
out.print(((int) (ds.getDoubleValue(k) * 100)) / 100.0);
}
} else {
out.print(((DataSource)s).getValue());
out.print(((int)((DataSource)s).getDoubleValue() * 100) / 100.0);
}
}
out.println();