Add arguments and now yemu is modular so other systems can be added easier

This commit is contained in:
g1n 2021-10-25 18:20:41 +03:00
parent 5c7112879a
commit 7068c10171
3 changed files with 61 additions and 7 deletions

2
src/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*~
yemu

View File

@ -3,7 +3,7 @@ CFLAGS= -O2 -Wall -Wextra
LFLAGS=
SRCFILES= main.c 6502/6502.c
OBJFILES= yemu-6502
OBJFILES= yemu
.PHONY: all clean

View File

@ -1,18 +1,70 @@
#include "6502/6502.h"
#include <stdio.h>
#include <stddef.h>
#include <string.h>
void usage() {
printf("%s - Yet another EMUlator\n", "yemu");
printf("Usage: %s [OPTIONS] [--] filename\n", "yemu");
printf(" %s --help\n", "yemu");
printf("Options:\n");
printf("\n");
printf(" --help display this message\n");
printf(" --system system_name choose one of supported systems\n");
}
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("%s: No input file specified\n", "yemu");
char *infilename = NULL;
char *system_name = NULL;
if (argc == 1) {
usage();
return 0;
} else if (argc >= 2) {
for (int i = 1; i <= argc-1; i++) {
if (argv[i][0] == '-') {
argv[i]++;
if(argv[i][0] == '-')
argv[i]++;
if (!strcmp(argv[i], "system")) {
system_name = argv[i+1];
i+=2;
} else if (!strcmp(argv[i], "help")) {
usage();
return 0;
} else {
printf("Unknown argument: %s\n", argv[i]);
return 1;
}
} else {
infilename = argv[i];
}
}
}
if (infilename == NULL) {
printf("%s: no input file specified\n", "yemu");
return 1;
}
FILE *infile = fopen(argv[1], "rb");
FILE *infile = fopen(infilename, "rb");
if (infile == NULL) {
perror("yemu");
return 1;
}
init6502(infile);
}
if (system_name == NULL) {
printf("%s: no system specified\n", "yemu");
return 1;
} else if (!strcmp(system_name, "6502")) {
init6502(infile);
} else {
printf("%s: not supported system\n", "yemu");
return 1;
}
fclose(infile);
return 0;
}