From b79a6744a0798ea7277b55164813be9c8747a4a3 Mon Sep 17 00:00:00 2001 From: "Satoshi N. M" Date: Mon, 15 Jan 2018 14:23:12 -0800 Subject: [PATCH] Merge emulated frequency measurement into ^T command --- README.md | 3 +-- src/main.c | 35 +++++++++++++++-------------------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index ca41343..68c151a 100644 --- a/README.md +++ b/README.md @@ -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), diff --git a/src/main.c b/src/main.c index 5928418..7916d19 100644 --- a/src/main.c +++ b/src/main.c @@ -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;