1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-10 18:22:07 +00:00
serenity/Kernel/VGA.cpp
Andreas Kling 018da1be11 Generalize the SpinLock and move it to AK.
Add a separate lock to protect the VFS. I think this might be a good idea.
I'm not sure it's a good approach though. I'll fiddle with it as I go along.

It's really fun to figure out all these things on my own.
2018-10-23 23:34:05 +02:00

74 lines
1.3 KiB
C++

#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;
void vga_scroll_up()
{
memcpy(vga_mem, vga_mem + 160, 160 * 24);
memset(vga_mem + (160 * 24), 0, 160);
}
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;
}
void vga_set_attr(BYTE attr)
{
current_attr = attr;
}
byte vga_get_attr()
{
return current_attr;
}
void vga_init()
{
current_attr = 0x07;
vga_mem = (byte*)0xb8000;
for (word i = 0; i < (80 * 25); ++i) {
vga_mem[i*2] = ' ';
vga_mem[i*2 + 1] = 0x07;
}
vga_set_cursor(0);
}
WORD vga_get_cursor()
{
WORD value;
IO::out8(0x3d4, 0x0e);
value = IO::in8(0x3d5) << 8;
IO::out8(0x3d4, 0x0f);
value |= IO::in8(0x3d5);
return value;
}
void vga_set_cursor(WORD value)
{
if (value >= (80 * 25)) {
/* XXX: If you try to move the cursor off the screen, I will go reddish pink! */
vga_set_cursor(0);
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);
}