From bfce52a11a5ee7441b9486d40da9975e1e2f343e Mon Sep 17 00:00:00 2001 From: shockrah Date: Thu, 5 Dec 2019 01:38:57 -0800 Subject: [PATCH] renamed a __kbd_state to __char_set and added note about gcc bs'ery --- stlio.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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);