11 static void *fb_pixels;
12 static int scr_width, scr_height;
13 static int fb_width, fb_height, fb_depth, fb_size, fb_pitch;
14 static int fb_xoffs, fb_yoffs;
19 struct rpi_prop *prop;
27 fb_height = scr_height;
30 printf("Requesting video mode: %dx%d %d bpp (fb:%dx%d)\n", scr_width, scr_height,
31 fb_depth, fb_width, fb_height);
33 rpi_prop(RPI_TAG_ALLOCFB, 16);
34 rpi_prop(RPI_TAG_SETFBVIRT, scr_width, scr_height);
35 rpi_prop(RPI_TAG_SETFBPHYS, fb_width, fb_height);
36 rpi_prop(RPI_TAG_SETFBDEPTH, fb_depth);
40 while((prop = rpi_prop_next())) {
42 case RPI_TAG_SETFBPHYS:
44 fb_width = prop->data[0];
45 fb_height = prop->data[1];
48 case RPI_TAG_SETFBVIRT:
50 scr_width = prop->data[0];
51 scr_height = prop->data[1];
54 case RPI_TAG_SETFBDEPTH:
55 printf(" setfbdepth");
56 fb_depth = prop->data[0];
61 fb_pixels = (void*)(prop->data[0] & 0x3fffffff);
62 fb_size = prop->data[1];
66 printf(" tag %x", prop->id);
70 printf(" %08x (%u bytes):", prop->res, prop->size);
71 for(i=0; i<prop->size / 4; i++) {
72 printf(" %u", prop->data[i]);
78 rpi_prop(RPI_TAG_ALLOCFB, 16);
79 if(rpi_prop_send() == -1 || !(prop = rpi_prop_find(RPI_TAG_ALLOCFB))) {
80 printf("Failed to allocate framebuffer\n");
83 fb_pixels = (void*)(prop->data[0] & 0x3fffffff);
84 fb_size = prop->data[1];
87 rpi_prop(RPI_TAG_GETFBPITCH);
88 rpi_prop(RPI_TAG_GETFBOFFS);
91 if(rpi_prop_send() == -1) {
92 printf("Failed to get pitch\n");
97 while((prop = rpi_prop_next())) {
99 case RPI_TAG_GETFBPITCH:
100 fb_pitch = prop->data[0];
103 case RPI_TAG_GETFBOFFS:
104 fb_xoffs = prop->data[0];
105 fb_yoffs = prop->data[1];
113 printf("Got video mode: %dx%d (%d bpp)\n", scr_width, scr_height, fb_depth);
114 printf("Framebuffer: %dx%d at %p (%d bytes)\n", fb_width, fb_height, fb_pixels, fb_size);
115 printf(" virtual offset: %d, %d\n", fb_xoffs, fb_yoffs);
116 printf(" scanline pitch: %d\n", fb_pitch);
119 for(i=0; i<fb_height; i++) {
120 for(j=0; j<fb_width; j++) {
122 int g = (i ^ j) >> 1;
123 int b = (i ^ j) >> 2;
124 fbptr[j] = b | (g << 8) | (r << 16) | 0xff000000;
126 fbptr += fb_pitch >> 2;
129 sysctl_dcache_clean_inval((uint32_t)fb_pixels, fb_size);
133 int video_scroll(int x, int y)
135 struct rpi_prop *prop;
137 rpi_prop(RPI_TAG_SETFBOFFS, x, y);
138 if(rpi_prop_send() == -1 || !(prop = rpi_prop_find(RPI_TAG_SETFBOFFS))) {
142 fb_xoffs = prop->data[0];
143 fb_yoffs = prop->data[1];
147 void video_update(int dt)
149 static int dirx = 1, diry = 1;
152 nx = fb_xoffs + dirx * dt;
153 ny = fb_yoffs + diry * dt;
158 } else if(nx + scr_width >= fb_width) {
159 nx = fb_width - scr_width;
165 } else if(ny + scr_height >= fb_height) {
166 ny = fb_height - scr_height;
170 video_scroll(nx, ny);