Compare commits

..

6 Commits

Author SHA1 Message Date
0xmac
36e43fead5 Added Argument fetch + other stuff 2024-12-17 13:10:45 +01:00
0xmac
c5bca1ef5b Added function key functions 2024-12-17 13:10:31 +01:00
0xmac
308fe5ba50 Added function key functions 2024-12-17 13:10:12 +01:00
0xmac
c2a41c824c Added font reference to Makefile 2024-12-17 13:10:01 +01:00
0xmac
e4a05e27c7 Added Singlestepping feature 2024-12-12 14:23:47 +01:00
0xmac
1eb50d953d Cleanup 2024-12-12 14:23:33 +01:00
5 changed files with 152 additions and 38 deletions

View File

@ -20,6 +20,7 @@ ls7emulator:
cd ../bin cd ../bin
mv ../src/ls7emulator ./ mv ../src/ls7emulator ./
strip ls7emulator strip ls7emulator
cp ../src/assets/font.ttf ./
install: ls7emulator install: ls7emulator
mkdir -p $(PREFIX)/bin mkdir -p $(PREFIX)/bin

View File

@ -10,8 +10,36 @@
#define ROMLOC 0xC000 /* ROM Page Location */ #define ROMLOC 0xC000 /* ROM Page Location */
#define BACKCOLOR sfBlack #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;

View File

@ -4,10 +4,15 @@
#include <SFML/Window.h> #include <SFML/Window.h>
extern float displayScale; extern float displayScale;
extern int clocksteps;
extern uint8_t halt;
extern uint8_t showDebug;
extern uint8_t showHelp;
extern void resetSystem(); extern void resetSystem();
extern void irq6502(); extern void irq6502();
extern void nmi6502(); extern void nmi6502();
extern void step6502();
extern void updateRenderStates(); extern void updateRenderStates();
extern void scanKeyboard(); extern void scanKeyboard();
@ -27,34 +32,61 @@ void pollEvents(sfRenderWindow *window){
break; break;
case sfEvtKeyPressed: case sfEvtKeyPressed:
switch (event.key.code){ switch (event.key.code){
case sfKeyEscape: case sfKeyF1: /* Close Window or show help*/
sfRenderWindow_close(window); sfRenderWindow_close(window);
break; 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--; if (displayscale > 1) displayscale--;
updateRenderStates(); updateRenderStates();
break; break;
case sfKeyF3:
case sfKeyF7: /* Scale ++ */
displayscale++; displayscale++;
updateRenderStates(); updateRenderStates();
break; break;
case sfKeyF5:
resetSystem(); case sfKeyF8: /* CPU Singlestep */
for (int i = 0; i < clocksteps; i++) step6502();
break; break;
case sfKeyF12:
irq6502(); case sfKeyF9: /* CPU Save Snapshot */
break; break;
case sfKeyF11:
case sfKeyF10: /* CPU Load recent or given snapshot */
break;
case sfKeyF11: /* CPU NMI */
nmi6502(); nmi6502();
break; break;
case sfKeyF12: /* CPU IRQ */
irq6502();
break;
default: default:
currentKey = event.key.code; currentKey = event.key.code;
break; break;
} }
break; break;
case sfEvtKeyReleased: case sfEvtKeyReleased:
// To tell keyboard.c, that no key is being pressed
currentKey = sfKeyUnknown; currentKey = sfKeyUnknown;
break; break;

View File

@ -18,26 +18,30 @@
sfVertexArray *renderArray; sfVertexArray *renderArray;
sfRenderWindow *window; sfRenderWindow *window;
sfFont *font;
sfText *renderText;
sfRenderStates renderStates; 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"); FILE *file = fopen(inputFile, "rb");
int retCode = 0;
if (file != NULL){ if (file != NULL){
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
long filelen = ftell(file); long filelen = ftell(file);
rewind(file); rewind(file);
fread(rom, filelen, 1, file); if (fread(rom, filelen, 1, file) != 1) retCode = 1;
} else retCode = 1;
printf("Loaded File\n");
} else {
printf("Error while opening file\n");
exit(1);
}
fclose(file); fclose(file);
return retCode;
} }
void resetSystem(){ void resetSystem(){
@ -48,35 +52,87 @@ void resetSystem(){
void updateRenderStates(){ void updateRenderStates(){
renderStates.transform = sfTransform_Identity; renderStates.transform = sfTransform_Identity;
sfTransform_scale(&renderStates.transform, displayScale, displayScale); sfTransform_scale(&renderStates.transform, displayscale, displayscale);
} }
void drawScreen(){ void drawScreen(){
sfRenderWindow_drawVertexArray(window, renderArray, &renderStates); 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[]){ int main(int argc, char *argv[]){
if (argc == 2) { openFile(argv[1]); } fetchArgs(argc, argv);
else {
puts("Please specify a input file as an Argument");
exit(1);
}
window = sfRenderWindow_create((sfVideoMode){800, 600, 24}, "LS7 Emulator", sfResize | sfClose, NULL); window = sfRenderWindow_create((sfVideoMode){800, 600, 24}, "LS7 Emulator", sfResize | sfClose, NULL);
sfRenderWindow_setVerticalSyncEnabled(window, sfFalse); sfRenderWindow_setVerticalSyncEnabled(window, sfFalse);
sfRenderWindow_setFramerateLimit(window, 60); sfRenderWindow_setFramerateLimit(window, FPS);
sfRenderWindow_setKeyRepeatEnabled(window, sfFalse); 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(); renderStates = sfRenderStates_default();
sfTransform_scale(&renderStates.transform, 2, 2); sfTransform_scale(&renderStates.transform, displayscale, displayscale);
resetSystem(); resetSystem();
while (sfRenderWindow_isOpen(window)){ while (sfRenderWindow_isOpen(window)){
pollEvents(window); pollEvents(window);
for (int i = 0; i < CPUSPEED; i++) step6502(); if (!singlestep && !halt){
irq6502(); for (int i = 0; i < cpuspeed / FPS; i++) step6502();
irq6502();
}
sfRenderWindow_clear(window, BACKCOLOR); sfRenderWindow_clear(window, BACKCOLOR);
updateVideo(); updateVideo();
@ -86,7 +142,7 @@ int main(int argc, char *argv[]){
sfRenderWindow_destroy(window); sfRenderWindow_destroy(window);
return 0; return EXIT_SUCCESS;
} }

View File

@ -21,9 +21,7 @@ uint8_t read6502(uint16_t address){
return keyboardResult; return keyboardResult;
break; break;
default: default: return NOP;
return NOP;
break;
} }
} }
@ -54,11 +52,10 @@ void write6502(uint16_t address, uint8_t value){
break; break;
} }
break; break;
case 0xBC00:
systemRegister = value; case 0xBC00:
break; systemRegister = value;
break;
default: default: break;
break;
} }
} }