diff options
Diffstat (limited to 'userspace')
| -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 |
16 files changed, 240 insertions, 67 deletions
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); } |
