diff --git a/src/main.c b/src/main.c index feb1cd9..dc63743 100644 --- a/src/main.c +++ b/src/main.c @@ -31,17 +31,20 @@ uint8_t fpsCount = 0; uint8_t displayMmap = 0; uint8_t documentReload = 0; uint8_t randomize = 0; +uint8_t trueViewport = 0; uint8_t fpsStore = 60; uint8_t FPS = 30; -uint8_t cpuHealth; +uint8_t cpuHealth = 100; +uint32_t videoStore = 0; +uint32_t videoUpdates = 0; unsigned long cpuTicks = 0; unsigned long tickTrigger = 0; char debugString[512]; char snapshotFile[32]; -char *reloadExecute; +char *reloadExecute = 0; char *inputFile; char *displaySpeed; @@ -109,6 +112,7 @@ void fetchArgs(int argc, char *argv[]){ else if (!strcmp(argv[i], "--script")) reloadExecute = argv[++i]; else if (!strcmp(argv[i], "--resizable")) WINMODE |= SDL_WINDOW_RESIZABLE; else if (!strcmp(argv[i], "--randomize")) randomize = 1; + else if (!strcmp(argv[i], "--true-viewport")) trueViewport = 1; else { inputFile = argv[i]; if (openFile()){ @@ -132,8 +136,7 @@ int main(int argc, char *argv[]){ pollEvents(); fpsCount++; - updateVideo(); - + if (!singleStep && !halt){ for (int i = 0; i < ((float)cpuSpeed / (float)fpsStore); i++) { step6502(); @@ -141,33 +144,33 @@ int main(int argc, char *argv[]){ } irq6502(); } - - if ((unsigned)time(NULL) != tickTrigger){ - tickTrigger = (unsigned)time(NULL); - + + /* Ticker before menu draw */ + if ((unsigned)time(NULL) != tickTrigger){ cpuHealth = (uint8_t)((cpuTicks / (float)cpuSpeed) * 100.); cpuTicks = 0; fpsStore = fpsCount; fpsCount = 0; - - /* Refresh entire video buffer */ - videoModified = 1; + + /* Refresh entire video field every second */ + updateVideo(); } uint16_t vStack = 16; if (halt) { - drawString("!CPU Haltet!", renderMemory, + drawString("!CPU HALTET!", renderMemory, SDL_X_SIZE, 0x000000FF, time(NULL) % 2 ? 0xAAAAAAFF : 0xFFFFFFFF, 16, vStack, 1); vStack += (FONT_HEIGHT * 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); + sprintf(debugString, "LOADED BINARY: \"%s\"\nSCREENSIZE: %dx%d\nFPS: %d\nSCALE: %d\nVIDEO UPDATES: %d", + inputFile, SDL_X_SIZE, SDL_Y_SIZE, fpsStore, (int)displayScale, videoStore); drawString(debugString, renderMemory, SDL_X_SIZE, 0x000000FF, 0xAAAAAAFF, 16, vStack, 1); - vStack += (FONT_HEIGHT * 4); + vStack += (FONT_HEIGHT * 5); sprintf(debugString, "CPU: %d%% @ %s", cpuHealth, displaySpeed); drawString(debugString, renderMemory, @@ -196,6 +199,15 @@ int main(int argc, char *argv[]){ } SDL_RenderPresent(renderer); + + + /* Ticker after menu draw */ + if ((unsigned)time(NULL) != tickTrigger){ + tickTrigger = (unsigned)time(NULL); + + videoStore = videoUpdates; + videoUpdates = 0; + } } return EXIT_SUCCESS; diff --git a/src/memory.c b/src/memory.c index fa5b7fb..4edcfdf 100644 --- a/src/memory.c +++ b/src/memory.c @@ -2,6 +2,7 @@ #include "config.h" extern void scanKeyboard(); +extern void updateVideo(); extern void writeVideo(); extern uint8_t readVideo(); extern uint8_t videoX; @@ -64,6 +65,7 @@ void write6502(uint16_t address, uint8_t value){ break; case 2: /* Video M Register */ videoMode = value; + updateVideo(); break; case 3: /* Video A Register */ videoA = value; diff --git a/src/video.c b/src/video.c index 47afda4..779b282 100644 --- a/src/video.c +++ b/src/video.c @@ -5,12 +5,10 @@ #define HIGHCOLOR 255 #define LOWCOLOR 96 +extern uint32_t videoUpdates; extern float displayScale; extern uint8_t randomize; -/* Public Variables */ -int8_t videoModified; - /* Hardware-like Registers */ uint8_t videoX; uint8_t videoY; @@ -47,22 +45,10 @@ void updatePalette(){ } void initVideo(){ - videoModified = 1; videoMode = 0x01; updatePalette(); - if (randomize) { - for (int i = 0; i < 0x8000; i++) videoMemory[i] = rand(); - } -} - -void writeVideo(){ - videoMemory[videoX + (videoY * 128)] = videoA; - videoModified = 1; -} - -uint8_t readVideo(){ - return videoMemory[videoX + (videoY * 128)]; + if (randomize) for (int i = 0; i < 0x8000; i++) videoMemory[i] = rand(); } void setPixels(uint8_t x, uint8_t y){ @@ -84,6 +70,7 @@ void setPixels(uint8_t x, uint8_t y){ videoColorValue = videoMemory[(((y & 0xF8) >> 3) << 7) + (x | 0x40)]; } else { + /* Bitmapped Graphics mode fetch */ videoValue = videoMemory[(y * 128) + x]; videoColorValue = videoMemory[(y * 128) + (x | 0x40)]; } @@ -97,13 +84,35 @@ void setPixels(uint8_t x, uint8_t y){ } void updateVideo(){ - if (videoModified){ - for (uint16_t y = 0; y < 256; y++){ - for (uint8_t x = 0; x < 48; x++){ - setPixels(x, (uint8_t)y); - } + for (uint16_t y = 0; y < 256; y++){ + for (uint8_t x = 0; x < 48; x++){ + setPixels(x, (uint8_t)y); } - - videoModified = 0; } } + +void writeVideo(){ + /* Update actual video memory */ + videoMemory[videoX + (videoY * 128)] = videoA; + + /* X has to be in a viewable location and must not be in font */ + if ((videoX > 0x3F || videoX < 0x30) && videoX < 0x70){ + + if ((videoMode & 0x01) == 0) { + /* For text mode, update the entire block */ + for (uint8_t i = 0; i < 8; i++){ + setPixels((videoX & 0b00111111), (uint8_t)((videoY*8) + i)); + } + videoUpdates++; + } else { + /* Graphics mode, just update line */ + setPixels(videoX & 0b00111111, videoY); + videoUpdates++; + } + } +} + +uint8_t readVideo(){ + return videoMemory[videoX + (videoY * 128)]; +} +