forked from haldean/x6502
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
56 lines (48 loc) · 1.19 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
#include "cpu.h"
#include "emu.h"
#include "opcodes.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void usage() {
printf("x6502: a simple 6502 emulator\n");
printf("usage: x6502 [OPTION]... [FILE] \n");
printf("options:\n");
printf("\t-b addr\t\tthe base address at which code will be loaded\n");
printf("\t\t\t(optional, defaults to zero)\n");
}
int main(int argc, char *argv[]) {
int base_addr = 0;
int c;
while ((c = getopt(argc, argv, "hb:")) != -1) {
switch (c) {
case 'b':
base_addr = atoi(optarg);
break;
case 'h':
usage();
return 0;
case '?':
if (optopt == 'b') {
fprintf(stderr, "Option -%c requires an argument.\n", optopt);
}
usage();
return -1;
}
}
if (optind == argc) {
printf("no input file specified.\n");
usage();
return -1;
}
FILE *in_f = fopen(argv[optind], "rb");
int b;
int i = base_addr;
cpu *m = new_cpu();
while ((b = fgetc(in_f)) != EOF) {
m->mem[i++] = (uint8_t) b;
}
main_loop(m);
return 0;
}