Terminal
This commit is contained in:
@@ -18,8 +18,7 @@ file(GLOB KERN_SRC "*.asm" "*.cpp")
|
||||
file(GLOB KERN_LIB_SRC "kernel/*.cpp" "kernel/*.asm")
|
||||
|
||||
# Driver source
|
||||
file(GLOB DRIV_DISP_VGA "kernel/drivers/VGA/*.cpp" "kernel/drivers/VGA/*.asm")
|
||||
file(GLOB DRIV_DISP_TERM "kernel/drivers/terminal/*.cpp" "kernel/drivers/terminal/*.asm")
|
||||
file(GLOB DRIV_DISP_VGA "kernel/drivers/terminal/*.cpp" "kernel/drivers/terminal/*.asm")
|
||||
|
||||
# Lib source
|
||||
file(GLOB LIB_STD "lib/std/*.cpp" "lib/std/*.asm")
|
||||
@@ -27,7 +26,7 @@ file(GLOB LIB_STD "lib/std/*.cpp" "lib/std/*.asm")
|
||||
|
||||
|
||||
add_executable(OwOS ${KERN_SRC} ${KERN_LIB_SRC}
|
||||
${DRIV_DISP_VGA} ${DRIV_DISP_TERM}
|
||||
${DRIV_DISP_VGA}
|
||||
${LIB_STD})
|
||||
|
||||
set_target_properties(OwOS PROPERTIES OUTPUT_NAME "OwOS.bin")
|
||||
|
||||
BIN
build/OwOS.bin
BIN
build/OwOS.bin
Binary file not shown.
BIN
build/OwOS.iso
BIN
build/OwOS.iso
Binary file not shown.
Binary file not shown.
52
kernel.cpp
52
kernel.cpp
@@ -1,4 +1,3 @@
|
||||
#include <kernel/drivers/VGA/vga.h>
|
||||
#include <kernel/drivers/terminal/terminal.h>
|
||||
|
||||
extern "C"
|
||||
@@ -7,20 +6,45 @@ int kernel_main() {
|
||||
|
||||
cls();
|
||||
showCursor();
|
||||
|
||||
putcar(0, 0, 'H', 0x01, 0x07);
|
||||
putcar(1, 0, 'A', 0x01, 0x07);
|
||||
putcar(2, 0, 'H', 0x01, 0x07);
|
||||
putcar(3, 0, 'A', 0x01, 0x07);
|
||||
putcar(4, 0, '!', 0x01, 0x07);
|
||||
putcar(5, 0, ' ', 0x01, 0x07);
|
||||
putcar(6, 0, 'P', 0x01, 0x07);
|
||||
putcar(7, 0, 'E', 0x01, 0x07);
|
||||
putcar(8, 0, 'N', 0x01, 0x07);
|
||||
putcar(9, 0, 'I', 0x01, 0x07);
|
||||
putcar(10, 0, 'S', 0x01, 0x07);
|
||||
putcar(11, 0, '!', 0x01, 0x07);
|
||||
|
||||
// putchar('P');
|
||||
// putchar('E');
|
||||
// putchar('N');
|
||||
// setFGColour(VGA_BLACK);
|
||||
// setBGColour(VGA_BRIGHT_MAGENTA);
|
||||
// putchar('I');
|
||||
// putchar('S');
|
||||
// putchar('\n');
|
||||
// putchar('L');
|
||||
// putchar('m');
|
||||
// putchar('a');
|
||||
// putchar('o');
|
||||
|
||||
// write("HAHHAHAHAHAHAHAHHAHAHAHAHHAHAHAHAHAHAHHAHAHAHHAHAHAHHAAHAHAHHAHAHAHAHAHAHAHAHAHHAAHHAHA Penis!");
|
||||
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
// writeln("LMAO I WANT TO DIE");
|
||||
|
||||
for (;;)
|
||||
asm("hlt");
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#include "vga.h"
|
||||
|
||||
VGAChar_t* framebuffer = (VGAChar_t*)0xB8000;
|
||||
|
||||
void putcar(int x, int y, char c, char foreground, char background) {
|
||||
framebuffer[(y * TERM_WIDTH) + x].c = c;
|
||||
framebuffer[(y * TERM_WIDTH) + x].foreground = foreground;
|
||||
framebuffer[(y * TERM_WIDTH) + x].background = background;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
#define TERM_WIDTH 80
|
||||
#define TERM_HEIGHT 25
|
||||
|
||||
struct VGAChar_t {
|
||||
char c;
|
||||
char foreground:4;
|
||||
char background:4;
|
||||
}__attribute__((packed));
|
||||
|
||||
void putcar(int x, int y, char c, char foreground, char background);
|
||||
@@ -5,35 +5,55 @@
|
||||
static const int TERMINAL_WIDTH = 80;
|
||||
static const int TERMINAL_HEIGHT = 24;
|
||||
|
||||
static char* frameBuffer = (char*)0xB8000;
|
||||
static VGAChar_t* frameBuffer = (VGAChar_t*)0xB8000;
|
||||
|
||||
static char clearColour = 0x0;
|
||||
static char bgColour = 0x0;
|
||||
static char bgColour = 0x0;
|
||||
static char fgColour = 0xF;
|
||||
|
||||
struct Cursor {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
} __attribute__((packed));
|
||||
|
||||
Cursor cursor;
|
||||
|
||||
void cls() {
|
||||
for (uint8_t x = 0; x < TERMINAL_WIDTH; x++) {
|
||||
for (uint8_t y = 0; y < TERMINAL_HEIGHT; y++) {
|
||||
frameBuffer[x + TERMINAL_WIDTH * y] = 0;
|
||||
}
|
||||
}
|
||||
for (uint8_t x = 0; x < TERMINAL_WIDTH; x++)
|
||||
for (uint8_t y = 0; y < TERMINAL_HEIGHT; y++)
|
||||
putchar(x, y, ' ', fgColour, clearColour);
|
||||
|
||||
moveCursor(0,0);
|
||||
cursor.x = 0; cursor.y = 0;
|
||||
updateCursor(cursor);
|
||||
}
|
||||
|
||||
void putchar(char input) {
|
||||
if (cursor.x + 1 > TERMINAL_WIDTH) {
|
||||
nline();
|
||||
}
|
||||
if (input == '\n') {
|
||||
nline();
|
||||
} else {
|
||||
putchar(cursor.x, cursor.y, input, fgColour, bgColour);
|
||||
cursor.x++;
|
||||
}
|
||||
updateCursor(cursor);
|
||||
}
|
||||
|
||||
void putchar(int x, int y, char c, char foreground, char background) {
|
||||
frameBuffer[(y * TERMINAL_WIDTH) + x].c = c;
|
||||
frameBuffer[(y * TERMINAL_WIDTH) + x].foreground = foreground;
|
||||
frameBuffer[(y * TERMINAL_WIDTH) + x].background = background;
|
||||
}
|
||||
|
||||
void write(char* input) {
|
||||
|
||||
for (uint32_t i = 0; i < strlen(input); i++) {
|
||||
if (cursor.x + 1 > TERMINAL_WIDTH) {
|
||||
nline();
|
||||
}
|
||||
if (input[i] == '\n') {
|
||||
nline();
|
||||
} else {
|
||||
putchar(cursor.x, cursor.y, input[i], fgColour, bgColour);
|
||||
cursor.x++;
|
||||
}
|
||||
}
|
||||
updateCursor(cursor);
|
||||
}
|
||||
|
||||
void writeln(char* input) {
|
||||
@@ -42,19 +62,29 @@ void writeln(char* input) {
|
||||
}
|
||||
|
||||
void nline() {
|
||||
|
||||
cursor.y++;
|
||||
cursor.x = 0;
|
||||
updateCursor(cursor);
|
||||
}
|
||||
|
||||
void setClearColour(char col) {
|
||||
clearColour = col;
|
||||
}
|
||||
|
||||
void setFGColour(char col) {
|
||||
fgColour = col;
|
||||
}
|
||||
|
||||
void setBGColour(char col) {
|
||||
bgColour = col;
|
||||
}
|
||||
|
||||
void showCursor() {
|
||||
outb(0x3D4, 0x0A);
|
||||
outb(0x3D5, (inb(0x3D5) & 0xC0) | 1);
|
||||
outb(0x3D5, (inb(0x3D5) & 0xC0) | 0x0); // Cursor start top
|
||||
|
||||
outb(0x3D4, 0x0B);
|
||||
outb(0x3D5, (inb(0x3D5) & 0xE0) | 1);
|
||||
outb(0x3D5, (inb(0x3D5) & 0xE0) | 0xF); // Cursor start bottom
|
||||
}
|
||||
|
||||
void hideCursor() {
|
||||
@@ -62,11 +92,20 @@ void hideCursor() {
|
||||
outb(0x3D5, 0x20);
|
||||
}
|
||||
|
||||
void moveCursor(int x, int y) {
|
||||
uint16_t pos = y * TERMINAL_WIDTH + x;
|
||||
void updateCursor(Cursor c) {
|
||||
uint16_t pos = c.y * TERMINAL_WIDTH + c.x;
|
||||
|
||||
outb(0x3D4, 0x0F);
|
||||
outb(0x3D5, (uint8_t) (pos & 0xFF));
|
||||
outb(0x3D4, 0x0E);
|
||||
outb(0x3D5, (uint8_t) ((pos >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
void setCursorPosition(int x, int y) {
|
||||
cursor.x = x; cursor.y = y;
|
||||
updateCursor(cursor);
|
||||
}
|
||||
|
||||
uint8_t getVGACol(char f, char b) {
|
||||
return f | b << 4;
|
||||
}
|
||||
|
||||
@@ -2,27 +2,39 @@
|
||||
#include <lib/stdint.h>
|
||||
|
||||
enum {
|
||||
BLACK = 0x0,
|
||||
BLUE = 0x1,
|
||||
GREEN = 0x2,
|
||||
CYAN = 0x3,
|
||||
RED = 0x4,
|
||||
MAGENTA = 0x5,
|
||||
BROWN = 0x6,
|
||||
GREY = 0x7,
|
||||
DARK_GREY = 0x8,
|
||||
BRIGHT_BLUE = 0x9,
|
||||
BRIGHT_GREEN = 0xA,
|
||||
BRIGHT_CYAN = 0xB,
|
||||
BRIGHT_RED = 0xC,
|
||||
BRIGHT_MAGENTA = 0xD,
|
||||
YELLOW = 0xE,
|
||||
WHITE = 0xF,
|
||||
VGA_BLACK = 0x0,
|
||||
VGA_BLUE = 0x1,
|
||||
VGA_GREEN = 0x2,
|
||||
VGA_CYAN = 0x3,
|
||||
VGA_RED = 0x4,
|
||||
VGA_MAGENTA = 0x5,
|
||||
VGA_BROWN = 0x6,
|
||||
VGA_GREY = 0x7,
|
||||
VGA_DARK_GREY = 0x8,
|
||||
VGA_BRIGHT_BLUE = 0x9,
|
||||
VGA_BRIGHT_GREEN = 0xA,
|
||||
VGA_BRIGHT_CYAN = 0xB,
|
||||
VGA_BRIGHT_RED = 0xC,
|
||||
VGA_BRIGHT_MAGENTA = 0xD,
|
||||
VGA_YELLOW = 0xE,
|
||||
VGA_WHITE = 0xF,
|
||||
};
|
||||
|
||||
struct VGAChar_t {
|
||||
char c;
|
||||
char foreground:4;
|
||||
char background:4;
|
||||
}__attribute__((packed));
|
||||
|
||||
struct Cursor {
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
} __attribute__((packed));
|
||||
|
||||
void cls();
|
||||
|
||||
void putchar(char input);
|
||||
void putchar(int x, int y, char c, char foreground, char background);
|
||||
|
||||
void write(char* input);
|
||||
void writeln(char* input);
|
||||
@@ -30,8 +42,11 @@ void writeln(char* input);
|
||||
void nline();
|
||||
|
||||
void setClearColour(char col);
|
||||
void setFGColour(char col);
|
||||
void setBGColour(char col);
|
||||
|
||||
void showCursor();
|
||||
void hideCursor();
|
||||
|
||||
void moveCursor(int x, int y);
|
||||
void updateCursor(Cursor c);
|
||||
void setCursorPosition(int x, int y);
|
||||
|
||||
0
lib/std/memory.cpp
Normal file
0
lib/std/memory.cpp
Normal file
6
lib/std/memory.h
Normal file
6
lib/std/memory.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <lib/stdint.h>
|
||||
|
||||
int memcmp(const void* a, const void* b, uint32_t sze);
|
||||
void* memcpy(const void* dst, const void* src, uint32_t sze);
|
||||
void* memmove(void* dst, const void* src, uint32_t sze);
|
||||
void* memset(void* ptr, int val, uint32_t sze);
|
||||
@@ -1,5 +1,8 @@
|
||||
#include "string.h"
|
||||
|
||||
uint32_t strlen(char* str) {
|
||||
|
||||
uint32_t len = 0;
|
||||
while (str[len])
|
||||
len++;
|
||||
return len;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user