added libimago
[eradicate] / src / dos / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "game.h"
5 #include "keyb.h"
6 #include "timer.h"
7 #include "gfx.h"
8 #include "logger.h"
9 #include "cdpmi.h"
10
11 static struct video_mode *vmode;
12 static int quit;
13
14 int main(int argc, char **argv)
15 {
16         void *fb_buf;
17         struct video_mode *vmodes;
18         int vmidx, status = 0;
19
20         init_logger("game.log");
21
22         init_timer(100);
23         kb_init(32);
24
25         if(init_video() == -1) {
26                 return 1;
27         }
28         vmodes = video_modes();
29
30         if((vmidx = match_video_mode(640, 480, 16)) == -1) {
31                 return 1;
32         }
33         if(!(vmem = set_video_mode(vmidx, 1))) {
34                 return 1;
35         }
36         vmode = vmodes + vmidx;
37
38         fb_width = vmode->xsz;
39         fb_height = vmode->ysz;
40         fb_size = vmode->pitch * vmode->ysz;
41
42         if(!(fb_buf = malloc(fb_size + vmode->pitch * 2))) {
43                 fprintf(stderr, "failed to allocate framebuffer\n");
44                 status = -1;
45                 goto break_evloop;
46         }
47         fb_pixels = (char*)fb_buf + vmode->pitch;
48
49         reset_timer();
50
51         for(;;) {
52                 int key;
53                 while((key = kb_getkey()) != -1) {
54                         if(key == 27) goto break_evloop;
55                 }
56
57                 if(quit) goto break_evloop;
58
59                 time_msec = get_msec();
60                 draw();
61         }
62
63 break_evloop:
64         free(fb_buf);
65         set_text_mode();
66         cleanup_video();
67         kb_shutdown();
68         return status;
69 }
70
71 void game_quit(void)
72 {
73         quit = 1;
74 }