summaryrefslogtreecommitdiff
path: root/userspace
diff options
context:
space:
mode:
authorMiguel <m.i@gmx.at>2018-10-19 02:41:53 +0200
committerMiguel <m.i@gmx.at>2018-10-19 02:41:53 +0200
commit45ce8728224caa44d31dca3117992b193fa3cd98 (patch)
tree8d37cfe273e9feeb8376b6205abe29c995e40ac2 /userspace
parent9bfd9fb6a7c568b56a5ef525a2b76351780bae66 (diff)
window manager continued
Diffstat (limited to 'userspace')
-rw-r--r--userspace/Makefile12
-rw-r--r--userspace/fsh.c1
-rw-r--r--userspace/init.c41
-rw-r--r--userspace/newcalls.h9
-rw-r--r--userspace/pain/pain1.c2
-rw-r--r--userspace/pain2.c4
-rw-r--r--userspace/pain3.c5
-rw-r--r--userspace/xterm/rect.c22
-rw-r--r--userspace/xterm/vesa.c126
-rw-r--r--userspace/xterm/vesa.h1
-rw-r--r--userspace/xterm/xterm.c25
11 files changed, 101 insertions, 147 deletions
diff --git a/userspace/Makefile b/userspace/Makefile
index 8d9cf8e..16d67ac 100644
--- a/userspace/Makefile
+++ b/userspace/Makefile
@@ -1,7 +1,8 @@
-IMAGESIZE=80000 #ext2.img size in Kb
#######################
+IMAGESIZE=80000 #ext2.img size in Kb
+
GIT_REVISION=$(shell git rev-parse HEAD)
CC=i686-foolos-gcc
@@ -32,9 +33,14 @@ include ../Makefile.common
all: ext2.img
-ext2.img: $(PROGS)
- make -C fonts
+xterm:
+ @echo "building fool-term"
make -C xterm
+
+
+ext2.img: $(PROGS) xterm
+ make -C xterm
+ make -C fonts
make -C cpp
make -C ncurses
make -C pain
diff --git a/userspace/fsh.c b/userspace/fsh.c
index 17a3942..b81912e 100644
--- a/userspace/fsh.c
+++ b/userspace/fsh.c
@@ -87,7 +87,6 @@ int main(int argc, char **argv)
while(1)
{
- _gui_rect();
char c=fgetc(stdin);
if(c=='\b')
diff --git a/userspace/init.c b/userspace/init.c
index e432ef9..0fb23d2 100644
--- a/userspace/init.c
+++ b/userspace/init.c
@@ -1,46 +1,35 @@
-/** xinit
- *
- * TODO: console version
- *
- * */
-
-#define LAUNCH_COUNT 0
-static char *env1[]={"HOME=/home/miguel","PS1=\033[34m$\033[37m","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0};
+ /*
+ * @file
+ *
+ * This is the FoolOS Init process running on pid=1.
+ *
+ * I just spawns a `fool-term` each time an character arrives
+ * on its '/dev/tty' (controlling terminal of this process)
+ *
+ */
+
+static char *env1[]={"HOME=/home/miguel","PS1=$","PWD=/home/miguel","PATH=/bin","TERM=fool-term",0};
static char *argv1[]={"xterm","/bin/fsh",0};
-/*
-
-char *argv1[][4]={
- {"/bin/xterm","xterm","/bin/fsh",0},
- {"/bin/xterm","xterm","/bin/fsh",0},
- {"/bin/xterm","xterm","/bin/fsh",0},
-};
-*/
-
void fork_and_exec()
{
int pid=fork();
- if(!pid) //child
+
+ if(!pid)
{
+ // execve in child
execve("/bin/xterm",argv1,env1);
}
}
int main(int argc, char **argv)
{
- int pid=fork();
-
- for(int i=0;i<LAUNCH_COUNT;i++)
- {
- fork_and_exec();
- }
-
int tty_fd=_open("/dev/tty");
while(1)
{
char buf[1];
- read(tty_fd,buf,1); //
+ read(tty_fd,buf,1);
fork_and_exec();
}
}
diff --git a/userspace/newcalls.h b/userspace/newcalls.h
deleted file mode 100644
index 177e100..0000000
--- a/userspace/newcalls.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <stdio.h>
-#include "../interface/syscalls.h"
-
-/** invalidate screen rectangle */
-// we pack x,y and width,height togehter
-int _gui_inval(uint32_t xy, uint32_t wh)
-{
- return syscall(SYSCALL_GUI_RECT,xy,wh,0);
-}
diff --git a/userspace/pain/pain1.c b/userspace/pain/pain1.c
index a3fb03a..2c23000 100644
--- a/userspace/pain/pain1.c
+++ b/userspace/pain/pain1.c
@@ -192,7 +192,7 @@ int main(int argc, char **argv)
_gui_win();
read_png_file(argv[1]);
process_file();
- _gui_rect();
+ _gui_inval(0,0,640,480);
while(1);
// write_png_file(argv[2]);
diff --git a/userspace/pain2.c b/userspace/pain2.c
index 3c62463..50dc716 100644
--- a/userspace/pain2.c
+++ b/userspace/pain2.c
@@ -33,14 +33,14 @@ int main(int argc,char **argv)
{
put_rect(0,0,640,480,0xff0000);
put_rect(i,i,100,100,0x0000ff);
- _gui_rect();
+ _gui_inval(0,0,640,400);
}
for(int i=380;i>0;i-=80)
{
put_rect(0,0,640,480,0xff0000);
put_rect(i,i,100,100,0x0000ff);
- _gui_rect();
+ _gui_inval(0,0,640,400);
}
}
diff --git a/userspace/pain3.c b/userspace/pain3.c
index bd1aa8b..7114ada 100644
--- a/userspace/pain3.c
+++ b/userspace/pain3.c
@@ -6,6 +6,7 @@
#define dimx 640
#define dimy 480
+
/*
void doscolor(int color,int color2)
{
@@ -32,14 +33,14 @@ int main(int argc,char **argv)
{
put_rect(0,0,640,480,0xffff00);
put_rect(i,i,100,100,0x00ffff);
- _gui_rect();
+ _gui_inval(0,0,640,480);
}
for(int i=380;i>0;i-=80)
{
put_rect(0,0,640,480,0xffff00);
put_rect(i,i,100,100,0xffffff);
- _gui_rect();
+ _gui_inval(0,0,640,480);
}
}
diff --git a/userspace/xterm/rect.c b/userspace/xterm/rect.c
index 35711f0..57cea62 100644
--- a/userspace/xterm/rect.c
+++ b/userspace/xterm/rect.c
@@ -1,25 +1,29 @@
#include <stdlib.h>
#include <stdio.h>
-#include "../put_pixel.h"
+#include "vesa.h"
extern char**environ;
int main(int argc, char **argv)
{
// we need a window
- _gui_win();
+ _gui_win(0|0,300<<16|300,0);
+ uint8_t *fb=malloc(4*300*300);
// basically loads font and sets a few constants
- vesa_init(NULL);
+ vesa_init(300,300,fb,NULL);
while(1)
{
- int x = rand()%600;
+ int x = rand()%300;
int y = rand()%300;
- int width=10;
- int height=10;
- int col = rand()% 0x00ffff;
- put_rect( x, y, width,height,col);
- _gui_inval((x<<16)|(y),(width<<16)|height);
+ int col = rand()% 0x0000ff;
+
+ int width=1;
+ int height=1;
+
+ //put_rect( x, y, width,height,col);
+ PutPixel(x,y,col|0xff<<24);
+ _gui_inval((x<<16)|(y),(width<<16)|height,fb);
}
}
diff --git a/userspace/xterm/vesa.c b/userspace/xterm/vesa.c
index 6d61498..16c8649 100644
--- a/userspace/xterm/vesa.c
+++ b/userspace/xterm/vesa.c
@@ -4,11 +4,6 @@
#include <stdio.h>
#include <malloc.h>
#include "vesa.h"
-#include "../newcalls.h"
-
-void PutFont(char c, int x,int y, int color_fg,int color_bg);
-
-#define VMEM_USER_FRAMEBUFFER 0xf5100000
// framebuffer info
static uint32_t vesaXres;
@@ -34,9 +29,12 @@ static uint8_t termdata[80*24];
static uint8_t termdata_bg[80*24];
static uint8_t termdata_fg[80*24];
+void PutFont(char c, int x,int y, uint32_t color_fg,uint32_t color_bg);
+
// same colors as in screen.h
+/*
static uint32_t cols[] = {
- 0x0, // black
+ 0x0, //black
0x0066cc, //blue
0x009900, //green
0x33ffff, //cyan
@@ -53,6 +51,28 @@ static uint32_t cols[] = {
0xffff00, //yellow
0xffffff, //white
};
+*/
+
+/** solarized theme */
+
+static uint32_t cols[] = {
+ 0x073642, // S_base02
+ 0xdc322f, // S_red
+ 0x859900, // S_green
+ 0xb58900, // S_yellow
+ 0x268bd2, // S_blue
+ 0xd33682, // S_magenta
+ 0x2aa198, // S_cyan
+ 0xeee8d5, // S_base2
+ 0x002b36, // S_base03
+ 0xcb4b16, // S_orange
+ 0x586e75, // S_base01
+ 0x657b83, // S_base00
+ 0x839496, // S_base0
+ 0x6c71c4, // S_violet
+ 0x93a1a1, // S_base1
+ 0xfdf6e3, // S_base3
+};
/** update cursor position */
void vesa_update_cursor(uint32_t col,uint32_t row)
@@ -77,34 +97,13 @@ void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_
if(x==console_x&&y==console_y)PutFont(c, x,y, cols[color_fg],cols[color_bg]);
else PutFont(c, x,y, cols[color_bg],cols[color_fg]);
}
-
- //
- // We want to get output to the screen as fast as possible!
- //
- // Our Fool-Boot-Loader did set up VESA already for us.
- // The desired VESA mode is hardcoded in [boot/mbr.asm].
- //
- // The [vesa_init(...)] function requires:
- //
- // * the addresses of the vbeinfo struct
- // * the address of the vbemodeinfo struct (for selected mode).
- // * Fool Font loaded inside ramimage
- //
- // The first two paramters are hardcoded in [boot/mbr.asm],
- // while the last one is set in the Makefile. The font binary
- // is integrated in the kernel image.
- //
- // this function returns the physical base address of
- // our video memory
- //
-uint32_t vesa_init(char *fontname)
+uint32_t vesa_init(int w,int h, int fb, char *fontname)
{
// LOAD FONT
FILE *f;
- //if(fontname==NULL)f=fopen("/doc/fonts/binfont.bin","r");
- //if(fontname==NULL)f=fopen("/doc/fonts/tinyfont.bin","r");
if(fontname==NULL)f=fopen("/doc/fonts/envypn7x13.bin","r");
+ else f=fopen("fontname","r");
fread(&font_width,1,1,f);
fread(&font_height,1,1,f);
@@ -116,13 +115,12 @@ uint32_t vesa_init(char *fontname)
fread(foolfont,1,alloc_bytes,f);
// virtual screen
- vesaXres=640;
- vesaYres=480;
+ vesaXres=w;
+ vesaYres=h;
- vesaPitch=640*4;
+ vesaPitch=vesaXres*4;
vesaBpp=4; //32bit
- vesaAddr=VMEM_USER_FRAMEBUFFER;
- //
+ vesaAddr=fb;//// TODOVMEM_USER_FRAMEBUFFER;
//
console_x=0;
@@ -135,33 +133,15 @@ uint32_t vesa_init(char *fontname)
return vesaAddr;
}
-
-// TODO: what will happen in 24bit mode?
-// TODO: optimize
-void PutPixel(int x,int y, int color)
+void PutPixel(int x,int y, uint32_t color)
{
- /*
- //do not write memory outside the screen buffer, check parameters against the VBE mode info
- if (x<0 || x>vesaXres|| y<0 || y>vesaYres) return;
- if (x) x = (x*(vesaBpp>>3)); // get bytes (divide by 8)
- if (y) y = (y*vesaPitch);
- //uint8_t *cTemp=VbeModeInfoBlock->physbase;
- uint8_t *cTemp=VMEM_USER_FRAMEBUFFER;
-
- cTemp[x+y] = (uint8_t)(color & 0xff);
- cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff);
- cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff);
- */
-
- uint8_t *p=VMEM_USER_FRAMEBUFFER+y*vesaPitch+x*vesaBpp;
+ uint8_t *p=vesaAddr+y*vesaPitch+x*vesaBpp;
uint32_t *pix=p;
*pix=color;
}
-
static bool check_pixel(int idx,int x,int y)
{
-// x=font_width-x-1;
int pixel_index=idx*font_width*font_height+y*font_width+x;
return foolfont[pixel_index/8]&(1<<(7-(pixel_index%8)));
}
@@ -169,48 +149,32 @@ static bool check_pixel(int idx,int x,int y)
/**
* Put character C in column X of row Y using colors fg and bg
*/
-void PutFont(char c, int x,int y, int color_fg,int color_bg)
+void PutFont(char c, int x,int y, uint32_t color_fg,uint32_t color_bg)
{
+ static uint8_t opac=0xbb;
int fnt;
if(c>=0x20&&c<=0x126)fnt=c-0x20;
else return; // any other fonts??
- //x=x*(1+font_width);
- //y=y*(1+font_height);
x=x*(font_width+1);
y=y*(font_height+1);
//fill broder with bg color
- for(int posx=x;posx<x+font_width+1;posx++)PutPixel(posx,y+font_height,color_bg);
- for(int posy=y;posy<y+font_height;posy++)PutPixel(x+font_width,posy,color_bg);
+ for(int posx=x;posx<x+font_width+1;posx++)PutPixel(posx,y+font_height,color_bg|(opac<<24));
+ for(int posy=y;posy<y+font_height;posy++)PutPixel(x+font_width,posy,color_bg|(opac<<24));
// paint letter
for(int posx=x;posx<x+font_width;posx++)
{
- for(int posy=y;posy<y+font_height;posy++)
- {
- //if(deffont[fnt].line[posy-y]&1<<(7-(posx-x)))
- if(check_pixel(fnt,posx-x,posy-y))PutPixel(posx,posy,color_fg);
- else PutPixel(posx,posy,color_bg);
- }
+ for(int posy=y;posy<y+font_height;posy++)
+ {
+ //if(deffont[fnt].line[posy-y]&1<<(7-(posx-x)))
+ if(check_pixel(fnt,posx-x,posy-y))PutPixel(posx,posy,color_fg|(0xff<<24));
+ else PutPixel(posx,posy,color_bg|(opac<<24));
+ }
}
// invalidate area
- _gui_inval((x<<16)|(y),(font_width+1<<16)|(font_height+1));
+ _gui_inval((x<<16)|(y),(font_width+1<<16)|(font_height+1),vesaAddr);
- /*
- for(int y=0;y<vesaYres;y++)
- {
- PutPixel(0,y,0xff);
- PutPixel(100,y,0xff);
- PutPixel(vesaXres-1,y,0xff);
- }
-
- for(int x=0;x<vesaXres;x++)
- {
- PutPixel(x,0,0xff);
- PutPixel(x,100,0xff);
- PutPixel(x,vesaYres-1,0xff);
- }
- */
}
diff --git a/userspace/xterm/vesa.h b/userspace/xterm/vesa.h
index 16a52f1..ac3257e 100644
--- a/userspace/xterm/vesa.h
+++ b/userspace/xterm/vesa.h
@@ -1,2 +1,3 @@
void vesa_update_cursor(uint32_t col,uint32_t row);
void vesa_console_put_char(uint8_t c,uint8_t color_bg, uint8_t color_fg, uint32_t x, uint32_t y);
+uint32_t vesa_init(int w,int h, int fb, char *fontname);
diff --git a/userspace/xterm/xterm.c b/userspace/xterm/xterm.c
index 90b2fe0..8d3ea97 100644
--- a/userspace/xterm/xterm.c
+++ b/userspace/xterm/xterm.c
@@ -1,27 +1,32 @@
#include <stdlib.h>
#include <stdio.h>
-#include "../put_pixel.h"
+#include "vesa.h"
extern char**environ;
+// TODO quit if execve fails or child exits...
+
//default
char *argv1[]={"xterm","/bin/fsh",0};
int main(int argc, char **argv)
{
- // we need a window
- _gui_win();
+ // we need a 640x336 window for a 80x24 terminal using the
+ // default 7x13 pixel font +1 pixel margin so it is 8x14
+ int w=640;
+ int h=336;
+ _gui_win(0<<16|0,w<<16|h,0);
// basically loads font and sets a few constants
- vesa_init(NULL);
+ void *fb=malloc(w*h*4);
+ // 32bit mode so we have 4bytes per pixel. first one holds alpha
+
+ vesa_init(w,h, fb, NULL);
// init tty and set vesa output funcs
void *tty=terminal_init_vesa();
- //int xterm_in[2];
int xterm_out[2];
-
- //_pipe(xterm_in);
pipe(xterm_out);
int tty_fd=_open("/dev/tty");
@@ -30,7 +35,6 @@ int main(int argc, char **argv)
if(!pid) // child
{
- //_close(xterm_in[1]);
close(xterm_out[0]);
dup2(tty_fd,0);// stdin
@@ -45,13 +49,8 @@ int main(int argc, char **argv)
while(1);
}
else{
- // TODO quit if execve fails or child exits...
- //_close(xterm_in[0]);
close(xterm_out[1]);
-
- //_dup2(xterm_in[1],0); // compositor writes here.
- //_close(xterm_in[1]);
while(1)
{