-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.c
More file actions
59 lines (51 loc) · 1.41 KB
/
kernel.c
File metadata and controls
59 lines (51 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "kernel.h"
/*
16 bit video buffer elements(register ax)
8 bits(ah) higher :
lower 4 bits - forec olor
higher 4 bits - back color
8 bits(al) lower :
8 bits : ASCII character to print
*/
uint16 vga_entry(unsigned char ch, uint8 fore_color, uint8 back_color)
{
uint16 ax = 0;
uint8 ah = 0, al = 0;
ah = back_color;
ah <<= 4;
ah |= fore_color;
ax = ah;
ax <<= 8;
al = ch;
ax |= al;
return ax;
}
//clear video buffer array
void clear_vga_buffer(uint16 **buffer, uint8 fore_color, uint8 back_color)
{
uint32 i;
for(i = 0; i < BUFSIZE; i++){
(*buffer)[i] = vga_entry(NULL, fore_color, back_color);
}
}
//initialize vga buffer
void init_vga(uint8 fore_color, uint8 back_color)
{
vga_buffer = (uint16*)VGA_ADDRESS; //point vga_buffer pointer to VGA_ADDRESS
clear_vga_buffer(&vga_buffer, fore_color, back_color);
}
void kernel_entry()
{
init_vga(WHITE, BLACK);
vga_buffer[0] = vga_entry('H', WHITE, BLACK);
vga_buffer[1] = vga_entry('e', WHITE, BLACK);
vga_buffer[2] = vga_entry('l', WHITE, BLACK);
vga_buffer[3] = vga_entry('l', WHITE, BLACK);
vga_buffer[4] = vga_entry('o', WHITE, BLACK);
vga_buffer[5] = vga_entry(' ', WHITE, BLACK);
vga_buffer[6] = vga_entry('W', WHITE, BLACK);
vga_buffer[7] = vga_entry('o', WHITE, BLACK);
vga_buffer[8] = vga_entry('r', WHITE, BLACK);
vga_buffer[9] = vga_entry('l', WHITE, BLACK);
vga_buffer[10] = vga_entry('d', WHITE, BLACK);
}