diff --git a/stlio.c b/stlio.c index 5bc95aa..59f14d9 100644 --- a/stlio.c +++ b/stlio.c @@ -37,7 +37,7 @@ u32 write(const char* buffer, const u32 size) { } // this is here to get around gcc's optimizations -static void __kbd_state(u8* dest, u8 desire) { +static void __char_set(u8* dest, u8 desire) { *dest = desire; } @@ -47,13 +47,15 @@ u32 read(char* buffer, u32 size) { u8 state = 0; while(bytes < size) { - //if(pit_timer_ticks - kbd_time < 0x20) { - - __kbd_state(&state, kbd_state); + // All of these calls to __char_set is to avoid gcc from optimizing things away and ruining intended behavior + // Basically gcc will tread all assignments here as one time deals so we have to cram that operation into a routine + // by itself, that way the compiler won't try to optimize and do the assignment once. instead it does the call + // every iteration + __char_set(&state, kbd_state); if(pit_timer_ticks - kbd_time < 0x20 && state == KBD_RELEASE) { - __kbd_state(&buffer[bytes], (u8)kbd_key); + __char_set(&(buffer[bytes]), (u8)kbd_key); bytes++; - __kbd_state(&kbd_state, KBD_WAITING); // reset the kbd_state since we've now used it + __char_set(&kbd_state, KBD_WAITING); // reset the kbd_state since we've now used it putch(kbd_key); } pit_timer_wait(1);