diff options
| -rw-r--r-- | asm/int_syscall_handler.asm | 13 | ||||
| -rw-r--r-- | kernel/kernel.c | 1 | ||||
| -rw-r--r-- | kernel/kernel.h | 2 | ||||
| -rw-r--r-- | kernel/syscalls.c | 39 | ||||
| -rw-r--r-- | kernel/syscalls.h | 2 | ||||
| -rw-r--r-- | terminal/terminal.c | 13 | ||||
| -rw-r--r-- | terminal/terminal.h | 4 | ||||
| -rw-r--r-- | userspace/snake.c | 16 | ||||
| -rw-r--r-- | userspace/sys/libfool.a | bin | 35776 -> 37292 bytes | |||
| -rw-r--r-- | userspace/sys/syscalls.c | 12 | ||||
| -rw-r--r-- | userspace/sys/syscalls.o | bin | 17092 -> 18572 bytes |
11 files changed, 94 insertions, 8 deletions
diff --git a/asm/int_syscall_handler.asm b/asm/int_syscall_handler.asm index 70090f0..619ef84 100644 --- a/asm/int_syscall_handler.asm +++ b/asm/int_syscall_handler.asm @@ -18,6 +18,8 @@ global int_syscall_handler [extern syscall_stat] [extern syscall_lstat] [extern syscall_fork] +[extern syscall_has_data_waiting] +[extern syscall_tune] [extern syscall_unhandled] [bits 32] @@ -78,6 +80,11 @@ je call_wait cmp eax, 79 je call_lstat + cmp eax, 80 + je call_has_data + + cmp eax, 81 + je call_tune push eax jmp call_unhandled @@ -208,6 +215,12 @@ call_sbrk: call syscall_sbrk jmp done +call_has_data: + call syscall_has_data_waiting + jmp done +call_tune: + call syscall_tune + jmp done call_unhandled: call syscall_unhandled diff --git a/kernel/kernel.c b/kernel/kernel.c index 6937031..d54baf6 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -75,6 +75,7 @@ static void init_stdio() input.put_char=stdin_put_char; tty1=terminal_init(&screen,&input); + get_fool()->tty=&tty1; get_fool()->std_out.data=&tty1; get_fool()->std_out.put=terminal_put; diff --git a/kernel/kernel.h b/kernel/kernel.h index 2929a28..757c3bf 100644 --- a/kernel/kernel.h +++ b/kernel/kernel.h @@ -4,12 +4,14 @@ #define KERNEL_VERSION "FoolOs 0.2.1" #include "fifo.h" +#include "terminal/terminal.h" typedef struct fool_os_struct { fifo std_in; fifo std_out; + terminal_tty* tty; }fool_os; diff --git a/kernel/syscalls.c b/kernel/syscalls.c index f5169e7..c935ecd 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -87,6 +87,45 @@ int syscall_readdir(const char *name,fs_dirent *dirs,int max) return fs_readdir(name,dirs,max); } +// for non blocking io? +int syscall_has_data_waiting(int file) +{ + + #ifdef LOG_SYSCALLS + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"has data waiting?"); + #endif + + return fifo_has(&get_fool()->std_in); +} + +int syscall_tune(int v1,int v2, int v3) +{ + + + #ifdef LOG_SYSCALLS + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"tuning request"); + #endif + + + if(v1==0) // regular tty mode + { + get_fool()->tty->set_buff=true; + get_fool()->tty->set_echo=true; + } + if(v1==1) // gaming tty mode + { + get_fool()->tty->set_buff=false; + get_fool()->tty->set_echo=false; + } + + + return 0; +} + + + + + int copy_args(char **in, char **out) { log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"copy_args(0x%08x, 0x%08X)",in,out); diff --git a/kernel/syscalls.h b/kernel/syscalls.h index ff7c2e5..5c7a772 100644 --- a/kernel/syscalls.h +++ b/kernel/syscalls.h @@ -6,6 +6,8 @@ //fool-os syscalls #define SYSCALL_READDIR 63 +#define SYSCALL_HAS_DATA 80 +#define SYSCALL_TUNE 81 //syscalls required by newlib #define SYSCALL_EXIT 60 diff --git a/terminal/terminal.c b/terminal/terminal.c index 7fc6f93..ccea64e 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -8,9 +8,6 @@ #include "kernel/kmalloc.h" #include "driver/screen.h" -#define SET_LFNL true -#define SET_BUFF false -#define SET_ECHO true typedef enum { @@ -238,6 +235,10 @@ terminal_tty terminal_init(term_out *screen,term_in *input) tty.data=kballoc(2); + tty.set_buff=true; + tty.set_lfnl=true; + tty.set_echo=true; + tty.command=kballoc(1); tty.command_l=0; @@ -262,9 +263,9 @@ terminal_tty terminal_init(term_out *screen,term_in *input) void terminal_kb(terminal_tty *tty, uint8_t c) { - if(SET_ECHO)terminal_put(tty,c); + if(tty->set_echo)terminal_put(tty,c); - if(SET_BUFF) + if(tty->set_buff) { tty->command[tty->command_l]=c; (tty->command_l)++; @@ -328,7 +329,7 @@ bool terminal_put(terminal_tty *tty, uint8_t c) set_char(tty,x,tty->y,' ',tty->fg,tty->bg); } tty->y++; - if(SET_LFNL)tty->x=0; + if(tty->set_lfnl)tty->x=0; } else // { diff --git a/terminal/terminal.h b/terminal/terminal.h index e97a413..5e97cc1 100644 --- a/terminal/terminal.h +++ b/terminal/terminal.h @@ -48,6 +48,10 @@ typedef struct terminal_tty_struct uint8_t fg; uint8_t bg; + bool set_buff; + bool set_lfnl; + bool set_echo; + uint32_t width; uint32_t height; uint32_t x; diff --git a/userspace/snake.c b/userspace/snake.c index aedf191..8352d1b 100644 --- a/userspace/snake.c +++ b/userspace/snake.c @@ -3,11 +3,23 @@ int main() { printf("Hello I am FoolSnake 0.1\n"); - printf("setvbuf returned %i",setvbuf(stdin,NULL,_IONBF,0)); + printf("setvbuf returned %i\n",setvbuf(stdin,NULL,_IONBF,0)); + + fool_tune(1,0,0); // activate gaming mode while(1) { - printf("%c",fgetc(stdin)); + while(!has_data_waiting()) + { + + } + + char c=fgetc(stdin); + printf("[%c]\n",c); + if(c=='q')break; + } + + fool_tune(0,0,0); // de-activate gaming mode } diff --git a/userspace/sys/libfool.a b/userspace/sys/libfool.a Binary files differindex 7c47ee4..81a4f16 100644 --- a/userspace/sys/libfool.a +++ b/userspace/sys/libfool.a diff --git a/userspace/sys/syscalls.c b/userspace/sys/syscalls.c index 9dfd313..4b29451 100644 --- a/userspace/sys/syscalls.c +++ b/userspace/sys/syscalls.c @@ -35,6 +35,18 @@ int readdir(const char *name,fs_dirent *dirs,int max) return syscall(SYSCALL_READDIR,name,dirs,max); } +int has_data_waiting() +{ + + return syscall(SYSCALL_HAS_DATA,0,0,0); +} + +int fool_tune(int v1, int v2, int v3) +{ + + return syscall(SYSCALL_TUNE,v1,v2,v3); +} + void _exit(int ret) { _exit2(ret,environ); diff --git a/userspace/sys/syscalls.o b/userspace/sys/syscalls.o Binary files differindex 2176036..f8fd94b 100644 --- a/userspace/sys/syscalls.o +++ b/userspace/sys/syscalls.o |
