-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
56 lines (54 loc) · 1.15 KB
/
main.c
File metadata and controls
56 lines (54 loc) · 1.15 KB
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
#include <stdio.h>
#include <stdint.h>
#include <SDL/SDL.h>
#include "sdl.h"
#include "cpu.h"
#define usage "Usage: chip8 romfile"
int main(int argc, char** argv)
{
cpu_t* cpu = NULL;
cpu = new_cpu();
FILE* infile = NULL;
int rv = 0;
SDL_Surface* screen = NULL;
switch(argc)
{
case 0:
printf("Your system is incompatible with this software.\n");
rv = !0;
break;
case 1:
printf("%s\n",usage);
rv = !0;
break;
case 2:
infile = fopen(argv[1],"r");
rv = (infile == NULL ? !0 : 0);
break;
case 3:
infile = fopen(argv[1],"r");
rv = (infile == NULL ? !0 : 0);
break;
default:
printf("%s\n",usage);
rv = !0;
break;
}
if(infile != NULL)
{
cpu_load(infile,cpu);
// must do this after cpu has initialized
if(argc == 3)
cpu->breakpoint = atoi(argv[2]);
sdl_init(&screen);
// make sure the 'screen' could be initialized
if(screen != NULL)
cpu_run(cpu,screen);
else
fprintf(stderr,"ERROR: could not initialize SDL_Surface* screen.\n");
fclose(infile);
}
free_cpu(cpu);
SDL_Quit();
return rv;
}