~kernel/kernel.cr
.cr
Crystal
(text/x-crystal)
require "./vga.cr"
require "./tiny_alloc_i386.cr"
require "./idt.cr"
require "./irq.cr"
# require "./pmm.cr"

lib LibBootstrap
  @[Packed]
  struct StartInfo
    multiboot_ptr : UInt32
    end_of_kernel : UInt32
  end
end

fun kearly(info_ptr: LibBootstrap::StartInfo*)
  # Get the startup info
  info = info_ptr.value
end

fun kmain
  VGA.init
  VGA.puts(
    "[CrystalOS Kernel] Hello from Crystal.\n",
    color: VGA::Colors::BLACK_ON_CYAN,
  )

  IDT.init
  IRQ.init # Should be PS2 ?
  TinyAllocI386.init
  # PMM.init # Physical Memory Init

  puts("weeeeeeee\n")

  VGA.puts("Can print on multiple lines\n", color: VGA::Colors::BLACK_ON_LIME)
  VGA.puts("\nWe still don't have a heap, but now the puts stores the last row and col so it can call the putchar method with the \x1b[32mright\x1b[0m col / row instead of overlaying subsequent calls on-top one of another (this is super long line to test word wrap).\n")
  VGA.puts "\nFeatures:\n"
  VGA.puts("\tIt supports \\t char at start\taswell as in text.\n\tIt supports \\n char at end aswell as in text.\n")
  VGA.puts "\t"
  VGA.puts "It support writing on same line"
  VGA.puts " "
  VGA.puts "(YAY)", VGA::Colors::GREEN_ON_WHITE
  VGA.puts "\n"
  VGA.puts("\tCan use custom colors", VGA::Colors::RED_ON_BLACK)
  VGA.puts("\tCan use another custom color\n", VGA::Colors::GREEN_ON_BLACK)
  VGA.puts("\tCan use lot of custom color\n", VGA::Colors::CYAN_ON_BLACK)

  # VGA.set_cursor(0, 5)
  # VGA.hide_cursor
  
  # asm (%(sti))

  while true
    asm (%(hlt))
  end
end