diff --git a/src/ls7emulator.c b/src/ls7emulator.c new file mode 100644 index 0000000..b99c529 --- /dev/null +++ b/src/ls7emulator.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "ls7emulator.h" +#include "config.h" +#include "events.c" +#include "cpu.c" +#include "memory.c" +#include "video.c" +#include "keyboard.c" + + + +void openFile(const char *inputFile){ + FILE *file = fopen(inputFile, "rb"); + + if (file != NULL){ + fseek(file, 0, SEEK_END); + long filelen = ftell(file); + rewind(file); + + fread(rom, filelen, 1, file); + + printf("Loaded File\n"); + } else { + printf("Error while opening file\n"); + exit(1); + } + + fclose(file); +} + +void resetSystem(){ + initVideo(); + updateVideo(); + reset6502(); +} + +void updateRenderStates(){ + renderStates.transform = sfTransform_Identity; + sfTransform_scale(&renderStates.transform, displayScale, displayScale); +} + +void drawScreen(){ + sfRenderWindow_drawVertexArray(window, renderArray, &renderStates); +} + +int main(int argc, char *argv[]){ + window = sfRenderWindow_create((sfVideoMode){800, 600, 24}, "LS7 Emulator", sfResize | sfClose, NULL); + sfRenderWindow_setVerticalSyncEnabled(window, sfFalse); + sfRenderWindow_setFramerateLimit(window, 60); + sfRenderWindow_setKeyRepeatEnabled(window, sfFalse); + + renderStates = sfRenderStates_default(); + sfTransform_scale(&renderStates.transform, 2, 2); + + if (argc == 2) { openFile(argv[1]); } + else { + printf("Please specify a input file\n"); + exit(1); + } + resetSystem(); + + while (sfRenderWindow_isOpen(window)){ + pollEvents(window); + + for (int i = 0; i < 4096 * 16; i++) step6502(); + irq6502(); + + sfRenderWindow_clear(window, BACKCOLOR); + updateVideo(); + drawScreen(); + sfRenderWindow_display(window); + } + + sfRenderWindow_destroy(window); + + return 0; +} + + diff --git a/src/ls7emulator.h b/src/ls7emulator.h new file mode 100644 index 0000000..d305acc --- /dev/null +++ b/src/ls7emulator.h @@ -0,0 +1,13 @@ +#include +#include +#include + + +/* Display Scale used for VertexArray */ +static float displayScale = 2; + + +static sfVertexArray *renderArray; + +static sfRenderWindow *window; +static sfRenderStates renderStates;