119 lines
3.5 KiB
C
119 lines
3.5 KiB
C
//----------------------------------------------------------------------------//
|
|
// GNU GPL OS/K //
|
|
// //
|
|
// Desc: Terminal-related 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/term.h>
|
|
|
|
extern void VGA_Init(void);
|
|
extern Terminal_t VGA_Terminal;
|
|
|
|
//
|
|
// Initialize standard output
|
|
//
|
|
void InitTerms(void)
|
|
{
|
|
KalAssert(!GetStdOut() && !GetStdDbg());
|
|
|
|
VGA_Init();
|
|
|
|
SetStdDbg(&VGA_Terminal);
|
|
SetStdOut(&VGA_Terminal);
|
|
|
|
ClearTerm(GetStdOut());
|
|
}
|
|
|
|
//
|
|
// Fill terminal with spaces
|
|
//
|
|
error_t ClearTerm(Terminal_t *term)
|
|
{
|
|
error_t retcode;
|
|
|
|
if (term == NULL) return EINVAL;
|
|
KalAssert(term->initDone == INITOK);
|
|
|
|
AquireLock(&term->lock);
|
|
retcode = term->ClearTermUnlocked(term);
|
|
ReleaseLock(&term->lock);
|
|
|
|
return retcode;
|
|
}
|
|
|
|
//
|
|
// Change the color code
|
|
//
|
|
error_t ChTermColor(Terminal_t *term, TermColor_t fgColor, TermColor_t bgColor)
|
|
{
|
|
if (fgColor > KTERM_COLOR_WHITE || bgColor > KTERM_COLOR_WHITE)
|
|
return EINVAL;
|
|
|
|
if (term == NULL)
|
|
return EINVAL;
|
|
|
|
AquireLock(&term->lock);
|
|
|
|
term->fgColor = fgColor;
|
|
term->bgColor = bgColor;
|
|
|
|
ReleaseLock(&term->lock);
|
|
|
|
return EOK;
|
|
}
|
|
|
|
//
|
|
// Write a single character on the terminal
|
|
//
|
|
error_t PutOnTerm(Terminal_t *term, char ch)
|
|
{
|
|
error_t retcode;
|
|
|
|
if (term == NULL) return EINVAL;
|
|
KalAssert(term->initDone == INITOK);
|
|
|
|
AquireLock(&term->lock);
|
|
retcode = term->PutOnTermUnlocked(term, ch);
|
|
ReleaseLock(&term->lock);
|
|
|
|
return retcode;
|
|
}
|
|
|
|
//
|
|
// Print string on terminal
|
|
//
|
|
error_t PrintOnTerm(Terminal_t *term, const char *str)
|
|
{
|
|
error_t retcode = EOK;
|
|
|
|
if (term == NULL) return EINVAL;
|
|
KalAssert(term->initDone == INITOK);
|
|
|
|
AquireLock(&term->lock);
|
|
while (*str && retcode == EOK) {
|
|
retcode = term->PutOnTermUnlocked(term, *str++);
|
|
}
|
|
ReleaseLock(&term->lock);
|
|
|
|
return retcode;
|
|
}
|
|
|