wip: good text support (scrolling not quite working rn)
This commit is contained in:
parent
2edc92bbcc
commit
917ccf0465
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ obj
|
|||||||
.*
|
.*
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
tags
|
tags
|
||||||
|
fonts
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#define FONT_SIZE 13
|
||||||
|
|
||||||
struct font {
|
struct font {
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
|
@ -5,9 +5,10 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define SCREEN_WIDTH 80
|
#define VGA_WIDTH 80
|
||||||
#define SCREEN_HEIGHT 25
|
#define VGA_HEIGHT 25
|
||||||
#define TERM_BUF ((uint16_t *)0xC03FF000)
|
#define SCREEN_WIDTH 1024
|
||||||
|
#define SCREEN_HEIGHT 768
|
||||||
#define TERM_COUNT 10
|
#define TERM_COUNT 10
|
||||||
|
|
||||||
struct screen {
|
struct screen {
|
||||||
@ -15,7 +16,7 @@ struct screen {
|
|||||||
size_t column;
|
size_t column;
|
||||||
uint32_t fg_color;
|
uint32_t fg_color;
|
||||||
uint32_t bg_color;
|
uint32_t bg_color;
|
||||||
uint16_t buffer[SCREEN_WIDTH * SCREEN_HEIGHT];
|
uint16_t buffer[VGA_WIDTH * VGA_HEIGHT];
|
||||||
uint32_t default_color;
|
uint32_t default_color;
|
||||||
char line[256];
|
char line[256];
|
||||||
};
|
};
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
extern struct screen *screen;
|
|
||||||
|
|
||||||
static bool new_input_indicator = false;
|
static bool new_input_indicator = false;
|
||||||
static struct key_event new_input = {};
|
static struct key_event new_input = {};
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
||||||
{
|
{
|
||||||
/* terminal_initialize(); */
|
terminal_initialize();
|
||||||
init_gdt();
|
init_gdt();
|
||||||
init_idt();
|
init_idt();
|
||||||
init_memory(mbd, magic);
|
init_memory(mbd, magic);
|
||||||
@ -42,7 +42,7 @@ void kernel_main(multiboot_info_t *mbd, uint32_t magic)
|
|||||||
/* "complex 8*unknown quantity -byte descriptor table. -- Troy "
|
/* "complex 8*unknown quantity -byte descriptor table. -- Troy "
|
||||||
*/
|
*/
|
||||||
/* "Martin 03:50, 22 March 2009 (UTC)\n"); */
|
/* "Martin 03:50, 22 March 2009 (UTC)\n"); */
|
||||||
terminal_putchar('A');
|
/* terminal_putchar('A'); */
|
||||||
/* memset(display.buff, 255, 1024 * 1024); */
|
/* memset(display.buff, 255, 1024 * 1024); */
|
||||||
/* shell_init(); */
|
shell_init();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#include "ctype.h"
|
#include "ctype.h"
|
||||||
|
#include "debug.h"
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
#include "fonts/eating_pasta_regular_32.h"
|
#include "fonts/eating_pasta_regular_13.h"
|
||||||
|
#include "fonts/minecraft_medium_13.h"
|
||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
@ -14,6 +16,7 @@
|
|||||||
|
|
||||||
static struct screen screens[TERM_COUNT];
|
static struct screen screens[TERM_COUNT];
|
||||||
struct screen *screen = &screens[0];
|
struct screen *screen = &screens[0];
|
||||||
|
struct font *current_font = eating_pasta_regular_13_font;
|
||||||
|
|
||||||
void terminal_initialize(void)
|
void terminal_initialize(void)
|
||||||
{
|
{
|
||||||
@ -22,7 +25,8 @@ void terminal_initialize(void)
|
|||||||
screens[i].column = 0;
|
screens[i].column = 0;
|
||||||
screens[i].default_color = 0xffffff;
|
screens[i].default_color = 0xffffff;
|
||||||
screens[i].fg_color = screens[i].default_color;
|
screens[i].fg_color = screens[i].default_color;
|
||||||
memcpy(screens[i].buffer, TERM_BUF, sizeof(screen->buffer));
|
/* memcpy(screens[i].buffer, TERM_BUF, sizeof(screen->buffer));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,39 +69,49 @@ uint32_t terminal_get_default_color(void)
|
|||||||
|
|
||||||
uint8_t terminal_get_char(int x, int y)
|
uint8_t terminal_get_char(int x, int y)
|
||||||
{
|
{
|
||||||
return screen->buffer[y * SCREEN_WIDTH + x];
|
return screen->buffer[y * VGA_WIDTH + x];
|
||||||
}
|
}
|
||||||
|
|
||||||
void terminal_putentryat(char c, uint32_t fg_color, uint32_t bg_color, size_t x,
|
void terminal_putentryat(struct font node, uint32_t fg_color, uint32_t bg_color,
|
||||||
size_t y)
|
size_t x, size_t y)
|
||||||
{
|
{
|
||||||
struct font node = eating_pasta_regular_32_font[(int)c];
|
|
||||||
char *glyph = node.bitmap;
|
char *glyph = node.bitmap;
|
||||||
for (size_t cy = 0; cy < node.height; cy++) {
|
for (size_t cy = 0; cy < node.height; cy++) {
|
||||||
for (size_t cx = 0; cx < node.width; cx++) {
|
for (size_t cx = 0; cx < node.width; cx++) {
|
||||||
if (glyph[cy * node.width + cx] == '#')
|
put_pixel((glyph[cy * node.width + cx] == '#')
|
||||||
put_pixel(fg_color, x + cx, y + cy);
|
? fg_color
|
||||||
else if (bg_color)
|
: bg_color,
|
||||||
put_pixel(bg_color, x + cx, y + cy);
|
x + cx, y + cy);
|
||||||
|
/* put_pixel((fg_color, x + cx, y + cy); */
|
||||||
|
/* else if (bg_color) */
|
||||||
|
/* put_pixel(bg_color, x + cx, y + cy); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct font get_font_node(int c)
|
||||||
|
{
|
||||||
|
return current_font[c];
|
||||||
|
}
|
||||||
|
|
||||||
static void terminal_scroll(void)
|
static void terminal_scroll(void)
|
||||||
{
|
{
|
||||||
// TODO
|
screen->row--;
|
||||||
/* screen->row--; */
|
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++) {
|
||||||
/* for (size_t i = 0; i < SCREEN_WIDTH * (SCREEN_HEIGHT - 1); i++) */
|
const uint32_t x = (i % VGA_WIDTH) * FONT_SIZE;
|
||||||
/* TERM_BUF[i] = TERM_BUF[i + SCREEN_WIDTH]; */
|
const uint32_t y = (i / VGA_WIDTH) * FONT_SIZE;
|
||||||
/* for (size_t i = 0; i < SCREEN_WIDTH; i++) */
|
terminal_putentryat(get_font_node(screen->buffer[i]),
|
||||||
/* terminal_putentryat(' ', VGA_COLOR_WHITE, i, SCREEN_HEIGHT - 1);
|
screen->fg_color, screen->bg_color, x, y);
|
||||||
*/
|
}
|
||||||
|
/* for (size_t i = 0; i < VGA_WIDTH; i++) */
|
||||||
|
/* terminal_putentryat(get_font_node(' '), 0, 0, i * FONT_SIZE, */
|
||||||
|
/* VGA_HEIGHT - 1); */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void terminal_new_line(void)
|
static void terminal_new_line(void)
|
||||||
{
|
{
|
||||||
screen->column = 0;
|
screen->column = 0;
|
||||||
if (++screen->row == SCREEN_HEIGHT)
|
if (++screen->row == VGA_HEIGHT)
|
||||||
terminal_scroll();
|
terminal_scroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,15 +119,18 @@ void terminal_change_default_color(uint32_t color)
|
|||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
/* terminal_set_color(color); */
|
/* terminal_set_color(color); */
|
||||||
/* for (size_t y = 0; y < SCREEN_HEIGHT; y++) { */
|
/* for (size_t y = 0; y < VGA_HEIGHT; y++) { */
|
||||||
/* for (size_t x = 0; x < SCREEN_WIDTH; x++) { */
|
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */
|
||||||
/* const size_t index = y * SCREEN_WIDTH + x; */
|
/* const size_t index = y * VGA_WIDTH + x; */
|
||||||
/* uint8_t entry_color = get_entry_color(TERM_BUF[index]);
|
/* uint8_t entry_color =
|
||||||
|
* get_entry_color(TERM_BUF[index]);
|
||||||
*/
|
*/
|
||||||
/* TERM_BUF[index] = vga_entry( */
|
/* TERM_BUF[index] = vga_entry( */
|
||||||
/* TERM_BUF[index], */
|
/* TERM_BUF[index], */
|
||||||
/* entry_color == screen->default_color ? color */
|
/* entry_color == screen->default_color ? color
|
||||||
/* : entry_color);
|
*/
|
||||||
|
/* :
|
||||||
|
* entry_color);
|
||||||
*/
|
*/
|
||||||
/* } */
|
/* } */
|
||||||
/* } */
|
/* } */
|
||||||
@ -131,10 +148,11 @@ void terminal_change_default_fg_color(uint32_t fg_color)
|
|||||||
void terminal_clear(void)
|
void terminal_clear(void)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
/* for (size_t y = 0; y < SCREEN_HEIGHT; y++) { */
|
/* for (size_t y = 0; y < VGA_HEIGHT; y++) { */
|
||||||
/* for (size_t x = 0; x < SCREEN_WIDTH; x++) { */
|
/* for (size_t x = 0; x < VGA_WIDTH; x++) { */
|
||||||
/* const size_t index = y * SCREEN_WIDTH + x; */
|
/* const size_t index = y * VGA_WIDTH + x; */
|
||||||
/* TERM_BUF[index] = vga_entry(' ', screen->color); */
|
/* TERM_BUF[index] = vga_entry(' ', screen->color);
|
||||||
|
*/
|
||||||
/* } */
|
/* } */
|
||||||
/* } */
|
/* } */
|
||||||
/* memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); */
|
/* memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); */
|
||||||
@ -144,16 +162,17 @@ void terminal_clear(void)
|
|||||||
|
|
||||||
int terminal_putchar(char c)
|
int terminal_putchar(char c)
|
||||||
{
|
{
|
||||||
terminal_putentryat(c, 0xCCFFE5, 0xCCCC00, 10, 10);
|
|
||||||
if (c == '\r')
|
if (c == '\r')
|
||||||
screen->column = 0;
|
screen->column = 0;
|
||||||
else if (c == '\n')
|
else if (c == '\n')
|
||||||
terminal_new_line();
|
terminal_new_line();
|
||||||
if (!isprint(c))
|
if (!isprint(c))
|
||||||
return 1;
|
return 1;
|
||||||
terminal_putentryat(c, screen->fg_color, screen->bg_color,
|
screen->buffer[screen->column + screen->row * VGA_WIDTH] = c;
|
||||||
screen->column, screen->row);
|
terminal_putentryat(get_font_node(c), screen->fg_color,
|
||||||
if (++screen->column == SCREEN_WIDTH)
|
screen->bg_color, screen->column * FONT_SIZE,
|
||||||
|
screen->row * FONT_SIZE);
|
||||||
|
if (++screen->column == VGA_WIDTH)
|
||||||
terminal_new_line();
|
terminal_new_line();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -175,12 +194,12 @@ int terminal_writestring(const char *data)
|
|||||||
|
|
||||||
void update_cursor(void)
|
void update_cursor(void)
|
||||||
{
|
{
|
||||||
uint16_t pos = screen->row * SCREEN_WIDTH + screen->column;
|
/* uint16_t pos = screen->row * VGA_WIDTH + screen->column; */
|
||||||
|
|
||||||
outb(0x3D4, 0x0F);
|
/* outb(0x3D4, 0x0F); */
|
||||||
outb(0x3D5, pos & 0xFF);
|
/* outb(0x3D5, pos & 0xFF); */
|
||||||
outb(0x3D4, 0x0E);
|
/* outb(0x3D4, 0x0E); */
|
||||||
outb(0x3D5, (pos >> 8) & 0xFF);
|
/* outb(0x3D5, (pos >> 8) & 0xFF); */
|
||||||
}
|
}
|
||||||
|
|
||||||
void move_cursor(int direction)
|
void move_cursor(int direction)
|
||||||
@ -190,14 +209,14 @@ void move_cursor(int direction)
|
|||||||
if (screen->column) {
|
if (screen->column) {
|
||||||
screen->column--;
|
screen->column--;
|
||||||
} else if (screen->row) {
|
} else if (screen->row) {
|
||||||
screen->column = SCREEN_WIDTH - 1;
|
screen->column = VGA_WIDTH - 1;
|
||||||
screen->row--;
|
screen->row--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
if (screen->column < SCREEN_WIDTH - 1) {
|
if (screen->column < VGA_WIDTH - 1) {
|
||||||
screen->column++;
|
screen->column++;
|
||||||
} else if (screen->row < SCREEN_HEIGHT - 1) {
|
} else if (screen->row < VGA_HEIGHT - 1) {
|
||||||
screen->column = 0;
|
screen->column = 0;
|
||||||
screen->row++;
|
screen->row++;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user