Compare commits
6 Commits
cfce402934
...
36e43fead5
Author | SHA1 | Date | |
---|---|---|---|
|
36e43fead5 | ||
|
c5bca1ef5b | ||
|
308fe5ba50 | ||
|
c2a41c824c | ||
|
e4a05e27c7 | ||
|
1eb50d953d |
1
Makefile
1
Makefile
@ -20,6 +20,7 @@ ls7emulator:
|
||||
cd ../bin
|
||||
mv ../src/ls7emulator ./
|
||||
strip ls7emulator
|
||||
cp ../src/assets/font.ttf ./
|
||||
|
||||
install: ls7emulator
|
||||
mkdir -p $(PREFIX)/bin
|
||||
|
32
src/config.h
32
src/config.h
@ -10,8 +10,36 @@
|
||||
#define ROMLOC 0xC000 /* ROM Page Location */
|
||||
|
||||
#define BACKCOLOR sfBlack
|
||||
#define FPS 60
|
||||
|
||||
#define CPUSPEED 4096 * 16
|
||||
#define PREAMBLE "LS7 Emulator by Gabriel Weingardt.\nLicense: GPL v.3+\n\n"
|
||||
|
||||
#define HELP "Usage: LS7Emulator [options] file\n\n\
|
||||
Options: Type Default Desc\n\
|
||||
--help Show this menu\n\
|
||||
--help-keys Show emulator key functions\n\
|
||||
--cpuspeed [int] 100000 CPU Speed given in Herz. KHz and MHz annotations like 1KHz are supported\n\
|
||||
--scale [float] 2.0 Set the starting scale of the video output\n\
|
||||
--singlestep Enable singlestepping with the 'F8' key\n\
|
||||
--clocksteps [int] 1 Set the clock cycles cycled by a singlestep\n\
|
||||
--snapshot [string] Import a CPU snapshot\n\
|
||||
\n"
|
||||
|
||||
static float displayScale = 2;
|
||||
#define HELPKEYS "\
|
||||
F1 Exit emulator\n\
|
||||
F2 Show Key Help\n\
|
||||
F3 Show Debug Menu\n\
|
||||
F4 Halt CPU\n\
|
||||
F5 Reset CPU\n\
|
||||
F6 Scale--\n\
|
||||
F7 Scale++\n\
|
||||
F8 Single step CPU\n\
|
||||
F9 Save CPU snapshot\n\
|
||||
F10 Load previous snapshot\n\
|
||||
F11 CPU NMI\n\
|
||||
F12 CPU IRQ\n\n"
|
||||
|
||||
static float displayscale = 2;
|
||||
static int cpuspeed = 100000; // 100 kHz
|
||||
static int singlestep = 0;
|
||||
static int clocksteps = 1;
|
||||
|
48
src/events.c
48
src/events.c
@ -4,10 +4,15 @@
|
||||
#include <SFML/Window.h>
|
||||
|
||||
extern float displayScale;
|
||||
extern int clocksteps;
|
||||
extern uint8_t halt;
|
||||
extern uint8_t showDebug;
|
||||
extern uint8_t showHelp;
|
||||
|
||||
extern void resetSystem();
|
||||
extern void irq6502();
|
||||
extern void nmi6502();
|
||||
extern void step6502();
|
||||
extern void updateRenderStates();
|
||||
extern void scanKeyboard();
|
||||
|
||||
@ -27,34 +32,61 @@ void pollEvents(sfRenderWindow *window){
|
||||
break;
|
||||
case sfEvtKeyPressed:
|
||||
switch (event.key.code){
|
||||
case sfKeyEscape:
|
||||
case sfKeyF1: /* Close Window or show help*/
|
||||
sfRenderWindow_close(window);
|
||||
break;
|
||||
|
||||
case sfKeyF2:
|
||||
case sfKeyF2: /* Show Key Help */
|
||||
showHelp = !showHelp;
|
||||
break;
|
||||
|
||||
case sfKeyF3: /* Show Debug Menu */
|
||||
showDebug = !showDebug;
|
||||
break;
|
||||
|
||||
case sfKeyF4: /* CPU Halt */
|
||||
halt = !halt;
|
||||
break;
|
||||
|
||||
case sfKeyF5: /* CPU Reset */
|
||||
resetSystem();
|
||||
break;
|
||||
|
||||
case sfKeyF6: /* Scale -- */
|
||||
if (displayscale > 1) displayscale--;
|
||||
updateRenderStates();
|
||||
break;
|
||||
case sfKeyF3:
|
||||
|
||||
case sfKeyF7: /* Scale ++ */
|
||||
displayscale++;
|
||||
updateRenderStates();
|
||||
break;
|
||||
case sfKeyF5:
|
||||
resetSystem();
|
||||
|
||||
case sfKeyF8: /* CPU Singlestep */
|
||||
for (int i = 0; i < clocksteps; i++) step6502();
|
||||
break;
|
||||
case sfKeyF12:
|
||||
irq6502();
|
||||
|
||||
case sfKeyF9: /* CPU Save Snapshot */
|
||||
break;
|
||||
case sfKeyF11:
|
||||
|
||||
case sfKeyF10: /* CPU Load recent or given snapshot */
|
||||
break;
|
||||
|
||||
case sfKeyF11: /* CPU NMI */
|
||||
nmi6502();
|
||||
break;
|
||||
|
||||
case sfKeyF12: /* CPU IRQ */
|
||||
irq6502();
|
||||
break;
|
||||
|
||||
default:
|
||||
currentKey = event.key.code;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case sfEvtKeyReleased:
|
||||
// To tell keyboard.c, that no key is being pressed
|
||||
currentKey = sfKeyUnknown;
|
||||
break;
|
||||
|
||||
|
94
src/main.c
94
src/main.c
@ -18,26 +18,30 @@
|
||||
|
||||
sfVertexArray *renderArray;
|
||||
sfRenderWindow *window;
|
||||
sfFont *font;
|
||||
sfText *renderText;
|
||||
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");
|
||||
int retCode = 0;
|
||||
|
||||
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);
|
||||
}
|
||||
if (fread(rom, filelen, 1, file) != 1) retCode = 1;
|
||||
} else retCode = 1;
|
||||
|
||||
fclose(file);
|
||||
|
||||
return retCode;
|
||||
}
|
||||
|
||||
void resetSystem(){
|
||||
@ -48,35 +52,87 @@ void resetSystem(){
|
||||
|
||||
void updateRenderStates(){
|
||||
renderStates.transform = sfTransform_Identity;
|
||||
sfTransform_scale(&renderStates.transform, displayScale, displayScale);
|
||||
sfTransform_scale(&renderStates.transform, displayscale, displayscale);
|
||||
}
|
||||
|
||||
void drawScreen(){
|
||||
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[]){
|
||||
if (argc == 2) { openFile(argv[1]); }
|
||||
else {
|
||||
puts("Please specify a input file as an Argument");
|
||||
exit(1);
|
||||
}
|
||||
fetchArgs(argc, argv);
|
||||
|
||||
window = sfRenderWindow_create((sfVideoMode){800, 600, 24}, "LS7 Emulator", sfResize | sfClose, NULL);
|
||||
sfRenderWindow_setVerticalSyncEnabled(window, sfFalse);
|
||||
sfRenderWindow_setFramerateLimit(window, 60);
|
||||
sfRenderWindow_setFramerateLimit(window, FPS);
|
||||
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();
|
||||
sfTransform_scale(&renderStates.transform, 2, 2);
|
||||
sfTransform_scale(&renderStates.transform, displayscale, displayscale);
|
||||
|
||||
resetSystem();
|
||||
|
||||
while (sfRenderWindow_isOpen(window)){
|
||||
pollEvents(window);
|
||||
|
||||
for (int i = 0; i < CPUSPEED; i++) step6502();
|
||||
irq6502();
|
||||
if (!singlestep && !halt){
|
||||
for (int i = 0; i < cpuspeed / FPS; i++) step6502();
|
||||
irq6502();
|
||||
}
|
||||
|
||||
sfRenderWindow_clear(window, BACKCOLOR);
|
||||
updateVideo();
|
||||
@ -86,7 +142,7 @@ int main(int argc, char *argv[]){
|
||||
|
||||
sfRenderWindow_destroy(window);
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
15
src/memory.c
15
src/memory.c
@ -21,9 +21,7 @@ uint8_t read6502(uint16_t address){
|
||||
return keyboardResult;
|
||||
break;
|
||||
|
||||
default:
|
||||
return NOP;
|
||||
break;
|
||||
default: return NOP;
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,11 +52,10 @@ void write6502(uint16_t address, uint8_t value){
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case 0xBC00:
|
||||
systemRegister = value;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
case 0xBC00:
|
||||
systemRegister = value;
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user