more insight gained on how quick the pit timer moves for checking recent keypresses
This commit is contained in:
parent
43a653ec8a
commit
771536c427
3
kbd.c
3
kbd.c
@ -59,8 +59,9 @@ void kbd_read_key(struct cpu_reg_state* cpu) {
|
|||||||
// Key pressed
|
// Key pressed
|
||||||
kbd_key = keymap[scancode & 0x7f]; // clamp to 127 as the max val(gcc is anoying)
|
kbd_key = keymap[scancode & 0x7f]; // clamp to 127 as the max val(gcc is anoying)
|
||||||
kbd_state = kbd_state & !KBD_RELEASE & KBD_PRESS;
|
kbd_state = kbd_state & !KBD_RELEASE & KBD_PRESS;
|
||||||
|
//printf("@");printhex(pit_timer_ticks);
|
||||||
|
//printf("diff:"); printhex(pit_timer_ticks - kbd_time);
|
||||||
kbd_time = pit_timer_ticks;
|
kbd_time = pit_timer_ticks;
|
||||||
putch(kbd_key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
stlio.c
28
stlio.c
@ -1,9 +1,11 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "kbd.h"
|
#include "kbd.h"
|
||||||
#include "stlio.h"
|
#include "stlio.h"
|
||||||
|
#include "pit.h"
|
||||||
|
|
||||||
|
extern char kbd_key;
|
||||||
|
extern u8 kbd_state;
|
||||||
|
|
||||||
extern char kbd_prev_key;
|
|
||||||
extern int kbd_prev_active;
|
|
||||||
static u8 COLOR_FG = Green;
|
static u8 COLOR_FG = Green;
|
||||||
static u8 COLOR_BG = White;
|
static u8 COLOR_BG = White;
|
||||||
|
|
||||||
@ -37,23 +39,17 @@ u32 write(const char* buffer, const u32 size) {
|
|||||||
u32 read(char* buffer, u32 size) {
|
u32 read(char* buffer, u32 size) {
|
||||||
// Read up to size-1 characters or until a \n is written
|
// 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
|
// once we reacch size -1 bytes read then we change the last char to a \0
|
||||||
kbd_prev_active = false; // we only do this to discard the leftovers from
|
u32 bytes = 0;
|
||||||
u32 bytes_read = 0;
|
while(bytes < size - 1) {
|
||||||
|
// was this key pressed recently?
|
||||||
while(bytes_read < size-1) {
|
if(pit_timer_ticks - kbd_time < 200) {
|
||||||
if(kbd_prev_active) {
|
buffer[bytes] = kbd_key;
|
||||||
bytes_read++;
|
|
||||||
if(kbd_prev_key == '\n') {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
buffer[bytes_read] = kbd_prev_key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
printf("You entered: "); printf(buffer);
|
buffer[size - 1] = '\0';
|
||||||
return bytes_read;
|
return bytes + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void printf(const char* fmt) {
|
void printf(const char* fmt) {
|
||||||
// Variadic fuller version of print on seperate branch but its nowhere near stable/ready/working
|
// Variadic fuller version of print on seperate branch but its nowhere near stable/ready/working
|
||||||
u32 size = strlen(fmt);
|
u32 size = strlen(fmt);
|
||||||
|
Loading…
Reference in New Issue
Block a user