forked from PoliEcho-holding-org/kern
Implemented custom font and text drawing in VBE graphics mode! No colors :(
This commit is contained in:
+3
-3
@@ -113,11 +113,11 @@ void setupIsrs() {
|
||||
|
||||
void faultHandler(struct regs* r) {
|
||||
if (r->intNo < 32) {
|
||||
print(exceptionMessages[r->intNo], 0x04);
|
||||
print(exceptionMessages[r->intNo]);
|
||||
|
||||
if (r->errCode) {
|
||||
print(": 0x", 0x04);
|
||||
print(itoa(r->errCode, 16), 0x04);
|
||||
print(": 0x");
|
||||
print(itoa(r->errCode, 16));
|
||||
}
|
||||
|
||||
cli();
|
||||
|
||||
+3
-5
@@ -49,7 +49,6 @@ uint8_t shift = 0;
|
||||
uint16_t bufferLen = 0;
|
||||
char buffer[MAX_BUFFER_SIZE + 1] = { 0 };
|
||||
bool echo = false;
|
||||
uint8_t echoAttr = 0x0f;
|
||||
bool canBackspace = false;
|
||||
|
||||
void keyboardHandler() {
|
||||
@@ -64,7 +63,7 @@ void keyboardHandler() {
|
||||
if (scancode & 0x80) { // Keyup
|
||||
} else if (c != 0) {
|
||||
if (!canBackspace && c == '\b') return;
|
||||
if (echo) putc(c, echoAttr);
|
||||
if (echo) putc(c);
|
||||
|
||||
buffer[bufferLen] = c;
|
||||
|
||||
@@ -76,10 +75,9 @@ void keyboardHandler() {
|
||||
}
|
||||
}
|
||||
|
||||
char* read(char terminator, uint8_t attr) {
|
||||
char* read(char terminator) {
|
||||
bufferLen = 0;
|
||||
echo = attr ? true : false;
|
||||
echoAttr = attr;
|
||||
echo = true;
|
||||
|
||||
while (buffer[bufferLen-1] != terminator && bufferLen < MAX_BUFFER_SIZE);
|
||||
|
||||
|
||||
+47
-111
@@ -1,138 +1,74 @@
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
#include "screen.h"
|
||||
#include "stdint.h"
|
||||
#include "system.h"
|
||||
#include "string.h"
|
||||
|
||||
#define VIDMEM 0xb8000
|
||||
#define CURSOR_HIGH 14
|
||||
#define CURSOR_LOW 15
|
||||
#define CTRLREG 0x3d4
|
||||
#define DATAREG 0x3d5
|
||||
#define MODE_INFO_BLOCK 0x5000
|
||||
#define WIDTH 1920
|
||||
#define HEIGHT 1080
|
||||
#define BG_COLOR 0xff1f2937
|
||||
#define FG_COLOR 0xffd1d5db
|
||||
|
||||
// 80x25 VGA Text mode
|
||||
#define ROWS 25
|
||||
#define COLS 80
|
||||
#define CHARS (ROWS*COLS)
|
||||
struct cursor_s {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
};
|
||||
|
||||
uint32_t cursor = 0;
|
||||
char* font;
|
||||
uint32_t* vidmem;
|
||||
uint16_t bytesPerScanline;
|
||||
|
||||
void updateCursor() {
|
||||
// Move visual cursor position
|
||||
outb(0x3d4, 0x0f); // Low byte
|
||||
outb(0x3d5, cursor & 0xff);
|
||||
outb(0x3d4, 0x0e); // High byte
|
||||
outb(0x3d5, cursor >> 8);
|
||||
struct cursor_s cursor = { 0, 0 };
|
||||
|
||||
void setupScreen() {
|
||||
vidmem = *(uint32_t**)(MODE_INFO_BLOCK + 40); // Vidmem pointer location
|
||||
bytesPerScanline = *(uint16_t*)(MODE_INFO_BLOCK + 16); // Bytes per scanline location
|
||||
}
|
||||
|
||||
void setCursorPos(uint32_t offset) {
|
||||
cursor = offset;
|
||||
updateCursor();
|
||||
}
|
||||
void putcAt(char c, uint32_t x, uint32_t y) {
|
||||
uint32_t offset = WIDTH * y * 16 + x * 8;
|
||||
|
||||
uint32_t getCursorPos() {
|
||||
return cursor;
|
||||
}
|
||||
|
||||
uint32_t calcOffset(uint8_t col, uint8_t row) {
|
||||
return row * COLS + col;
|
||||
}
|
||||
|
||||
void scroll() {
|
||||
if (cursor < COLS * ROWS) return;
|
||||
|
||||
for (int i = 1; i < ROWS; i++) {
|
||||
memcopy((char*)(calcOffset(0, i)*2)+VIDMEM, (char*)(calcOffset(0, i-1)*2)+VIDMEM, COLS*2);
|
||||
char* bitmap = &font[(c-1) * 16];
|
||||
for (uint8_t i = 0; i < 16; i++) { // Rows
|
||||
char bitmapRow = bitmap[i];
|
||||
for (uint8_t j = 0; j < 8; j++) { // Cols
|
||||
vidmem[offset + j] = (bitmapRow & 0x80) ? FG_COLOR : BG_COLOR;
|
||||
bitmapRow = bitmapRow << 1;
|
||||
}
|
||||
offset += WIDTH;
|
||||
}
|
||||
|
||||
char* lastRow = (char*)(calcOffset(0, ROWS-1)*2)+VIDMEM;
|
||||
for (int i = 0; i < COLS*2; i += 2) {
|
||||
lastRow[i] = '\0';
|
||||
lastRow[i+1] = 0x0f;
|
||||
}
|
||||
|
||||
cursor = calcOffset(0, ROWS-1);
|
||||
}
|
||||
|
||||
void putc(char c, uint8_t attr) {
|
||||
void putc(char c) {
|
||||
putcAt(c, cursor.x, cursor.y);
|
||||
|
||||
if (c == '\n') {
|
||||
uint16_t line = cursor - (cursor % COLS);
|
||||
setCursorPos(line + COLS);
|
||||
scroll();
|
||||
updateCursor();
|
||||
return;
|
||||
} else if (c == '\b') {
|
||||
cursor--;
|
||||
int mem = VIDMEM + cursor * 2;
|
||||
*(char*)(mem) = ' ';
|
||||
*(char*)(mem+1) = attr;
|
||||
updateCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
int mem = VIDMEM + cursor * 2;
|
||||
*(char*)(mem) = c;
|
||||
*(char*)(mem+1) = attr;
|
||||
|
||||
cursor++;
|
||||
|
||||
scroll();
|
||||
updateCursor();
|
||||
}
|
||||
|
||||
void print(char* s, uint8_t attr) {
|
||||
char c = *s;
|
||||
while (c != '\0') {
|
||||
putc(c, attr);
|
||||
c = *(++s);
|
||||
}
|
||||
|
||||
scroll();
|
||||
updateCursor();
|
||||
}
|
||||
|
||||
void putcAt(char c, uint8_t attr, uint8_t col, uint8_t row) {
|
||||
uint16_t offset = calcOffset(col, row);
|
||||
*(char*)(VIDMEM + offset * 2) = c;
|
||||
*(char*)(VIDMEM + offset * 2 + 1) = attr;
|
||||
}
|
||||
|
||||
void printAt(char* s, uint8_t attr, uint8_t col, uint8_t row) {
|
||||
uint16_t offset = calcOffset(col, row);
|
||||
|
||||
char c = *s;
|
||||
while (c != '\0') {
|
||||
*(char*)(VIDMEM + offset * 2) = c;
|
||||
*(char*)(VIDMEM + offset * 2 + 1) = attr;
|
||||
c = *(++s);
|
||||
offset++;
|
||||
cursor.y++;
|
||||
cursor.x = 0;
|
||||
} else {
|
||||
cursor.x++;
|
||||
}
|
||||
}
|
||||
|
||||
void clear(uint8_t attr) {
|
||||
for (int i = 0; i < CHARS*2; i += 2) {
|
||||
*(char*)(VIDMEM + i) = ' ';
|
||||
*(char*)(VIDMEM + i + 1) = attr;
|
||||
void print(const char* str) {
|
||||
while (*str != '\0') {
|
||||
putc(*str++);
|
||||
}
|
||||
cursor = 0;
|
||||
|
||||
updateCursor();
|
||||
}
|
||||
|
||||
void enableCursor(uint8_t start, uint8_t end) {
|
||||
outb(0x3d4, 0x0a); // Sending cursor start
|
||||
outb(0x3d5, (inb(0x3d5) & 0xc0) | start);
|
||||
void clear() {
|
||||
size_t i = 0;
|
||||
while (i < WIDTH*HEIGHT) {
|
||||
vidmem[i] = BG_COLOR; // #1f2937
|
||||
i++;
|
||||
}
|
||||
|
||||
outb(0x3d4, 0x0b); // Sending cursor end
|
||||
outb(0x3d5, (inb(0x3d5) & 0xe0) | end);
|
||||
cursor.x = 0;
|
||||
cursor.y = 0;
|
||||
}
|
||||
|
||||
void disableCursor() {
|
||||
outb(0x3d4, 0x0a);
|
||||
outb(0x3d4, 0x0b);
|
||||
void loadFont(char* address) {
|
||||
font = address;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user