#pragma once

#include <hilbert/kernel/utility.hpp>
#include <stdint.h>

namespace hilbert::kernel {

  extern "C" void serial_init();

  extern "C" void serial_putchar(char ch);

  static inline void serial_putstr(const char *str) {
    while (*str) {
      serial_putchar(*str);
      ++str;
    }
  }

  static inline void serial_putstr(const utility::string &str) {
    for (unsigned i = 0; i < str.count; ++i)
      serial_putchar(str.buffer[i]);
  }

  template <int digits, int dot_every = 4>
  static inline void serial_puthex(uint64_t n) {
    for (int d = digits - 1; d >= 0; --d) {
      serial_putchar("0123456789abcdef"[(n >> (d * 4)) & 0xf]);
      if (d % dot_every == 0 && d != 0)
        serial_putchar('.');
    }
  }

}
