Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,3 @@ To install all the required tools, you can use the following commands:

```bash
make run
```
273 changes: 273 additions & 0 deletions docs/assets/tty/tty.drawio.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/tty/tty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions includes/driver/console.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef CONSOLE_H
#define CONSOLE_H

#include "driver/keyboard/event_queue.h"
#include "keyboard_keys.h"
#include "keyboard_layout.h"
#include "types.h"

struct console_t;

typedef struct {
void (*write)(struct console_t *self, char *str);
void (*clear)(struct console_t *self);
} console_interface_t;

typedef struct console_t {
console_interface_t method;
} console_t;

void console_init(console_t *console);

#endif
46 changes: 23 additions & 23 deletions includes/driver/keyboard/event_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@
#include "ps2.h"
#include "types.h"

#define KEYBOARD_EVENT_QUEUE_SIZE 256

typedef struct {
key_event_t events[KEYBOARD_EVENT_QUEUE_SIZE];
uint32_t head;
uint32_t tail;
} keyboard_event_queue_t;

extern keyboard_event_queue_t keyboard_queue;
#define INPUT_EVENT_QUEUE_SIZE 256

typedef enum {
INPUT_CHAR,
INPUT_ENTER,
INPUT_BACKSPACE,
INPUT_TAB,
INPUT_UP,
INPUT_DOWN,
INPUT_LEFT,
INPUT_RIGHT,
} input_type_t;
INPUT_EVENT_KEY,
INPUT_EVENT_CHAR,
} input_event_type_t;

typedef struct {
input_type_t type;
input_event_type_t type;
keycode_t key;
key_action_t action;
bool shift;
bool ctrl;
bool alt;
char character;
} input_event_t;

typedef struct {
input_event_t events[INPUT_EVENT_QUEUE_SIZE];
uint32_t head;
uint32_t tail;
} input_event_queue_t;

extern input_event_queue_t input_event_queue;

void input_queue_init(void);
void input_queue_push(input_event_t event);
void input_queue_pop(input_event_t *event);
bool input_queue_pop(input_event_t *event);
bool input_queue_is_empty(void);
bool input_queue_is_full(void);
void input_queue_print();
void input_queue_print_last();
void input_queue_clear();

extern input_event_t input_queue[KEYBOARD_EVENT_QUEUE_SIZE];
void input_queue_clear(void);

#endif
1 change: 1 addition & 0 deletions includes/driver/keyboard/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef enum {
void init_keyboard(void);

void reset_keyboard(void);
void set_scanning(bool state);
void set_scaning(bool state);
void select_scancode_set(uint8_t set);
void keyboard_set_layout(const keyboard_layout_t *layout);
Expand Down
5 changes: 0 additions & 5 deletions includes/driver/keyboard/keyboard_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ typedef enum {

typedef enum { KEY_PRESSED, KEY_RELEASED } key_action_t;

typedef struct {
keycode_t key;
key_action_t action;
} key_event_t;

typedef struct {
keycode_t normal[256];
keycode_t extended[256];
Expand Down
58 changes: 58 additions & 0 deletions includes/driver/tty.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef TTY_H
#define TTY_H

#include "driver/keyboard/event_queue.h"
#include "keyboard_keys.h"
#include "keyboard_layout.h"
#include "types.h"

#include "console.h"

#define TTY_BUFFER_SIZE 4096

// modifiers
typedef enum {
MOD_NONE = 0,
MOD_SHIFT = 1 << 0,
MOD_CTRL = 1 << 1,
MOD_ALT = 1 << 2,
MOD_ALTGR = 1 << 3,
MOD_CAPS = 1 << 4,
MOD_NUM = 1 << 5,
MOD_SCROLL = 1 << 6,
MOD_SUPER = 1 << 7
} keyboard_modifiers_t;

struct tty_t;

typedef struct {
void (*putc)(struct tty_t *tty, char c);
void (*write)(struct tty_t *tty, const char *str);
void (*read)(struct tty_t *tty, char *buf, size_t len);
void (*clear)(struct tty_t *tty);
} tty_interface_t;

typedef struct tty_t {
bool echo;
bool line_ready;

int input_length;
int buffer_index;
int cursor_index;
char buffer[TTY_BUFFER_SIZE];

keyboard_modifiers_t modifiers;

tty_interface_t method;

console_t *console;
} tty_t;

void tty_init(tty_t *tty);

void tty_handle_event(tty_t *tty, const input_event_t *event);
void tty_update_modifiers(tty_t *tty, const input_event_t *event);

void tty_process_events(tty_t *tty);

#endif
13 changes: 12 additions & 1 deletion includes/driver/vga.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#define BROWN 0x06 // YELLOW
#define LIGHT_GRAY 0x07 // WHITE

#define DARK_GRAY BLACk | LIGHT_FLAG
#define DARK_GRAY BLACK | LIGHT_FLAG
#define LIGHT_BLUE BLUE | LIGHT_FLAG
#define LIGHT_GREEN GREEN | LIGHT_FLAG
#define LIGHT_CYAN CYAN | LIGHT_FLAG
Expand Down Expand Up @@ -77,10 +77,21 @@ void vga_set_cursor(uint8_t x, uint8_t y);

void vga_set_cursor_position(uint16_t p);

void vga_cursor_up(void);
void vga_cursor_down(void);
void vga_cursor_left(void);
void vga_cursor_right(void);

uint16_t vga_get_cursor_position(void);

uint8_t vga_get_cursor_x(void);

uint8_t vga_get_cursor_y(void);

void vga_put_at(uint8_t x, uint8_t y, char c, uint8_t color);
void vga_clear_region(uint8_t x, uint8_t y, uint8_t width, uint8_t height, uint8_t color);

void vga_print_at(uint8_t x, uint8_t y, const char *str, uint8_t color);
void vga_print_at_center(uint8_t y, const char *str, uint8_t color);

#endif
2 changes: 2 additions & 0 deletions includes/lib/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ void print_at_end(const char *str, uint8_t color);

void printf(const char *format, ...);
void snprintf(char *buffer, size_t buffer_size, const char *format, ...);
char scan_char(void);
int scanf(const char *format, ...);

char *vformatter(const char *format, va_list args);
char *formatter(const char *format, ...);
Expand Down
2 changes: 1 addition & 1 deletion includes/lib/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "types.h"

int strlen(char *str);
int strlen(const char *str);

void strcpy(char *dest, char *src);
void strcat(char *dest, const char *src);
Expand Down
26 changes: 13 additions & 13 deletions src/bootloader/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@ int 0x13

jc disk_read_error

jmp start
; jmp start

msg db 13, 10,"Welcom to my bootLoader", 13, 10
db "press any key to continue...", 0
; msg db 13, 10,"Welcom to my bootLoader", 13, 10
; db "press any key to continue...", 0

s_msg db 13,10,10,"starting...",0
; s_msg db 13,10,10,"starting...",0



%include "src/bootloader/utils.asm"
; %include "src/bootloader/utils.asm"


start:
; start:

call clear_screen
; call clear_screen


MOV si, msg
call print
; MOV si, msg
; call print

call get_key
; call get_key

MOV si, s_msg
call print
jmp PM_start
; MOV si, s_msg
; call print
; jmp PM_start


PM_start:
Expand Down
39 changes: 39 additions & 0 deletions src/driver/console/vga/vga_console.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "driver/vga.h"

#include "types.h"

#include "console.h"

#include "driver/tty.h"

#include "stdio.h"

void console_write(console_t *console, char *str);
void console_clear(console_t *console);

static const console_interface_t console_default_interface = {
.write = console_write,
.clear = console_clear,
};

void console_init(console_t *console) {
if (console == NULL)
return;

console->method = console_default_interface;
}

void console_write(console_t *console, char *str) {

if (console == NULL || str == NULL)
return;

print(str);
}

void console_clear(console_t *console) {
if (console == NULL)
return;

vga_clear();
}
Loading
Loading