2018-10-16 11:01:38 +02:00
|
|
|
#include "types.h"
|
|
|
|
#include "VGA.h"
|
|
|
|
#include "i386.h"
|
|
|
|
#include "IO.h"
|
|
|
|
#include "StdLib.h"
|
2018-11-01 13:15:46 +01:00
|
|
|
#include "Process.h"
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-10-30 23:49:06 +01:00
|
|
|
static byte* vga_mem = nullptr;
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-10-22 11:15:16 +02:00
|
|
|
void vga_scroll_up()
|
2018-10-16 11:01:38 +02:00
|
|
|
{
|
2018-10-24 13:19:36 +02:00
|
|
|
InterruptDisabler disabler;
|
2018-10-23 15:47:03 +02:00
|
|
|
memcpy(vga_mem, vga_mem + 160, 160 * 24);
|
2018-10-30 13:59:29 +01:00
|
|
|
vga_clear_row(24);
|
|
|
|
}
|
|
|
|
|
|
|
|
void vga_clear_row(word line)
|
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
|
|
|
word* linemem = (word*)&vga_mem[line * 160];
|
|
|
|
for (word i = 0; i < 80; ++i) {
|
|
|
|
linemem[i] = 0x0720;
|
|
|
|
}
|
2018-10-22 11:15:16 +02:00
|
|
|
}
|
2018-10-21 22:11:46 +02:00
|
|
|
|
2018-10-27 23:42:20 +02:00
|
|
|
void vga_clear()
|
|
|
|
{
|
|
|
|
InterruptDisabler disabler;
|
2018-10-30 13:59:29 +01:00
|
|
|
for (word i = 0; i < 25; ++i)
|
|
|
|
vga_clear_row(i);
|
2018-10-27 23:42:20 +02:00
|
|
|
}
|
|
|
|
|
2018-10-30 15:33:37 +01:00
|
|
|
void vga_putch_at(byte row, byte column, byte ch, byte attr)
|
2018-10-22 11:15:16 +02:00
|
|
|
{
|
|
|
|
word cur = (row * 160) + (column * 2);
|
|
|
|
vga_mem[cur] = ch;
|
2018-10-30 15:33:37 +01:00
|
|
|
vga_mem[cur + 1] = attr;
|
2018-10-16 11:01:38 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 13:20:35 +02:00
|
|
|
void vga_init()
|
2018-10-16 11:01:38 +02:00
|
|
|
{
|
2018-10-23 23:32:53 +02:00
|
|
|
vga_mem = (byte*)0xb8000;
|
2018-10-16 11:01:38 +02:00
|
|
|
|
2018-10-23 23:32:53 +02:00
|
|
|
for (word i = 0; i < (80 * 25); ++i) {
|
2018-10-16 11:01:38 +02:00
|
|
|
vga_mem[i*2] = ' ';
|
|
|
|
vga_mem[i*2 + 1] = 0x07;
|
|
|
|
}
|
|
|
|
|
2018-10-23 23:32:53 +02:00
|
|
|
vga_set_cursor(0);
|
2018-10-16 11:01:38 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 13:20:35 +02:00
|
|
|
WORD vga_get_cursor()
|
2018-10-16 11:01:38 +02: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 13:20:35 +02:00
|
|
|
void vga_set_cursor(WORD value)
|
2018-10-16 11:01:38 +02:00
|
|
|
{
|
2018-10-22 13:20:35 +02:00
|
|
|
if (value >= (80 * 25)) {
|
|
|
|
vga_set_cursor(0);
|
2018-10-16 11:01:38 +02:00
|
|
|
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);
|
|
|
|
}
|