1#include <stdio.h>
2#include <OS.h>
3#include "cotton.h"
4#include "cottonwindow.h"
5#include "interpreter.h"
6
7int main(int argc, char **argv)
8{
9 if (argc != 2)
10 {
11 fprintf(stderr, "usage: cotton <file.cot>\n");
12 return 1;
13 }
14
15 CottonWindow cw;
16
17 cottonwindow_init(&cw, "cotton", VIDEO_WIDTH*2, VIDEO_HEIGHT*2, VIDEO_WIDTH, VIDEO_HEIGHT);
18
19 Cotton cotton;
20 cotton_init(&cotton);
21
22 FILE *file = fopen(argv[1], "r");
23 if (!file)
24 {
25 fprintf(stderr, "cotton couldn't open \"%s\" :(\n", argv[1]);
26 return 1;
27 }
28
29 int pitch = sizeof(cotton.video[0]) * VIDEO_WIDTH;
30 int quit = 0;
31
32 while (!quit)
33 {
34 quit = cottonwindow_process_input(&cw, NULL);
35
36 if (system_time() / 1000 >= cotton.ticktock)
37 {
38 cotton_interpret(&cotton, &cw, file);
39 }
40
41 cottonwindow_update(&cw, cotton.video, pitch);
42 }
43
44 fclose(file);
45 cottonwindow_destroy(&cw);
46 return 0;
47}