diff options
| -rw-r--r-- | README.md | 15 | ||||
| -rw-r--r-- | driver/keyboard.c | 56 | ||||
| -rw-r--r-- | fs/fd.c | 8 | ||||
| -rw-r--r-- | fs/fifo.c | 4 | ||||
| -rw-r--r-- | fs/fifo.h | 2 | ||||
| -rw-r--r-- | fs/stdstreams.c | 1 | ||||
| -rw-r--r-- | kernel/apic.c | 2 | ||||
| -rw-r--r-- | kernel/interrupts.c | 1 | ||||
| -rw-r--r-- | kernel/scheduler.c | 9 | ||||
| -rw-r--r-- | kernel/syscalls.c | 161 | ||||
| -rw-r--r-- | kernel/syscalls.h | 6 | ||||
| -rw-r--r-- | packages/ncurses-6.1/foolterm.ti | 102 | ||||
| -rw-r--r-- | userspace/Makefile | 8 | ||||
| -rw-r--r-- | userspace/fsh.c | 12 | ||||
| -rw-r--r-- | userspace/init.c | 15 | ||||
| -rw-r--r-- | userspace/ncurses/Makefile | 4 | ||||
| -rw-r--r-- | userspace/ncurses/foolstart.c | 149 | ||||
| -rw-r--r-- | userspace/ncurses/ncurs.c | 5 | ||||
| -rw-r--r-- | userspace/newcalls.h | 30 | ||||
| -rw-r--r-- | userspace/pain1.c | 1 | ||||
| -rw-r--r-- | userspace/pain2.c | 1 | ||||
| -rw-r--r-- | userspace/pain3.c | 1 | ||||
| -rw-r--r-- | userspace/put_pixel.h | 2 | ||||
| -rw-r--r-- | userspace/snake2.c | 1 | ||||
| -rw-r--r-- | userspace/threading.c | 1 | ||||
| -rw-r--r-- | userspace/xterm/terminal.c | 69 | ||||
| -rw-r--r-- | userspace/xterm/vesa.c | 1 | ||||
| -rw-r--r-- | userspace/xterm/xterm.c | 7 | ||||
| -rw-r--r-- | xxx/packages/ncurses-5.9/foolterm.ti | 77 |
29 files changed, 566 insertions, 185 deletions
@@ -89,11 +89,15 @@ FoolOS was/is tested/developed on the following emulators/machines Todos ----- +Autobuild via Jenkins (sanbboxed?) +streamline: binutils,gcc,newlib,ncurses,ncurses-examples.vim building +mesa3d, quake,doom, netwookring tcp/ip + * PRIO: ringbuffers (spinlock on/off, interrupts on/off, read/write blocks of data); * PRIO: Writing to ext2 RAM-image!!!! * PRIO: Fix scheduler. use all cpus! / accounting/bookkeppiung x86: tsc /rdtscp? / load bareer / queues? * PRIO: gcc toolchain -* PRIO: /dev/tty +* PRIO: /dev/tty / function and arrow keys * PRIO: semaphores/ mutexes * PRIO: return value / argv / env @@ -122,6 +126,9 @@ Todos * EXTRA: Crazy & Funny terminal effects while typing (idea) * EXTRA: port to arm and berryboot / minicom? * EXTRA: port doom/quake/mesa 3d +* EXTRA: ghc cross compiler / ghc port +* EXTRA: piper-os +* EXTRE: matrix desgin. star wars terminal etc.. 1.GCC & Binutils @@ -150,9 +157,15 @@ Todos * ncurses: ../ncurses-6.1/configure --host=i686-foolos --without-tests --with-fallbacks="fool-term" --with-debug --prefix=/usr --with-termlib + + ../ncurses-6.1/configure --host=i686-foolos --with-fallbacks="fool-term" --prefix=/usr + * ncurses-examples: ../ncurses-examples-20180127/configure --host=i686-foolos --prefix=/usr --with-ncurses make DESTDIR=/home/miguel/temp/foolos/ install + * vim: + vim_cv_memcpy_handles_overlap=no vim_cv_bcopy_handles_overlap=no vim_cv_memmove_handles_overlap=no vim_cv_stat_ignores_slash=no vim_cv_getcwd_broken=no vim_cv_tty_group=world vim_cv_tty_mode=0620 vim_cv_tgetent=zero vim_cv_terminfo=no vim_cv_toupper_broken=no ./configure --host=i686-foolos --prefix=/usr --with-tlib=tinfo + Disclaimer ========== diff --git a/driver/keyboard.c b/driver/keyboard.c index 87cd7d7..b333b78 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -24,7 +24,6 @@ int hex_to_dec(char c) { if(c>='0'&&c<='9')return c-'0'; return c+10-'a'; - } extern struct netdev e1000_dev; @@ -50,7 +49,6 @@ bool keyboard_worker() return wake; } - void keyboard_init() { kb_in=ringbuffer_init(1);// 4096 bytes ringbuffer; @@ -59,6 +57,52 @@ void keyboard_init() void keyboard_handle(uint8_t in) { + static bool last_e0=false; + + if(last_e0) + { + last_e0=false; + if(in==0x50)//down + { + x86_cli(); + put(27); + put('v'); + x86_sti(); + } + if(in==0x4b)//left + { + x86_cli(); + put(27); + put('<'); + x86_sti(); + } + if(in==0x4d)//right + { + x86_cli(); + put(27); + put('>'); + x86_sti(); + } + if(in==0x48)//up + { + x86_cli(); + put(27); + put('a'); + x86_sti(); + } + + + + return; + } + + if(in==0xe0) + { + last_e0=true; + return; + } + + last_e0=false; // klog("kb_in 0x%x",in); uint8_t make_alpha[]={ 0x1e, // A @@ -132,7 +176,7 @@ void keyboard_handle(uint8_t in) 0x8a, // 9 }; - +// http://stanislavs.org/helppc/make_codes.html uint8_t break_key_enter=0x9c; uint8_t break_key_space=0xb9; uint8_t break_key_backspace=0x8e; @@ -210,6 +254,12 @@ void keyboard_handle(uint8_t in) if(shift_l||shift_r||capslock) ascii='_'; match=true; } + else if(in==0xa7) + { + ascii=';'; + if(shift_l||shift_r||capslock) ascii=':'; + match=true; + } else if(in==0x9A) { ascii='['; @@ -246,6 +246,8 @@ int fds_from_pipe(fd pipefds[2]) mem+=4; *mem=1; + read.can_write=0; + read.read=pipe_get; wrt.read=0; @@ -312,6 +314,11 @@ fd fd_from_sysfs(void(*g)(ringbuffer *r,void (*f)(ringbuffer *r,char *fmt, ...)) return f; } +bool fifo_can_write(fifo *f) +{ + return !(f->full(f->data)); +} + fd fd_from_fifo(fifo* fif) { fd f; @@ -323,5 +330,6 @@ fd fd_from_fifo(fifo* fif) f.has=fifo_has; f.dupl=default_dupl; f.close=default_close; + f.can_write=fifo_can_write; return f; } @@ -14,3 +14,7 @@ bool fifo_has(fifo* f) { return f->has(f->data); } +bool fifo_full(fifo* f) +{ + return f->full(f->data); +} @@ -11,6 +11,7 @@ typedef struct fifo_struct bool (*put)(struct fifo_struct*,uint8_t); uint8_t (*get)(struct fifo_struct*); bool (*has)(struct fifo_struct*); + bool (*full)(struct fifo_struct*); void *data; // opaque data }fifo; @@ -18,6 +19,7 @@ typedef struct fifo_struct bool fifo_put(fifo*,uint8_t); uint8_t fifo_get(fifo*); bool fifo_has(fifo*); +bool fifo_full(fifo*); fifo fifo_create_buffered(uint8_t size); #endif diff --git a/fs/stdstreams.c b/fs/stdstreams.c index 1cb9402..e5a2a08 100644 --- a/fs/stdstreams.c +++ b/fs/stdstreams.c @@ -52,5 +52,6 @@ fd fd_from_ringbuffer() f->put=ringbuffer_put; f->get=ringbuffer_get; f->has=ringbuffer_has; + f->full=ringbuffer_full; return fd_from_fifo(f); } diff --git a/kernel/apic.c b/kernel/apic.c index 509fd3b..9dc774f 100644 --- a/kernel/apic.c +++ b/kernel/apic.c @@ -157,7 +157,7 @@ void ioapic_config() // ioapic_config_entry(2,0x90|0xa000,0x3<<24); // level trigger on low // CPU -// ioapic_config_entry(2, INTERRUPT_PIT_TIMER, 0x0<<24); // pit + ioapic_config_entry(2, INTERRUPT_PIT_TIMER, 0x0<<24); // pit ioapic_config_entry(1, INTERRUPT_KEYBOARD, 0x0<<24); // kb ioapic_config_entry(12, INTERRUPT_MOUSE, 0x0<<24); // mouse ioapic_config_entry(11, INTERRUPT_E1000|0x8000, 0x0<<24); // e1000 (level trigger on high) diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 2ab1490..61a03e2 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -81,6 +81,7 @@ uint32_t interrupt_handler(uint32_t esp, uint32_t irq) if(cpu==0) { compositor_wake2(); + scheduler_wake_all(); scheduler_wake_worker(esp); } } diff --git a/kernel/scheduler.c b/kernel/scheduler.c index bddd705..2112659 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -417,6 +417,7 @@ void task_syscall_worker() } } +// !!! REMEMBER THIS IS INSIDE AN INTERRUPT !!! volatile uint32_t task_syscall(uint32_t eax,uint32_t ebx, uint32_t ecx, uint32_t edx) { if(eax==2)while(1); @@ -427,6 +428,14 @@ volatile uint32_t task_syscall(uint32_t eax,uint32_t ebx, uint32_t ecx, uint32_t task_list[cpu][current_task[cpu]].ebx=ebx; task_list[cpu][current_task[cpu]].ecx=ecx; task_list[cpu][current_task[cpu]].edx=edx; + + // chance for some preparations // + int i=current_task[cpu]; + syscall_generic_prep(task_list[cpu][i].eax, + task_list[cpu][i].edx, + task_list[cpu][i].ecx, + task_list[cpu][i].ebx, + task_list[cpu][i].pid); return 1; } diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 507be13..228b70a 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -24,6 +24,7 @@ #include "errno.h" #include "compositor.h" #include "stdstreams.h" +#include "sys/unistd.h" #define MAX_PID 200 @@ -65,58 +66,60 @@ char* syscall_get_name(uint32_t num) { switch(num) { - case 60: + case SYSCALL_EXIT: return "SYSCALL_EXIT"; - case 66: + case SYSCALL_CLOSE: return "SYSCALL_CLOSE"; - case 64: + case SYSCALL_EXECVE: return "SYSCALL_EXECVE"; - case 72: + case SYSCALL_FORK: return "SYSCALL_FORK"; - case 78: + case SYSCALL_GETPID: return "SYSCALL_GETPID"; - case 68: + case SYSCALL_ISATTY: return "SYSCALL_ISATTY"; - case 82: + case SYSCALL_LINK: return "SYSCALL_LINK"; - case 69: + case SYSCALL_LSEEK: return "SYSCALL_LSEEK"; - case 65: + case SYSCALL_OPEN: return "SYSCALL_OPEN"; - case 62: + case SYSCALL_READ: return "SYSCALL_READ"; - case 70: + case SYSCALL_SBRK: return "SYSCALL_SBRK"; - case 74: + case SYSCALL_STAT: return "SYSCALL_STAT"; - case 67: + case SYSCALL_FSTAT: return "SYSCALL_FSTAT"; - case 79: + case SYSCALL_LSTAT: return "SYSCALL_LSTAT"; - case 75: + case SYSCALL_TIMES: return "SYSCALL_TIMES"; - case 76: + case SYSCALL_UNLINK: return "SYSCALL_UNLINK"; - case 77: + case SYSCALL_WAIT: return "SYSCALL_WAIT"; - case 61: + case SYSCALL_WRITE: return "SYSCALL_WRITE"; - case 71: + case SYSCALL_GETTIMEOFDAY: return "SYSCALL_GETTIMEOFDAY"; - case 63: + case SYSCALL_READDIR: return "SYSCALL_READDIR"; - case 73: + case SYSCALL_KILL: return "SYSCALL_KILL"; - case 80: + case SYSCALL_CLONE: return "SYSCALL_CLONE"; - case 84: + case SYSCALL_PIPE: return "SYSCALL_PIPE"; - case 86: + case SYSCALL_DUP2: return "SYSCALL_DUP2"; - case 87: + case SYSCALL_GUI_RECT: return "SYSCALL_GUI_RECT"; - case 88: + case SYSCALL_GUI_WIN: return "SYSCALL_GUI_WIN"; + case SYSCALL_SELECT: + return "SYSCALL_SELECT"; } kpanic("UNKNOWN SYSCALL NUM"); } @@ -142,16 +145,6 @@ int syscall_gettimeofday(struct timeval *tv, struct timezone *tz,uint32_t none1, int syscall_lseek(int file,int ptr,int dir,uint32_t pid) { -#ifndef SEEK_SET -#define SEEK_SET 0 /* set file offset to offset */ -#endif -#ifndef SEEK_CUR -#define SEEK_CUR 1 /* set file offset to current plus offset */ -#endif -#ifndef SEEK_END -#define SEEK_END 2 /* set file offset to EOF plus offset */ -#endif - if(dir==SEEK_CUR) { uint32_t *dat=fds[pid][file].data; @@ -187,6 +180,71 @@ int syscall_read(int file, char *buf, int len,uint32_t pid) return 1; } +int syscall_select(int maxxfd,struct timeval *tv, fd_set **fd_sets, uint32_t pid, bool test) +{ + int ret=0; + + // TODO: wake when timeout runs out! + + if(!test) + { + if(tv==NULL)klog("select with infinite timeout"); + else klog ("select with timeout: sec=%d, usec=%d",tv->tv_sec,tv->tv_usec); + } + + for(int i=0;i<maxxfd;i++) + { + if(FD_ISSET(i,fd_sets[0])) + { + // klog("%d in readfds",i); + if(fd_has(&fds[pid][i])||fd_eof(&fds[pid][i])) + { + ret++; + } + else + { + if(!test)FD_CLR(i,fd_sets[0]); + } + } + if(FD_ISSET(i,fd_sets[1])) + { +// klog("%d in writefds",i); + + if(fd_can_write(&fds[pid][i])) + { + ret++; + } + else + { + if(!test)FD_CLR(i,fd_sets[1]); + } + } + + if(FD_ISSET(i,fd_sets[2])) + { + // klog("%d in exceptfds",i); // TODO! + } + } + + if(!test)FD_ZERO(fd_sets[2]); // we dont give a shit about exceptions! :P TODO!!! + + if(test&&ret==0&&tv!=NULL) // check if time did not run out already + { + uint64_t t=timer_get_ms(); // current time in milliseconds (10^-3) + + uint64_t t0=0; + t0+=tv->tv_sec*1000; // seconds * 10^3 + t0+=tv->tv_usec/1000; // microseconds * 10^-3 + + if(t>t0)return 1; // ready to fire! + } + + return ret; + + + +} + //TODO: replace with dirent! int syscall_readdir(const char *name,fs_dirent *dirs,int *pos,uint32_t pid) { @@ -404,6 +462,8 @@ uint32_t syscall_pipe(uint32_t *addr,int none1, int none2, uint32_t pid) uint32_t syscall_dup2(uint32_t oldfd,int newfd, int none2, uint32_t pid) { + if(newfd==0xffffffff)klog("dup mode not supported yet !!!"); + fds[pid][newfd]=fd_dupl(&fds[pid][oldfd]); return newfd; } @@ -424,6 +484,31 @@ uint32_t syscall_gui_win(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) } /** Generics */ +uint32_t syscall_generic_prep(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) +{ + struct timeval *tv=p2; + + switch(nr){ + case SYSCALL_SELECT : + + // change to absolute time for easier timout + if(tv!=NULL) + { + uint64_t t=timer_get_ms(); // current time in milliseconds (10^-3) + t+=tv->tv_sec*1000; // seconds * 10^3 + t+=tv->tv_usec/1000; // microseconds * 10^-3 + + tv->tv_sec=t/1000; + tv->tv_usec=(t%1000)*1000; + + } + + break; + } + return 1; +} + +/** Generics */ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid) { switch(nr){ @@ -433,6 +518,8 @@ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, return fd_has(&fds[pid][p1])||fd_eof(&fds[pid][p1]); case SYSCALL_WRITE : return fd_can_write(&fds[pid][p1]); + case SYSCALL_SELECT : + return syscall_select(p1,p2,p3,pid,true); } return 1;//other syscalls never block for now. @@ -495,6 +582,8 @@ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint return syscall_pipe(p1,p2,p3,pid); case SYSCALL_DUP2 : return syscall_dup2(p1,p2,p3,pid); + case SYSCALL_SELECT : + return syscall_select(p1,p2,p3,pid,false); case SYSCALL_GUI_RECT : return syscall_gui_rect(p1,p2,p3,pid); case SYSCALL_GUI_WIN : diff --git a/kernel/syscalls.h b/kernel/syscalls.h index 5579dd7..d3223a5 100644 --- a/kernel/syscalls.h +++ b/kernel/syscalls.h @@ -16,6 +16,8 @@ #include <stdbool.h> #include "fd.h" +#include "/home/miguel/Downloads/newlib-foolos/newlib/libc/sys/foolos/syscalls.h" +/* #define SYSCALL_EXIT 60 #define SYSCALL_EXECVE 64 #define SYSCALL_FORK 72 @@ -45,6 +47,7 @@ #define SYSCALL_GUI_RECT 87 #define SYSCALL_GUI_WIN 88 +*/ /** Todo move somewhere else and init per process , think how to make thread safe */ void fd_init_std_streams(uint32_t pid); @@ -59,6 +62,9 @@ uint32_t syscall_generic(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint /** test if a specific syscall is ready to be processed */ uint32_t syscall_generic_test(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid); +/** prepare syscall */ +uint32_t syscall_generic_prep(uint32_t nr,uint32_t p1, uint32_t p2, uint32_t p3, uint32_t pid); + // new planned syscalls for graphx // TODO: split ncurses and our syscalls?? diff --git a/packages/ncurses-6.1/foolterm.ti b/packages/ncurses-6.1/foolterm.ti new file mode 100644 index 0000000..acef9ad --- /dev/null +++ b/packages/ncurses-6.1/foolterm.ti @@ -0,0 +1,102 @@ +# https://en.wikipedia.org/wiki/ANSI_escape_code +# FoolOS built-in terminal emulator +# check "man 5 terminfo" to understand this file + +fool-term|FoolOS built-in terminal emulator, + +# automargins + am, +# erased with background color + bce, +# can erase overstrikes with blanks + eo, +# safe to move in insert mode + mir, +# safe to move in standout mode + msgr, + +# xenl, xon, + +# size + cols#80, lines#24, + +# max colors and colorpairs + colors#8, + pairs#64, + +# tabwidth + it#8, + +# this could hold an alterntive table paiting method +# acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260i\316j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376, + + clear=\Ec, cr=\015, + +# movement +# + home=\EH, + + cub1=\Eb, + cud1=\Ed, + cuf1=\Ef, + cuu1=\Eu, + + +# cursor position %i increases so it is 1 based +# %p1%d pushes row and prints as int +# %p2%d pushes col and prints as int + cup=\E[%i%p1%d;%p2%dH, + +# cup=\EY%p1%' '%+%c%p2%' '%+%c, + +# clear to end of screen / line + ed=\EJ, + el=\EK, + +# delchar + dch1=\Ex, + +# backspace + kbs=\010, + +# tab + ht=\011, + +# newline + nel=\012, + +# scrolling (down,reverse) + ind=\ED, + ri=\EM, + +# keys + kcub1=\E<, kcud1=\Ev, + kcuf1=\E>, kcuu1=\Ea, + +# function keys (todo: kb driver..) +## kf1=\E[[A, +## kf10=\E[21~, +## kf11=\E[23~, +## kf12=\E[24~, +### kf13=\E[25~, +### kf14=\E[26~, +### kf15=\E[28~, +### kf16=\E[29~, +### kf17=\E[31~, +### kf18=\E[32~, +### kf19=\E[33~, +## kf2=\E[[B, +### kf20=\E[34~, +## kf3=\E[[C, +## kf4=\E[[D, +## kf5=\E[[E, +## kf6=\E[17~, +## kf7=\E[18~, +## kf8=\E[19~, +## kf9=\E[20~, + +#colors + setab=\E[4%p1%dm, + setaf=\E[3%p1%dm, + oc=\E[37;40m, + diff --git a/userspace/Makefile b/userspace/Makefile index dc5509c..94d35c4 100644 --- a/userspace/Makefile +++ b/userspace/Makefile @@ -52,11 +52,15 @@ ext2.img: $(PROGS) @mkdir -p mnt/sys # mountpoint for sysfs @mkdir -p mnt/pipes # mountpoint for pipes @cp $(PROGS) mnt/bin + @cp /home/miguel/git/EXT/vim/src/vim mnt/bin @cp fonts/binfont.bin mnt/doc/fonts @cp xterm/xterm mnt/bin @cp cpp/testcpp mnt/bin - @cp ncurses/ncurs mnt/bin - @cp /home/miguel/temp/foolos/usr/bin/* mnt/bin + @cp ncurses/foolstart mnt/bin +# @cp /home/miguel/temp/foolos/usr/bin/* mnt/bin + @cp /home/miguel/temp/foolos/usr/bin/worm mnt/bin + @cp /home/miguel/temp/foolos/usr/bin/xmas mnt/bin + @cp /home/miguel/temp/foolos/usr/bin/tput mnt/bin # cp ~/temp/fool-os-stuff/binutils-build-host-foolos/binutils/readelf mnt/bin # cp ../font/binfont.bin mnt/ diff --git a/userspace/fsh.c b/userspace/fsh.c index 0b3acfd..d74d9d5 100644 --- a/userspace/fsh.c +++ b/userspace/fsh.c @@ -21,7 +21,6 @@ #include <string.h> #include "interface/fs.h" -#include "newcalls.h" extern char **environ; @@ -230,8 +229,12 @@ bool process(char *buf) else // otherwise treat command as exectutable and send to execve { - int pid=_fork(); + int last=0; + for(last=0;token[last+1]!=NULL;last++); + bool branch=!strcmp(token[last],"&"); + if(branch)token[last]=NULL; + int pid=_fork(); if(pid==0) { @@ -242,10 +245,9 @@ bool process(char *buf) exit(1); } - int last=0; - for(last=0;token[last+1]!=NULL;last++); + //printf("last: %s\n",token[last]); - if(strcmp(token[last],"&"))_wait(pid); + if(!branch)_wait(pid); } return true; diff --git a/userspace/init.c b/userspace/init.c index 57809a6..5dfd55d 100644 --- a/userspace/init.c +++ b/userspace/init.c @@ -1,15 +1,13 @@ -#include <stdio.h> -#include <time.h> -#include "put_pixel.h" -#include "newcalls.h" +char *argv1[]={"xterm","/bin/foolstart",0}; +char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; int main(int argc, char **argv) { - char *argv1[]={"xterm","/bin/fsh",0}; - char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; - - _execve("/bin/xterm",argv1,env1); + _execve("/bin/xterm",argv1,env1); + while(1); // never reached hopefully +} + /* int pid=_fork(); if(pid==0) @@ -74,3 +72,4 @@ int main(int argc, char **argv) return 0; } + */ diff --git a/userspace/ncurses/Makefile b/userspace/ncurses/Makefile index 22bae34..5fa350f 100644 --- a/userspace/ncurses/Makefile +++ b/userspace/ncurses/Makefile @@ -7,7 +7,7 @@ CFLAGS+=-g #LDLIBS=-lncurses -lform -lmenu -lpanel -ltinfo LDLIBS=-lncurses -ltinfo -ncurs: +foolstart: clean: - rm -f *.o ncurs + rm -f *.o ncurs foolstart diff --git a/userspace/ncurses/foolstart.c b/userspace/ncurses/foolstart.c new file mode 100644 index 0000000..0b795aa --- /dev/null +++ b/userspace/ncurses/foolstart.c @@ -0,0 +1,149 @@ +#include <ncurses.h> + +// http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/printw.html + +#include <stdio.h> +#include <ncurses.h> + +#define WIDTH 50 +#define HEIGHT 20 + +int startx = 0; +int starty = 0; + + +/* + COLOR_BLACK 0 + COLOR_RED 1 + COLOR_GREEN 2 + COLOR_YELLOW 3 + COLOR_BLUE 4 + COLOR_MAGENTA 5 + COLOR_CYAN 6 + COLOR_WHITE 7 + */ + +char *choices[] = { + "Choice 1", + "Choice 2", + "Choice 3", + "Choice 4", + "Exit", + }; + + +int n_choices = sizeof(choices) / sizeof(char *); +void print_menu(WINDOW *menu_win, int highlight); + +int main() +{ WINDOW *menu_win; + int highlight = 1; + int choice = 0; + int c; + + initscr(); + clear(); + noecho(); + cbreak(); /* Line buffering disabled. pass on everything */ + + startx = (80 - WIDTH) / 2; + starty = (24 - HEIGHT) / 2; + + start_color(); /* Start color */ + init_pair(1, COLOR_BLACK, COLOR_WHITE); + init_pair(2, COLOR_WHITE, COLOR_BLUE); + + menu_win = newwin(HEIGHT, WIDTH, starty, startx); + wbkgd(menu_win, COLOR_PAIR(2)); + + keypad(menu_win, TRUE); + + /* + nodelay(menu_win,FALSE); + notimeout(menu_win,FALSE); + wtimeout(menu_win,-1); + */ + + mvprintw(0, 0, "Use W/S/A/D to go up and down, Press enter to select a choice"); + refresh(); + print_menu(menu_win, highlight); + while(1) + { + choice=0; + int y=0; + while(1) + { c = wgetch(menu_win); + mvprintw(y++,0, "%3d / '%c'", c, c); + y%=24; + + refresh(); + switch(c) + { case 'w': + case KEY_UP: + + if(highlight == 1) + highlight = n_choices; + else + --highlight; + break; + + case 's': + case KEY_DOWN: + + if(highlight == n_choices) + highlight = 1; + else + ++highlight; + break; + + case 10: + + choice = highlight; + break; + } + print_menu(menu_win, highlight); + if(choice != 0) /* User did a choice come out of the infinite loop */ + break; + } + mvprintw(23, 0, "You chose choice %d with choice string %s\n", choice, choices[choice - 1]); + + char *argv1[]={"xterm","/bin/fsh",0}; + char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0}; + + + int pid=_fork(); + + if(pid==0) + { + _execve("/bin/xterm",argv1,env1); + } +} + + clrtoeol(); + refresh(); + endwin(); + return 0; +} + + +void print_menu(WINDOW *menu_win, int highlight) +{ + int x, y, i; + + x = 2; + y = 2; + + box(menu_win, 0, 0); + + for(i = 0; i < n_choices; ++i) + { if(highlight == i + 1) /* High light the present choice */ + { wattron(menu_win, COLOR_PAIR(1)); + mvwprintw(menu_win, y, x, ">> %40s <<", choices[i]); + wattroff(menu_win, COLOR_PAIR(1)); + } + else + mvwprintw(menu_win, y, x, " %40s ", choices[i]); + ++y; + } + wrefresh(menu_win); +} diff --git a/userspace/ncurses/ncurs.c b/userspace/ncurses/ncurs.c index 26068fa..88b6e09 100644 --- a/userspace/ncurses/ncurs.c +++ b/userspace/ncurses/ncurs.c @@ -1,11 +1,6 @@ #include <ncurses.h> #include "../newcalls.h" -int dup(int oldfd) -{ - return _dup2(oldfd,0xffffffff); // dup emulation mode -} - void print_in_middle(WINDOW *win, int starty, int startx, int width, char *string) { int length, x, y; diff --git a/userspace/newcalls.h b/userspace/newcalls.h deleted file mode 100644 index e22bc78..0000000 --- a/userspace/newcalls.h +++ /dev/null @@ -1,30 +0,0 @@ -////////////////////////////////////////////////// - -// this syscall will be moved to newlib later! TODO! -#define SYSCALL_CLONE 83 -#define SYSCALL_PIPE 84 -#define SYSCALL_DUP2 86 -#define SYSCALL_GUI_RECT 87 -#define SYSCALL_GUI_WIN 88 - -int _clone(void) -{ - return syscall(SYSCALL_CLONE,0,0,0); -} -int _pipe(uint32_t fds[2]) -{ - return syscall(SYSCALL_PIPE,fds,0,0); -} -int _dup2(uint32_t oldfd,uint32_t newfd) -{ - return syscall(SYSCALL_DUP2,oldfd,newfd,0); -} -int _gui_rect() -{ - return syscall(SYSCALL_GUI_RECT,0,0,0); -} -int _gui_win() -{ - return syscall(SYSCALL_GUI_WIN,0,0,0); -} -// diff --git a/userspace/pain1.c b/userspace/pain1.c index c486636..ddceaa5 100644 --- a/userspace/pain1.c +++ b/userspace/pain1.c @@ -1,5 +1,4 @@ #include "put_pixel.h" -#include "newcalls.h" #include <stdlib.h> #include <stdio.h> diff --git a/userspace/pain2.c b/userspace/pain2.c index 259f00e..68ca715 100644 --- a/userspace/pain2.c +++ b/userspace/pain2.c @@ -1,5 +1,4 @@ #include "put_pixel.h" -#include "newcalls.h" #include <stdlib.h> #include <stdio.h> diff --git a/userspace/pain3.c b/userspace/pain3.c index 2633c73..bd1aa8b 100644 --- a/userspace/pain3.c +++ b/userspace/pain3.c @@ -1,5 +1,4 @@ #include "put_pixel.h" -#include "newcalls.h" #include <stdlib.h> #include <stdio.h> diff --git a/userspace/put_pixel.h b/userspace/put_pixel.h index 445e890..936026f 100644 --- a/userspace/put_pixel.h +++ b/userspace/put_pixel.h @@ -1,6 +1,6 @@ #include <stdint.h> -#define VESA_FRAMEBUFFER 0xfa000000 +#define VESA_FRAMEBUFFER 0xfc000000 #define VESA_PITCH 2560 #define VESA_BPP 4 diff --git a/userspace/snake2.c b/userspace/snake2.c index 6fbd092..8a68c05 100644 --- a/userspace/snake2.c +++ b/userspace/snake2.c @@ -1,5 +1,4 @@ #include <stdio.h> -#include "newcalls.h" static char lastc='d'; diff --git a/userspace/threading.c b/userspace/threading.c index 2fd3b5e..0316ac1 100644 --- a/userspace/threading.c +++ b/userspace/threading.c @@ -1,5 +1,4 @@ #include <stdio.h> -#include "newcalls.h" volatile unsigned int c=0xbeef; diff --git a/userspace/xterm/terminal.c b/userspace/xterm/terminal.c index ba7986e..ed2b175 100644 --- a/userspace/xterm/terminal.c +++ b/userspace/xterm/terminal.c @@ -1,3 +1,4 @@ +// https://en.wikipedia.org/wiki/ANSI_escape_code // http://en.wikipedia.org/wiki/VT52 // http://vt100.net/docs/vt520-rm/ // man 4 console_codes @@ -96,7 +97,7 @@ typedef struct terminal_tty_struct uint32_t height; uint32_t x; uint32_t y; - uint32_t *data; // screen data + uint32_t *data; // screen data (need this for linefeed and rev linefeed) uint8_t *command; // command line / also holds npar for escape sequences somewhere int32_t command_l; // command line length @@ -250,6 +251,60 @@ static void process_graphic_npar(terminal_tty *tty, terminal_settings s) } } +// string needs to have leading zeroes! +static uint32_t myatoi(char *str,int len) +{ + uint32_t res=0; + + for(int i=0;i<len;i++) + { + res*=10; + res+=str[i]-'0'; + } + + return res; +} + +static void process_cup(terminal_tty *tty) +{ + + // the CSI CUP command: + // + // - starts at: tty->command[NPAR_START] + // - has length: tty->npar + // - has the form: row;col + + char buf[10]; + int b=0; + bool row=true; + + for(int i=0;i<tty->npar+1;i++) + { + char c=tty->command[NPAR_START+i]; + + // hit the separating ';' or hit the end + if(i==tty->npar||c==';') + { + if(row) //row 1-based + { + tty->y=myatoi(buf,b)-1; + } + else //col 1-based + { + tty->x=myatoi(buf,b)-1; + } + row=false; + b=0; + } + else + { + buf[b++]=c; + } + } + + tty->npar=0; +} + static void process_graphic_npars(terminal_tty *tty) { @@ -508,7 +563,6 @@ void terminal_put(terminal_tty *tty, uint8_t c) if(c=='8'){}// RESTORE STATE if(c=='['){tty->escaping=2;tty->npar=0;return;} // CONTROL SEQ INTRODUCER - // TODO // %, %@, %G, %8, #8, (, (B, (O, (U, (K // ), >, =, ] (???) @@ -521,19 +575,20 @@ void terminal_put(terminal_tty *tty, uint8_t c) else if(tty->escaping==2) { //ECMA-48: TODO - - - //ECMA-48 GRAPHIC RENDITION: OK - if(c!='m') + if(c!='m' && c!='H') { tty->command[NPAR_START+(tty->npar++)]=c; } - else + else if(c=='m') { process_graphic_npars(tty); } + else if(c=='H') + { + process_cup(tty); + } //ECMA-48 MODE SWITCHES: TODO //ECMA-48 STATUS REPORT: TODO diff --git a/userspace/xterm/vesa.c b/userspace/xterm/vesa.c index 085d1b0..9e89cbe 100644 --- a/userspace/xterm/vesa.c +++ b/userspace/xterm/vesa.c @@ -1,7 +1,6 @@ #include <stdarg.h> #include <stdint.h> #include <stdio.h> -#include "../newcalls.h" #include "vesa.h" #define VMEM_USER_FRAMEBUFFER 0xfc000000 diff --git a/userspace/xterm/xterm.c b/userspace/xterm/xterm.c index fdee768..bee8d8d 100644 --- a/userspace/xterm/xterm.c +++ b/userspace/xterm/xterm.c @@ -3,6 +3,9 @@ extern char**environ; +//default +char *argv1[]={"xterm","/bin/fsh",0}; + int main(int argc, char **argv) { _gui_win(); @@ -30,7 +33,9 @@ int main(int argc, char **argv) _dup2(xterm_out[1],1);// stdout _dup2(xterm_out[1],2);// stderr - _execve(argv[1],argv,environ); // replace process with our foolshell or whatever + // replace process with our foolshell or whatever + if(argc==1)_execve(argv1[1],argv1,environ); + _execve(argv[1],argv,environ); while(1); } diff --git a/xxx/packages/ncurses-5.9/foolterm.ti b/xxx/packages/ncurses-5.9/foolterm.ti deleted file mode 100644 index ea60e0e..0000000 --- a/xxx/packages/ncurses-5.9/foolterm.ti +++ /dev/null @@ -1,77 +0,0 @@ - -# FoolOS built-in terminal emulator -# check "man 5 terminfo" to understand this file - -fool-term|FoolOS built-in terminal emulator, - am, bce, eo, mir, msgr, -# xenl, xon, - cols#80, lines#24, colors#8, pairs#64, it#8, - -# this could hold an alterntive table paiting method -# acsc=+\020\,\021-\030.^Y0\333`\004a\261f\370g\361h\260i\316j\331k\277l\332m\300n\305o~p\304q\304r\304s_t\303u\264v\301w\302x\263y\363z\362{\343|\330}\234~\376, - - clear=\Ec, cr=\015, - -# movement TODO -# - home=\EH, - - cub1=\Eb, - cud1=\Ed, - cuf1=\Ef, - cuu1=\Eu, - -# cup=\EY%p1%' '%+%c%p2%' '%+%c, - -# clear to end of screen / line - ed=\EJ, - el=\EK, - -# delchar - dch1=\Ex, - -# backspace - kbs=\010, - -# tab - ht=\011, - -# newline - nel=\012, - -# scrolling (down,reverse) - ind=\ED, - ri=\EM, - -# keys - kcub1=\E<, kcud1=\E^, - kcuf1=\E>, kcuu1=\Ev, - - -# function keys -# kf1=\E[[A, -# kf10=\E[21~, -# kf11=\E[23~, -# kf12=\E[24~, -# kf13=\E[25~, -# kf14=\E[26~, -# kf15=\E[28~, -# kf16=\E[29~, -# kf17=\E[31~, -# kf18=\E[32~, -# kf19=\E[33~, -# kf2=\E[[B, -# kf20=\E[34~, -# kf3=\E[[C, -# kf4=\E[[D, -# kf5=\E[[E, -# kf6=\E[17~, -# kf7=\E[18~, -# kf8=\E[19~, -# kf9=\E[20~, - -#colors - setab=\E[4%p1%dm, - setaf=\E[3%p1%dm, - oc=\E[37;40m, - |
