113 lines
1.8 KiB
C
113 lines
1.8 KiB
C
#include "io.h"
|
|
#include "stdio.h"
|
|
#include "string.h"
|
|
|
|
char* fb = (char *) 0x000B8000;
|
|
const unsigned VGA_WIDTH = 80;
|
|
const unsigned VGA_HEIGHT = 25;
|
|
const unsigned int COLOR = 0x7;
|
|
unsigned int VGA_X = 0, VGA_Y = 0;
|
|
|
|
void move_cursor(int x, int y)
|
|
{
|
|
unsigned short pos = y*VGA_WIDTH+x;
|
|
|
|
outb(FB_CMD_PORT, FB_HIGH_BYTE_CMD);
|
|
outb(FB_DATA_PORT, ((pos >> 8) & 0x00FF));
|
|
outb(FB_CMD_PORT, FB_LOW_BYTE_CMD);
|
|
outb(FB_DATA_PORT, pos & 0x00FF);
|
|
}
|
|
|
|
void putchar(int x, int y, char c)
|
|
{
|
|
fb[2*(y*VGA_WIDTH+x)] = c;
|
|
}
|
|
|
|
void putcolor(int x, int y, unsigned int color)
|
|
{
|
|
fb[2*(y*VGA_WIDTH+x)+1] = color;
|
|
}
|
|
|
|
void clear(void)
|
|
{
|
|
for (unsigned int y=0; y<VGA_HEIGHT; y++)
|
|
{
|
|
for (unsigned int x=0; x<VGA_WIDTH; x++)
|
|
{
|
|
putchar(x, y, '\0');
|
|
putcolor(x, y, COLOR);
|
|
}
|
|
}
|
|
VGA_X = 0;
|
|
VGA_Y = 0;
|
|
move_cursor(VGA_X, VGA_Y);
|
|
}
|
|
|
|
char getchar(int x, int y)
|
|
{
|
|
return fb[2*(y*VGA_WIDTH+x)];
|
|
}
|
|
|
|
unsigned int getcolor(int x, int y)
|
|
{
|
|
return fb[2*(y*VGA_WIDTH+x)+1];
|
|
}
|
|
|
|
void scroll(int lines)
|
|
{
|
|
for (unsigned int y = lines; y < VGA_HEIGHT; y++)
|
|
{
|
|
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
|
{
|
|
putchar(x, y-lines, getchar(x, y));
|
|
putcolor(x, y-lines, getcolor(x, y));
|
|
}
|
|
}
|
|
|
|
for (unsigned int y = VGA_HEIGHT-lines; y<VGA_HEIGHT; y++)
|
|
{
|
|
for (unsigned int x = 0; x < VGA_WIDTH; x++)
|
|
{
|
|
putchar(x, y, '\0');
|
|
putcolor(x, y, COLOR);
|
|
}
|
|
}
|
|
}
|
|
|
|
void putc(char c)
|
|
{
|
|
switch(c)
|
|
{
|
|
case '\n':
|
|
VGA_X = 0;
|
|
VGA_Y++;
|
|
break;
|
|
case '\r':
|
|
VGA_X = 0;
|
|
break;
|
|
default:
|
|
putchar(VGA_X, VGA_Y, c);
|
|
VGA_X++;
|
|
break;
|
|
}
|
|
|
|
if (VGA_X >= VGA_WIDTH)
|
|
{
|
|
VGA_Y++;
|
|
VGA_X = 0;
|
|
}
|
|
if (VGA_Y >= VGA_HEIGHT) scroll(1);
|
|
|
|
move_cursor(VGA_X, VGA_Y);
|
|
}
|
|
|
|
void puts(const char* str)
|
|
{
|
|
while (*str)
|
|
{
|
|
putc(*str);
|
|
str++;
|
|
}
|
|
}
|
|
|