diff --git a/README.md b/README.md index 67b0067..68c151a 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Special commands built-in, not passed to the ACIA and 6502: | ^P | Pause/resume 6502 processor execution | | ^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/Makefile b/src/Makefile index 8a62758..0b6759e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ MAKEFLAGS += --no-print-dir Q := @ endif -OPT_FLAGS ?= -O2 +OPT_FLAGS = -O0 -g CFLAGS += -Wall -Wextra -Werror -Wno-char-subscripts\ $(OPT_FLAGS) -std=gnu99 -g3 -MD \ @@ -22,7 +22,6 @@ CROSS_COMPILE ?= arm-none-eabi- CC = $(CROSS_COMPILE)gcc OBJCOPY = $(CROSS_COMPILE)objcopy -OPT_FLAGS = -Os CFLAGS += -mcpu=cortex-m3 -mthumb \ -DSTM32F1 -DDISCOVERY_STLINK -I../libopencm3/include \ -I . diff --git a/src/main.c b/src/main.c index 1c17f4f..7916d19 100644 --- a/src/main.c +++ b/src/main.c @@ -84,9 +84,11 @@ static const char *usb_strings[] = { }; static bool paused = true; +uint32_t millis = 0; void sys_tick_handler(void) { if (paused) return; + ++millis; step6502(); gpio_toggle(GPIOC, GPIO13); } @@ -110,6 +112,7 @@ char *process_serial_command(char b) { } else if (b == '\x10') { // ^P paused = !paused; return paused ? "paused" : "resumed"; + } else if (b == '\x06') { // ^F } else if (b == '\x12') { // ^R reset6502(); paused = false; @@ -118,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 ^T=ticks ^G=help"; + return "^V=version ^R=reset ^E=echo ^P=pause ^T=timing ^G=help"; } return NULL;