diff --git a/Makefile b/Makefile index ff4d184..c06986a 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --idata-loc 0x80 #SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 256 --stack-auto --model-large FLASHFILE ?= main.hex LARGE_LDFLAGS += -L/usr/share/sdcc/lib/large/ -# CFLAGS += -DSTACK_DEBUG # write the stack pointer to P3_4 +# CFLAGS += -DSTACK_DEBUG -DSHOW_STACK # write the stack pointer to P3_4 SRC = src/lcd.c src/key.c src/utils.c src/decn/decn.c src/calc.c src/stack_debug.c diff --git a/src/lcd.c b/src/lcd.c index b5eac5c..c6319b6 100644 --- a/src/lcd.c +++ b/src/lcd.c @@ -285,3 +285,15 @@ void LCD_Clear() { col = 0; } +void TERMIO_PrintU8(uint8_t x) { + uint8_t i; + for (i = 2; i; i--) { + const uint8_t upper_nibble = (x & 0xf0) >> 4; + if (upper_nibble <= 9) { + TERMIO_PutChar(upper_nibble + '0'); + } else { + TERMIO_PutChar((upper_nibble - 0x0a) + 'A'); + } + x <<= 4; + } +} diff --git a/src/lcd.h b/src/lcd.h index 8002d1f..57d7254 100644 --- a/src/lcd.h +++ b/src/lcd.h @@ -31,6 +31,7 @@ void LCD_GoTo(uint8_t row, uint8_t col); void LCD_OutString(__xdata const char* string, uint8_t max_chars); void LCD_OutString_Initial(__code const char* string); short TERMIO_PutChar(unsigned char letter); +void TERMIO_PrintU8(uint8_t x); void LCD_OutNibble(uint8_t x); void LCD_ClearToEnd(uint8_t curr_row); diff --git a/src/main.c b/src/main.c index 613c600..9a2d39f 100644 --- a/src/main.c +++ b/src/main.c @@ -523,6 +523,10 @@ int main() //print shifted status if (IsShifted){ TERMIO_PutChar('^'); +#if defined(STACK_DEBUG) && defined(SHOW_STACK) + TERMIO_PutChar(' '); + TERMIO_PrintU8(stack_max); +#endif } #ifdef DESKTOP diff --git a/src/stack_debug.c b/src/stack_debug.c index eb7da94..ff6139e 100644 --- a/src/stack_debug.c +++ b/src/stack_debug.c @@ -84,8 +84,15 @@ stack_debug_3$: __endasm; } +#if defined(STACK_DEBUG) && defined(SHOW_STACK) +__xdata uint8_t stack_max = 0x00; +#endif + void stack_debug(uint8_t marker) { +#ifdef SHOW_STACK + if (SP > stack_max) stack_max = SP; +#endif stack_debug_write(marker); stack_debug_write(SP); } -#endif // !defined(DESKTOP) +#endif // defined(STACK_DEBUG) diff --git a/src/stack_debug.h b/src/stack_debug.h index a22567e..ef4adcb 100644 --- a/src/stack_debug.h +++ b/src/stack_debug.h @@ -35,6 +35,10 @@ void stack_debug_write(uint8_t value) __naked; #define stack_debug(marker) #endif +#if defined(STACK_DEBUG) && defined(SHOW_STACK) +extern __xdata uint8_t stack_max; +#endif + #if defined(DESKTOP) || defined(STACK_DEBUG) #define backlight_on() #define backlight_off()