From 468b755a8e6ce0f9e302db9449f62091e18b5e65 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Sat, 6 Jun 2020 02:49:54 +0200 Subject: [PATCH 1/3] Added a function to display signed integers Implemented in C since I don't know if the kernel supports it natively. --- include/knightos/display.h | 6 ++++++ src/knightos/display.c | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/knightos/display.h b/include/knightos/display.h index 37f5760..b71a29f 100644 --- a/include/knightos/display.h +++ b/include/knightos/display.h @@ -97,8 +97,14 @@ void draw_short(SCREEN *screen, unsigned char x, unsigned char y, unsigned short **/ void draw_byte(SCREEN *screen, unsigned char x, unsigned char y, unsigned char value); +/** + * Draws a signed short at x, y +**/ +void draw_signed(SCREEN *screen, unsigned char x, unsigned char y, signed short value); + /*.* * Draws a long at x, y +* NYI **/ void draw_long(SCREEN *screen, unsigned char x, unsigned char y, unsigned long value); diff --git a/src/knightos/display.c b/src/knightos/display.c index a970f78..1f0d183 100644 --- a/src/knightos/display.c +++ b/src/knightos/display.c @@ -330,6 +330,16 @@ void draw_short(SCREEN *screen, unsigned char x, unsigned char y, unsigned short screen; x; y; value; } +void draw_signed(SCREEN* screen, unsigned char x, unsigned char y, signed short value) { + if(value < 0){ + draw_char(screen, x, y, '-'); + x += 4; + value = -value; + } + draw_short(screen, x, y, value); + return; +} + void invert_pixel(SCREEN *screen, char x, char y) { __asm POP BC ; return From a6e584f8b57ff648d071cb8763d0d6e65e5b2267 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Sat, 6 Jun 2020 03:16:27 +0200 Subject: [PATCH 2/3] Added a draw_float function (implemented in C) --- include/knightos/display.h | 8 +++++++- src/knightos/display.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/knightos/display.h b/include/knightos/display.h index b71a29f..a2425e1 100644 --- a/include/knightos/display.h +++ b/include/knightos/display.h @@ -102,7 +102,13 @@ void draw_byte(SCREEN *screen, unsigned char x, unsigned char y, unsigned char v **/ void draw_signed(SCREEN *screen, unsigned char x, unsigned char y, signed short value); -/*.* +/** + * Draws a float at x,y +**/ + +void draw_float(SCREEN* screen, unsigned char x, unsigned char y, float value); + +/** * Draws a long at x, y * NYI **/ diff --git a/src/knightos/display.c b/src/knightos/display.c index 1f0d183..66a2a1b 100644 --- a/src/knightos/display.c +++ b/src/knightos/display.c @@ -340,6 +340,40 @@ void draw_signed(SCREEN* screen, unsigned char x, unsigned char y, signed short return; } +void draw_float(SCREEN* screen, unsigned char x, unsigned char y, float value){ + /* Implementation is weird and slow because of non-working snprintf. Indeed, %f format strings are not yet implemented */ + unsigned int integer_part; + unsigned int frac_part; + unsigned int integer_part_len; + bool sgn = (value < 0); + + + value = sgn ? -value : value; + + integer_part = (unsigned int)value; + frac_part = ((value - (float)integer_part)*10000); + +#define __log10u(x) ((x >= 10000000u) ? 7 : (x >= 1000000u) ? 6 : \ + (x >= 100000u) ? 5 : (x >= 10000u) ? 4 : \ + (x >= 1000u) ? 3 : (x >= 100u) ? 2 : (x >= 10u) ? 1u : 0u) + + integer_part_len = (__log10u(integer_part)) + 1; + + if(sgn){ + draw_char(screen, x, y, '-'); + x += 4; + } + + draw_short(screen, x, y, integer_part); + x += integer_part_len*4; + draw_char(screen, x, y, '.'); + + x += 4; + draw_short(screen, x, y, frac_part); + + return; +} + void invert_pixel(SCREEN *screen, char x, char y) { __asm POP BC ; return From a35754c23a794dc0483a10ca1c678619bebfdc83 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Sun, 14 Jun 2020 22:00:06 +0200 Subject: [PATCH 3/3] Use log10u from math.h --- src/knightos/display.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/knightos/display.c b/src/knightos/display.c index 66a2a1b..b2c4db3 100644 --- a/src/knightos/display.c +++ b/src/knightos/display.c @@ -353,11 +353,7 @@ void draw_float(SCREEN* screen, unsigned char x, unsigned char y, float value){ integer_part = (unsigned int)value; frac_part = ((value - (float)integer_part)*10000); -#define __log10u(x) ((x >= 10000000u) ? 7 : (x >= 1000000u) ? 6 : \ - (x >= 100000u) ? 5 : (x >= 10000u) ? 4 : \ - (x >= 1000u) ? 3 : (x >= 100u) ? 2 : (x >= 10u) ? 1u : 0u) - - integer_part_len = (__log10u(integer_part)) + 1; + integer_part_len = (log10u(integer_part)) + 1; if(sgn){ draw_char(screen, x, y, '-');