[0x3a] = 'm',
/* special */
- [0x29] = ' '
+ [0x29] = ' ',
+ [0x5a] = '\n',
+ [0x66] = 0x7f /* backspace */
};
extern int ps2_initialize();
extern void ps2_input_wait();
extern void ps2_output_wait();
+extern char ps2_get_keystroke();
#endif
extern void screen_clear(void);
extern void kprint(const char *string, uint8_t color);
+extern void kprintc(const char character, uint8_t color);
extern void kprintb(const uint8_t byte);
extern void kprintw(const uint16_t word);
extern void kprintd(const uint32_t dword);
+
+extern char *kgets(void);
#endif
#include <io.h>
#include <tty.h>
#include <stdint.h>
+#include <input/ps2.h>
#define VGA_WIDTH 80
#define VGA_HEIGHT 25
static int cursor_y = 0;
char *hex_chars = "0123456789ABCDEF";
+char kgets_buffer[100];
void screen_clear(void)
{
uint16_t crtc_port;
if ( character == '\n') { cursor_x = 0; cursor_y++; }
+ if (character == 0x7f) {
+ cursor_x--;
+ if (cursor_x < 0) {
+ if (cursor_y > 0) {
+ cursor_x = VGA_WIDTH - 1;
+ cursor_y--;
+ } else cursor_x = 0;
+ }
+ video_memory[(cursor_y * VGA_WIDTH + cursor_x) * 2] = ' ';
+ }
else { video_memory[(cursor_y * VGA_WIDTH + cursor_x) * 2] = character; video_memory[((cursor_y * VGA_WIDTH + cursor_x++) * 2)+ 1] = color != 0 ? color : VGA_COLOR_LIGHT_GRAY; }
if ( cursor_x >= VGA_WIDTH ) { cursor_x = 0; cursor_y++; }
if ( cursor_y >= VGA_HEIGHT ) { scroll_up(); }
temp = dword & 0xF;
kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
}
+
+char *kgets()
+{
+ for (int i=0; i<100; i++) {
+ kgets_buffer[i] = '\0';
+ }
+
+ int i=0;
+ while (i<100) {
+ char temp = ps2_get_keystroke();
+ if (temp == '\n') break;
+ if (temp == 0x7f) {
+ if (i>0) {
+ i-=1;
+ kgets_buffer[i] = '\0';
+ kprintc(temp, 0);
+ }
+ continue;
+ }
+ kgets_buffer[i] = temp;
+ kprintc(temp, 0);
+ i++;
+ }
+
+ return kgets_buffer;
+}
#include <irq/interrupt.h>
static int was_released = 0, is_caps = 0;
+static char buffer;
int ps2_keyb_handler()
{
return 0;
}
if (!is_caps) {
- kprintc(scancodes[scancode], 0);
+ buffer = scancodes[scancode];
} else {
- kprintc(scancodes[scancode] - ('a'-'A'), 0);
+ buffer = scancodes[scancode] - ('a'-'A');
}
}
return 0;
}
+char ps2_get_keystroke()
+{
+ buffer = 0;
+ while (!buffer);
+ return buffer;
+}
+
int ps2_initialize()
{
uint8_t ccb, is_2channel, port_1_test, port_2_test;
#include <irq/interrupt.h>
#include <irq/i8259a.h>
#include <input/ps2.h>
+#include <stddef.h>
struct idt_descriptor idt[256] __attribute__((aligned(0x10)));
struct idtr idtr __attribute__((aligned(0x10)));
}
asm volatile ("sti");
kprint("All done\n", 0);
- while(1);
+
+ while(1) {
+ char *string = NULL;
+ string = kgets();
+ kprint(string, VGA_COLOR_LIME);
+ kprint("\n", 0);
+ }
}