-
-
Save zid/ee3cd10d06ecb5b975b200740add7a0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static const char *layout[3][3] = { | |
{"1","2","3"}, | |
{"4","5","6"}, | |
{"7","8","9"} | |
}; | |
static char layout2[3][3] = { | |
{1,2,3}, | |
{4,5,6}, | |
{7,8,9} | |
}; | |
static char *itoa(int value, char *str, int base) | |
{ | |
char *rc, *ptr, *low; | |
/* Early exit for unsupported bases */ | |
if (base < 2 || base > 36 ) { | |
*str = '\0'; | |
return str; | |
} | |
rc = ptr = str; | |
if (value < 0 && base == 10) | |
{ | |
*ptr++ = '-'; | |
value = -value; | |
} | |
low = ptr; | |
do { | |
*ptr++ = "0123456789abcdefghijklmnopqrstuvwxyz"[value % base]; | |
value /= base; | |
} while (value); | |
*ptr-- = '\0'; | |
while (low < ptr) | |
{ | |
char tmp = *low; | |
*low++ = *ptr; | |
*ptr-- = tmp; | |
} | |
return rc; | |
} | |
void print(const char *s, int offset, char color) | |
{ | |
char *d = (char *)0xb8000; | |
offset *= 2; | |
while (*s) | |
{ | |
d[offset+0] = *s++; | |
d[offset+1] = color; | |
d += 2; | |
} | |
} | |
static void grid(void) | |
{ | |
int count = 0; | |
char str[128]; | |
for (int i = 0; i < 3; i++ ){ | |
for (int j = 0; j < 3; j++ ){ | |
layout2[i][j] = *itoa(count, str, 10); | |
count++; | |
} | |
} | |
print(layout[0][0], 80*5, 0x17); | |
print(&layout2[0][1], 80*6, 0x17); | |
} | |
static void clear_screen(void) | |
{ | |
char *d = (char *)0xb8000; | |
unsigned int i=0; | |
for(i = 0; i < 80*25*2; i += 2) | |
{ | |
d[i+0] = ' '; | |
d[i+1] = 0x11; /* Macro me to COLOR_BLANK or something */ | |
} | |
} | |
int k_main() | |
{ | |
clear_screen(); | |
print("Kernel", 80*2, 0x17); | |
grid(); | |
while(1) | |
; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment