From a061366ff25f9bb32ccafb87cdb17a05421ab30d Mon Sep 17 00:00:00 2001 From: Garritt McCune Date: Sun, 11 Nov 2018 16:31:41 -0600 Subject: [PATCH] Added support for the shift key in the keyboard driver. --- .gitignore | 3 ++- build-number.txt | 1 + buildnumber.mak | 11 +++++++++++ include/system.h | 3 ++- src/kb.c | 20 ++++++++++++++++++-- src/main.c | 4 ++-- 6 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 build-number.txt create mode 100644 buildnumber.mak diff --git a/.gitignore b/.gitignore index a079651..f854b0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ obj/ -iso/ \ No newline at end of file +iso/ +kernel.iso \ No newline at end of file diff --git a/build-number.txt b/build-number.txt new file mode 100644 index 0000000..00750ed --- /dev/null +++ b/build-number.txt @@ -0,0 +1 @@ +3 diff --git a/buildnumber.mak b/buildnumber.mak new file mode 100644 index 0000000..6f78504 --- /dev/null +++ b/buildnumber.mak @@ -0,0 +1,11 @@ +# Create an auto-incrementing build number. + +BUILD_NUMBER_LDFLAGS = --defsym __BUILD_DATE=$$(date +'%Y%m%d') +BUILD_NUMBER_LDFLAGS += --defsym __BUILD_NUMBER=$$(cat $(BUILD_NUMBER_FILE)) + +# Build number file. Increment if any object file changes. +$(BUILD_NUMBER_FILE): $(OBJECTS) + if ! test -f build-number.txt; then echo 0 > build-number.txt; fi + echo $(($(cat build-number.txt) + 1)) > build-number.txt + echo __BUILD_DATE + echo __BUILD_NUMBER \ No newline at end of file diff --git a/include/system.h b/include/system.h index 0e513f9..41f87a4 100644 --- a/include/system.h +++ b/include/system.h @@ -1,6 +1,7 @@ #ifndef __SYSTEM_H #define __SYSTEM_H - +/* Primitives */ +typedef enum { false, true } bool; /* MAIN.C */ extern unsigned char *memcpy(unsigned char *dest, const unsigned char *src, int count); extern unsigned char *memset(unsigned char *dest, unsigned char val, int count); diff --git a/src/kb.c b/src/kb.c index f9fd7a8..eae88cb 100644 --- a/src/kb.c +++ b/src/kb.c @@ -44,6 +44,9 @@ unsigned char kbdus[128] = 0, /* F12 Key */ 0, /* All other keys are undefined */ }; + +bool shift = false; + /* Handles the keyboard interrupt */ void keyboard_handler(struct regs *r) { @@ -58,13 +61,21 @@ void keyboard_handler(struct regs *r) { /* You can use this one to see if the user released the * shift, alt, or control keys... */ + if(scancode == 0xAA || scancode == 0xB6) + { + shift = false; + } } 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 == 0x2A || scancode == 0x36) + { + shift = true; + return; + } /* Just to show you how this works, we simply translate * the keyboard scancode into an ASCII value, and then * display it to the screen. You can get creative and @@ -73,7 +84,12 @@ void keyboard_handler(struct regs *r) * to the above layout to correspond to 'shift' being * held. If shift is held using the larger lookup table, * you would add 128 to the scancode when you look for it */ - putch(kbdus[scancode]); + unsigned char* letter = kbdus[scancode]; + if(shift) + { + letter = letter - 32; + } + putch(letter); } } diff --git a/src/main.c b/src/main.c index cf42942..a16f1fb 100644 --- a/src/main.c +++ b/src/main.c @@ -63,8 +63,8 @@ void outportb (unsigned short _port, unsigned char _data) __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data)); } -extern char __BUILD_DATE; -extern char __BUILD_NUMBER; +//extern char __BUILD_DATE; +//extern char __BUILD_NUMBER; /* This is a very simple main() function. All it does is sit in an * infinite loop. This will be like our 'idle' loop */