forked from PoliEcho-holding-org/kern
Continuing terminal I/O
- Made stdio.h work - Moved printFiletable back into kernel.c - TODO: Add stdio.h to all files that should use it (probably next commmit) - Added some more global addresses. There's a memory layout, but i'm not using it - Got cursor to be drawn - Calc program now gets user input
This commit is contained in:
+15
-73
@@ -1,39 +1,29 @@
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
#include <terminal/terminal.h>
|
||||
#include <memory/addresses.h>
|
||||
#include <screen/gfxmode.h>
|
||||
#include <disk/filesys.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
struct cursor_s {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
};
|
||||
|
||||
static char* font = (char*)FONT_LOC;
|
||||
static struct cursor_s cursor = { 0, 0 };
|
||||
|
||||
uint32_t bgColor = BG_COLOR;
|
||||
uint32_t fgColor = FG_COLOR;
|
||||
|
||||
uint32_t convertColor(uint32_t color) {
|
||||
if (gfxMode->bpp == 8) { // Uses VGA Color pallete, idk how to support that
|
||||
return color & 0xff;
|
||||
}
|
||||
// TODO: Make this check if it's a valid font
|
||||
// TODO: Make it take a fileEntry_t?
|
||||
uint8_t loadFont(char* filename) {
|
||||
if (readFile(filename, (void*)FONT_LOC) != 0) { return 1; } // File not found
|
||||
if (*(uint8_t*)FONT_WIDTH == 0 || *(uint8_t*)FONT_HEIGHT == 0) { return 1; } // Not a font
|
||||
|
||||
// TODO: !! Important !! - Is should be divided by 255.0 (for floats), but using '-mgeneral-regs-only' removes fp-registers and
|
||||
// wants to use some dumb functions for converting fp numbers in the stdlib (that we don't have)
|
||||
uint8_t red = ((color >> 16) & 0xff) * (((1 << gfxMode->linearRedMaskSize) - 1) / 255);
|
||||
uint8_t green = ((color >> 8 ) & 0xff) * (((1 << gfxMode->linearGreenMaskSize) - 1) / 255);
|
||||
uint8_t blue = ((color ) & 0xff) * (((1 << gfxMode->linearBlueMaskSize) - 1) / 255);
|
||||
|
||||
return (red << gfxMode->redFieldPos) | (green << gfxMode->greenFieldPos) | (blue << gfxMode->blueFieldPos);
|
||||
return 0; // Success
|
||||
}
|
||||
|
||||
// TODO: Reimplement larger text
|
||||
void putcAt(unsigned char c, uint32_t x, uint32_t y) {
|
||||
void putcAt(char c, uint32_t x, uint32_t y) {
|
||||
// Font info
|
||||
char* font = (char*)FONT_LOC;
|
||||
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
|
||||
@@ -62,21 +52,12 @@ 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);
|
||||
x++;
|
||||
}
|
||||
}
|
||||
|
||||
// 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 = *(uint8_t*)FONT_HEIGHT;
|
||||
if ((cursor.y+1) * charHeight < gfxMode->yRes) { return; } // Check if we should scroll
|
||||
if (terminal->y+1 < terminal->height) { return; } // Check if we should scroll
|
||||
|
||||
uint32_t bytesPerLine = charHeight * gfxMode->bytesPerScanline;
|
||||
uint32_t lines = gfxMode->yRes / charHeight;
|
||||
uint32_t lines = terminal->height;
|
||||
uint32_t vidmem = gfxMode->physicalBasePtr;
|
||||
|
||||
for (uint32_t i = 1; i < lines; i++) {
|
||||
@@ -95,46 +76,7 @@ void scroll() { // TODO: Make this faster (still kinda slow, but memcpy32() help
|
||||
lastLine += bytesPerPx;
|
||||
}
|
||||
|
||||
cursor.y--;
|
||||
}
|
||||
|
||||
// DEPRICATED - TODO: Remove this from everywhere so i can delete it
|
||||
void putc(char c) {
|
||||
uint8_t charWidth = *(uint8_t*)FONT_WIDTH;
|
||||
|
||||
if (c == '\n') {
|
||||
putcAt(' ', cursor.x, cursor.y); // Make sure we don't leave an extra cursor
|
||||
cursor.y++;
|
||||
cursor.x = 0;
|
||||
} else if (c == '\b') {
|
||||
putcAt(' ', cursor.x, cursor.y); // Make sure we don't leave an extra cursor
|
||||
|
||||
if (cursor.x == 0) {
|
||||
cursor.x = gfxMode->xRes / charWidth - 1; // Subtract one so we don't overflow to the line start
|
||||
cursor.y--; // y could be 0
|
||||
} else {
|
||||
cursor.x--;
|
||||
}
|
||||
|
||||
putcAt(' ', cursor.x, cursor.y);
|
||||
} else {
|
||||
putcAt(c, cursor.x, cursor.y);
|
||||
cursor.x++;
|
||||
|
||||
if (cursor.x >= gfxMode->xRes / charWidth) {
|
||||
cursor.y++;
|
||||
cursor.x = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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++);
|
||||
}
|
||||
terminal->y--;
|
||||
}
|
||||
|
||||
// TODO: Make this comply with the new terminal.h thing!
|
||||
@@ -142,8 +84,8 @@ void clear() {
|
||||
uint8_t* vidmem = (uint8_t*)gfxMode->physicalBasePtr;
|
||||
uint8_t bytesPerPx = (gfxMode->bpp+1) / 8;
|
||||
|
||||
cursor.x = 0;
|
||||
cursor.y = 0;
|
||||
terminal->x = 0;
|
||||
terminal->y = 0;
|
||||
|
||||
uint32_t color = convertColor(bgColor);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user