-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrolling & Multiple Shells & 1 screen per shell #1
base: main
Are you sure you want to change the base?
Changes from all commits
8eaf8aa
80e2747
37dae49
d4bd160
ace66c1
a7be119
276b13c
5e1eb18
7f6bace
d90d945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ IT_49_handler: | |
popl %edi | ||
popl %esi | ||
|
||
iret | ||
iret |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,49 @@ | ||
#include "kbd.h" | ||
#include "stdio.h" | ||
#include "cpu.h" | ||
#include "mem.h" | ||
#include "string.h" | ||
#include "process.h" | ||
#include "queue.h" | ||
|
||
kbd_buf keyboard_buffer; | ||
int writing; | ||
int echo = 1; | ||
int echoing = 0; | ||
|
||
void init_keyboard_buffer(void){ | ||
void init_keyboard_buffer(void) { | ||
keyboard_buffer.count = 0; | ||
keyboard_buffer.write_head = 0; | ||
keyboard_buffer.read_head = 0; | ||
writing = 0; | ||
} | ||
|
||
void kbd_int(void){ | ||
void kbd_int(void) { | ||
// Read the scancode from the keyboard port | ||
unsigned char scancode = inb(0x60); | ||
|
||
// Acknowledge the interruption | ||
outb(0x20,0x20); | ||
|
||
// Translate scancode to a character | ||
do_scancode((char) scancode); | ||
if(scancode == 224){ | ||
scancode = inb(0x60); | ||
outb(0x20,0x20); | ||
if (scancode == 72) { | ||
cmd_hist_up(); | ||
} | ||
if (scancode == 73) { | ||
scroll_up(); | ||
} | ||
if (scancode == 80) { | ||
cmd_hist_down(); | ||
} | ||
if (scancode == 81) { | ||
scroll_down(); | ||
} | ||
} | ||
else if(scancode == 73 || scancode == 81 || scancode == 72 || scancode == 80) { | ||
return; | ||
} else { | ||
// Translate scancode to a character | ||
do_scancode((char) scancode); | ||
} | ||
} | ||
|
||
void keyboard_data(char *str){ | ||
void keyboard_data(char *str) { | ||
int i = 0; | ||
char c = str[i]; | ||
|
||
|
@@ -44,14 +59,18 @@ void keyboard_data(char *str){ | |
keyboard_buffer.count--; | ||
if(echo){ | ||
c = '\b'; | ||
echoing = true; | ||
cons_write(&c, 1); | ||
echoing = false; | ||
} | ||
} | ||
} else { | ||
// Echo the char to the console if enabled | ||
if (echo) { | ||
echoing = true; | ||
if (c == '\r') cons_write("\n", 1); | ||
cons_write(&c, 1); | ||
echoing = false; | ||
} | ||
// Increase kbd buffers counters | ||
keyboard_buffer.write_head = (keyboard_buffer.write_head + 1) % KBD_BUF_SIZE; | ||
|
@@ -71,9 +90,79 @@ void keyboard_data(char *str){ | |
} | ||
} | ||
|
||
void kbd_leds(unsigned char leds){ | ||
void kbd_leds(unsigned char leds) { | ||
// Write the led status to the keyboard port | ||
outb(0xED, 0x60); | ||
for (int i = 0; i < 100000; i++); | ||
outb(leds, 0x60); | ||
} | ||
|
||
void cons_echo(int on) { | ||
echo = on; | ||
} | ||
|
||
int cons_read(char *string, unsigned long length){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could benefit from another file like cons.c/h |
||
if(length <= 0) return 0; | ||
long unsigned int read = 0; | ||
char buffer[length]; | ||
|
||
// If precedent call left a cons_read | ||
if(keyboard_buffer.buf[keyboard_buffer.read_head] == 13){ | ||
keyboard_buffer.count--; | ||
keyboard_buffer.read_head = (keyboard_buffer.read_head + 1) % KBD_BUF_SIZE; | ||
return 0; | ||
} | ||
writing++; | ||
|
||
// Lock until 13 char | ||
process_t* running = process_table->running; | ||
running->state = LOCKED_IO; | ||
queue_add(running, process_table->io_queue, process_t, queue_link, priority); | ||
scheduler(); | ||
|
||
for(read = 0 ; read < length ; read++){ | ||
if(keyboard_buffer.buf[keyboard_buffer.read_head] == 13){ | ||
keyboard_buffer.read_head = (keyboard_buffer.read_head + 1) % KBD_BUF_SIZE; | ||
keyboard_buffer.count--; | ||
break; | ||
} | ||
// Copy keyboard buffer to final buffer, atomically | ||
buffer[read] = keyboard_buffer.buf[keyboard_buffer.read_head]; | ||
keyboard_buffer.count--; | ||
keyboard_buffer.read_head = (keyboard_buffer.read_head + 1) % KBD_BUF_SIZE; | ||
} | ||
|
||
// Copy to caller buffer | ||
memcpy(string, buffer, read); | ||
// Add cmd to history | ||
if (running->shell_props != NULL) { | ||
cmd_hist_t* cmd_hist = running->shell_props->cmd_hist; | ||
if (read > 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would happen if the " |
||
// Clear the buffer cell we are about to write to | ||
for (uint16_t i = 0; i<MAX_COMMAND_LENGTH; i++) { | ||
cmd_hist->buf[cmd_hist->max][i] = '\0'; | ||
} | ||
strcpy(cmd_hist->buf[cmd_hist->max], string); | ||
cmd_hist->index = cmd_hist->max; | ||
cmd_hist->count_read = 0; | ||
cmd_hist->max = (cmd_hist->max + 1) % MAX_COMMANDS_HIST; | ||
if (cmd_hist->count < MAX_COMMANDS_HIST) { | ||
cmd_hist->count++; | ||
} | ||
} else { | ||
cmd_hist->index = cmd_hist->max; | ||
cmd_hist->count_read = 0; | ||
} | ||
} | ||
|
||
// End of writing phase | ||
writing--; | ||
return read; | ||
} | ||
|
||
void cons_write(const char *str, long size) { | ||
if (size < 0){ | ||
return; | ||
} | ||
console_putbytes(str, size); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!! Do not use absolute path.
Make could provide something like $(PWD).