Merge emulated frequency measurement into ^T command

This commit is contained in:
Satoshi N. M 2018-01-15 14:23:12 -08:00
parent 01a0f0f63c
commit b79a6744a0
2 changed files with 16 additions and 22 deletions

View File

@ -22,10 +22,9 @@ Special commands built-in, not passed to the ACIA and 6502:
| --------- | ------ |
| ^V | Show `pill_6502` version |
| ^P | Pause/resume 6502 processor execution |
| ^F | Show frequency |
| ^R | Reset the 6502 processor (also reset on USB reset) |
| ^E | Local echo toggle, off by default |
| ^T | Show clock ticks and instruction count |
| ^T | Show clock ticks, instruction count, and frequency since last ^T |
| ^G | Show help |
Intended to be somewhat compatible with [Grant Searle's Simple6502](http://searle.hostei.com/grant/6502/Simple6502.html),

View File

@ -113,24 +113,6 @@ char *process_serial_command(char b) {
paused = !paused;
return paused ? "paused" : "resumed";
} else if (b == '\x06') { // ^F
static uint32_t last_ticks = 0;
static uint32_t last_millis = 0;
if (last_ticks == 0) {
last_ticks = clockticks6502;
last_millis = millis;
return "press ^F again to measure frequency";
}
uint32_t hz = (clockticks6502 - last_ticks) * 1000 / (millis - last_millis);
static char buf[64];
snprintf(buf, sizeof(buf), "%ld Hz", hz);
last_ticks = clockticks6502;
last_millis = millis;
return buf;
} else if (b == '\x12') { // ^R
reset6502();
paused = false;
@ -139,11 +121,24 @@ char *process_serial_command(char b) {
local_echo = !local_echo;
return local_echo ? "local echo enabled" : "local echo disabled";
} else if (b == '\x14') { // ^T
static uint32_t last_ticks = 0;
static uint32_t last_millis = 0;
uint32_t hz = 0;
if (last_ticks != 0) {
uint32_t elapsed_ticks = clockticks6502 - last_ticks;
uint32_t elapsed_millis = millis - last_millis;
if (elapsed_millis != 0) hz = elapsed_ticks * 1000 / elapsed_millis;
}
last_ticks = clockticks6502;
last_millis = millis;
static char buf[64];
snprintf(buf, sizeof(buf), "%ld ticks\r\n%ld instructions", clockticks6502, instructions);
snprintf(buf, sizeof(buf), "%ld ticks\r\n%ld instructions\r\n%ld Hz", clockticks6502, instructions, hz);
return buf;
} else if (b == '\x07') { // ^G
return "^V=version ^R=reset ^E=echo ^P=pause ^F=freq ^T=ticks ^G=help";
return "^V=version ^R=reset ^E=echo ^P=pause ^T=timing ^G=help";
}
return NULL;