diff options
| author | Miguel <m.i@gmx.at> | 2018-09-28 11:13:06 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-09-28 11:13:06 +0200 |
| commit | 5f6c2bcf0d2f9c416134aba224d90a605f216818 (patch) | |
| tree | 6fda812ecd1ce06f743c292f3d0495d0b2941bbd /userspace | |
| parent | 4ddca59e2c07a98988ffb07571d2b35c4c90f5ac (diff) | |
struggling with scheduler and userprog to view ppm files
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/fsh.c | 1 | ||||
| -rw-r--r-- | userspace/paint.c | 35 | ||||
| -rw-r--r-- | userspace/put_pixel.h | 21 | ||||
| -rw-r--r-- | userspace/threading.c | 20 |
4 files changed, 74 insertions, 3 deletions
diff --git a/userspace/fsh.c b/userspace/fsh.c index 5609256..81c2bce 100644 --- a/userspace/fsh.c +++ b/userspace/fsh.c @@ -224,6 +224,7 @@ bool process(char *buf) i++; } } + else // otherwise treat command as exectutable and send to execve { int pid=_fork(); diff --git a/userspace/paint.c b/userspace/paint.c new file mode 100644 index 0000000..15f2a5e --- /dev/null +++ b/userspace/paint.c @@ -0,0 +1,35 @@ +#include "put_pixel.h" + +#include <stdlib.h> +#include <stdio.h> + +int main(int argc,char **argv) +{ + const int dimx = 640, dimy = 480; + int i, j; + + FILE *fp = fopen(argv[1], "r"); /* b - binary mode */ + +// (void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy); + + for (j = 0; j < dimy; ++j) + { + for (i = 0; i < dimx; ++i) + { + static unsigned char color[3]; +// color[0] = i % 256; /* red */ + // color[1] = j % 256; /* green */ + // color[2] = (i * j) % 256; /* blue */ + // + fread(&color[0], 1, 1, fp); + fread(&color[1], 1, 1, fp); + fread(&color[2], 1, 1, fp); + + put_pixel(i,j,color[0]*256*256+color[1]*256+color[3]); + } + } + + (void) fclose(fp); + return EXIT_SUCCESS; +} + diff --git a/userspace/put_pixel.h b/userspace/put_pixel.h new file mode 100644 index 0000000..f4b9332 --- /dev/null +++ b/userspace/put_pixel.h @@ -0,0 +1,21 @@ +#include <stdint.h> + +#define VESA_FRAMEBUFFER 0xf6000000 +#define VESA_PITCH 2560 +#define VESA_BPP 32 + +// TODO: what will happen in 24bit mode? +static void put_pixel(int x,int y, int 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*(VESA_BPP>>3)); // get bytes (divide by 8) + if (y) y = (y*VESA_PITCH); + //uint8_t *cTemp=VbeModeInfoBlock->physbase; + uint8_t *cTemp=VESA_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); +} + diff --git a/userspace/threading.c b/userspace/threading.c index 2ceaad3..2fd3b5e 100644 --- a/userspace/threading.c +++ b/userspace/threading.c @@ -1,17 +1,31 @@ #include <stdio.h> #include "newcalls.h" +volatile unsigned int c=0xbeef; + +int inc(int i) +{ + i++; + if(i==0)i=1; + return i; +} + int main() { - int thread=_clone(); // we want two threads + + int thread=_clone(); if(thread!=0) // thread 1 { - while(1) printf("a\n"); + while(1) + { + c++; + } } + else // thread2 { - while(1) printf("b\n"); + while(1) printf("0x%08x\n",c); } } |
