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:
43 fb_width = prop->data[0];
44 fb_height = prop->data[1];
47 case RPI_TAG_SETFBVIRT:
48 scr_width = prop->data[0];
49 scr_height = prop->data[1];
52 case RPI_TAG_SETFBDEPTH:
53 fb_depth = prop->data[0];
57 fb_pixels = (void*)(prop->data[0] & 0x3fffffff);
58 fb_size = prop->data[1];
67 rpi_prop(RPI_TAG_ALLOCFB, 16);
68 if(rpi_prop_send() == -1 || !(prop = rpi_prop_find(RPI_TAG_ALLOCFB))) {
69 printf("Failed to allocate framebuffer\n");
72 fb_pixels = (void*)(prop->data[0] & 0x3fffffff);
73 fb_size = prop->data[1];
76 rpi_prop(RPI_TAG_GETFBPITCH);
77 rpi_prop(RPI_TAG_GETFBOFFS);
80 if(rpi_prop_send() == -1) {
81 printf("Failed to get pitch\n");
86 while((prop = rpi_prop_next())) {
88 case RPI_TAG_GETFBPITCH:
89 fb_pitch = prop->data[0];
92 case RPI_TAG_GETFBOFFS:
93 fb_xoffs = prop->data[0];
94 fb_yoffs = prop->data[1];
102 printf("Got video mode: %dx%d (%d bpp)\n", scr_width, scr_height, fb_depth);
103 printf("Framebuffer: %dx%d at %p (%d bytes)\n", fb_width, fb_height, fb_pixels, fb_size);
104 printf(" virtual offset: %d, %d\n", fb_xoffs, fb_yoffs);
105 printf(" scanline pitch: %d\n", fb_pitch);
108 for(i=0; i<fb_height; i++) {
109 for(j=0; j<fb_width; j++) {
111 int g = (i ^ j) >> 1;
112 int b = (i ^ j) >> 2;
113 fbptr[j] = b | (g << 8) | (r << 16) | 0xff000000;
115 fbptr += fb_pitch >> 2;
118 sysctl_dcache_clean_inval((uint32_t)fb_pixels, fb_size);
122 int video_scroll(int x, int y)
124 struct rpi_prop *prop;
126 rpi_prop(RPI_TAG_SETFBOFFS, x, y);
127 if(rpi_prop_send() == -1 || !(prop = rpi_prop_find(RPI_TAG_SETFBOFFS))) {
131 fb_xoffs = prop->data[0];
132 fb_yoffs = prop->data[1];
136 void video_update(int dt)
138 static int dirx = 1, diry = 1;
141 nx = fb_xoffs + dirx * dt;
142 ny = fb_yoffs + diry * dt;
147 } else if(nx + scr_width >= fb_width) {
148 nx = fb_width - scr_width;
154 } else if(ny + scr_height >= fb_height) {
155 ny = fb_height - scr_height;
159 video_scroll(nx, ny);