Skip to content

Commit

Permalink
Shift and arrow key handling fixed
Browse files Browse the repository at this point in the history
Ix can now perform shift properly and navigate with arrow keys
Side effects:
* I broke caps lock
* While both the normal arrow keys and the numpad arrow keys work properly, so do a large number of things that are not arrow keys, because the keymap is full of lies
* For some reason, the arrow keys are 'sticky': you often have to press them several times even in nav mode.
  • Loading branch information
enkiv2 committed Jul 13, 2011
1 parent 9e8415e commit ad718e6
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 44 deletions.
1 change: 1 addition & 0 deletions include/kb.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
void handle_kb();

#ifndef kb_c
extern unsigned char* kbcmd_trans;
extern char kb_buf;
extern char kb_cmd;
#endif // not kb.c
Expand Down
86 changes: 49 additions & 37 deletions src/kb.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
/* bkerndev - Bran's Kernel Development Tutorial
* By: Brandon F. ([email protected])
* Desc: Keyboard driver
*
* Notes: No warranty expressed or implied. Use at own risk. */
#include <system.h>
#define kb_c
#include "kb.h"

/* KBDUS means US Keyboard Layout. This is a scancode table
* used to layout a standard US keyboard. I have left some
* comments in to give you an idea of what key is what, even
* though I set it's array index to 0. You can change that to
* whatever you want using a macro, if you wish! */
unsigned char kbdus[128] = {
unsigned char kbdus_qwerty[128] = {
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
'9', '0', '-', '=', '\b', /* Backspace */
'\t', /* Tab */
Expand Down Expand Up @@ -40,7 +30,7 @@ unsigned char kbdus[128] = {
0,
0, /* Right Arrow */
'+',
79, /* 79 - End key*/
0, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
Expand All @@ -50,6 +40,45 @@ unsigned char kbdus[128] = {
0, /* F12 Key */
0, /* All other keys are undefined */
};
unsigned char kbdus_qwerty_shifted[128] = {
0, 27, '!', '@', '#', '$', '%', '^', '&', '*', /* 9 */
'(', ')', '_', '+', '\b', /* Backspace */
'\t', /* Tab */
'Q', 'W', 'E', 'R', /* 19 */
'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', '\n', /* Enter key */
0, /* 29 - Control */
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* 39 */
'\"', '~', 0,
'|', 'Z', 'X', 'C', 'V', 'B', 'N', /* 49 */
'M', ',', '.', '?', 0, /* Right shift */
'*',
0, /* Alt */
' ', /* Space bar */
0, /* Caps lock */
0, /* 59 - F1 key ... > */
0, 0, 0, 0, 0, 0, 0, 0,
0, /* < ... F10 */
0, /* 69 - Num lock*/
0, /* Scroll Lock */
0, /* Home key */
0, /* Up Arrow */
0, /* Page Up */
'-',
0, /* Left Arrow */
0,
0, /* Right Arrow */
'+',
79, /* 79 - End key*/
0, /* Down Arrow */
0, /* Page Down */
0, /* Insert Key */
0, /* Delete Key */
0, 0, 0,
0, /* F11 Key */
0, /* F12 Key */
0, /* All other keys are undefined */
};
unsigned char* kbcmd_trans = "w00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00sw00a0d00s";

/* Handles the keyboard interrupt */
void keyboard_handler(struct regs *r) {
Expand All @@ -60,38 +89,21 @@ void keyboard_handler(struct regs *r) {
scancode = inportb(0x60);
kb_cmd=scancode;

/* If the top bit of the byte we read from the keyboard is
* set, that means that a key has just been released */
if (scancode & 0x80) {
/* You can use this one to see if the user released the
* shift, alt, or control keys... */
scancode &= 0x7f; // clear the top bit
if (!(scancode & 0x80)) {
//scancode &= 0x7f; // clear the top bit
if (scancode==42 || scancode==54) { // shifts
if(!(mode&3)) { // capslock
mode|=1;
}
mode|=1;
} else if(scancode==58) { // capslock
if(mode&3) {
mode^=3;
} else {
mode|=3;
}
}
} else {
/* Here, a key was just pressed. Please note that if you
* hold a key down, you will get repeated key press
* interrupts. */
if(scancode==42 || scancode==54) { // shifts
if(!(mode&3)) {
mode^=1;
}
}
kb_buf=kbdus[scancode];
if(mode&1) {
if(kb_buf>='a' && kb_buf<='z') {
kb_buf=(kb_buf-'a')+'A';
}
if(!(mode&2)) mode^=1; // turn off caps
} else if(mode&1) {
kb_buf=kbdus_qwerty_shifted[scancode];
/*if(!(mode&3)) */ mode&=0xfe; // turn off caps
} else {
kb_buf=kbdus_qwerty[scancode];
}
}
request_atomicity(0);
Expand Down
1 change: 1 addition & 0 deletions src/vga.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const char* editpane(int x, int y, int width, int height, char* text, int maxlen
if(kb_buf==27) return text; // ESC
if(kb_buf=='\b') {
text[strlen(text)-1]=0;
kb_buf=0;
} else if(strlen(text)<(maxlen-2)) {
text[strlen(text)+1]='\0';
text[strlen(text)]=kb_buf;
Expand Down
26 changes: 19 additions & 7 deletions src/zz.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ const void nav_cells(int pid) { //@ handle navigation, display, and editing
if (zz_mode==zz_delay_mode && kb_buf)
zz_mode=zz_display_mode;
if(zz_mode == zz_display_mode) {
if (kb_cmd > 65) { // translate arrow keys to wasd
kb_buf=kbcmd_trans[kb_cmd];
}
if (kb_buf) cls();
switch(kb_buf) {
case 'i':
Expand Down Expand Up @@ -239,6 +242,7 @@ const void nav_cells(int pid) { //@ handle navigation, display, and editing
if(zz_mode==zz_display_mode) display_cells(); // hack
} else {
if(zz_mode==zz_edit_mode) {
if(kb_cmd > 65) kb_buf=kbcmd_trans[kb_buf];
if(kb_buf) cls();
switch(kb_buf) {
case 'w':
Expand Down Expand Up @@ -323,13 +327,17 @@ const void nav_cells(int pid) { //@ handle navigation, display, and editing
forelink=0;
} else if(kb_buf=='a') {
dimlink=dimx;
forelink=0;
forelink=0;
} else if(kb_buf=='s') {
dimlink=dimy;
dimlink=dimy;
forelink=1;
} else if(kb_buf=='d') {
dimlink=dimx;
forelink=1;
}
} else {
kb_buf=0;
yield();
}
locate(0, 1);
currcell_old=currcell;
currcell=maxcell;
Expand Down Expand Up @@ -438,11 +446,15 @@ const inline void relink() {
} else if(kb_buf=='d') {
dimlink=dimx;
forelink=1;
} else {
zz_mode=zz_edit_mode;
}
if(zz_mode!=zz_edit_mode) {
locate(0, 1);
puts("Good! Now, navigate to the cell you want to link to and press 'm' to mark it.");
currcell_old = currcell;
modality=0;
}
locate(0, 1);
puts("Good! Now, navigate to the cell you want to link to and press 'm' to mark it.");
currcell_old = currcell;
modality=0;
}
}
}
Expand Down

0 comments on commit ad718e6

Please sign in to comment.