From: Amelia Coutard Date: Fri, 27 May 2022 00:57:59 +0000 (+0200) Subject: Generalized a bit the functions for printing to the serial port X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=737e6a18ff6b318320d2617ca54a6aec307d7435;p=voyage-au-centre-des-fichiers.git Generalized a bit the functions for printing to the serial port --- diff --git a/src/serial.cpp b/src/serial.cpp index 86142ca..2820cdf 100644 --- a/src/serial.cpp +++ b/src/serial.cpp @@ -49,24 +49,6 @@ void os::print(std::uint64_t v) { os::printc(c < 10 ? c + '0' : c + 'A' - 10); } } -void os::print(std::uint32_t v) { - for (int i = 28; i >= 0; i -= 4) { - const int c = (v >> i) & 0xF; - os::printc(c < 10 ? c + '0' : c + 'A' - 10); - } -} -void os::print(std::uint16_t v) { - for (int i = 12; i >= 0; i -= 4) { - const int c = (v >> i) & 0xF; - os::printc(c < 10 ? c + '0' : c + 'A' - 10); - } -} -void os::print(std::uint8_t v) { - for (int i = 4; i >= 0; i -= 4) { - const int c = (v >> i) & 0xF; - os::printc(c < 10 ? c + '0' : c + 'A' - 10); - } -} void os::print(std::int64_t v) { if (v < 0) { os::printc('-'); @@ -76,40 +58,16 @@ void os::print(std::int64_t v) { os::print(std::uint64_t(v)); } } -void os::print(std::int32_t v) { - if (v < 0) { - os::printc('-'); - os::print(std::uint32_t(-v)); - } else { - os::printc(' '); - os::print(std::uint32_t(v)); - } -} -void os::print(std::int16_t v) { - if (v < 0) { - os::printc('-'); - os::print(std::uint16_t(-v)); - } else { - os::printc(' '); - os::print(std::uint16_t(v)); - } -} -void os::print(std::int8_t v) { - if (v < 0) { - os::printc('-'); - os::print(std::uint8_t(-v)); - } else { - os::printc(' '); - os::print(std::uint8_t(v)); - } -} -void os::println(const char* str) { - os::print(str); - os::printc('\n'); -} +void os::print(std::uint32_t v) { os::print(std::uint64_t(v)); } +void os::print(std::uint16_t v) { os::print(std::uint64_t(v)); } +void os::print(std::uint8_t v) { os::print(std::uint64_t(v)); } +void os::print(std::int32_t v) { os::print(std::int64_t(v)); } +void os::print(std::int16_t v) { os::print(std::int64_t(v)); } +void os::print(std::int8_t v) { os::print(std::int64_t(v)); } void os::assert(bool cond, const char* diagnostic) { if (!cond) { os::print("Error: "); os::println(diagnostic); + while (true) { os::hlt(); } } } diff --git a/src/serial.hpp b/src/serial.hpp index 39bb4b4..d159456 100644 --- a/src/serial.hpp +++ b/src/serial.hpp @@ -23,7 +23,11 @@ void print(std::int64_t v); void print(std::int32_t v); void print(std::int16_t v); void print(std::int8_t v); -void println(const char* str); +template +void println(const T& v) { + print(v); + printc('\n'); +} void assert(bool cond, const char* diagnostic); }