-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
44 lines (40 loc) · 1.01 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <pthread.h>
#include <stdio.h>
#include "chip8.h"
#include "color.h"
#include "draw.h"
#include "io.h"
#include "load.h"
#include "timer.h"
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("[USAGE] %s ROM\n", argv[0]);
return 1;
}
else
{
g_romfile = argv[1];
}
pthread_t t1, t2;
enter_color_prompt();
io_init();
pthread_mutex_init(&g_display_mutex, NULL);
pthread_mutex_init(&g_input_mutex, NULL);
pthread_mutex_init(&g_timer_mutex, NULL);
pthread_cond_init(&g_display_cond, NULL);
pthread_cond_init(&g_input_cond, NULL);
pthread_create(&t1, NULL, timer_fn, NULL);
pthread_create(&t2, NULL, cpu_fn, NULL);
io_loop();
pthread_join(t1, NULL);
pthread_join(t2, NULL);
pthread_cond_destroy(&g_display_cond);
pthread_cond_destroy(&g_input_cond);
pthread_mutex_destroy(&g_display_mutex);
pthread_mutex_destroy(&g_input_mutex);
pthread_mutex_destroy(&g_timer_mutex);
io_quit();
return 0;
}