Added Argument fetch + other stuff
This commit is contained in:
parent
c5bca1ef5b
commit
36e43fead5
92
src/main.c
92
src/main.c
@ -18,26 +18,30 @@
|
|||||||
|
|
||||||
sfVertexArray *renderArray;
|
sfVertexArray *renderArray;
|
||||||
sfRenderWindow *window;
|
sfRenderWindow *window;
|
||||||
|
sfFont *font;
|
||||||
|
sfText *renderText;
|
||||||
sfRenderStates renderStates;
|
sfRenderStates renderStates;
|
||||||
|
sfRectangleShape *haltRect;
|
||||||
|
|
||||||
|
uint8_t halt = 0;
|
||||||
|
uint8_t showHelp = 0;
|
||||||
|
uint8_t showDebug = 0;
|
||||||
|
|
||||||
void openFile(const char *inputFile){
|
int openFile(const char *inputFile){
|
||||||
FILE *file = fopen(inputFile, "rb");
|
FILE *file = fopen(inputFile, "rb");
|
||||||
|
int retCode = 0;
|
||||||
|
|
||||||
if (file != NULL){
|
if (file != NULL){
|
||||||
fseek(file, 0, SEEK_END);
|
fseek(file, 0, SEEK_END);
|
||||||
long filelen = ftell(file);
|
long filelen = ftell(file);
|
||||||
rewind(file);
|
rewind(file);
|
||||||
|
|
||||||
fread(rom, filelen, 1, file);
|
if (fread(rom, filelen, 1, file) != 1) retCode = 1;
|
||||||
|
} else retCode = 1;
|
||||||
printf("Loaded File\n");
|
|
||||||
} else {
|
|
||||||
printf("Error while opening file\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetSystem(){
|
void resetSystem(){
|
||||||
@ -48,35 +52,87 @@ void resetSystem(){
|
|||||||
|
|
||||||
void updateRenderStates(){
|
void updateRenderStates(){
|
||||||
renderStates.transform = sfTransform_Identity;
|
renderStates.transform = sfTransform_Identity;
|
||||||
sfTransform_scale(&renderStates.transform, displayScale, displayScale);
|
sfTransform_scale(&renderStates.transform, displayscale, displayscale);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawScreen(){
|
void drawScreen(){
|
||||||
sfRenderWindow_drawVertexArray(window, renderArray, &renderStates);
|
sfRenderWindow_drawVertexArray(window, renderArray, &renderStates);
|
||||||
|
if (halt){
|
||||||
|
sfRenderWindow_drawRectangleShape(window, haltRect, &renderStates);
|
||||||
|
}
|
||||||
|
if (showHelp){
|
||||||
|
sfText_setString(renderText, HELPKEYS);
|
||||||
|
|
||||||
|
sfRenderWindow_drawText(window, renderText, &renderStates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeHelp(int type){
|
||||||
|
if (!type) printf(HELP);
|
||||||
|
else printf(HELPKEYS);
|
||||||
|
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writePreamble() {
|
||||||
|
printf(PREAMBLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fetchArgs(int argc, char *argv[]){
|
||||||
|
writePreamble();
|
||||||
|
|
||||||
|
for (int i = 1; i < argc; i++) {
|
||||||
|
if (!strcmp(argv[i], "--help")) writeHelp(0);
|
||||||
|
else if (!strcmp(argv[i], "--help-keys")) writeHelp(1);
|
||||||
|
else if (!strcmp(argv[i], "--cpuspeed")) cpuspeed = atoi(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "--scale")) displayscale = atof(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "--singlestep")) singlestep = 1;
|
||||||
|
else if (!strcmp(argv[i], "--clocksteps")) clocksteps = atoi(argv[++i]);
|
||||||
|
//else if (!strcmp(argv[i], "--snapshot")) snapshotFile = &argv[i];
|
||||||
|
|
||||||
|
else {
|
||||||
|
if (openFile(argv[i])){
|
||||||
|
printf("Unknown parameter or file '%s'\nTry '--help' for help\n", argv[i]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
if (argc == 2) { openFile(argv[1]); }
|
fetchArgs(argc, argv);
|
||||||
else {
|
|
||||||
puts("Please specify a input file as an Argument");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
window = sfRenderWindow_create((sfVideoMode){800, 600, 24}, "LS7 Emulator", sfResize | sfClose, NULL);
|
window = sfRenderWindow_create((sfVideoMode){800, 600, 24}, "LS7 Emulator", sfResize | sfClose, NULL);
|
||||||
sfRenderWindow_setVerticalSyncEnabled(window, sfFalse);
|
sfRenderWindow_setVerticalSyncEnabled(window, sfFalse);
|
||||||
sfRenderWindow_setFramerateLimit(window, 60);
|
sfRenderWindow_setFramerateLimit(window, FPS);
|
||||||
sfRenderWindow_setKeyRepeatEnabled(window, sfFalse);
|
sfRenderWindow_setKeyRepeatEnabled(window, sfFalse);
|
||||||
|
|
||||||
|
font = sfFont_createFromFile("bin/font.ttf");
|
||||||
|
|
||||||
|
renderText = sfText_create();
|
||||||
|
sfText_setPosition(renderText, (sfVector2f){ 50, 50 });
|
||||||
|
sfText_setFont(renderText, font);
|
||||||
|
sfText_setCharacterSize(renderText, 10);
|
||||||
|
sfText_setFillColor(renderText, sfWhite);
|
||||||
|
sfText_setOutlineColor(renderText, sfBlack);
|
||||||
|
sfText_setOutlineThickness(renderText, 1);
|
||||||
|
|
||||||
|
haltRect = sfRectangleShape_create();
|
||||||
|
sfRectangleShape_setFillColor(haltRect, (sfColor){ 0, 0, 0, 128 });
|
||||||
|
sfRectangleShape_setSize(haltRect, (sfVector2f){ 384, 256 });
|
||||||
|
|
||||||
renderStates = sfRenderStates_default();
|
renderStates = sfRenderStates_default();
|
||||||
sfTransform_scale(&renderStates.transform, 2, 2);
|
sfTransform_scale(&renderStates.transform, displayscale, displayscale);
|
||||||
|
|
||||||
resetSystem();
|
resetSystem();
|
||||||
|
|
||||||
while (sfRenderWindow_isOpen(window)){
|
while (sfRenderWindow_isOpen(window)){
|
||||||
pollEvents(window);
|
pollEvents(window);
|
||||||
|
|
||||||
for (int i = 0; i < CPUSPEED; i++) step6502();
|
if (!singlestep && !halt){
|
||||||
|
for (int i = 0; i < cpuspeed / FPS; i++) step6502();
|
||||||
irq6502();
|
irq6502();
|
||||||
|
}
|
||||||
|
|
||||||
sfRenderWindow_clear(window, BACKCOLOR);
|
sfRenderWindow_clear(window, BACKCOLOR);
|
||||||
updateVideo();
|
updateVideo();
|
||||||
@ -86,7 +142,7 @@ int main(int argc, char *argv[]){
|
|||||||
|
|
||||||
sfRenderWindow_destroy(window);
|
sfRenderWindow_destroy(window);
|
||||||
|
|
||||||
return 0;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user