read() now reads the proper amount of data into our buffer as it should

This commit is contained in:
shockrah 2019-12-05 01:31:33 -08:00
parent 1af2fd3c52
commit 8296abd54b

31
stlio.c
View File

@ -36,18 +36,30 @@ u32 write(const char* buffer, const u32 size) {
return i;
}
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
u32 bytes = 0;
while(bytes < size - 1) {
// was this key pressed recently?
if(pit_timer_ticks - kbd_time < 200) {
buffer[bytes] = kbd_key;
// 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) {
// try the timing thing again after this
u32 bytes = 0;
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;
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;