From a81f35022a17e7ef64cf0ae58bf83d4bb24d02fd Mon Sep 17 00:00:00 2001 From: Phil Hord Date: Sun, 27 Oct 2013 16:05:00 -0400 Subject: [PATCH] Add debug pin-tracing code for investigation. --- simulator/simulator.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/simulator/simulator.c b/simulator/simulator.c index b284902..f9b07c7 100644 --- a/simulator/simulator.c +++ b/simulator/simulator.c @@ -41,8 +41,10 @@ void sim_start(int argc, char** argv) { static void fgreen(void) { fputs("\033[0;32m" , stdout); } static void fred(void) { fputs("\033[0;31m" , stdout); } +static void fcyan(void) { fputs("\033[0;36m" , stdout); } static void fbreset(void) { fputs("\033[m" , stdout); } +static void bred(void) { fputs("\033[0;41m" , stdout); } void sim_info(const char fmt[], ...) { va_list ap; @@ -66,6 +68,13 @@ void sim_debug(const char fmt[], ...) { #endif } +void sim_tick(char ch) { + fcyan(); + fprintf(stdout, "%c", ch); + fbreset(); + fflush(stdout); +} + void sim_error(const char msg[]) { fred(); printf("ERROR: %s\n", msg); @@ -118,6 +127,26 @@ void WRITE(pin_t pin, bool s) { if (direction[pin] == out) { state[pin] = s; } + + if (old_state != s) { + #ifdef TRACE_ALL_PINS + fgreen(); + for (int i = 0; i < PIN_NB; i++) { + if (state[i]) bred(); else bblack(); + fputc('A' + i, stdout); + } + fbreset(); + printf("\n"); + #else + bred(); + if (s) + sim_tick('A' + pin); + else + sim_tick('a' + pin); + fbreset(); + #endif + } + if (s && !old_state) { /* rising edge */ switch (pin) { case X_STEP_PIN: