aboutsummaryrefslogtreecommitdiff
path: root/include/06.keyboard
diff options
context:
space:
mode:
authorAleksa Vučković <aleksav013@gmail.com>2022-01-10 22:15:15 +0100
committerAleksa Vučković <aleksav013@gmail.com>2022-01-10 22:43:56 +0100
commit0bff8199e4a800d5ea1bd422dcf06643d6daf008 (patch)
tree15108a0073d66afc026c0a2225474c2d61e71b34 /include/06.keyboard
parent97d99fa196d4b732cfd6635dcb8b0a9c9228c88d (diff)
include/setup.sh
Diffstat (limited to 'include/06.keyboard')
-rw-r--r--include/06.keyboard/deo1 (renamed from include/06.keyboard/keyboard00.c)0
-rw-r--r--include/06.keyboard/deo1018
-rw-r--r--include/06.keyboard/deo11 (renamed from include/06.keyboard/keyboard09.c)0
-rw-r--r--include/06.keyboard/deo1211
-rw-r--r--include/06.keyboard/deo1311
-rw-r--r--include/06.keyboard/deo143
-rw-r--r--include/06.keyboard/deo153
-rw-r--r--include/06.keyboard/deo164
-rw-r--r--include/06.keyboard/deo178
-rw-r--r--include/06.keyboard/deo1823
-rw-r--r--include/06.keyboard/deo1922
-rw-r--r--include/06.keyboard/deo2 (renamed from include/06.keyboard/keyboard01.c)0
-rw-r--r--include/06.keyboard/deo207
-rw-r--r--include/06.keyboard/deo3 (renamed from include/06.keyboard/keyboard02.c)0
-rw-r--r--include/06.keyboard/deo4 (renamed from include/06.keyboard/keyboard03.c)0
-rw-r--r--include/06.keyboard/deo57
-rw-r--r--include/06.keyboard/deo6 (renamed from include/06.keyboard/keyboard05.c)0
-rw-r--r--include/06.keyboard/deo7 (renamed from include/06.keyboard/keyboard06.c)0
-rw-r--r--include/06.keyboard/deo83
-rw-r--r--include/06.keyboard/deo9 (renamed from include/06.keyboard/keyboard07.c)4
-rw-r--r--include/06.keyboard/keyboard.c182
-rw-r--r--include/06.keyboard/keyboard04.c6
-rw-r--r--include/06.keyboard/keyboard08.c18
-rw-r--r--include/06.keyboard/keyboard10.c11
-rw-r--r--include/06.keyboard/keyboard11.c11
-rw-r--r--include/06.keyboard/keyboard12.c48
26 files changed, 302 insertions, 98 deletions
diff --git a/include/06.keyboard/keyboard00.c b/include/06.keyboard/deo1
index 13fd550..13fd550 100644
--- a/include/06.keyboard/keyboard00.c
+++ b/include/06.keyboard/deo1
diff --git a/include/06.keyboard/deo10 b/include/06.keyboard/deo10
new file mode 100644
index 0000000..e5d558c
--- /dev/null
+++ b/include/06.keyboard/deo10
@@ -0,0 +1,18 @@
+void enter()
+{
+ printf("\n");
+ if(buffer_index>0)
+ {
+ tty(buffer[buffer_current]);
+ buffer_size[buffer_current]=buffer_index;
+ if(buffer_current==buffer_all) buffer_current=(++buffer_all);
+ else
+ {
+ for(size_t i=0;i<BUFFER_SIZE;i++) buffer[buffer_all][i]='\0';
+ buffer_current=buffer_all;
+ }
+ buffer_index=0;
+ }
+ prompt();
+ return;
+}
diff --git a/include/06.keyboard/keyboard09.c b/include/06.keyboard/deo11
index 33bc64b..33bc64b 100644
--- a/include/06.keyboard/keyboard09.c
+++ b/include/06.keyboard/deo11
diff --git a/include/06.keyboard/deo12 b/include/06.keyboard/deo12
new file mode 100644
index 0000000..b40c42b
--- /dev/null
+++ b/include/06.keyboard/deo12
@@ -0,0 +1,11 @@
+void keyup()
+{
+ if(buffer_current>0)
+ {
+ buffer_size[buffer_current]=buffer_index;
+ for(size_t i=0;i<buffer_index;i++) deletelast();
+ buffer_current--;
+ buffer_index=buffer_size[buffer_current];
+ printf("%s",buffer[buffer_current]);
+ }
+}
diff --git a/include/06.keyboard/deo13 b/include/06.keyboard/deo13
new file mode 100644
index 0000000..87b6e42
--- /dev/null
+++ b/include/06.keyboard/deo13
@@ -0,0 +1,11 @@
+void keydown()
+{
+ if(buffer_current<buffer_all)
+ {
+ buffer_size[buffer_current]=buffer_index;
+ for(size_t i=0;i<buffer_index;i++) deletelast();
+ buffer_current++;
+ buffer_index=buffer_size[buffer_current];
+ printf("%s",buffer[buffer_current]);
+ }
+}
diff --git a/include/06.keyboard/deo14 b/include/06.keyboard/deo14
new file mode 100644
index 0000000..15df074
--- /dev/null
+++ b/include/06.keyboard/deo14
@@ -0,0 +1,3 @@
+void keyleft()
+{
+}
diff --git a/include/06.keyboard/deo15 b/include/06.keyboard/deo15
new file mode 100644
index 0000000..c7fca4c
--- /dev/null
+++ b/include/06.keyboard/deo15
@@ -0,0 +1,3 @@
+void keyright()
+{
+}
diff --git a/include/06.keyboard/deo16 b/include/06.keyboard/deo16
new file mode 100644
index 0000000..a55e9c2
--- /dev/null
+++ b/include/06.keyboard/deo16
@@ -0,0 +1,4 @@
+void keyboard_handler()
+{
+ ioport_out(PIC1_COMMAND_PORT, 0x20);
+ uint8_t status = ioport_in(KEYBOARD_STATUS_PORT);
diff --git a/include/06.keyboard/deo17 b/include/06.keyboard/deo17
new file mode 100644
index 0000000..ded0af2
--- /dev/null
+++ b/include/06.keyboard/deo17
@@ -0,0 +1,8 @@
+ if (status & 0x1)
+ {
+ uint8_t keycode = ioport_in(KEYBOARD_DATA_PORT);
+ if(keycode<0x80)
+ {
+ char c=charcode[keycode];
+ ispressed[keycode]=1;
+ // printf("%d ",&keycode);
diff --git a/include/06.keyboard/deo18 b/include/06.keyboard/deo18
new file mode 100644
index 0000000..04688a9
--- /dev/null
+++ b/include/06.keyboard/deo18
@@ -0,0 +1,23 @@
+ switch(keycode)
+ {
+ case 0x0E:
+ backspace();
+ break;
+ case 0x1C:
+ enter();
+ break;
+ case 0x39:
+ space();
+ break;
+ case 72:
+ keyup();
+ break;
+ case 80:
+ keydown();
+ break;
+ case 75:
+ keyleft();
+ break;
+ case 77:
+ keyright();
+ break;
diff --git a/include/06.keyboard/deo19 b/include/06.keyboard/deo19
new file mode 100644
index 0000000..359ba30
--- /dev/null
+++ b/include/06.keyboard/deo19
@@ -0,0 +1,22 @@
+ default:
+ if(c!=' ')
+ {
+ if(ispressed[lctrl]||ispressed[rctrl])
+ {
+ if(c=='l')
+ {
+ clear();
+ prompt();
+ printf("%s",buffer[buffer_current]);
+ return;
+ }
+ }
+ if(ispressed[lshift]||ispressed[rshift])
+ {
+ c=shift_charcode[keycode];
+ }
+ buffer[buffer_current][buffer_index++]=c;
+ printf("%c",c);
+ }
+ break;
+ }
diff --git a/include/06.keyboard/keyboard01.c b/include/06.keyboard/deo2
index 50d7c07..50d7c07 100644
--- a/include/06.keyboard/keyboard01.c
+++ b/include/06.keyboard/deo2
diff --git a/include/06.keyboard/deo20 b/include/06.keyboard/deo20
new file mode 100644
index 0000000..d594130
--- /dev/null
+++ b/include/06.keyboard/deo20
@@ -0,0 +1,7 @@
+ }
+ else
+ {
+ ispressed[keycode-0x80]=0;
+ }
+ }
+}
diff --git a/include/06.keyboard/keyboard02.c b/include/06.keyboard/deo3
index 239c874..239c874 100644
--- a/include/06.keyboard/keyboard02.c
+++ b/include/06.keyboard/deo3
diff --git a/include/06.keyboard/keyboard03.c b/include/06.keyboard/deo4
index 3322fd7..3322fd7 100644
--- a/include/06.keyboard/keyboard03.c
+++ b/include/06.keyboard/deo4
diff --git a/include/06.keyboard/deo5 b/include/06.keyboard/deo5
new file mode 100644
index 0000000..57028c5
--- /dev/null
+++ b/include/06.keyboard/deo5
@@ -0,0 +1,7 @@
+char charcode[256];
+char shift_charcode[256];
+bool ispressed[128];
+#define lshift 0x2A
+#define rshift 0x36
+#define lctrl 0x1D
+#define rctrl 0x1D
diff --git a/include/06.keyboard/keyboard05.c b/include/06.keyboard/deo6
index 5c089ce..5c089ce 100644
--- a/include/06.keyboard/keyboard05.c
+++ b/include/06.keyboard/deo6
diff --git a/include/06.keyboard/keyboard06.c b/include/06.keyboard/deo7
index 55e04b8..55e04b8 100644
--- a/include/06.keyboard/keyboard06.c
+++ b/include/06.keyboard/deo7
diff --git a/include/06.keyboard/deo8 b/include/06.keyboard/deo8
new file mode 100644
index 0000000..95a5ac5
--- /dev/null
+++ b/include/06.keyboard/deo8
@@ -0,0 +1,3 @@
+void backspace()
+{
+ if(buffer_index<=0) return;
diff --git a/include/06.keyboard/keyboard07.c b/include/06.keyboard/deo9
index 480abb1..bc07378 100644
--- a/include/06.keyboard/keyboard07.c
+++ b/include/06.keyboard/deo9
@@ -1,7 +1,3 @@
-void backspace()
-{
- if(buffer_index<=0) return;
-
deletelast();
buffer[buffer_current][--buffer_index]='\0';
return;
diff --git a/include/06.keyboard/keyboard.c b/include/06.keyboard/keyboard.c
new file mode 100644
index 0000000..2218f09
--- /dev/null
+++ b/include/06.keyboard/keyboard.c
@@ -0,0 +1,182 @@
+#include<types.h>
+#include<asm.h>
+#include<stdio.h>
+
+#define BUFFER_SIZE 200
+#define BUFFER_LOG 200
+char buffer[BUFFER_LOG][BUFFER_SIZE];
+size_t buffer_size[BUFFER_LOG];
+size_t buffer_current=0;
+size_t buffer_all=0;
+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 tty(char *buffer);
+void prompt(void);
+void clear();
+void us_en(char keymap[]);
+void us_en_shift(char keymap[]);
+
+char charcode[256];
+char shift_charcode[256];
+bool ispressed[128];
+#define lshift 0x2A
+#define rshift 0x36
+#define lctrl 0x1D
+#define rctrl 0x1D
+
+void init_keyboard()
+{
+ us_en(charcode);
+ us_en_shift(shift_charcode);
+}
+
+void deletelast()
+{
+ previous_field();
+ printf(" ");
+ previous_field();
+}
+
+void backspace()
+{
+ if(buffer_index<=0) return;
+
+ deletelast();
+ buffer[buffer_current][--buffer_index]='\0';
+ return;
+}
+
+void enter()
+{
+ printf("\n");
+ if(buffer_index>0)
+ {
+ tty(buffer[buffer_current]);
+ buffer_size[buffer_current]=buffer_index;
+ if(buffer_current==buffer_all) buffer_current=(++buffer_all);
+ else
+ {
+ for(size_t i=0;i<BUFFER_SIZE;i++) buffer[buffer_all][i]='\0';
+ buffer_current=buffer_all;
+ }
+ buffer_index=0;
+ }
+ prompt();
+ return;
+}
+
+void space()
+{
+ buffer[buffer_current][buffer_index++]=' ';
+ printf(" ");
+}
+
+void keyup()
+{
+ if(buffer_current>0)
+ {
+ buffer_size[buffer_current]=buffer_index;
+ for(size_t i=0;i<buffer_index;i++) deletelast();
+ buffer_current--;
+ buffer_index=buffer_size[buffer_current];
+ printf("%s",buffer[buffer_current]);
+ }
+}
+
+void keydown()
+{
+ if(buffer_current<buffer_all)
+ {
+ buffer_size[buffer_current]=buffer_index;
+ for(size_t i=0;i<buffer_index;i++) deletelast();
+ buffer_current++;
+ buffer_index=buffer_size[buffer_current];
+ printf("%s",buffer[buffer_current]);
+ }
+}
+
+void keyleft()
+{
+}
+
+void keyright()
+{
+}
+
+void keyboard_handler()
+{
+ 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)
+ {
+ char c=charcode[keycode];
+ ispressed[keycode]=1;
+ // printf("%d ",&keycode);
+
+ switch(keycode)
+ {
+ case 0x0E:
+ backspace();
+ break;
+ case 0x1C:
+ enter();
+ break;
+ case 0x39:
+ space();
+ break;
+ case 72:
+ keyup();
+ break;
+ case 80:
+ keydown();
+ break;
+ case 75:
+ keyleft();
+ break;
+ case 77:
+ keyright();
+ break;
+
+ default:
+ if(c!=' ')
+ {
+ if(ispressed[lctrl]||ispressed[rctrl])
+ {
+ if(c=='l')
+ {
+ clear();
+ prompt();
+ printf("%s",buffer[buffer_current]);
+ return;
+ }
+ }
+ if(ispressed[lshift]||ispressed[rshift])
+ {
+ c=shift_charcode[keycode];
+ }
+ buffer[buffer_current][buffer_index++]=c;
+ printf("%c",c);
+ }
+ break;
+ }
+
+ }
+ else
+ {
+ ispressed[keycode-0x80]=0;
+ }
+ }
+}
diff --git a/include/06.keyboard/keyboard04.c b/include/06.keyboard/keyboard04.c
deleted file mode 100644
index cc6e7d5..0000000
--- a/include/06.keyboard/keyboard04.c
+++ /dev/null
@@ -1,6 +0,0 @@
-char charcode[256];
-char shift_charcode[256];
-bool ispressed[128];
-#define lshift ispressed[0x2A]
-#define rshift ispressed[0x36]
-#define lctrl ispressed[0x1D]
diff --git a/include/06.keyboard/keyboard08.c b/include/06.keyboard/keyboard08.c
deleted file mode 100644
index 822e038..0000000
--- a/include/06.keyboard/keyboard08.c
+++ /dev/null
@@ -1,18 +0,0 @@
-void enter()
-{
- printf("\n");
- if(buffer_index>0)
- {
- tty(buffer[buffer_current]);
- buffer_size[buffer_current]=buffer_index;
- if(buffer_current==buffer_all) buffer_current=(++buffer_all);
- else
- {
- for(size_t i=0;i<BUFFER_SIZE;i++) buffer[buffer_all][i]='\0';
- buffer_current=buffer_all;
- }
- buffer_index=0;
- }
- prompt();
- return;
-}
diff --git a/include/06.keyboard/keyboard10.c b/include/06.keyboard/keyboard10.c
deleted file mode 100644
index 5c6d048..0000000
--- a/include/06.keyboard/keyboard10.c
+++ /dev/null
@@ -1,11 +0,0 @@
-void keyup()
-{
- if(buffer_current>0)
- {
- buffer_size[buffer_current]=buffer_index;
- for(size_t i=0;i<buffer_index;i++) deletelast();
- buffer_current--;
- buffer_index=buffer_size[buffer_current];
- printf("%s",buffer[buffer_current]);
- }
-}
diff --git a/include/06.keyboard/keyboard11.c b/include/06.keyboard/keyboard11.c
deleted file mode 100644
index 50841fa..0000000
--- a/include/06.keyboard/keyboard11.c
+++ /dev/null
@@ -1,11 +0,0 @@
-void keydown()
-{
- if(buffer_current<buffer_all)
- {
- buffer_size[buffer_current]=buffer_index;
- for(size_t i=0;i<buffer_index;i++) deletelast();
- buffer_current++;
- buffer_index=buffer_size[buffer_current];
- printf("%s",buffer[buffer_current]);
- }
-}
diff --git a/include/06.keyboard/keyboard12.c b/include/06.keyboard/keyboard12.c
deleted file mode 100644
index a0a8a0f..0000000
--- a/include/06.keyboard/keyboard12.c
+++ /dev/null
@@ -1,48 +0,0 @@
-void keyboard_handler()
-{
- 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 if(keycode==72) keyup();
- else if(keycode==80) keydown();
- else if(keycode==75) keyleft();
- else if(keycode==77) keyright();
- else
- {
- char c=charcode[keycode];
- if(c!=' ')
- {
- if(lctrl)
- {
- if(c=='l')
- {
- clear();
- prompt();
- printf("%s",buffer[buffer_current]);
- return;
- }
- }
- if(lshift||rshift)
- {
- c=shift_charcode[keycode];
- }
- buffer[buffer_current][buffer_index++]=c;
- printf("%c",c);
- }
- }
- }
- else
- {
- ispressed[keycode-0x80]=0;
- }
- }
-}