diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/paint.c | 93 | ||||
| -rw-r--r-- | userspace/put_pixel.h | 31 |
2 files changed, 104 insertions, 20 deletions
diff --git a/userspace/paint.c b/userspace/paint.c index 15f2a5e..a734ea6 100644 --- a/userspace/paint.c +++ b/userspace/paint.c @@ -3,32 +3,93 @@ #include <stdlib.h> #include <stdio.h> -int main(int argc,char **argv) +#define dimx 640 +#define dimy 480 + +uint32_t backbuffer[dimx*dimy]; + +void paintbuffer() +{ + for (int x = 100; x < dimx-100; x++) + for (int y = 100; y < dimy-100; y++) + { + { + put_pixel(x,y,backbuffer[x+y*640]); + } + } +} + +void unicolor(int color) { - const int dimx = 640, dimy = 480; - int i, j; + for (int x = 100; x < dimx-100; x++) + for (int y = 100; y < dimy-100; y++) + { + { + put_pixel(x,y,color); + } + } +} - FILE *fp = fopen(argv[1], "r"); /* b - binary mode */ +void doscolor(int color,int color2) +{ + int i=0; + + for (int y = 100; y < dimy-100; y++) + for (int x = 100; x < dimx-100; x++) + { + { + if(x%2&&y%2)put_pixel(x,y,color); + else put_pixel(x,y,color2); + } + } +} + +int main(int argc,char **argv) +{ + FILE *fp = fopen("/home/miguel/bg.ppm", "r"); /* b - binary mode */ // (void) fprintf(fp, "P6\n%d %d\n255\n", dimx, dimy); - for (j = 0; j < dimy; ++j) + int i=0; + for (int y = 0; y < dimy; y++) + for (int x = 0; x < dimx; x++) { - 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]); + static unsigned char color[3]; + fread(&color[0], 1, 1, fp); //red + fread(&color[1], 1, 1, fp); //green + fread(&color[2], 1, 1, fp); //blue + + backbuffer[i++]=color[0]*256*256+color[1]*256+color[2]; + + + // if(x<100||x>dimx-100)continue; + // if(y<100||y>dimy-100)continue; + + // put_pixel(x,y,color[0]*256*256+color[1]*256+color[2]);//*256*256+color[1]*256+color[3]); } } + if(argc==2&&!strcmp(argv[1],"demo")) + { + for(int i=0;i<10000;i++) +// while(1) + { + unicolor(0xffffff); + unicolor(0x000000); + doscolor(0x0,0xffffff); + paintbuffer(); + } + return EXIT_SUCCESS; + } + + for(int i=0;i<argc-1;i++) + { + unicolor(strtol(argv[1+i],NULL,16)); + } + if(argc>1) return EXIT_SUCCESS; + + (void) fclose(fp); return EXIT_SUCCESS; } diff --git a/userspace/put_pixel.h b/userspace/put_pixel.h index f4b9332..f879772 100644 --- a/userspace/put_pixel.h +++ b/userspace/put_pixel.h @@ -2,14 +2,38 @@ #define VESA_FRAMEBUFFER 0xf6000000 #define VESA_PITCH 2560 -#define VESA_BPP 32 +#define VESA_BPP 4 +//https://forum.osdev.org/viewtopic.php?t=10018&p=64358 // TODO: what will happen in 24bit mode? -static void put_pixel(int x,int y, int color) + +volatile int c; +int delay() +{ + c++; +} +void put_pixel(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*(VESA_BPP>>3)); // get bytes (divide by 8) + //if (y) y = (y*VESA_PITCH); + //uint8_t *cTemp=VbeModeInfoBlock->physbase; + + uint8_t *p=VESA_FRAMEBUFFER+y*VESA_PITCH+x*VESA_BPP; + uint32_t *pix=p; + *pix=color; + +// for(int i=0;i<100;i++)delay(); +} + + + +void put_pixel_old(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 (x) x = (x*VESA_BPP); // get bytes (divide by 8) if (y) y = (y*VESA_PITCH); //uint8_t *cTemp=VbeModeInfoBlock->physbase; uint8_t *cTemp=VESA_FRAMEBUFFER; @@ -18,4 +42,3 @@ static void put_pixel(int x,int y, int color) cTemp[x+y+1] = (uint8_t)((color>>8) & 0xff); cTemp[x+y+2] = (uint8_t)((color>>16) & 0xff); } - |
