From c37d19891df4906fc42be25aa8de8a5a56d7f905 Mon Sep 17 00:00:00 2001 From: Stephan Veigl Date: Thu, 23 Jun 2011 16:01:44 +0200 Subject: [PATCH] output: add NO_COLOR define to disable / enable color output for simavr core messages and UART Signed-off-by: Stephan Veigl --- simavr/sim/avr_uart.c | 11 ++++++++++- simavr/sim/sim_core.c | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/simavr/sim/avr_uart.c b/simavr/sim/avr_uart.c index 7cb019a..51ad736 100644 --- a/simavr/sim/avr_uart.c +++ b/simavr/sim/avr_uart.c @@ -23,8 +23,17 @@ along with simavr. If not, see . */ +#ifdef NO_COLOR + #define FONT_GREEN + #define FONT_DEFAULT +#else + #define FONT_GREEN "\e[32m" + #define FONT_DEFAULT "\e[0m" +#endif + #include #include +#include #include "avr_uart.h" #include "sim_hex.h" @@ -145,7 +154,7 @@ static void avr_uart_write(struct avr_t * avr, avr_io_addr_t addr, uint8_t v, vo buf[l] = 0; if (v == '\n' || l == 127) { l = 0; - printf("\e[32m%s\e[0m\n", buf); + printf( FONT_GREEN "%s\n" FONT_DEFAULT, buf); } } // printf("UDR%c(%02x) = %02x\n", p->name, addr, v); diff --git a/simavr/sim/sim_core.c b/simavr/sim/sim_core.c index aa36220..9dcf4bd 100644 --- a/simavr/sim/sim_core.c +++ b/simavr/sim/sim_core.c @@ -31,6 +31,14 @@ // SREG bit names const char * _sreg_bit_name = "cznvshti"; +#ifdef NO_COLOR + #define FONT_RED + #define FONT_DEFAULT +#else + #define FONT_RED "\e[31m" + #define FONT_DEFAULT "\e[0m" +#endif + /* * Handle "touching" registers, marking them changed. * This is used only for debugging purposes to be able to @@ -108,7 +116,7 @@ void avr_core_watch_write(avr_t *avr, uint16_t addr, uint8_t v) * frame and is munching on it's own return address. */ if (avr->trace_data->stack_frame_index > 1 && addr > avr->trace_data->stack_frame[avr->trace_data->stack_frame_index-2].sp) { - printf("\e[31m%04x : munching stack SP %04x, A=%04x <= %02x\e[0m\n", avr->pc, _avr_sp_get(avr), addr, v); + printf( FONT_RED "%04x : munching stack SP %04x, A=%04x <= %02x\n" FONT_DEFAULT, avr->pc, _avr_sp_get(avr), addr, v); } #endif avr->data[addr] = v; @@ -117,7 +125,7 @@ void avr_core_watch_write(avr_t *avr, uint16_t addr, uint8_t v) uint8_t avr_core_watch_read(avr_t *avr, uint16_t addr) { if (addr > avr->ramend) { - printf("*** Invalid read address PC=%04x SP=%04x O=%04x Address %04x out of ram (%04x)\n", + printf( FONT_RED "*** Invalid read address PC=%04x SP=%04x O=%04x Address %04x out of ram (%04x)\n" FONT_DEFAULT, avr->pc, _avr_sp_get(avr), avr->flash[avr->pc] | (avr->flash[avr->pc]<<8), addr, avr->ramend); CRASH(); } @@ -276,10 +284,10 @@ const char * avr_regname(uint8_t reg) static void _avr_invalid_opcode(avr_t * avr) { #if CONFIG_SIMAVR_TRACE - printf("\e[31m*** %04x: %-25s Invalid Opcode SP=%04x O=%04x \e[0m\n", + printf( FONT_RED "*** %04x: %-25s Invalid Opcode SP=%04x O=%04x \n" FONT_DEFAULT, avr->pc, avr->trace_data->codeline[avr->pc>>1]->symbol, _avr_sp_get(avr), avr->flash[avr->pc] | (avr->flash[avr->pc+1]<<8)); #else - printf("\e[31m*** %04x: Invalid Opcode SP=%04x O=%04x \e[0m\n", + printf( FONT_RED "*** %04x: Invalid Opcode SP=%04x O=%04x \n" FONT_DEFAULT, avr->pc, _avr_sp_get(avr), avr->flash[avr->pc] | (avr->flash[avr->pc+1]<<8)); #endif } -- 2.39.5