2019-01-14 14:31:49 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
// //
|
2019-02-06 14:07:38 +01:00
|
|
|
// Desc: VGA terminal functions //
|
2019-02-16 23:36:33 +01:00
|
|
|
// //
|
|
|
|
// //
|
|
|
|
// Copyright © 2018-2019 The OS/K Team //
|
|
|
|
// //
|
|
|
|
// This file is part of OS/K. //
|
|
|
|
// //
|
|
|
|
// OS/K is free software: you can redistribute it and/or modify //
|
|
|
|
// it under the terms of the GNU General Public License as published by //
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or //
|
|
|
|
// any later version. //
|
|
|
|
// //
|
|
|
|
// OS/K is distributed in the hope that it will be useful, //
|
|
|
|
// but WITHOUT ANY WARRANTY//without even the implied warranty of //
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
|
|
|
// GNU General Public License for more details. //
|
|
|
|
// //
|
|
|
|
// You should have received a copy of the GNU General Public License //
|
|
|
|
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
2019-01-14 14:31:49 +01:00
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
2019-02-16 23:36:33 +01:00
|
|
|
#include <kernel/term.h>
|
2019-01-14 14:31:49 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------//
|
|
|
|
// Internal functions for VGA terminals //
|
|
|
|
// These DO NOT check input correctness //
|
|
|
|
//----------------------------------------------------------//
|
|
|
|
|
|
|
|
//
|
|
|
|
// VGA-related macros
|
|
|
|
//
|
|
|
|
#define VGA_ComputeColorCode(fg, bg) ((fg) | (bg) << 4)
|
|
|
|
#define VGA_ComputeOffset(term, x, y) ((y) * (term)->width + (x))
|
|
|
|
#define VGA_ComputeEntry(ch, cl) (((ushort)(ch)) | (ushort)(cl) << 8)
|
|
|
|
|
|
|
|
//
|
2019-03-18 17:25:44 +01:00
|
|
|
// Clears terminal
|
2019-01-14 14:31:49 +01:00
|
|
|
//
|
|
|
|
error_t VGA_ClearTermUnlocked(Terminal_t *term)
|
|
|
|
{
|
|
|
|
const uchar color = VGA_ComputeColorCode(term->fgColor, term->bgColor);
|
2019-03-11 19:22:37 +01:00
|
|
|
const ushort filler = VGA_ComputeEntry(' ', color);
|
2019-01-14 14:31:49 +01:00
|
|
|
const size_t bufsize = term->width * term->height;
|
|
|
|
|
|
|
|
// Fill the buffer
|
|
|
|
memsetw((ushort *)term->data, filler, bufsize);
|
|
|
|
|
|
|
|
// XXX update cursor too
|
|
|
|
term->currentX = term->currentY = 0;
|
|
|
|
|
|
|
|
return EOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-03-18 17:25:44 +01:00
|
|
|
// Writes a single character on the terminal
|
2019-01-14 14:31:49 +01:00
|
|
|
//
|
|
|
|
error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch)
|
|
|
|
{
|
2019-03-19 13:37:23 +01:00
|
|
|
ushort *buffer = (ushort *)term->data;
|
|
|
|
const size_t offset = VGA_ComputeOffset(term, term->currentX, term->currentY);
|
|
|
|
buffer[offset] = VGA_ComputeEntry(ch, VGA_ComputeColorCode(term->fgColor, term->bgColor));
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-03-19 13:37:23 +01:00
|
|
|
return EOK;
|
2019-01-14 14:31:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// VGA output
|
|
|
|
//
|
2019-02-06 14:07:38 +01:00
|
|
|
Terminal_t VGA_Terminal = {
|
2019-01-14 14:31:49 +01:00
|
|
|
.initDone = FALSE,
|
|
|
|
.lock = INITLOCK(KLOCK_MUTEX),
|
|
|
|
|
|
|
|
.name = "VGA Output Terminal",
|
|
|
|
.type = "VGA",
|
|
|
|
|
2019-03-23 23:52:18 +01:00
|
|
|
.data = (void *)0,
|
|
|
|
.width = 0,
|
|
|
|
.height = 0,
|
2019-01-14 14:31:49 +01:00
|
|
|
.currentX = 0,
|
|
|
|
.currentY = 0,
|
|
|
|
|
|
|
|
.tabSize = KTABSIZE,
|
|
|
|
.fgColor = KTERM_COLOR_LGREY,
|
|
|
|
.bgColor = KTERM_COLOR_BLACK,
|
|
|
|
|
2019-03-19 13:37:23 +01:00
|
|
|
.clear = VGA_ClearTermUnlocked,
|
|
|
|
.putchar = VGA_PutOnTermUnlocked,
|
2019-01-14 14:31:49 +01:00
|
|
|
};
|
|
|
|
|
2019-02-06 14:07:38 +01:00
|
|
|
//
|
|
|
|
// Initialize VGA output
|
|
|
|
//
|
|
|
|
void VGA_Init(void)
|
|
|
|
{
|
|
|
|
KalAssert(VGA_Terminal.initDone != INITOK);
|
|
|
|
|
2019-03-23 23:52:18 +01:00
|
|
|
//Use the infos provided in the BootInfo_t structure
|
|
|
|
VGA_Terminal.data = GetBootInfo(video).framebufferAddr;
|
|
|
|
VGA_Terminal.width = GetBootInfo(video).framebufferWidth;
|
|
|
|
VGA_Terminal.height = GetBootInfo(video).framebufferHeight;
|
|
|
|
|
2019-02-06 14:07:38 +01:00
|
|
|
VGA_Terminal.initDone = INITOK;
|
|
|
|
}
|
|
|
|
|