diff options
Diffstat (limited to 'include/06.keyboard')
| -rw-r--r-- | include/06.keyboard/keyboard00.c | 3 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard01.c | 7 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard02.c | 7 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard03.c | 6 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard04.c | 6 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard05.c | 5 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard06.c | 6 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard07.c | 8 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard08.c | 18 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard09.c | 5 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard10.c | 11 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard11.c | 11 | ||||
| -rw-r--r-- | include/06.keyboard/keyboard12.c | 48 |
13 files changed, 141 insertions, 0 deletions
diff --git a/include/06.keyboard/keyboard00.c b/include/06.keyboard/keyboard00.c new file mode 100644 index 0000000..13fd550 --- /dev/null +++ b/include/06.keyboard/keyboard00.c @@ -0,0 +1,3 @@ +#include<types.h> +#include<asm.h> +#include<stdio.h> diff --git a/include/06.keyboard/keyboard01.c b/include/06.keyboard/keyboard01.c new file mode 100644 index 0000000..50d7c07 --- /dev/null +++ b/include/06.keyboard/keyboard01.c @@ -0,0 +1,7 @@ +#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; diff --git a/include/06.keyboard/keyboard02.c b/include/06.keyboard/keyboard02.c new file mode 100644 index 0000000..239c874 --- /dev/null +++ b/include/06.keyboard/keyboard02.c @@ -0,0 +1,7 @@ +#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 diff --git a/include/06.keyboard/keyboard03.c b/include/06.keyboard/keyboard03.c new file mode 100644 index 0000000..3322fd7 --- /dev/null +++ b/include/06.keyboard/keyboard03.c @@ -0,0 +1,6 @@ +void previous_field(void); +void tty(char *buffer); +void prompt(void); +void clear(); +void us_en(char keymap[]); +void us_en_shift(char keymap[]); diff --git a/include/06.keyboard/keyboard04.c b/include/06.keyboard/keyboard04.c new file mode 100644 index 0000000..cc6e7d5 --- /dev/null +++ b/include/06.keyboard/keyboard04.c @@ -0,0 +1,6 @@ +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/keyboard05.c b/include/06.keyboard/keyboard05.c new file mode 100644 index 0000000..5c089ce --- /dev/null +++ b/include/06.keyboard/keyboard05.c @@ -0,0 +1,5 @@ +void init_keyboard() +{ + us_en(charcode); + us_en_shift(shift_charcode); +} diff --git a/include/06.keyboard/keyboard06.c b/include/06.keyboard/keyboard06.c new file mode 100644 index 0000000..55e04b8 --- /dev/null +++ b/include/06.keyboard/keyboard06.c @@ -0,0 +1,6 @@ +void deletelast() +{ + previous_field(); + printf(" "); + previous_field(); +} diff --git a/include/06.keyboard/keyboard07.c b/include/06.keyboard/keyboard07.c new file mode 100644 index 0000000..480abb1 --- /dev/null +++ b/include/06.keyboard/keyboard07.c @@ -0,0 +1,8 @@ +void backspace() +{ + if(buffer_index<=0) return; + + deletelast(); + buffer[buffer_current][--buffer_index]='\0'; + return; +} diff --git a/include/06.keyboard/keyboard08.c b/include/06.keyboard/keyboard08.c new file mode 100644 index 0000000..822e038 --- /dev/null +++ b/include/06.keyboard/keyboard08.c @@ -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/keyboard09.c new file mode 100644 index 0000000..33bc64b --- /dev/null +++ b/include/06.keyboard/keyboard09.c @@ -0,0 +1,5 @@ +void space() +{ + buffer[buffer_current][buffer_index++]=' '; + printf(" "); +} diff --git a/include/06.keyboard/keyboard10.c b/include/06.keyboard/keyboard10.c new file mode 100644 index 0000000..5c6d048 --- /dev/null +++ b/include/06.keyboard/keyboard10.c @@ -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/keyboard11.c b/include/06.keyboard/keyboard11.c new file mode 100644 index 0000000..50841fa --- /dev/null +++ b/include/06.keyboard/keyboard11.c @@ -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/keyboard12.c b/include/06.keyboard/keyboard12.c new file mode 100644 index 0000000..a0a8a0f --- /dev/null +++ b/include/06.keyboard/keyboard12.c @@ -0,0 +1,48 @@ +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; + } + } +} |
