simplified print
This commit is contained in:
@@ -3,5 +3,5 @@
|
|||||||
void init(void)
|
void init(void)
|
||||||
{
|
{
|
||||||
print_init();
|
print_init();
|
||||||
print("Starting nub-os\n", VGA_FG_WHITE, VGA_BG_BLACK);
|
println("Starting nub-os");
|
||||||
}
|
}
|
||||||
|
|||||||
101
src/print.c
101
src/print.c
@@ -10,85 +10,32 @@ void print_init(void)
|
|||||||
vga_text_pos = (char*)0xb8000;
|
vga_text_pos = (char*)0xb8000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print(char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color)
|
void print_newline(void)
|
||||||
|
{
|
||||||
|
vga_text_pos += 160 - ((vga_text_pos - (char*)0xb8000) % 160);
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color)
|
||||||
{
|
{
|
||||||
for (int i = 0; string[i]; i++)
|
for (int i = 0; string[i]; i++)
|
||||||
{
|
{
|
||||||
char c = string[i];
|
*vga_text_pos++ = string[i];
|
||||||
|
*vga_text_pos++ = (bg_color << 4) | fg_color;
|
||||||
switch (c)
|
|
||||||
{
|
|
||||||
case '\n':
|
|
||||||
{
|
|
||||||
|
|
||||||
vga_text_pos += 160 - ((vga_text_pos - (char*)0xb8000) % 160);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case '\r':
|
|
||||||
{
|
|
||||||
vga_text_pos -= ((vga_text_pos - (char*)0xb8000) % 160);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case '\t':
|
|
||||||
{
|
|
||||||
int offset = (vga_text_pos - (char*)0xb8000) % 160;
|
|
||||||
int next_tab = ((offset / 16) + 1) * 16;
|
|
||||||
vga_text_pos += next_tab - offset;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case '\b':
|
|
||||||
{
|
|
||||||
if (vga_text_pos > (char*)0xb8000)
|
|
||||||
{
|
|
||||||
vga_text_pos -= 2;
|
|
||||||
*vga_text_pos = ' ';
|
|
||||||
*(vga_text_pos + 1) = (bg_color << 4) | fg_color;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case '\f':
|
|
||||||
{
|
|
||||||
char* start = (char*)0xb8000;
|
|
||||||
for (int j = 0; j < 80 * 25 * 2; j += 2)
|
|
||||||
{
|
|
||||||
start[j] = ' ';
|
|
||||||
start[j + 1] = (bg_color << 4) | fg_color;
|
|
||||||
}
|
|
||||||
vga_text_pos = (char*)0xb8000;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case '\a':
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
*vga_text_pos++ = c;
|
|
||||||
*vga_text_pos++ = (bg_color << 4) | fg_color;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vga_text_pos >= (char*)0xb8000 + VGA_WIDTH * VGA_HEIGHT * 2)
|
|
||||||
{
|
|
||||||
char* start = (char*)0xb8000;
|
|
||||||
|
|
||||||
for (int row = 1; row < VGA_HEIGHT; row++)
|
|
||||||
{
|
|
||||||
for (int col = 0; col < VGA_WIDTH * 2; col++)
|
|
||||||
{
|
|
||||||
start[(row - 1) * VGA_WIDTH * 2 + col] = start[row * VGA_WIDTH * 2 + col];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char* last_row = start + (VGA_HEIGHT - 1) * VGA_WIDTH * 2;
|
|
||||||
for (int col = 0; col < VGA_WIDTH * 2; col += 2)
|
|
||||||
{
|
|
||||||
last_row[col] = ' ';
|
|
||||||
last_row[col + 1] = (VGA_BG_BLACK << 4) | VGA_FG_WHITE;
|
|
||||||
}
|
|
||||||
|
|
||||||
vga_text_pos -= VGA_WIDTH * 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void println_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color)
|
||||||
|
{
|
||||||
|
print_clr(string, fg_color, bg_color);
|
||||||
|
print_newline();
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(const char* string)
|
||||||
|
{
|
||||||
|
print_clr(string, VGA_FG_WHITE, VGA_BG_BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void println(const char* string)
|
||||||
|
{
|
||||||
|
println_clr(string, VGA_FG_WHITE, VGA_BG_BLACK);
|
||||||
}
|
}
|
||||||
11
src/print.h
11
src/print.h
@@ -30,5 +30,12 @@ enum VGA_BG_COLOR
|
|||||||
VGA_BG_LIGHT_GRAY = 0x7,
|
VGA_BG_LIGHT_GRAY = 0x7,
|
||||||
};
|
};
|
||||||
|
|
||||||
void print(char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color);
|
void print_init(void);
|
||||||
void print_init(void);
|
|
||||||
|
void print_newline(void);
|
||||||
|
|
||||||
|
void print(const char* string);
|
||||||
|
void println(const char* string);
|
||||||
|
|
||||||
|
void print_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color);
|
||||||
|
void println_clr(const char* string, enum VGA_FG_COLOR fg_color, enum VGA_BG_COLOR bg_color);
|
||||||
Reference in New Issue
Block a user