#include "framebuffer.h"
#include "serial.h"
#include "gdt.h"

unsigned int write(char *buf, unsigned int len)
{
  unsigned int ret = 0;
  int pos = 0;
  fb_move_cursor(ret);

  while (ret < len)
  {
    fb_write_cell(pos, *(buf + ret), FB_WHITE, FB_BLACK);
    ret++;
    fb_move_cursor(ret);

    pos += 2;
  }

  return ret;
}

int strlen(char *buf)
{
  int ret = 0;
  while (*(buf + ret) != '\0') ret++;
  return ret;
}

void kmain(void)
{
  char *str = "Port série prêt pour la communication.";
  char *fb_str = "Framebuffer fonctionnel.";
  int len = strlen(fb_str);
  write(fb_str, len);

  config_gdt();
  serial_set_baud(COM1_PORT, 5);
  serial_config(COM1_PORT);
  serial_write(COM1_PORT, str, strlen(str));
}