From 24f588effd56257b28fc38efdc0dd8905d16f488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20van=20Dorst?= Date: Wed, 10 Sep 2025 16:07:59 +0200 Subject: [PATCH] httpd: Also don't byte_to_html() and itoa_html() to save 1.5kbytes. Also fixed compiler "warning page_impl.c:47: warning 126: unreachable code". But I think it was a false-positive. --- httpd/page_impl.c | 36 ++++++++++++++++++++++++++++++++---- rtlplayground.mem | 2 +- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 7ed6c94..1cff493 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -27,10 +27,26 @@ extern __xdata uint8_t isRTL8373; extern __xdata uint8_t sfp_pins_last; extern __xdata uint8_t vlan_names[VLAN_NAMES_SIZE]; -inline void byte_to_html(uint8_t a) + +/* Convert only the lower nibble to ascii HEX char. + For convenience the upper nibble is masked out. +*/ +inline char itohex(uint8_t val) { + // Ignore upper nibble for convenience. + val &= 0x0f; + val -= 10; + + // 10 or above + if ((int8_t)val >= 0) + val += ('a' - '0' - 10); + + return val + ('0' + 10); +} + +// Convert uint8_t to ascii HEX char push on html-buffer. +void charhex_to_html(char c) { - outbuf[slen++] = hex[(a >> 4) & 0xf]; - outbuf[slen++] = hex[a & 0xf]; + outbuf[slen++] = itohex(c); } @@ -40,7 +56,19 @@ void char_to_html(char c) } -inline void itoa_html(uint8_t v) +// Convert uint8_t to ascii HEX char. +void byte_to_html(uint8_t val) +{ + uint8_t cnt = 2; + do { + val = (val >> 4) | (val << 4); + charhex_to_html(val); + cnt -= 1; + } while(cnt); +} + + +void itoa_html(uint8_t v) { uint8_t t = (v / 100) % 10; if (t) diff --git a/rtlplayground.mem b/rtlplayground.mem index 03fcd49..c653536 100644 --- a/rtlplayground.mem +++ b/rtlplayground.mem @@ -26,4 +26,4 @@ Other memory: ---------------- -------- -------- -------- -------- PAGED EXT. RAM 0 256 EXTERNAL RAM 0x0001 0x1b28 6952 16777216 - ROM/EPROM/FLASH 0x0000 0x1bf4f 45844 16777216 + ROM/EPROM/FLASH 0x0000 0x1b967 44332 16777216