-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel.c
87 lines (69 loc) · 2.14 KB
/
kernel.c
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "multiboot.h"
#include "boot/init.h"
#define PLAYER_HEIGTH 128
#define PLAYER_WIDTH 32
#define BALL_SIZE 16
static int player_1_offset = 0;
static int player_2_offset = 0;
multiboot_info_t * mb_info;
void drawPlayers();
void drawBall();
void drawPixel(int x, int y, multiboot_uint32_t color);
void start_kernel(unsigned long magic, unsigned long multiboot_addr) {
mb_info = (multiboot_info_t *) multiboot_addr;
if (magic != MULTIBOOT_BOOTLOADER_MAGIC) {
//TODO implement printf
return;
}
init_gdt();
init_idt();
drawPlayers();
}
void drawPlayers() {
int height_offset = (mb_info->framebuffer_height - PLAYER_HEIGTH) / 2;
for (int x = 0; x < PLAYER_WIDTH; x++) {
for (int y = 0; y < PLAYER_HEIGTH; y++) {
drawPixel(x, y + height_offset + player_1_offset, 0xFFFFFFFF); //Player 1
drawPixel(
mb_info->framebuffer_width - x,
y + height_offset + player_2_offset
, 0xFFFFFFFF); //Player 2
}
}
}
void drawBall() {
int height_offset = (mb_info->framebuffer_height - BALL_SIZE) / 2;
int width_offset = (mb_info->framebuffer_width - BALL_SIZE) / 2;
for (int x = 0; x < BALL_SIZE; x++) {
for (int y = 0; y < BALL_SIZE; y++) {
drawPixel(x + width_offset, y + height_offset, 0xFFFFFFFF);
}
}
}
void drawPixel(int x, int y, multiboot_uint32_t color) {
void * fb_addr = (void *) mb_info->framebuffer_addr;
switch (mb_info->framebuffer_bpp) {
case 8: {
multiboot_uint8_t * pixel =
fb_addr + mb_info->framebuffer_pitch * y + x;
*pixel = color;
break;
}
case 15:
case 16: {
multiboot_uint16_t * pixel =
fb_addr + mb_info->framebuffer_pitch * y + 2 * x;
*pixel = color;
break;
}
case 32: {
multiboot_uint32_t * pixel =
fb_addr + mb_info->framebuffer_pitch * y + 4 * x;
*pixel = color;
break;
}
}
}
void keyboard_handler_main() {
drawBall();
}