Added on-screen info rendering
This commit is contained in:
parent
f1ff0606e7
commit
f99d710a8b
88
src/main.c
88
src/main.c
@ -1,3 +1,4 @@
|
|||||||
|
#include <SDL2/SDL_render.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -25,19 +26,23 @@ uint8_t halt = 0;
|
|||||||
uint8_t showHelp = 0;
|
uint8_t showHelp = 0;
|
||||||
uint8_t showDebug = 0;
|
uint8_t showDebug = 0;
|
||||||
uint8_t fpsCount = 0;
|
uint8_t fpsCount = 0;
|
||||||
|
uint8_t displayMmap = 0;
|
||||||
|
uint8_t documentReload = 0;
|
||||||
|
|
||||||
uint8_t fpsStore;
|
uint8_t fpsStore = 60;
|
||||||
|
uint8_t FPS = 30;
|
||||||
uint8_t cpuHealth;
|
uint8_t cpuHealth;
|
||||||
|
|
||||||
unsigned long cpuTicks = 0;
|
unsigned long cpuTicks = 0;
|
||||||
unsigned long tickTrigger = 0;
|
unsigned long tickTrigger = 0;
|
||||||
unsigned long renderTrigger = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char debugString[255];
|
char debugString[512];
|
||||||
|
char snapshotFile[32];
|
||||||
|
char *inputFile;
|
||||||
|
|
||||||
int openFile(const char *inputFile){
|
int openFile(){
|
||||||
FILE *file = fopen(inputFile, "rb");
|
FILE *file = fopen(inputFile, "rb");
|
||||||
int retCode = 0;
|
int retCode = 0;
|
||||||
|
|
||||||
@ -60,32 +65,23 @@ void resetSystem(){
|
|||||||
reset6502();
|
reset6502();
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeHelp(int type){
|
|
||||||
if (!type) printf(HELP);
|
|
||||||
else printf(HELPKEYS);
|
|
||||||
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
|
|
||||||
void writePreamble() {
|
|
||||||
printf(PREAMBLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void fetchArgs(int argc, char *argv[]){
|
void fetchArgs(int argc, char *argv[]){
|
||||||
writePreamble();
|
printf(PREAMBLE);
|
||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (!strcmp(argv[i], "--help")) writeHelp(0);
|
if (!strcmp(argv[i], "--help")) printf(HELP);
|
||||||
else if (!strcmp(argv[i], "--help-keys")) writeHelp(1);
|
else if (!strcmp(argv[i], "--help-keys")) printf(HELPKEYS);
|
||||||
else if (!strcmp(argv[i], "--cpuspeed")) cpuSpeed = atoi(argv[++i]);
|
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], "--scale")) displayScale = atof(argv[++i]);
|
||||||
else if (!strcmp(argv[i], "--singlestep")) singleStep = 1;
|
else if (!strcmp(argv[i], "--singlestep")) singleStep = 1;
|
||||||
else if (!strcmp(argv[i], "--clocksteps")) clockSteps = atoi(argv[++i]);
|
else if (!strcmp(argv[i], "--clocksteps")) clockSteps = atoi(argv[++i]);
|
||||||
//else if (!strcmp(argv[i], "--snapshot")) snapshotFile = &argv[i];
|
//else if (!strcmp(argv[i], "--snapshot")) snapshotFile = &argv[i];
|
||||||
|
else if (!strcmp(argv[i], "--fps")) FPS = atoi(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "--enable-reload")) documentReload = 1;
|
||||||
else {
|
else {
|
||||||
if (openFile(argv[i])){
|
inputFile = argv[i];
|
||||||
printf("Unknown parameter or file '%s'\nTry '--help' for help\n", argv[i]);
|
if (openFile()){
|
||||||
|
printf("%s: Unknown parameter or file '%s'\nTry '--help' for help\n", argv[0], argv[i]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,15 +96,14 @@ int main(int argc, char *argv[]){
|
|||||||
resetSystem();
|
resetSystem();
|
||||||
|
|
||||||
while (1){
|
while (1){
|
||||||
SDL_Delay(32);
|
SDL_Delay(1000.f / FPS);
|
||||||
pollEvents();
|
pollEvents();
|
||||||
|
|
||||||
fpsCount++;
|
fpsCount++;
|
||||||
|
|
||||||
updateVideo();
|
updateVideo();
|
||||||
|
|
||||||
if (!singleStep && !halt){
|
if (!singleStep && !halt){
|
||||||
for (int i = 0; i < (cpuSpeed / FPS) * 2; i++) {
|
for (int i = 0; i < ((float)cpuSpeed / (float)fpsStore); i++) {
|
||||||
step6502();
|
step6502();
|
||||||
cpuTicks++;
|
cpuTicks++;
|
||||||
}
|
}
|
||||||
@ -121,13 +116,45 @@ int main(int argc, char *argv[]){
|
|||||||
cpuHealth = (uint8_t)((cpuTicks / (float)cpuSpeed) * 100.);
|
cpuHealth = (uint8_t)((cpuTicks / (float)cpuSpeed) * 100.);
|
||||||
cpuTicks = 0;
|
cpuTicks = 0;
|
||||||
|
|
||||||
fpsStore = fpsCount;
|
fpsStore = fpsCount; fpsCount = 0;
|
||||||
fpsCount = 0;
|
|
||||||
|
/* Refresh entire video buffer */
|
||||||
|
videoModified = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Redraw entire screen every X seconds */
|
|
||||||
//if ((unsigned)time(NULL) > renderTrigger + 0){
|
uint16_t vStack = 16;
|
||||||
renderTrigger = (unsigned)time(NULL);
|
|
||||||
|
if (halt) {
|
||||||
|
drawString("!CPU Haltet!", renderMemory,
|
||||||
|
SDL_X_SIZE, 0x000000FF, time(NULL) % 2 ? 0xAAAAAAFF : 0xFFFFFFFF, 16, vStack, 2);
|
||||||
|
|
||||||
|
vStack += (FONT_HEIGHT * 2 * 2);
|
||||||
|
} if (showDebug){
|
||||||
|
sprintf(debugString, "LOADED BINARY: \"%s\"\nSCREENSIZE: %dx%d\nFPS: %d\nSCALE: %d", inputFile, SDL_X_SIZE, SDL_Y_SIZE, fpsStore, (int)displayScale);
|
||||||
|
drawString(debugString, renderMemory,
|
||||||
|
SDL_X_SIZE, 0x000000FF, 0xAAAAAAFF, 16, vStack, 2);
|
||||||
|
|
||||||
|
vStack += (FONT_HEIGHT * 4 * 2);
|
||||||
|
|
||||||
|
sprintf(debugString, "CPU: %d%%", cpuHealth);
|
||||||
|
drawString(debugString, renderMemory,
|
||||||
|
SDL_X_SIZE, 0x000000FF, time(NULL) % 2 ? 0xAAAAAAFF : cpuHealth < 10 ?
|
||||||
|
0xFF0000FF : cpuHealth < 50 ? 0xFFFF00FF : 0xAAAAAAFF, 16, vStack, 2);
|
||||||
|
|
||||||
|
vStack += (FONT_HEIGHT * 2 * 2);
|
||||||
|
} if (displayMmap){
|
||||||
|
sprintf(debugString, "RAM: $%04X - $%04X\nROM: $%04X - $%04X\nVIAADDRS: $%04X\nKBDADDRS: $%04X\nVIDADDRS: $%04X", RAMLOC, RAMLOC + RAMSIZE, ROMLOC, ROMLOC + ROMSIZE, VIAADDRS, KBDADDRS, VIDADDRS);
|
||||||
|
drawString(debugString, renderMemory, SDL_X_SIZE, 0x000000FF, 0xAAAAAAFF, 16, vStack, 2);
|
||||||
|
|
||||||
|
vStack += (FONT_HEIGHT * 6 * 2);
|
||||||
|
} if (showHelp) {
|
||||||
|
drawString(HELPKEYS, renderMemory, SDL_X_SIZE, 0x000000FF, 0xAAAAAAFF, 16, vStack, 2);
|
||||||
|
|
||||||
|
vStack += (FONT_HEIGHT * 2 * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (SDL_UpdateTexture(texture, NULL, renderMemory, (sizeof(uint32_t) * SDL_X_SIZE))) {
|
if (SDL_UpdateTexture(texture, NULL, renderMemory, (sizeof(uint32_t) * SDL_X_SIZE))) {
|
||||||
fprintf(stderr, "Could not update SDL texture: %s.\n", SDL_GetError());
|
fprintf(stderr, "Could not update SDL texture: %s.\n", SDL_GetError());
|
||||||
@ -137,11 +164,12 @@ int main(int argc, char *argv[]){
|
|||||||
fprintf(stderr, "Could not display SDL texture: %s.\n", SDL_GetError());
|
fprintf(stderr, "Could not display SDL texture: %s.\n", SDL_GetError());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user