2018-10-16 12:01:38 +03:00
|
|
|
#include "types.h"
|
|
|
|
#include "VGA.h"
|
|
|
|
#include "i386.h"
|
|
|
|
#include "IO.h"
|
|
|
|
#include "StdLib.h"
|
|
|
|
#include "Task.h"
|
|
|
|
|
|
|
|
PRIVATE BYTE *vga_mem = 0L;
|
|
|
|
PRIVATE BYTE current_attr = 0x07;
|
|
|
|
|
2018-10-22 12:15:16 +03:00
|
|
|
void vga_scroll_up()
|
2018-10-16 12:01:38 +03:00
|
|
|
{
|
2018-10-24 14:19:36 +03:00
|
|
|
InterruptDisabler disabler;
|
2018-10-23 16:47:03 +03:00
|
|
|
memcpy(vga_mem, vga_mem + 160, 160 * 24);
|
|
|
|
memset(vga_mem + (160 * 24), 0, 160);
|
2018-10-22 12:15:16 +03:00
|
|
|
}
|
2018-10-21 23:11:46 +03:00
|
|
|
|
2018-10-22 12:15:16 +03:00
|
|
|
void vga_putch_at(byte row, byte column, byte ch)
|
|
|
|
{
|
|
|
|
word cur = (row * 160) + (column * 2);
|
|
|
|
vga_mem[cur] = ch;
|
|
|
|
vga_mem[cur + 1] = current_attr;
|
2018-10-16 12:01:38 +03:00
|
|
|
}
|
|
|
|
|
2018-10-22 14:20:35 +03:00
|
|
|
void vga_set_attr(BYTE attr)
|
2018-10-16 12:01:38 +03:00
|
|
|
{
|
|
|
|
current_attr = attr;
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:20:35 +03:00
|
|
|
byte vga_get_attr()
|
2018-10-16 12:01:38 +03:00
|
|
|
{
|
|
|
|
return current_attr;
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:20:35 +03:00
|
|
|
void vga_init()
|
2018-10-16 12:01:38 +03:00
|
|
|
{
|
|
|
|
current_attr = 0x07;
|
2018-10-24 00:32:53 +03:00
|
|
|
vga_mem = (byte*)0xb8000;
|
2018-10-16 12:01:38 +03:00
|
|
|
|
2018-10-24 00:32:53 +03:00
|
|
|
for (word i = 0; i < (80 * 25); ++i) {
|
2018-10-16 12:01:38 +03:00
|
|
|
vga_mem[i*2] = ' ';
|
|
|
|
vga_mem[i*2 + 1] = 0x07;
|
|
|
|
}
|
|
|
|
|
2018-10-24 00:32:53 +03:00
|
|
|
vga_set_cursor(0);
|
2018-10-16 12:01:38 +03:00
|
|
|
}
|
|
|
|
|
2018-10-22 14:20:35 +03:00
|
|
|
WORD vga_get_cursor()
|
2018-10-16 12:01:38 +03:00
|
|
|
{
|
|
|
|
WORD value;
|
|
|
|
IO::out8(0x3d4, 0x0e);
|
|
|
|
value = IO::in8(0x3d5) << 8;
|
|
|
|
IO::out8(0x3d4, 0x0f);
|
|
|
|
value |= IO::in8(0x3d5);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:20:35 +03:00
|
|
|
void vga_set_cursor(WORD value)
|
2018-10-16 12:01:38 +03:00
|
|
|
{
|
2018-10-22 14:20:35 +03:00
|
|
|
if (value >= (80 * 25)) {
|
2018-10-16 12:01:38 +03:00
|
|
|
/* XXX: If you try to move the cursor off the screen, I will go reddish pink! */
|
2018-10-22 14:20:35 +03:00
|
|
|
vga_set_cursor(0);
|
2018-10-16 12:01:38 +03:00
|
|
|
current_attr = 0x0C;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
IO::out8(0x3d4, 0x0e);
|
|
|
|
IO::out8(0x3d5, MSB(value));
|
|
|
|
IO::out8(0x3d4, 0x0f);
|
|
|
|
IO::out8(0x3d5, LSB(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void vga_set_cursor(BYTE row, BYTE column)
|
|
|
|
{
|
|
|
|
vga_set_cursor(row * 80 + column);
|
|
|
|
}
|