diff options
author | Niklas Halle <niklas@niklashalle.net> | 2020-05-05 16:58:03 +0200 |
---|---|---|
committer | Niklas Halle <niklas@niklashalle.net> | 2020-05-05 16:58:03 +0200 |
commit | 88d3bc5df1933b2753f33e5436b49e37a193abe1 (patch) | |
tree | e40357ebf0ae1e86d1604d9533e9e53a3628b108 /01_exercise | |
parent | 247a79f26485eaa062f1cdd4545a3bfe6cd6ca81 (diff) | |
download | betriebssysteme-88d3bc5df1933b2753f33e5436b49e37a193abe1.tar.gz betriebssysteme-88d3bc5df1933b2753f33e5436b49e37a193abe1.zip |
getc now waits for keys
Diffstat (limited to '01_exercise')
-rw-r--r-- | 01_exercise/bootloader.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/01_exercise/bootloader.c b/01_exercise/bootloader.c index e891116..bc7d807 100644 --- a/01_exercise/bootloader.c +++ b/01_exercise/bootloader.c @@ -6,7 +6,7 @@ asm(".code16gcc\njmp $0, $main"); char WRITE_CHARACTER_TTY = 0x0E; // Syscall found here http://www.ctyme.com/intr/rb-0106.htm -void put(char c) { +void putc(char c) { short command = WRITE_CHARACTER_TTY << 8 | c; // volatile because there is no output, so the function might get optimized // away @@ -20,16 +20,29 @@ void put(char c) { void print(char const *const str) { for (int i = 0; str[i] != '\0'; ++i) { - put(str[i]); + putc(str[i]); } } // Syscall found here http://www.ctyme.com/intr/rb-1754.htm char getc() { char ret; - asm("mov $0x00, %%ah;" + asm volatile( + ".no_key:" + "xor %%ax, %%ax;" + "mov $0x0100, %%ax;" // check for keystroke: + "int $0x16;" // http://www.ctyme.com/intr/rb-1755.htm + "jz .no_key;" // wait for a key + ".done:" + "xor %%ax, %%ax;" + "mov $0x1000, %%ax;" // get keystroke: http://www.ctyme.com/intr/rb-1754.htm "int $0x16;" - : "=a"(ret)); + "mov %%al, %%bl;" // temp store char in bl + "mov $0400, %%ax;" // clear keyboard buffer: + "int $0x16;" // http://www.ctyme.com/intr/rb-1759.htm + : "=b"(ret) + : + : "ax"); return ret; } @@ -49,4 +62,7 @@ void sleep(short ms) { void main(void) { print("Hello!"); print("\n\r > "); + while (1) { + putc(getc()); + } }
\ No newline at end of file |