putc() advances lines when screen is full

This commit is contained in:
2021-04-19 06:56:49 -05:00
parent c5ca5e82a7
commit a68503538b

View File

@@ -35,6 +35,7 @@ size_t cursor = 0;
const size_t tab_width = 4; const size_t tab_width = 4;
const size_t line_width = 80; const size_t line_width = 80;
const size_t line_count = 25;
int initialize_screen() int initialize_screen()
{ {
@@ -62,6 +63,21 @@ int putchar(int c)
screen[cursor].c = (char) c; screen[cursor].c = (char) c;
cursor++; cursor++;
} }
if(cursor >= line_count * line_width)
{
for(int i = 0; i < line_count * line_width; i++)
{
if(i < (line_count - 1) * line_width)
{
screen[i] = screen[i + line_width];
}
else
{
screen[i].c = ' ';
}
}
cursor -= line_width;
}
return c; return c;
} }