finished tty system for now
This commit is contained in:
@@ -153,6 +153,7 @@ static uint8_t VGA_basic8x8font[128][8] = {
|
|||||||
static uint8_t VGA_palette[256][3];
|
static uint8_t VGA_palette[256][3];
|
||||||
void VGA_setchar(virtualConsole* con, uint8_t x, uint8_t y, char val);
|
void VGA_setchar(virtualConsole* con, uint8_t x, uint8_t y, char val);
|
||||||
void VGA_renderchar(virtualConsole* con);
|
void VGA_renderchar(virtualConsole* con);
|
||||||
|
void _VGA_renchar(uint8_t x, uint8_t y, char val, uint8_t fcolor[3], uint8_t bcolor[3]);
|
||||||
static uint8_t* VGA_fbuf = (unsigned char*)0xA0000;
|
static uint8_t* VGA_fbuf = (unsigned char*)0xA0000;
|
||||||
static uint8_t VGA_values[] = { // THIS. THIS IS CANCER.
|
static uint8_t VGA_values[] = { // THIS. THIS IS CANCER.
|
||||||
// MISC
|
// MISC
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ uint32_t strlen32(char* str);
|
|||||||
void strrev32(char* str);
|
void strrev32(char* str);
|
||||||
uint8_t uitoa32(uint32_t x, char* str);
|
uint8_t uitoa32(uint32_t x, char* str);
|
||||||
void memcopy(void* dest, void* src, size_t size);
|
void memcopy(void* dest, void* src, size_t size);
|
||||||
|
void kpanic(char* msg);
|
||||||
static inline void outb(uint16_t port, uint8_t val) {
|
static inline void outb(uint16_t port, uint8_t val) {
|
||||||
__asm__ volatile ( "outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
|
__asm__ volatile ( "outb %b0, %w1" : : "a"(val), "Nd"(port) : "memory");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "stddef.h"
|
|
||||||
|
|
||||||
void memcpy32(void* dest, void* src, uint32_t length);
|
|
||||||
@@ -8,12 +8,13 @@ typedef struct {
|
|||||||
uint8_t FU_forecolor[3];
|
uint8_t FU_forecolor[3];
|
||||||
uint8_t FU_backcolor[3];
|
uint8_t FU_backcolor[3];
|
||||||
char charbuf[40][25];
|
char charbuf[40][25];
|
||||||
|
uint8_t enableRendering;
|
||||||
} virtualConsole;
|
} virtualConsole;
|
||||||
typedef void (*FU_kupdbuf_t)(virtualConsole*);
|
typedef void (*FU_kupdbuf_t)(virtualConsole*);
|
||||||
|
|
||||||
#define consolesAmount 12
|
#define consolesAmount 12
|
||||||
static virtualConsole consoles[consolesAmount];
|
extern virtualConsole consoles[consolesAmount];
|
||||||
static uint8_t currentConsole = 0;
|
extern uint8_t currentConsole;
|
||||||
|
|
||||||
void con_kputchar(virtualConsole* con, char x);
|
void con_kputchar(virtualConsole* con, char x);
|
||||||
void con_kputstr(virtualConsole* con, char* x);
|
void con_kputstr(virtualConsole* con, char* x);
|
||||||
|
|||||||
@@ -50,6 +50,11 @@ void kernel_main(struct multiboot_info* header, uint32_t magic) {
|
|||||||
kputstr("Setting up stdout rendering: ");
|
kputstr("Setting up stdout rendering: ");
|
||||||
for (uint8_t i=0;i<consolesAmount;i++) {
|
for (uint8_t i=0;i<consolesAmount;i++) {
|
||||||
consoles[i].FU_kupdbuf = &VGA_kstrrend;
|
consoles[i].FU_kupdbuf = &VGA_kstrrend;
|
||||||
|
consoles[i].enableRendering = 1;
|
||||||
|
if (consoles[i].FU_kupdbuf != &VGA_kstrrend) {
|
||||||
|
kpanic("Failure with stdout: code 1");
|
||||||
|
while (1) {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
kputstr("OK\n");
|
kputstr("OK\n");
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ inline uint8_t _VGA_nearestmul(uint8_t val, uint8_t multiple) {
|
|||||||
if (val%multiple == 0) {return val;}
|
if (val%multiple == 0) {return val;}
|
||||||
return val + multiple - (val%multiple);
|
return val + multiple - (val%multiple);
|
||||||
}
|
}
|
||||||
void inline _VGA_renchar(uint8_t x, uint8_t y, char val, uint8_t fcolor[3], uint8_t bcolor[3]) {
|
void _VGA_renchar(uint8_t x, uint8_t y, char val, uint8_t fcolor[3], uint8_t bcolor[3]) {
|
||||||
|
if (val > 127) { // out of bounds, no ascii character
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (uint8_t px=0;px<8;px++) {
|
for (uint8_t px=0;px<8;px++) {
|
||||||
for (uint8_t py=0;py<8;py++) {
|
for (uint8_t py=0;py<8;py++) {
|
||||||
VGA_setpix(x*8+px,y*8+py,(VGA_basic8x8font[val][py] >> px) & 1 ? *(VGA_pixel*)fcolor : *(VGA_pixel*)bcolor);
|
VGA_setpix(x*8+px,y*8+py,(VGA_basic8x8font[val][py] >> px) & 1 ? *(VGA_pixel*)fcolor : *(VGA_pixel*)bcolor);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "../headers/stdlib.h"
|
#include "../headers/stdlib.h"
|
||||||
|
#include "../headers/graphics.h"
|
||||||
|
|
||||||
uint32_t strlen32(char* str) {
|
uint32_t strlen32(char* str) {
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
@@ -27,4 +28,23 @@ void memcopy(void* dest, void* src, size_t size) {
|
|||||||
for (size_t i=0;i<size;i++) {
|
for (size_t i=0;i<size;i++) {
|
||||||
((uint8_t*)dest)[i] = ((uint8_t*)src)[i];
|
((uint8_t*)dest)[i] = ((uint8_t*)src)[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void kpanic(char* msg) {
|
||||||
|
for (uint16_t x=0;x<320;x++) {
|
||||||
|
for (uint16_t y=0;y<200;y++) {
|
||||||
|
VGA_setpix(x,y,(VGA_pixel){0x00,0xFF,0x00});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
size_t x=0;
|
||||||
|
size_t y=0;
|
||||||
|
while (*msg != 0) {
|
||||||
|
if (*msg == '\n') {
|
||||||
|
y ++;
|
||||||
|
x = 0;
|
||||||
|
msg ++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_VGA_renchar(x++,y,*msg++,(uint8_t[]){0xFF,0xFF,0xFF},(uint8_t[]){0x00,0xFF,0x00});
|
||||||
|
}
|
||||||
|
while (1) {}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
#include "../headers/tty.h"
|
#include "../headers/tty.h"
|
||||||
#include "../headers/graphics.h"
|
#include "../headers/graphics.h"
|
||||||
|
#include "../headers/stdlib.h"
|
||||||
|
|
||||||
|
virtualConsole consoles[consolesAmount];
|
||||||
|
uint8_t currentConsole = 0;
|
||||||
void con_dummyrend(virtualConsole* con) {}
|
void con_dummyrend(virtualConsole* con) {}
|
||||||
void con_kputchar(virtualConsole* con, char x) {
|
void con_kputchar(virtualConsole* con, char x) {
|
||||||
if (con->kstdout_count == 8192) {
|
if (con->kstdout_count == 8192) {
|
||||||
@@ -10,9 +13,11 @@ void con_kputchar(virtualConsole* con, char x) {
|
|||||||
con->kstdout_count --;
|
con->kstdout_count --;
|
||||||
}
|
}
|
||||||
con->kstdout[con->kstdout_count++] = x;
|
con->kstdout[con->kstdout_count++] = x;
|
||||||
if (&consoles[currentConsole] == con) { // current console
|
if (&consoles[currentConsole] == con && con->enableRendering) { // current console
|
||||||
if (con->FU_kupdbuf != 0x00) {
|
if (con->FU_kupdbuf != 0x00) {
|
||||||
((FU_kupdbuf_t)con->FU_kupdbuf)(con);
|
((FU_kupdbuf_t)con->FU_kupdbuf)(con);
|
||||||
|
} else {
|
||||||
|
kpanic("virtualConsole failure:\nFU_kupdbuf is 0x00.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,6 +35,7 @@ void con_init(virtualConsole* con) {
|
|||||||
con->FU_backcolor[0] = 0x00;
|
con->FU_backcolor[0] = 0x00;
|
||||||
con->FU_backcolor[1] = 0x00;
|
con->FU_backcolor[1] = 0x00;
|
||||||
con->FU_backcolor[2] = 0x00;
|
con->FU_backcolor[2] = 0x00;
|
||||||
|
con->enableRendering = 0;
|
||||||
}
|
}
|
||||||
void kputchar(char x) {
|
void kputchar(char x) {
|
||||||
con_kputchar(&consoles[currentConsole], x);
|
con_kputchar(&consoles[currentConsole], x);
|
||||||
|
|||||||
Reference in New Issue
Block a user