diff options
author | Christian Cunningham <cc@localhost> | 2022-03-12 09:47:04 -0800 |
---|---|---|
committer | Christian Cunningham <cc@localhost> | 2022-03-12 09:47:04 -0800 |
commit | 468167fce9d64cb8f08832dd7586dd55f9200fb8 (patch) | |
tree | 2470776fdbf8ee4bb34fa36cb1e6010b5260cfc6 | |
parent | f1a310b37e482d091a4c4ac6cbbf7a27f4033a7e (diff) |
Draw Base-10 Numbers Easier
-rw-r--r-- | include/graphics/lfb.h | 3 | ||||
-rw-r--r-- | include/lib/strings.h | 1 | ||||
-rw-r--r-- | src/graphics/lfb.c | 14 | ||||
-rw-r--r-- | src/lib/strings.c | 10 | ||||
-rw-r--r-- | src/util/status.c | 26 |
5 files changed, 36 insertions, 18 deletions
diff --git a/include/graphics/lfb.h b/include/graphics/lfb.h index 17c85ac..e8a7766 100644 --- a/include/graphics/lfb.h +++ b/include/graphics/lfb.h @@ -26,4 +26,7 @@ void draw_string(unsigned int lx, unsigned int ly, char* s); void draw_chex32(unsigned int lx, unsigned int ly, unsigned long val, unsigned int c); void draw_hex32(unsigned int lx, unsigned int ly, unsigned long val); +unsigned long draw_cu10(unsigned int lx, unsigned int ly, unsigned long val, unsigned int c); +unsigned long draw_u10(unsigned int lx, unsigned int ly, unsigned long val); + #endif diff --git a/include/lib/strings.h b/include/lib/strings.h index dd77324..b4a945e 100644 --- a/include/lib/strings.h +++ b/include/lib/strings.h @@ -4,6 +4,7 @@ #define string_t char* unsigned long strlen(string_t s); +void strcpy(string_t src, string_t dest); unsigned char strcmp(string_t a, string_t b); unsigned char strcmpn(string_t a, string_t b, unsigned int n); char* u32_to_str(unsigned long value); diff --git a/src/graphics/lfb.c b/src/graphics/lfb.c index 8c9c395..7158afa 100644 --- a/src/graphics/lfb.c +++ b/src/graphics/lfb.c @@ -3,6 +3,7 @@ #include <graphics/glyphs.h> #include <graphics/lfb.h> #include <graphics/mbox.h> +#include <lib/strings.h> unsigned char *lfb; /* raw frame buffer address */ @@ -202,3 +203,16 @@ void draw_hex32(unsigned int lx, unsigned int ly, unsigned long val) { draw_chex32(lx, ly, val, 0xFFFFFF); } + +unsigned long draw_cu10(unsigned int lx, unsigned int ly, unsigned long val, unsigned int c) +{ + string_t vals = u32_to_str(val); + unsigned long len = strlen(vals); + draw_cstring(lx, ly, vals, c); + return len; +} + +unsigned long draw_u10(unsigned int lx, unsigned int ly, unsigned long val) +{ + return draw_cu10(lx, ly, val, 0xFFFFFF); +} diff --git a/src/lib/strings.c b/src/lib/strings.c index 3155afa..674af19 100644 --- a/src/lib/strings.c +++ b/src/lib/strings.c @@ -10,6 +10,16 @@ unsigned long strlen(string_t s) return len; } +void strcpy(string_t src, string_t dest) +{ + unsigned long idx = 0; + while (src[idx] != 0) { + dest[idx] = src[idx]; + idx++; + } + dest[idx] = src[idx]; +} + unsigned char strcmp(string_t a, string_t b) { unsigned long idx = 0; diff --git a/src/util/status.c b/src/util/status.c index 869fb40..f111251 100644 --- a/src/util/status.c +++ b/src/util/status.c @@ -73,33 +73,24 @@ void status(void) // Output the frequency draw_string(6, 3, "@"); unsigned long frq = read_cntfrq()/1000; - char* frq_str = u32_to_str(frq); - unsigned long fs_len = strlen(frq_str)+1; - draw_string(8, 3, frq_str); + unsigned long fs_len = draw_u10(8, 3, frq) + 1; draw_string(8+fs_len, 3, "kHz"); // Output the value unsigned long v = read_cntv_tval(); - char* v_str = u32_to_str(v); - unsigned long vs_len = strlen(v_str) + 1; - draw_string(8+fs_len+4, 3, v_str); + unsigned long vs_len = draw_u10(8+fs_len+4, 3, v)+1; draw_string(8+fs_len+4 +vs_len, 3, " "); draw_letter(8+fs_len+4 +vs_len+1, 3, '|'); draw_hex32(8+fs_len+7+vs_len, 3, v); // Video Status draw_cstring(0, 4, "VIDEO", 0x00FF00); - char* gwidth_str; - gwidth_str = u32_to_str(gwidth); - unsigned long gs_len = strlen(gwidth_str) + 1; - draw_string(6, 4, gwidth_str); - draw_letter(6+gs_len-1, 4, 'x'); - gwidth_str = u32_to_str(gheight); - unsigned long gs_len1 = strlen(gwidth_str) + 1; - draw_string(6+gs_len, 4, gwidth_str); + unsigned long gw_len = draw_u10(6, 4, gwidth); + unsigned long gh_len = draw_u10(6+gw_len+1, 4, gheight) + 1; + draw_letter(6+gw_len, 4, 'x'); if(gisrgb) - draw_string(6+gs_len+gs_len1, 4, "RGB"); + draw_string(6+gw_len+gh_len + 1, 4, "RGB"); else - draw_string(6+gs_len+gs_len1, 4, "BGR"); + draw_string(6+gw_len+gh_len + 1, 4, "BGR"); // Core Stacks draw_string(0, 5, "SVC IRQ FIQ User/SYS\n"); @@ -132,6 +123,5 @@ void status(void) draw_hex32(19+14+8+1, 8, coren); draw_string(19+14+9+8, 8, "|"); draw_string(19+14+18, 8, " "); - char* t_str = u32_to_str(((unsigned long)tval)/1000000); - draw_string(19+14+18, 8, t_str); + draw_u10(19+14+18, 8, ((unsigned long)tval)/1000000); } |