mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
87 lines
3.4 KiB
C
87 lines
3.4 KiB
C
//----------------------------------------------------------------------------//
|
|
// GNU GPL OS/K //
|
|
// //
|
|
// Desc: VGA terminal functions //
|
|
// //
|
|
// //
|
|
// 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/>. //
|
|
//----------------------------------------------------------------------------//
|
|
|
|
#include <kernel/buf.h>
|
|
|
|
//----------------------------------------------------------//
|
|
// 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)
|
|
|
|
//
|
|
// VGA Buffer Flusher
|
|
//
|
|
error_t bvgaflusher(Buffer_t *buf)
|
|
{
|
|
ushort *fbp = BtGetBootInfo(video).framebufferAddr;
|
|
const uchar color = 0xf;
|
|
|
|
assert(buf->lastLF == 0);
|
|
|
|
uchar *currentLine = buf->wp - buf->lineLen;
|
|
uchar *ptr = (uchar *)lmax((size_t)buf->buf,
|
|
(size_t)currentLine
|
|
- (buf->nLines - 1) * buf->lineLen);
|
|
|
|
for (; ptr < buf->wp ; ptr++) {
|
|
*fbp++ = VGA_ComputeEntry(*ptr, color);
|
|
}
|
|
|
|
const size_t bufSize = buf->nLines * buf->lineLen;
|
|
ushort *fbe = BtGetBootInfo(video).framebufferAddr
|
|
+ (bufSize * sizeof(ushort));
|
|
|
|
if (fbp < fbe) {
|
|
const ushort filler = VGA_ComputeEntry(' ', color);
|
|
while (fbp < fbe) *fbp++ = filler;
|
|
}
|
|
|
|
return EOK;
|
|
}
|
|
|
|
//
|
|
// Initialize VGA buffer
|
|
//
|
|
error_t IoInitVGABuffer(void)
|
|
{
|
|
static char bvgabuffer[1 * MB];
|
|
|
|
BStdOut = BOpenLineBuf(bvgabuffer, BS_WRONLY,
|
|
BtGetBootInfo(video).framebufferWidth,
|
|
BtGetBootInfo(video).framebufferHeight,
|
|
8, bvgaflusher);
|
|
|
|
BStdDbg = BStdOut;
|
|
|
|
return EOK;
|
|
}
|
|
|