1#include "screen.h"
 2#include "idt.h"
 3#include "keyboard.h"
 4#include "shell.h"
 5#include "font.h"
 6
 7void draw_pixel(int x, int y, unsigned char color) {
 8	unsigned char* vga = (unsigned char*) 0xA0000;
 9	vga[y * 320 + x] = color;
10}
11
12void draw_char(int x, int y, char c, unsigned char color) {
13	if (c < 0 || (unsigned char)c > 127) return;
14
15	for (int i = 0; i < 8; i++) {
16		unsigned char row = font8x8_basic[(unsigned char)c][i];
17		for (int j = 0; j < 8; j++) {
18			if ((row >> j) & 1) {
19				draw_pixel(x + j, y + i, color);
20			}
21		}
22	}
23}
24
25void draw_string(int x, int y, char* str, unsigned char color) {
26	int i = 0;
27	while (str[i] != 0) {
28		draw_char(x + (i * 8), y, str[i], color);
29		i++;
30	}
31}
32
33void exception_handler() {
34	draw_string(0, 0, "EXCEPTION OCCURRED!", 12); // Red text
35	while(1);
36}
37
38void kmain() {
39	// Initialize Interrupts
40	init_idt();
41
42	// Initialize Drivers
43	init_keyboard();
44
45	// Start Shell
46	init_shell();
47
48	// Enable Interrupts
49	extern void enable_interrupts();
50	enable_interrupts();
51
52	// Loop forever
53	while(1) {
54		// Busy wait instead of hlt to avoid power management issues in some VMs
55		// and to simplify debugging
56		__asm__ volatile("pause");
57	}
58}