read() now reads the proper amount of data into our buffer as it should
This commit is contained in:
parent
1af2fd3c52
commit
8296abd54b
29
stlio.c
29
stlio.c
@ -36,18 +36,30 @@ u32 write(const char* buffer, const u32 size) {
|
|||||||
return i;
|
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) {
|
u32 read(char* buffer, u32 size) {
|
||||||
// Read up to size-1 characters or until a \n is written
|
// try the timing thing again after this
|
||||||
// once we reacch size -1 bytes read then we change the last char to a \0
|
|
||||||
u32 bytes = 0;
|
u32 bytes = 0;
|
||||||
while(bytes < size - 1) {
|
u8 state = 0;
|
||||||
// was this key pressed recently?
|
|
||||||
if(pit_timer_ticks - kbd_time < 200) {
|
while(bytes < size) {
|
||||||
buffer[bytes] = kbd_key;
|
//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';
|
buffer[size-1] = '\0';
|
||||||
return bytes + 1;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printf(const char* fmt) {
|
void printf(const char* fmt) {
|
||||||
@ -68,6 +80,7 @@ void printhex(u32 num) {
|
|||||||
const char _chars[] = "0123456789abcdef";
|
const char _chars[] = "0123456789abcdef";
|
||||||
u32 idx = 0; // used as hash into the _chars mapping
|
u32 idx = 0; // used as hash into the _chars mapping
|
||||||
// iterate over each nibble
|
// iterate over each nibble
|
||||||
|
printf("0x");
|
||||||
for(u32 i = 0 ;i < 8;i++) {
|
for(u32 i = 0 ;i < 8;i++) {
|
||||||
idx = (num << (i * 4)) & 0xf0000000;
|
idx = (num << (i * 4)) & 0xf0000000;
|
||||||
idx = idx >> 28;
|
idx = idx >> 28;
|
||||||
|
Loading…
Reference in New Issue
Block a user