summaryrefslogtreecommitdiff
path: root/src/keyboard.c
diff options
context:
space:
mode:
authorAleksa Vučković <aleksav013@gmail.com>2021-10-25 00:36:33 +0200
committerAleksa Vučković <aleksav013@gmail.com>2021-10-25 00:36:33 +0200
commit20dd72e40dc2728d3c5335d860e4b8ab8da14fcc (patch)
treedabdfdf736c45f9632fa1388d2144b1de7a438b0 /src/keyboard.c
parent0bca634f7e70b05239f46f3bd40bb37468d67957 (diff)
Changing build system to recursive make
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c110
1 files changed, 0 insertions, 110 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
deleted file mode 100644
index c945acd..0000000
--- a/src/keyboard.c
+++ /dev/null
@@ -1,110 +0,0 @@
-#include"types.h"
-#include"asm.h"
-#include"stdio.h"
-
-#define BUFFER_SIZE 200
-char buffer[BUFFER_SIZE];
-size_t buffer_index=0;
-
-#define PIC1_COMMAND_PORT 0x20
-#define PIC1_DATA_PORT 0x21
-#define PIC2_COMMAND_PORT 0xA0
-#define PIC2_DATA_PORT 0xA1
-// IO Ports for Keyboard
-#define KEYBOARD_DATA_PORT 0x60
-#define KEYBOARD_STATUS_PORT 0x64
-
-void previous_field(void);
-void terminal_putchar(char c);
-void tty(char *buffer);
-void prompt(void);
-void clear();
-void us_en(char keymap[]);
-
-char charcode[256];
-bool ispressed[128];
-
-void init_keyboard()
-{
- // 0xFD = 1111 1101 in binary. enables only IRQ1
- // Why IRQ1? Remember, IRQ0 exists, it's 0-based
- ioport_out(PIC1_DATA_PORT, 0xFD);
- us_en(charcode);
-}
-
-void backspace()
-{
- if(buffer_index<=0) return;
-
- previous_field();
- printf(" ");
- previous_field();
- buffer[--buffer_index]='\0';
- return;
-}
-
-void enter()
-{
- printf("\n");
- if(buffer_index>0)
- {
- tty(buffer);
- for(int i=0;i<BUFFER_SIZE;i++) buffer[i]='\0';
- buffer_index=0;
- }
- prompt();
- return;
-}
-
-void space()
-{
- buffer[buffer_index++]=' ';
- printf(" ");
-}
-#define lshift ispressed[0x2A]
-#define lctrl ispressed[0x1D]
-
-void handle_keyboard_interrupt()
-{
- ioport_out(PIC1_COMMAND_PORT, 0x20);
- uint8_t status = ioport_in(KEYBOARD_STATUS_PORT);
-
- if (status & 0x1)
- {
- uint8_t keycode = ioport_in(KEYBOARD_DATA_PORT);
- if(keycode<0x80)
- {
- ispressed[keycode]=1;
- if(keycode==0x0E) backspace();
- else if(keycode==0x1C) enter();
- else if(keycode==0x39) space();
- else
- {
- char c=charcode[keycode];
- if(c!=' ')
- {
- if(lshift)
- {
- if(c>='a'&&c<='z') c-=32;
- }
- if(lctrl)
- {
- if(c=='l')
- {
- clear();
- prompt();
- return;
- }
- }
- buffer[buffer_index++]=c;
- printf("%c",c);
- }
- }
- }
- else
- {
- ispressed[keycode-0x80]=0;
- }
-
- }
-}