Began work on proper terminal I/O

- Chenged Puts() syscall to Write()
- Improved syscalls.h
- added a new header in terminal/terminal.h
- moved gfxMode into screen/gfxmode.h
This commit is contained in:
2024-05-27 15:16:07 +02:00
parent eac71f137e
commit 536f6b2320
11 changed files with 285 additions and 111 deletions
+12 -78
View File
@@ -1,89 +1,18 @@
#ifndef SCREEN_H
#define SCREEN_H
#include <memory/addresses.h>
#include <screen/gfxmode.h>
#include <stdint.h>
#include <string.h>
// Basic full saturation colors
#define BLACK 0x00000000 // 0
#define RED 0x00ff0000 // 1
#define GREEN 0x0000ff00 // 2
#define YELLOW 0x00ffff00 // 3
#define BLUE 0x000000ff // 4
#define MAGENTA 0x00ff00ff // 5
#define CYAN 0x0000ffff // 6
#define WHITE 0x00ffffff // 7
#define MODE_INFO_BLOCK 0x9000
#define BG_COLOR 0x00010b17
#define FG_COLOR 0x00ebddf4
typedef struct modeInfoBlock_s {
// Required by all VBE revisions
uint16_t modeAttr;
uint8_t windowAAtrr;
uint8_t windowBAttr;
uint16_t windowGranularity;
uint16_t windowSize;
uint16_t windowASegment;
uint16_t windowBSegment;
uint32_t windowFunctionPtr;
uint16_t bytesPerScanline;
// Required by VBE 1.2+
uint16_t xRes;
uint16_t yRes;
uint8_t xCharSize;
uint8_t yCharSize;
uint8_t planeCount;
uint8_t bpp;
uint8_t bankCount;
uint8_t memoryModel;
uint8_t bankSize;
uint8_t imagePageCount;
uint8_t reserved1;
// Direct color fields
uint8_t redMaskSize;
uint8_t redFieldPos;
uint8_t greenMaskSize;
uint8_t greenFieldPos;
uint8_t blueMaskSize;
uint8_t blueFieldPos;
uint8_t reservedMaskSize;
uint8_t reservedFieldPos;
uint8_t directColorModeInfo;
// Required by VBE 2.0+
uint32_t physicalBasePtr;
uint32_t reserved2;
uint16_t reserved3;
// Required by VBE 3.0+
uint16_t linearBytesPerScanline;
uint8_t bankImagePageCount;
uint8_t linearImagePageCount;
uint8_t linearRedMaskSize;
uint8_t linearRedFieldPos;
uint8_t linearGreenMaskSize;
uint8_t linearGreenFieldPos;
uint8_t linearBlueMaskSize;
uint8_t linearBlueFieldPos;
uint8_t linearReservedMaskSize;
uint8_t linearReservedFieldPos;
uint32_t maxPixelClock;
uint8_t reserved4[190];
} __attribute__ ((packed)) modeInfoBlock_t;
struct cursor_s {
uint32_t x;
uint32_t y;
};
static char* font = (char*)0x6000;
static char* font = (char*)FONT_LOC;
static struct cursor_s cursor = { 0, 0 };
static modeInfoBlock_t* gfxMode = (modeInfoBlock_t*)MODE_INFO_BLOCK;
uint32_t bgColor = BG_COLOR;
uint32_t fgColor = FG_COLOR;
@@ -105,8 +34,8 @@ uint32_t convertColor(uint32_t color) {
// TODO: Reimplement larger text
void putcAt(unsigned char c, uint32_t x, uint32_t y) {
// Font info
uint8_t charWidth = *(font);
uint8_t charHeight = *(font + 1);
uint8_t charWidth = *(uint8_t*)FONT_WIDTH;
uint8_t charHeight = *(uint8_t*)FONT_HEIGHT;
// uint8_t bitmapRowLen = (charWidth - 1) / 8 + 1; // TODO: Larger font support
// Video stuff
@@ -133,6 +62,7 @@ void putcAt(unsigned char c, uint32_t x, uint32_t y) {
}
}
// TODO: Probably get rid of this, idk (use terminal control codes)
void printAt(const char* str, uint32_t x, uint32_t y) {
while (*str != '\0') {
putcAt(*str++, x, y);
@@ -140,8 +70,9 @@ void printAt(const char* str, uint32_t x, uint32_t y) {
}
}
// TODO: Use terminal.x/y instead of cursor.x/y
void scroll() { // TODO: Make this faster (still kinda slow, but memcpy32() helped alot)
uint8_t charHeight = *(font + 1);
uint8_t charHeight = *(uint8_t*)FONT_HEIGHT;
if ((cursor.y+1) * charHeight < gfxMode->yRes) { return; } // Check if we should scroll
uint32_t bytesPerLine = charHeight * gfxMode->bytesPerScanline;
@@ -167,8 +98,9 @@ void scroll() { // TODO: Make this faster (still kinda slow, but memcpy32() help
cursor.y--;
}
// DEPRICATED - TODO: Remove this from everywhere so i can delete it
void putc(char c) {
uint8_t charWidth = *(font);
uint8_t charWidth = *(uint8_t*)FONT_WIDTH;
if (c == '\n') {
putcAt(' ', cursor.x, cursor.y); // Make sure we don't leave an extra cursor
@@ -198,12 +130,14 @@ void putc(char c) {
scroll();
}
// DEPRICATED - TODO: Remove this everywhere it's used and delete it's definition here
void print(const char* str) {
while (*str != '\0') {
putc(*str++);
}
}
// TODO: Make this comply with the new terminal.h thing!
void clear() {
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
uint8_t bytesPerPx = (gfxMode->bpp+1) / 8;