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-04-06 07:53:58 +02:00
|
|
|
#include <extras/buf.h>
|
|
|
|
#include <kernel/boot.h>
|
2019-04-21 21:18:13 +02:00
|
|
|
#include <kernel/cursor.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-29 14:19:29 +01:00
|
|
|
// VGA Buffer Flusher
|
2019-01-14 14:31:49 +01:00
|
|
|
//
|
2019-03-29 14:19:29 +01:00
|
|
|
error_t bvgaflusher(Buffer_t *buf)
|
2019-01-14 14:31:49 +01:00
|
|
|
{
|
2019-04-06 07:53:58 +02:00
|
|
|
ushort *fbp = BtVideoInfo.framebufferAddr;
|
2019-04-21 21:18:13 +02:00
|
|
|
uchar color = 0xf;
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-04-04 18:41:39 +02:00
|
|
|
uchar *currentLine = buf->wp - buf->lineLen - buf->lastLF;
|
2019-04-21 21:18:13 +02:00
|
|
|
uchar *bufStart = (uchar *)lmax((size_t)buf->buf,
|
|
|
|
(size_t)currentLine
|
|
|
|
- (buf->nLines - 1) * buf->lineLen);
|
|
|
|
|
|
|
|
uchar *ptr = bufStart;
|
|
|
|
|
|
|
|
// Writes the buffer's content
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-03-29 14:19:29 +01:00
|
|
|
for (; ptr < buf->wp ; ptr++) {
|
|
|
|
*fbp++ = VGA_ComputeEntry(*ptr, color);
|
|
|
|
}
|
2019-04-21 21:18:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Update the cursor
|
|
|
|
size_t curX = ((size_t)ptr - (size_t)bufStart) % buf->lineLen;
|
|
|
|
size_t curY = ((size_t)ptr - (size_t)bufStart) / buf->lineLen;
|
|
|
|
|
|
|
|
IoUpdateCursor(curX, curY);
|
|
|
|
|
|
|
|
// Empty the rest of the buffer
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-03-29 14:19:29 +01:00
|
|
|
const size_t bufSize = buf->nLines * buf->lineLen;
|
2019-04-06 07:53:58 +02:00
|
|
|
ushort *fbe = BtVideoInfo.framebufferAddr
|
2019-04-05 10:20:10 +02:00
|
|
|
+ (bufSize * sizeof(ushort));
|
2019-01-14 14:31:49 +01:00
|
|
|
|
2019-03-29 14:19:29 +01:00
|
|
|
if (fbp < fbe) {
|
|
|
|
const ushort filler = VGA_ComputeEntry(' ', color);
|
|
|
|
while (fbp < fbe) *fbp++ = filler;
|
|
|
|
}
|
2019-04-21 21:18:13 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2019-03-29 14:19:29 +01:00
|
|
|
// Initialize VGA buffer
|
2019-02-06 14:07:38 +01:00
|
|
|
//
|
2019-03-29 14:19:29 +01:00
|
|
|
error_t IoInitVGABuffer(void)
|
2019-02-06 14:07:38 +01:00
|
|
|
{
|
2019-03-29 14:19:29 +01:00
|
|
|
static char bvgabuffer[1 * MB];
|
|
|
|
|
|
|
|
BStdOut = BOpenLineBuf(bvgabuffer, BS_WRONLY,
|
2019-04-06 07:53:58 +02:00
|
|
|
BtVideoInfo.framebufferWidth,
|
|
|
|
BtVideoInfo.framebufferHeight,
|
2019-03-29 14:19:29 +01:00
|
|
|
8, bvgaflusher);
|
2019-02-06 14:07:38 +01:00
|
|
|
|
2019-03-29 14:19:29 +01:00
|
|
|
BStdDbg = BStdOut;
|
2019-03-23 23:52:18 +01:00
|
|
|
|
2019-03-29 14:19:29 +01:00
|
|
|
return EOK;
|
2019-02-06 14:07:38 +01:00
|
|
|
}
|
|
|
|
|