//----------------------------------------------------------------------------// // 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 . // //----------------------------------------------------------------------------// #include //----------------------------------------------------------// // 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) // // Clears terminal // error_t VGA_ClearTermUnlocked(Terminal_t *term) { const uchar color = VGA_ComputeColorCode(term->fgColor, term->bgColor); const ushort filler = VGA_ComputeEntry(' ', color); 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; } // // Writes a single character on the terminal // error_t VGA_PutOnTermUnlocked(Terminal_t *term, char ch) { 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)); return EOK; } // // VGA output // Terminal_t VGA_Terminal = { .initDone = FALSE, .lock = INITLOCK(KLOCK_MUTEX), .name = "VGA Output Terminal", .type = "VGA", .data = (void *)0xB8000, .width = 80, .height = 25, .currentX = 0, .currentY = 0, .tabSize = KTABSIZE, .fgColor = KTERM_COLOR_LGREY, .bgColor = KTERM_COLOR_BLACK, .clear = VGA_ClearTermUnlocked, .putchar = VGA_PutOnTermUnlocked, }; // // Initialize VGA output // void VGA_Init(void) { KalAssert(VGA_Terminal.initDone != INITOK); VGA_Terminal.initDone = INITOK; }