Added scrolling
[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
11 static int quit;
12 static int use_mouse;
13
14 int main(int argc, char **argv)
15 {
16         void *vmem;
17         long fbsize = fb_width * fb_height * fb_bpp / CHAR_BIT;
18
19         init_timer(100);
20         kb_init(32);
21
22         if((use_mouse = have_mouse())) {
23                 set_mouse_limits(0, 0, fb_width, fb_height);
24                 set_mouse(fb_width / 2, fb_height / 2);
25         }
26
27         if(!(fb_pixels = malloc(fbsize))) {
28                 fprintf(stderr, "failed to allocate backbuffer\n");
29                 return 1;
30         }
31
32         if(!(vmem = set_video_mode(fb_width, fb_height, fb_bpp))) {
33                 return 1;
34         }
35
36         if(demo_init(argc, argv) == -1) {
37                 set_text_mode();
38                 return 1;
39         }
40         reset_timer();
41
42         while(!quit) {
43                 int key;
44                 while((key = kb_getkey()) != -1) {
45                         demo_keyboard(key, 1);
46                 }
47                 if(quit) goto break_evloop;
48
49                 if(use_mouse) {
50                         mouse_bmask = read_mouse(&mouse_x, &mouse_y);
51                 }
52
53                 time_msec = get_msec();
54                 demo_draw();
55
56                 /*wait_vsync();*/
57                 memcpy(vmem, fb_pixels, fbsize);
58         }
59
60 break_evloop:
61         set_text_mode();
62         demo_cleanup();
63         kb_shutdown();
64         return 0;
65 }
66
67 void demo_quit(void)
68 {
69         quit = 1;
70 }