improve printing functions and project structure

This commit is contained in:
Robert 2023-09-05 19:11:15 +02:00
parent 3d25674623
commit 97341b9c46
8 changed files with 133 additions and 53 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
build/
*.ini
.clangd

7
roadmap.md Normal file
View file

@ -0,0 +1,7 @@
# Short-term goals
1. Paging
* Write a page allocator
* Setup the x86 for Paging
2. Process scheduling
3. Implement a filesystem

View file

@ -0,0 +1,10 @@
#ifndef _CLIPPER_IO_H_
#define _CLIPPER_IO_H_
#include <stdint.h>
inline void outb(uint16_t port, uint8_t val) {
asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
}
#endif // _CLIPPER_IO_H_

View file

@ -0,0 +1,39 @@
#ifndef _CLIPPER_TEXT_SCREEN_H_
#define _CLIPPER_TEXT_SCREEN_H_
#include <stdint.h>
enum text_screen_attribute {
TEXT_SCREEN_FG_BLACK = 0,
TEXT_SCREEN_FG_BLUE,
TEXT_SCREEN_FG_GREEN,
TEXT_SCREEN_FG_CYAN,
TEXT_SCREEN_FG_RED,
TEXT_SCREEN_FG_PURPLE,
TEXT_SCREEN_FG_BROWN,
TEXT_SCREEN_FG_GRAY,
TEXT_SCREEN_FG_DARK_GRAY,
TEXT_SCREEN_FG_LIGHT_BLUE,
TEXT_SCREEN_FG_LIGHT_GREEN,
TEXT_SCREEN_FG_LIGHT_CYAN,
TEXT_SCREEN_FG_LIGHT_RED,
TEXT_SCREEN_FG_LIGHT_PURPLE,
TEXT_SCREEN_FG_LIGHT_YELLOW,
TEXT_SCREEN_FG_WHITE,
TEXT_SCREEN_BG_BLACK = 0,
TEXT_SCREEN_BG_BLUE = (1 << 4),
TEXT_SCREEN_BG_GREEN = (2 << 4),
TEXT_SCREEN_BG_CYAN = (3 << 4),
TEXT_SCREEN_BG_RED = (4 << 4),
TEXT_SCREEN_BG_PURPLE = (5 << 4),
TEXT_SCREEN_BG_BROWN = (6 << 4),
TEXT_SCREEN_BG_GRAY = (7 << 4)
};
void tsinit(void);
void tsputch(char ch, uint8_t color);
void tsputs(const char* str, uint8_t color);
#endif // _CLIPPER_TEXT_SCREEN_H_

View file

@ -1,7 +0,0 @@
#ifndef _CLIPPER_STRING_H_
#define _CLIPPER_STRING_H_
void putch(char c);
void puts(const char* str);
#endif

View file

@ -1,3 +1,4 @@
#include "include/internal/text_screen.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -10,9 +11,13 @@
# error "Please use an ix86-elf compiler"
#endif
#include "string.h"
#include "internal/text_screen.h"
void kmain(void) {
puts("Clipper has booted!\r\n");
tsinit();
const char* msg = "Clipper set sail!\n~~~~~~~~~~~~~~~~~";
tsputs(msg, TEXT_SCREEN_BG_BLACK | TEXT_SCREEN_FG_LIGHT_CYAN);
return;
}

View file

@ -1,44 +0,0 @@
#include "string.h"
#include <stdint.h>
static volatile char* video = (volatile char*)0xB8000;
static uint8_t cursor_x = 0, cursor_y = 0;
#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25
static inline void advance_cursor(void) {
cursor_x++;
if (cursor_x >= SCREEN_WIDTH) {
cursor_x = 0;
cursor_y++;
if (cursor_y >= SCREEN_HEIGHT) {
cursor_y = 0;
}
}
}
static inline void linefeed(void) {
cursor_y++;
if (cursor_y >= SCREEN_HEIGHT) {
cursor_y = 0;
}
}
void putch(char c) {
switch(c) {
case '\r': cursor_x = 0; return;
case '\n': linefeed(); return;
}
video[cursor_y * (SCREEN_WIDTH * 2) + (cursor_x * 2)] = c;
advance_cursor();
}
void puts(const char* str) {
for (const char* c = str; *c != '\0'; c++) {
putch(*c);
}
}

View file

@ -0,0 +1,68 @@
#include "internal/text_screen.h"
#include "internal/io.h"
struct text_screen_char {
char character;
uint8_t attribute;
} __attribute__((packed));
static volatile struct text_screen_char* videomem = (struct text_screen_char*)0xB8000;
static uint8_t cursor_x = 0;
static uint8_t cursor_y = 0;
#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25
void tsinit(void) {
outb(0x3D4, 0x0A);
outb(0x3D5, 0x20);
}
void tsputch(char ch, uint8_t color) {
const char tmp[2] = { ch, 0 };
tsputs(tmp, color);
}
static void handle_special_char(char c) {
switch (c) {
case '\n': {
cursor_x = 0;
cursor_y++;
if (cursor_y >= SCREEN_HEIGHT) {
cursor_y = 0;
}
} break;
case '\r': cursor_x = 0; break;
case '\t': cursor_x += 4; break;
}
}
void tsputs(const char* ch, uint8_t color) {
struct text_screen_char tsch = {
.character = '\0',
.attribute = (color & 0x7F)
};
for(const char* c = ch; *c != '\0'; c++) {
if ((uint8_t)(*c) < 0x20) {
handle_special_char(*c);
continue;
}
tsch.character = *c;
videomem[cursor_y * SCREEN_WIDTH + cursor_x] = tsch;
cursor_x++;
if (cursor_x >= SCREEN_WIDTH) {
cursor_y++;
cursor_x = 0;
if (cursor_y >= SCREEN_HEIGHT) {
cursor_y = 0;
}
}
}
}