Feat: better screen formating & better project resstructure

This commit is contained in:
AfonsoCMSousa
2026-08-05 13:40:42 +01:00
parent 7a4394feb6
commit f80dafd03d
14 changed files with 277 additions and 170 deletions
+7
View File
@@ -0,0 +1,7 @@
#ifndef KERNEL_H
#define KERNEL_H
#define __KERNEL_VERSION "0.1.0-alpha"
#define __KERNEL_NAME "SoraOS"
#endif
+126
View File
@@ -0,0 +1,126 @@
#ifndef COLORS_H
#define COLORS_H
#include "stdmem.h"
#include "types.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
#define VGA_MEMORY_ADDRESS 0xB8000
/*
* FOR INPUT
*/
#define KEYBOARD_BUFFER_SIZE 256
#define SCANCODE_LSHIFT 0x2A
#define SCANCODE_RSHIFT 0x36
#define SCANCODE_CAPSLOCK 0x3A
#define RELEASE_MASK 0x80
static volatile unsigned char _keyboard_buffer[KEYBOARD_BUFFER_SIZE];
static volatile uint16_t _kb_head = 0;
static volatile uint16_t _kb_tail = 0;
static char __g_shift_pressed = 0;
static char __g_caps_lock_active = 0;
// C99 Designated Initializers for Unshifted ASCII Characters
static const char scancode_ascii_unshifted[128] = {
[0x01] = 27, // ESC
[0x02] = '1', [0x03] = '2', [0x04] = '3', [0x05] = '4', [0x06] = '5', [0x07] = '6', [0x08] = '7', [0x09] = '8', [0x0A] = '9', [0x0B] = '0', [0x0C] = '-',
[0x0D] = '=', [0x0E] = '\b', // Backspace
[0x0F] = '\t', // Tab
[0x10] = 'q', [0x11] = 'w', [0x12] = 'e', [0x13] = 'r', [0x14] = 't', [0x15] = 'y', [0x16] = 'u', [0x17] = 'i', [0x18] = 'o', [0x19] = 'p', [0x1A] = '[',
[0x1B] = ']', [0x1C] = '\n', // Enter
[0x1E] = 'a', [0x1F] = 's', [0x20] = 'd', [0x21] = 'f', [0x22] = 'g', [0x23] = 'h', [0x24] = 'j', [0x25] = 'k', [0x26] = 'l', [0x27] = ';', [0x28] = '\'',
[0x29] = '`', [0x2C] = 'z', [0x2D] = 'x', [0x2E] = 'c', [0x2F] = 'v', [0x30] = 'b', [0x31] = 'n', [0x32] = 'm', [0x33] = ',', [0x34] = '.', [0x35] = '/',
[0x39] = ' ' // Spacebar
};
// C99 Designated Initializers for Shifted ASCII Characters
static const char scancode_ascii_shifted[128] = {
[0x01] = 27, // ESC
[0x02] = '!', [0x03] = '@', [0x04] = '#', [0x05] = '$', [0x06] = '%', [0x07] = '^', [0x08] = '&', [0x09] = '*', [0x0A] = '(', [0x0B] = ')',
[0x0C] = '_', [0x0D] = '+', [0x0E] = '\b', [0x0F] = '\t', [0x10] = 'Q', [0x11] = 'W', [0x12] = 'E', [0x13] = 'R', [0x14] = 'T', [0x15] = 'Y',
[0x16] = 'U', [0x17] = 'I', [0x18] = 'O', [0x19] = 'P', [0x1A] = '{', [0x1B] = '}', [0x1C] = '\n', [0x1E] = 'A', [0x1F] = 'S', [0x20] = 'D',
[0x21] = 'F', [0x22] = 'G', [0x23] = 'H', [0x24] = 'J', [0x25] = 'K', [0x26] = 'L', [0x27] = ':', [0x28] = '"', [0x29] = '~', [0x2C] = 'Z',
[0x2D] = 'X', [0x2E] = 'C', [0x2F] = 'V', [0x30] = 'B', [0x31] = 'N', [0x32] = 'M', [0x33] = '<', [0x34] = '>', [0x35] = '?', [0x39] = ' '};
/* IN VGA - Video Memory Arrya:
* short
* 1s byte (left most) -> TEXT COLOR
* 2s byte -> BACK COLOR
* 3rd and 4rt byte -> TEXT (unsigned char) AKA CodePoint
*/
typedef struct __attribute__((packed)) _VGA {
unsigned char codepoint; // 3rd and 4th byte
unsigned char color; // 1st byte: text color, 2nd byte: background color
// LAST BIT IS BLINKING FLAG
} _VGA;
typedef enum _VGA_COLOR {
BLACK = 0x0,
BLUE = 0x1,
GREEN = 0x2,
CYAN = 0x3,
RED = 0x4,
MAGENTA = 0x5,
BROWN = 0x6,
LIGHT_GREY = 0x7,
DARK_GREY = 0x8,
LIGHT_BLUE = 0x9,
LIGHT_GREEN = 0xA,
LIGHT_CYAN = 0xB,
LIGHT_RED = 0xC,
LIGHT_MAGENTA = 0xD,
YELLOW = 0xE,
WHITE = 0xF
} _VGA_COLOR;
typedef struct _VGA_screen_space {
unsigned int line;
unsigned int column;
} _VGA_screen_space;
static _VGA_screen_space cursor_pos = {0, 0};
static _VGA_screen_space text_pos = {0, 0};
static unsigned int tab_pos = 0;
#define DEFAULT_BG BLUE
#define DEFAULT_FG WHITE
/*
* END OF DECLARATIONS
*/
/*
* START OF OUTPUT FUNCTIONS
*/
int printf(const char *fmt, ...);
void clear_screen();
/*
* END OF OUTPUT FUNCTIONS
*/
/*
* START OF INPUT FUNCTIONS
*/
void scursor(unsigned int column, unsigned int line);
void gets(char *buffer, size_t max_length);
int scanf(const char *fmt, ...);
#endif
+23
View File
@@ -0,0 +1,23 @@
#ifndef STDMEM_H
#define STDMEM_H
#include "types.h"
static inline void *__memmove(void *dest, const void *src, uint64_t n) {
unsigned char *__d = (unsigned char *)dest;
const unsigned char *__s = (const unsigned char *)src;
if (__d < __s) {
for (unsigned long long i = 0; i < n; i++) {
__d[i] = __s[i];
}
} else {
for (unsigned long long i = n; i > 0; i--) {
__d[i - 1] = __s[i - 1];
}
}
return dest;
}
#endif // STDMEM_H
+92
View File
@@ -0,0 +1,92 @@
#ifndef TYPES_H
#define TYPES_H
#include <stdint.h>
static char* __itoa(int value, char* buffer, int base) {
char* ptr = buffer, *ptr1 = buffer, tmp_char;
int tmp_value;
if (value < 0 && base == 10) {
value = -value;
*ptr++ = '-';
ptr1++;
}
do {
tmp_value = value;
value /= base;
*ptr++ = "0123456789ABCDEF"[tmp_value - value * base];
} while (value);
*ptr-- = '\0';
while (ptr1 < ptr) {
tmp_char = *ptr;
*ptr-- = *ptr1;
*ptr1++ = tmp_char;
}
return buffer;
}
static char* __utoa(unsigned int value, char* buffer, int base) {
char* ptr = buffer, *ptr1 = buffer, tmp_char;
unsigned int tmp_value;
do {
tmp_value = value;
value /= base;
*ptr++ = "0123456789ABCDEF"[tmp_value - value * base];
} while (value);
*ptr-- = '\0';
while (ptr1 < ptr) {
tmp_char = *ptr;
*ptr-- = *ptr1;
*ptr1++ = tmp_char;
}
return buffer;
}
static char* __ftoa(double value, char* buffer) {
int int_part = (int)value;
double frac_part = value - (double)int_part;
char* ptr = __itoa(int_part, buffer, 10);
*ptr++ = '.';
for (int i = 0; i < 6; i++) {
frac_part *= 10.0;
int digit = (int)frac_part;
*ptr++ = '0' + digit;
frac_part -= (double)digit;
}
*ptr = '\0';
return buffer;
}
static char* itoa(int value, char* buffer) {
return __itoa(value, buffer, 10);
}
static char* utoa(unsigned int value, char* buffer) {
return __utoa(value, buffer, 10);
}
static char* otoa(unsigned int value, char* buffer) {
return __utoa(value, buffer, 8);
}
static char* xtoa(unsigned int value, char* buffer) {
return __utoa(value, buffer, 16);
}
static char* ftoa(double value, char* buffer) {
return __ftoa(value, buffer);
}
#endif // TYPES_H