LS7-Emulator/src/ls7emulator.c

90 lines
1.9 KiB
C
Raw Normal View History

2024-12-02 14:06:05 +01:00
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <SFML/System.h>
#include <SFML/Graphics.h>
#include <SFML/Window.h>
#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[]){
2024-12-02 14:31:43 +01:00
if (argc == 2) { openFile(argv[1]); }
else {
puts("Please specify a input file as an Argument");
exit(1);
}
2024-12-02 14:06:05 +01:00
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);
resetSystem();
while (sfRenderWindow_isOpen(window)){
pollEvents(window);
2024-12-02 14:31:43 +01:00
for (int i = 0; i < CPUSPEED; i++) step6502();
2024-12-02 14:06:05 +01:00
irq6502();
sfRenderWindow_clear(window, BACKCOLOR);
updateVideo();
drawScreen();
sfRenderWindow_display(window);
}
sfRenderWindow_destroy(window);
return 0;
}