mirror of
https://github.com/satoshinm/pill_6502.git
synced 2025-03-13 01:33:36 +00:00
Add ^F command to measure and show frequency in hertz
This commit is contained in:
parent
7612198f41
commit
01a0f0f63c
@ -22,6 +22,7 @@ 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 |
|
||||
|
23
src/main.c
23
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,25 @@ char *process_serial_command(char b) {
|
||||
} else if (b == '\x10') { // ^P
|
||||
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;
|
||||
@ -122,7 +143,7 @@ char *process_serial_command(char b) {
|
||||
snprintf(buf, sizeof(buf), "%ld ticks\r\n%ld instructions", clockticks6502, instructions);
|
||||
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 ^F=freq ^T=ticks ^G=help";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user