-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
62 lines (55 loc) · 1.27 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <signal.h>
#include <getopt.h>
#include "io.h"
#include "jitter.h"
#include "sound.h"
bool trace_mode = false;
uint16_t* main_memory;
#define FMT_STRING "td:e:"
FILE* dump_file = NULL;
int dumpaddr_end = 0;
void finish(int);
int main(int argc, char** argv){
setenv("POSIXLY_CORRECT", "1",1);
int c;
FILE* bin = NULL;
while(optind < argc){
if((c = getopt(argc,argv, FMT_STRING)) != -1){
switch(c){
case 't':
trace_mode = true;
break;
case 'd':
dump_file = fopen(optarg, "wb");
break;
case 'e':
dumpaddr_end = strtol(optarg, NULL, 0);
break;
}
}
else{
if(bin == NULL){
bin = fopen(argv[optind],"rb");
}
optind++;
}
}
io_init();
IF_MIDI(init_sound());
signal(SIGINT, finish);
JIT_ONLY(init_jit();)
if(bin == NULL){
fprintf(stderr, "Error opening file\n");
exit(1);
}
main_memory = malloc(65535); //64K of memory
fread(main_memory,1,65535,bin);
fclose(bin);
jit_function f = branch_to(0, 0);
f(f);
return 0;
}