#ifndef COLORS_H #define COLORS_H #include "stdmem.h" #include "types.h" #include #include #include #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