int main(int argc, char **argv)
{
+ void *fb_buf;
struct video_mode *vmodes;
- int vmidx;
+ int vmidx, status = 0;
init_logger("game.log");
fb_width = vmode->xsz;
fb_height = vmode->ysz;
- fb_size = (vmode->xsz * vmode->bpp / 8) * vmode->ysz;
+ fb_size = vmode->pitch * vmode->ysz;
+
+ if(!(fb_buf = malloc(fb_size + vmode->pitch * 2))) {
+ fprintf(stderr, "failed to allocate framebuffer\n");
+ status = -1;
+ goto break_evloop;
+ }
+ fb_pixels = (char*)fb_buf + vmode->pitch;
reset_timer();
}
break_evloop:
+ free(fb_buf);
set_text_mode();
cleanup_video();
kb_shutdown();
- return 0;
+ return status;
}
static void draw(void)
{
int i, j;
- uint16_t *pptr = vmem;
+ uint16_t *pptr = fb_pixels;
for(i=0; i<fb_height; i++) {
for(j=0; j<fb_width; j++) {
*pptr++ = chess ? 0xff00 : 0x00ff;
}
}
-}
-void swap_buffers(void *pixels)
-{
- wait_vsync();
- memcpy(vmem, pixels, fb_size);
+ blit_frame(fb_pixels, 1);
}