Compare commits
No commits in common. "2edc92bbcc3c74fceab20cde48ec72b0879ea627" and "903b303322f5a29bfc338a9961556c527f7b8e01" have entirely different histories.
2edc92bbcc
...
903b303322
@ -5,18 +5,17 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define SCREEN_WIDTH 80
|
||||
#define SCREEN_HEIGHT 25
|
||||
#define TERM_BUF ((uint16_t *)0xC03FF000)
|
||||
#define TERM_COUNT 10
|
||||
#define VGA_WIDTH 80
|
||||
#define VGA_HEIGHT 25
|
||||
#define TERM_BUF ((uint16_t *)0xC03FF000)
|
||||
#define TERM_COUNT 10
|
||||
|
||||
struct screen {
|
||||
size_t row;
|
||||
size_t column;
|
||||
uint32_t fg_color;
|
||||
uint32_t bg_color;
|
||||
uint16_t buffer[SCREEN_WIDTH * SCREEN_HEIGHT];
|
||||
uint32_t default_color;
|
||||
uint8_t color;
|
||||
uint16_t buffer[VGA_WIDTH * VGA_HEIGHT];
|
||||
uint8_t default_color;
|
||||
char line[256];
|
||||
};
|
||||
|
||||
@ -42,8 +41,8 @@ typedef enum {
|
||||
enum cursor_direction { LEFT, RIGHT, UP, DOWN };
|
||||
|
||||
void terminal_initialize(void);
|
||||
void terminal_set_bg_color(uint32_t color);
|
||||
void terminal_set_fg_color(uint32_t color);
|
||||
void terminal_set_bg_color(uint8_t color);
|
||||
void terminal_set_fg_color(uint8_t color);
|
||||
int terminal_putchar(char c);
|
||||
int terminal_write(const char *data, size_t size);
|
||||
int terminal_writestring(const char *data);
|
||||
@ -54,8 +53,8 @@ struct key_event terminal_getkey(void);
|
||||
void update_cursor(void);
|
||||
void move_cursor(int direction);
|
||||
void set_color_level(int level);
|
||||
void terminal_set_default_fg_color(uint32_t fg_color);
|
||||
void terminal_set_default_bg_color(uint32_t fg_color);
|
||||
void terminal_change_default_fg_color(uint32_t color);
|
||||
uint32_t terminal_get_default_color(void);
|
||||
void terminal_set_default_fg_color(uint8_t fg_color);
|
||||
void terminal_set_default_bg_color(uint8_t fg_color);
|
||||
void terminal_change_default_fg_color(uint8_t color);
|
||||
uint8_t terminal_get_default_color(void);
|
||||
uint8_t terminal_get_char(int column, int row);
|
||||
|
@ -15,147 +15,163 @@
|
||||
static struct screen screens[TERM_COUNT];
|
||||
struct screen *screen = &screens[0];
|
||||
|
||||
static inline uint8_t vga_entry_color(vga_color fg, vga_color bg)
|
||||
{
|
||||
return fg | bg << 4;
|
||||
}
|
||||
|
||||
static inline uint16_t vga_entry(unsigned char uc, uint8_t color)
|
||||
{
|
||||
return (uint16_t)uc | (uint16_t)color << 8;
|
||||
}
|
||||
|
||||
void terminal_initialize(void)
|
||||
{
|
||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
const size_t index = y * VGA_WIDTH + x;
|
||||
TERM_BUF[index] = vga_entry(' ', VGA_COLOR_WHITE);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < TERM_COUNT; i++) {
|
||||
screens[i].row = 0;
|
||||
screens[i].column = 0;
|
||||
screens[i].default_color = 0xffffff;
|
||||
screens[i].fg_color = screens[i].default_color;
|
||||
screens[i].default_color =
|
||||
vga_entry_color(VGA_COLOR_WHITE, VGA_COLOR_BLACK);
|
||||
screens[i].color = screens[i].default_color;
|
||||
memcpy(screens[i].buffer, TERM_BUF, sizeof(screen->buffer));
|
||||
}
|
||||
}
|
||||
|
||||
void terminal_set_screen(int pos)
|
||||
{
|
||||
// TODO
|
||||
/* memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); */
|
||||
/* screen = &screens[pos]; */
|
||||
/* memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer)); */
|
||||
/* update_cursor(); */
|
||||
/* if (TERM_BUF[0] == vga_entry(' ', VGA_COLOR_WHITE)) */
|
||||
/* kprintf(PROMPT); */
|
||||
memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer));
|
||||
screen = &screens[pos];
|
||||
memcpy(TERM_BUF, screen->buffer, sizeof(screen->buffer));
|
||||
update_cursor();
|
||||
if (TERM_BUF[0] == vga_entry(' ', VGA_COLOR_WHITE))
|
||||
kprintf(PROMPT);
|
||||
}
|
||||
|
||||
void terminal_set_bg_color(uint32_t bg_color)
|
||||
void terminal_set_bg_color(uint8_t bg_color)
|
||||
{
|
||||
screen->bg_color = bg_color;
|
||||
screen->color = bg_color << 4 | (screen->color & 0x0F);
|
||||
}
|
||||
|
||||
void terminal_set_fg_color(uint32_t fg_color)
|
||||
void terminal_set_fg_color(uint8_t fg_color)
|
||||
{
|
||||
screen->fg_color = screen->fg_color;
|
||||
screen->color = (screen->color & 0xF0) | fg_color;
|
||||
}
|
||||
|
||||
void terminal_set_color(uint32_t fg_color, uint32_t bg_color)
|
||||
void terminal_set_color(uint8_t color)
|
||||
{
|
||||
screen->fg_color = fg_color;
|
||||
screen->bg_color = bg_color;
|
||||
screen->color = color;
|
||||
}
|
||||
|
||||
void terminal_set_default_fg_color(uint32_t fg_color)
|
||||
void terminal_set_default_fg_color(uint8_t fg_color)
|
||||
{
|
||||
screen->default_color = fg_color;
|
||||
screen->default_color = (screen->default_color & 0xF0) | fg_color;
|
||||
}
|
||||
|
||||
uint32_t terminal_get_default_color(void)
|
||||
void terminal_set_default_bg_color(uint8_t bg_color)
|
||||
{
|
||||
screen->default_color = bg_color << 4 | (screen->default_color & 0x0F);
|
||||
}
|
||||
|
||||
uint8_t terminal_get_default_color(void)
|
||||
{
|
||||
return screen->default_color;
|
||||
}
|
||||
|
||||
uint8_t terminal_get_char(int x, int y)
|
||||
uint8_t terminal_get_char(int column, int row)
|
||||
{
|
||||
return screen->buffer[y * SCREEN_WIDTH + x];
|
||||
return screen->buffer[row * VGA_WIDTH + column];
|
||||
}
|
||||
|
||||
void terminal_putentryat(char c, uint32_t fg_color, uint32_t bg_color, size_t x,
|
||||
size_t y)
|
||||
void terminal_putentryat(char c, uint32_t color, size_t x, size_t y)
|
||||
{
|
||||
struct font node = eating_pasta_regular_32_font[(int)c];
|
||||
char *glyph = node.bitmap;
|
||||
for (size_t cy = 0; cy < node.height; cy++) {
|
||||
for (size_t cx = 0; cx < node.width; cx++) {
|
||||
for (size_t cy = 0; cy < node.height; cy++)
|
||||
for (size_t cx = 0; cx < node.width; cx++)
|
||||
if (glyph[cy * node.width + cx] == '#')
|
||||
put_pixel(fg_color, x + cx, y + cy);
|
||||
else if (bg_color)
|
||||
put_pixel(bg_color, x + cx, y + cy);
|
||||
}
|
||||
}
|
||||
put_pixel(color, x + cx, y + cy);
|
||||
/* const size_t index = y * VGA_WIDTH + x; */
|
||||
/* TERM_BUF[index] = vga_entry(c, color); */
|
||||
}
|
||||
|
||||
static void terminal_scroll(void)
|
||||
{
|
||||
// TODO
|
||||
/* screen->row--; */
|
||||
/* for (size_t i = 0; i < SCREEN_WIDTH * (SCREEN_HEIGHT - 1); i++) */
|
||||
/* TERM_BUF[i] = TERM_BUF[i + SCREEN_WIDTH]; */
|
||||
/* for (size_t i = 0; i < SCREEN_WIDTH; i++) */
|
||||
/* terminal_putentryat(' ', VGA_COLOR_WHITE, i, SCREEN_HEIGHT - 1);
|
||||
*/
|
||||
screen->row--;
|
||||
for (size_t i = 0; i < VGA_WIDTH * (VGA_HEIGHT - 1); i++)
|
||||
TERM_BUF[i] = TERM_BUF[i + VGA_WIDTH];
|
||||
for (size_t i = 0; i < VGA_WIDTH; i++)
|
||||
terminal_putentryat(' ', VGA_COLOR_WHITE, i, VGA_HEIGHT - 1);
|
||||
}
|
||||
|
||||
static void terminal_new_line(void)
|
||||
{
|
||||
screen->column = 0;
|
||||
if (++screen->row == SCREEN_HEIGHT)
|
||||
if (++screen->row == VGA_HEIGHT)
|
||||
terminal_scroll();
|
||||
}
|
||||
|
||||
void terminal_change_default_color(uint32_t color)
|
||||
static uint8_t get_entry_color(uint16_t vga_entry)
|
||||
{
|
||||
// TODO
|
||||
/* terminal_set_color(color); */
|
||||
/* for (size_t y = 0; y < SCREEN_HEIGHT; y++) { */
|
||||
/* for (size_t x = 0; x < SCREEN_WIDTH; x++) { */
|
||||
/* const size_t index = y * SCREEN_WIDTH + x; */
|
||||
/* uint8_t entry_color = get_entry_color(TERM_BUF[index]);
|
||||
*/
|
||||
/* TERM_BUF[index] = vga_entry( */
|
||||
/* TERM_BUF[index], */
|
||||
/* entry_color == screen->default_color ? color */
|
||||
/* : entry_color);
|
||||
*/
|
||||
/* } */
|
||||
/* } */
|
||||
/* memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); */
|
||||
/* screen->default_color = color; */
|
||||
/* screen->color = color; */
|
||||
return vga_entry >> 8;
|
||||
}
|
||||
|
||||
void terminal_change_default_fg_color(uint32_t fg_color)
|
||||
void terminal_change_default_color(uint8_t color)
|
||||
{
|
||||
terminal_set_color(color);
|
||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
const size_t index = y * VGA_WIDTH + x;
|
||||
uint8_t entry_color = get_entry_color(TERM_BUF[index]);
|
||||
TERM_BUF[index] = vga_entry(
|
||||
TERM_BUF[index],
|
||||
entry_color == screen->default_color ? color
|
||||
: entry_color);
|
||||
}
|
||||
}
|
||||
memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer));
|
||||
screen->default_color = color;
|
||||
screen->color = color;
|
||||
}
|
||||
|
||||
void terminal_change_default_fg_color(uint8_t fg_color)
|
||||
{
|
||||
terminal_set_fg_color(fg_color);
|
||||
terminal_change_default_color(screen->fg_color);
|
||||
terminal_change_default_color(screen->color);
|
||||
}
|
||||
|
||||
void terminal_clear(void)
|
||||
{
|
||||
// TODO
|
||||
/* for (size_t y = 0; y < SCREEN_HEIGHT; y++) { */
|
||||
/* for (size_t x = 0; x < SCREEN_WIDTH; x++) { */
|
||||
/* const size_t index = y * SCREEN_WIDTH + x; */
|
||||
/* TERM_BUF[index] = vga_entry(' ', screen->color); */
|
||||
/* } */
|
||||
/* } */
|
||||
/* memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer)); */
|
||||
/* screen->column = 0; */
|
||||
/* screen->row = 0; */
|
||||
for (size_t y = 0; y < VGA_HEIGHT; y++) {
|
||||
for (size_t x = 0; x < VGA_WIDTH; x++) {
|
||||
const size_t index = y * VGA_WIDTH + x;
|
||||
TERM_BUF[index] = vga_entry(' ', screen->color);
|
||||
}
|
||||
}
|
||||
memcpy(screen->buffer, TERM_BUF, sizeof(screen->buffer));
|
||||
screen->column = 0;
|
||||
screen->row = 0;
|
||||
}
|
||||
|
||||
int terminal_putchar(char c)
|
||||
{
|
||||
terminal_putentryat(c, 0xCCFFE5, 0xCCCC00, 10, 10);
|
||||
if (c == '\r')
|
||||
screen->column = 0;
|
||||
else if (c == '\n')
|
||||
terminal_new_line();
|
||||
if (!isprint(c))
|
||||
return 1;
|
||||
terminal_putentryat(c, screen->fg_color, screen->bg_color,
|
||||
screen->column, screen->row);
|
||||
if (++screen->column == SCREEN_WIDTH)
|
||||
terminal_new_line();
|
||||
return 1;
|
||||
terminal_putentryat(c, 0xCCFFE5, 10, 10);
|
||||
/* if (c == '\r') */
|
||||
/* screen->column = 0; */
|
||||
/* else if (c == '\n') */
|
||||
/* terminal_new_line(); */
|
||||
/* if (!isprint(c)) */
|
||||
/* return 1; */
|
||||
/* terminal_putentryat(c, screen->color, screen->column, screen->row);
|
||||
*/
|
||||
/* if (++screen->column == VGA_WIDTH) */
|
||||
/* terminal_new_line(); */
|
||||
/* return 1; */
|
||||
}
|
||||
|
||||
int terminal_write(const char *data, size_t size)
|
||||
@ -175,7 +191,7 @@ int terminal_writestring(const char *data)
|
||||
|
||||
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(0x3D5, pos & 0xFF);
|
||||
@ -190,14 +206,14 @@ void move_cursor(int direction)
|
||||
if (screen->column) {
|
||||
screen->column--;
|
||||
} else if (screen->row) {
|
||||
screen->column = SCREEN_WIDTH - 1;
|
||||
screen->column = VGA_WIDTH - 1;
|
||||
screen->row--;
|
||||
}
|
||||
break;
|
||||
case RIGHT:
|
||||
if (screen->column < SCREEN_WIDTH - 1) {
|
||||
if (screen->column < VGA_WIDTH - 1) {
|
||||
screen->column++;
|
||||
} else if (screen->row < SCREEN_HEIGHT - 1) {
|
||||
} else if (screen->row < VGA_HEIGHT - 1) {
|
||||
screen->column = 0;
|
||||
screen->row++;
|
||||
} else {
|
||||
@ -224,7 +240,7 @@ void set_color_level(int level)
|
||||
VGA_COLOR_LIGHT_GREY};
|
||||
|
||||
if (level == 0) {
|
||||
terminal_set_color(screen->default_color, 0);
|
||||
terminal_set_color(screen->default_color);
|
||||
return;
|
||||
}
|
||||
terminal_set_fg_color(color_translation[level]);
|
||||
|
Loading…
Reference in New Issue
Block a user