OrionDesktop
Barry Initial commit 535aa62 (2 years, 4 months ago)diff --git a/winmgr/main.c b/winmgr/main.c new file mode 100644 index 0000000..847f151 --- /dev/null +++ b/winmgr/main.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <unistd.h> +#include <fcntl.h> +#include <string.h> +#include <sys/mman.h> +#include <sys/ioctl.h> +#include <sys/fb.h> + +FBVarInfo vinfo; +FBFixInfo finfo; +void *lfb; + +/* Put a pixel on the screen */ +static void +putpixel(int x, int y, int colour) +{ + *((uint32_t *) lfb + (y * vinfo.xres) + x) = colour; +} + +/* Main function */ +int +main(int argc, char *argv[]) +{ + printf("Staring Orion Desktop\n"); + + /* Open framebuffer */ + int fb = open("/dev/fb", O_RDWR); + if (fb == -1) { + perror("Failed to open framebuffer"); + goto exit_fail; + } + + /* Get size of framebuffer */ + if (ioctl(fb, FBIOGET_VSCREENINFO, &vinfo) == -1) { + perror("Failed to get framebuffer variable info"); + goto exit_fail; + } + if (ioctl(fb, FBIOGET_FSCREENINFO, &finfo) == -1) { + perror("Failed to get framebuffer fixed info"); + goto exit_fail; + } + printf("Screen is %dx%dx%d\n", vinfo.xres, vinfo.yres, vinfo.bpp); + + /* Map framebuffer */ + lfb = mmap(NULL, finfo.fbmemLen, PROT_READ|PROT_WRITE, + MAP_PRIVATE, fb, 0); + if ((int) lfb == -1) { + perror("Failed to map framebuffer"); + goto exit_fail; + } + close(fb); + printf("Framebuffer mapped at %#.8x (%d bytes)\n", lfb, finfo.fbmemLen); + + /* Draw to screen */ + int x, y; + for (y = 0; y < 720; y++) + for (x = 0; x < 1280; x++) + putpixel(x, y, ((x*0xFF)/vinfo.xres) + + (((y*0xFF)/vinfo.yres) << 8)); + + return 0; + +exit_fail: + if (fb != -1) + close(fb); + exit(EXIT_FAILURE); +}