6cf5de3636166b6d16a8cf2fb8cbc1e3320fbd51
[metatoy] / src / kern / main.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include "segm.h"
5 #include "intr.h"
6 #include "mem.h"
7 #include "contty.h"
8 #include "keyb.h"
9 #include "psaux.h"
10 #include "timer.h"
11 #include "game.h"
12
13 unsigned char *framebuf, *vmem = (unsigned char*)0xa0000;
14
15 static int quit;
16
17
18 int main(void)
19 {
20         int key;
21
22         init_segm();
23         init_intr();
24         con_init();
25         kb_init();
26         init_psaux();
27         init_mem();
28         init_timer();
29         enable_intr();
30
31         if(!(framebuf = malloc(320 * 200))) {
32                 printf("failed to allocate framebuffer\n");
33                 goto end;
34         }
35
36         if(game_init() == -1) {
37                 goto end;
38         }
39
40         for(;;) {
41                 if((key = kb_getkey()) >= 0) {
42                         game_keyboard(key, 1);
43                 }
44                 if(quit) break;
45                 game_draw();
46         }
47         game_shutdown();
48
49 end:
50         cleanup_intr(); /* also disables interrupts */
51         cleanup_timer();
52         return 0;
53 }
54
55 void game_quit(void)
56 {
57         quit = 1;
58 }
59
60 void game_swap_buffers(void)
61 {
62         memcpy(vmem, framebuf, 64000);
63 }