diff --git a/stlio.c b/stlio.c index 63ca3d6..5bc95aa 100644 --- a/stlio.c +++ b/stlio.c @@ -36,18 +36,30 @@ u32 write(const char* buffer, const u32 size) { return i; } +// this is here to get around gcc's optimizations +static void __kbd_state(u8* dest, u8 desire) { + *dest = desire; +} + u32 read(char* buffer, u32 size) { - // Read up to size-1 characters or until a \n is written - // once we reacch size -1 bytes read then we change the last char to a \0 + // try the timing thing again after this u32 bytes = 0; - while(bytes < size - 1) { - // was this key pressed recently? - if(pit_timer_ticks - kbd_time < 200) { - buffer[bytes] = kbd_key; + u8 state = 0; + + while(bytes < size) { + //if(pit_timer_ticks - kbd_time < 0x20) { + + __kbd_state(&state, kbd_state); + if(pit_timer_ticks - kbd_time < 0x20 && state == KBD_RELEASE) { + __kbd_state(&buffer[bytes], (u8)kbd_key); + bytes++; + __kbd_state(&kbd_state, KBD_WAITING); // reset the kbd_state since we've now used it + putch(kbd_key); } + pit_timer_wait(1); } - buffer[size - 1] = '\0'; - return bytes + 1; + buffer[size-1] = '\0'; + return bytes; } void printf(const char* fmt) { @@ -68,6 +80,7 @@ void printhex(u32 num) { const char _chars[] = "0123456789abcdef"; u32 idx = 0; // used as hash into the _chars mapping // iterate over each nibble + printf("0x"); for(u32 i = 0 ;i < 8;i++) { idx = (num << (i * 4)) & 0xf0000000; idx = idx >> 28;