moved the drawFps call to the backends so it works automatically for
[dosdemo] / src / dos / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <limits.h>
5 #include "demo.h"
6 #include "keyb.h"
7 #include "mouse.h"
8 #include "timer.h"
9 #include "gfx.h"
10 #include "logger.h"
11
12 static int quit;
13 static int use_mouse;
14 static long fbsize;
15
16 int main(int argc, char **argv)
17 {
18         fbsize = fb_width * fb_height * fb_bpp / CHAR_BIT;
19
20         init_logger("demo.log");
21
22         init_timer(100);
23         kb_init(32);
24
25         if((use_mouse = have_mouse())) {
26                 set_mouse_limits(0, 0, fb_width, fb_height);
27                 set_mouse(fb_width / 2, fb_height / 2);
28         }
29
30         if(!(fb_pixels = malloc(fbsize))) {
31                 fprintf(stderr, "failed to allocate backbuffer\n");
32                 return 1;
33         }
34
35         if(!(vmem_front = set_video_mode(fb_width, fb_height, fb_bpp))) {
36                 return 1;
37         }
38         /* TODO implement multiple video memory pages for flipping */
39         vmem_back = vmem_front;
40
41         if(demo_init(argc, argv) == -1) {
42                 set_text_mode();
43                 return 1;
44         }
45         reset_timer();
46
47         while(!quit) {
48                 int key;
49                 while((key = kb_getkey()) != -1) {
50                         demo_keyboard(key, 1);
51                 }
52                 if(quit) goto break_evloop;
53
54                 if(use_mouse) {
55                         mouse_bmask = read_mouse(&mouse_x, &mouse_y);
56                 }
57
58                 time_msec = get_msec();
59                 demo_draw();
60         }
61
62 break_evloop:
63         set_text_mode();
64         demo_cleanup();
65         kb_shutdown();
66         return 0;
67 }
68
69 void demo_quit(void)
70 {
71         quit = 1;
72 }
73
74 void swap_buffers(void *pixels)
75 {
76         /* TODO implement page flipping */
77         if(pixels) {
78                 /*wait_vsync();*/
79                 drawFps(pixels);
80                 memcpy(vmem_front, pixels, fbsize);
81         } else {
82                 drawFps(vmem_back);
83         }
84 }