89 lines
1.9 KiB
C
89 lines
1.9 KiB
C
|
#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[]){
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
|