Added main c file
This commit is contained in:
parent
a3fa133480
commit
0227bc634f
88
src/ls7emulator.c
Normal file
88
src/ls7emulator.c
Normal file
@ -0,0 +1,88 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
|
13
src/ls7emulator.h
Normal file
13
src/ls7emulator.h
Normal file
@ -0,0 +1,13 @@
|
||||
#include <SFML/System.h>
|
||||
#include <SFML/Graphics.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/* Display Scale used for VertexArray */
|
||||
static float displayScale = 2;
|
||||
|
||||
|
||||
static sfVertexArray *renderArray;
|
||||
|
||||
static sfRenderWindow *window;
|
||||
static sfRenderStates renderStates;
|
Loading…
Reference in New Issue
Block a user