Faster byte and word to hex string
I was alarmed to discover just how slow `String.format()` is for doing integer to hex conversions. Now that a trace window has been added to Symon, it became especially clear that I needed a more efficient way to handle it. I looked into using `Integer.toHexString()`, but I would have had to wrap it to do zero-padding, so I decided to just bite the bullet and do my own with a lookup table. The implementation in `HexUtil` is just as fast as `Integer.toHexString()`, but also zero-pads appropriately. Combined with Java's `+` String concatenation, it seems perfectly adequate. For yet better performance with the trace window, it would make a lot of sense to special-case stepping so that it just pops the top line off the log, and appends to the bottom, rather than re-stringifying the entire trace log each time. This will be a future enhancement.
This commit is contained in:
1 parent
bc3de80892
commit
807a43ce6f
5 files changed
+225
-56
No files matched your search
@@ -247,6 +247,7 @@ public class Simulator implements Observer {
|
||||
// Spin up the new run loop
|
||||
runLoop = new RunLoop();
|
||||
runLoop.start();
|
||||
traceLog.simulatorDidStart();
|
||||
}
|
||||
|
||||
private void handleStop() {
|
||||
@@ -268,6 +269,7 @@ public class Simulator implements Observer {
|
||||
statusPane.updateState(cpu);
|
||||
}
|
||||
});
|
||||
traceLog.simulatorDidStop();
|
||||
if (traceLog.isVisible()) {
|
||||
traceLog.refresh();
|
||||
}
|
||||
@@ -291,6 +293,8 @@ public class Simulator implements Observer {
|
||||
ram.fill(0x00);
|
||||
// Clear the console.
|
||||
console.reset();
|
||||
// Reset the trace log.
|
||||
traceLog.reset();
|
||||
// Update status.
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
@@ -320,13 +324,9 @@ public class Simulator implements Observer {
|
||||
* Perform a single step of the simulated system.
|
||||
*/
|
||||
private void step() throws MemoryAccessException {
|
||||
|
||||
cpu.step();
|
||||
// TODO: We need to profile this for performance. Possibly allow
|
||||
// a flag to turn trace on/off
|
||||
synchronized(traceLog) {
|
||||
traceLog.append(cpu.getCpuState());
|
||||
}
|
||||
|
||||
traceLog.append(cpu.getCpuState());
|
||||
|
||||
// Read from the ACIA and immediately update the console if there's
|
||||
// output ready.
|
||||
|
||||
Reference in new issue
Block a user