- printf("Got video mode: %dx%d (%d bpp) at %p (%d bytes)\n", fb_width, fb_height,
- fb_depth, fb_pixels, fb_size);
+ if(!fb_pixels) {
+ rpi_prop(RPI_TAG_ALLOCFB, 16);
+ if(rpi_prop_send() == -1 || !(prop = rpi_prop_find(RPI_TAG_ALLOCFB))) {
+ printf("Failed to allocate framebuffer\n");
+ return -1;
+ }
+ fb_pixels = (void*)(prop->data[0] & 0x3fffffff);
+ fb_size = prop->data[1];
+ }
+
+ rpi_prop(RPI_TAG_GETFBPITCH);
+ rpi_prop(RPI_TAG_GETFBOFFS);
+ rpi_prop_send();
+ /*
+ if(rpi_prop_send() == -1) {
+ printf("Failed to get pitch\n");
+ return -1;
+ }
+ */
+
+ while((prop = rpi_prop_next())) {
+ switch(prop->id) {
+ case RPI_TAG_GETFBPITCH:
+ fb_pitch = prop->data[0];
+ break;
+
+ case RPI_TAG_GETFBOFFS:
+ fb_xoffs = prop->data[0];
+ fb_yoffs = prop->data[1];
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ printf("Got video mode: %dx%d (%d bpp)\n", scr_width, scr_height, fb_depth);
+ printf("Framebuffer: %dx%d at %p (%d bytes)\n", fb_width, fb_height, fb_pixels, fb_size);
+ printf(" virtual offset: %d, %d\n", fb_xoffs, fb_yoffs);
+ printf(" scanline pitch: %d\n", fb_pitch);
+
+ fbptr = fb_pixels;
+ for(i=0; i<fb_height; i++) {
+ for(j=0; j<fb_width; j++) {
+ int r = i ^ j;
+ int g = (i ^ j) >> 1;
+ int b = (i ^ j) >> 2;
+ fbptr[j] = b | (g << 8) | (r << 16) | 0xff000000;
+ }
+ fbptr += fb_pitch >> 2;
+ }