Made individual pixel rendering more efficient
This commit is contained in:
parent
45b8993cdd
commit
17cb64b9dc
32
src/main.c
32
src/main.c
@ -31,17 +31,20 @@ uint8_t fpsCount = 0;
|
|||||||
uint8_t displayMmap = 0;
|
uint8_t displayMmap = 0;
|
||||||
uint8_t documentReload = 0;
|
uint8_t documentReload = 0;
|
||||||
uint8_t randomize = 0;
|
uint8_t randomize = 0;
|
||||||
|
uint8_t trueViewport = 0;
|
||||||
|
|
||||||
uint8_t fpsStore = 60;
|
uint8_t fpsStore = 60;
|
||||||
uint8_t FPS = 30;
|
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 cpuTicks = 0;
|
||||||
unsigned long tickTrigger = 0;
|
unsigned long tickTrigger = 0;
|
||||||
|
|
||||||
char debugString[512];
|
char debugString[512];
|
||||||
char snapshotFile[32];
|
char snapshotFile[32];
|
||||||
char *reloadExecute;
|
char *reloadExecute = 0;
|
||||||
char *inputFile;
|
char *inputFile;
|
||||||
char *displaySpeed;
|
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], "--script")) reloadExecute = argv[++i];
|
||||||
else if (!strcmp(argv[i], "--resizable")) WINMODE |= SDL_WINDOW_RESIZABLE;
|
else if (!strcmp(argv[i], "--resizable")) WINMODE |= SDL_WINDOW_RESIZABLE;
|
||||||
else if (!strcmp(argv[i], "--randomize")) randomize = 1;
|
else if (!strcmp(argv[i], "--randomize")) randomize = 1;
|
||||||
|
else if (!strcmp(argv[i], "--true-viewport")) trueViewport = 1;
|
||||||
else {
|
else {
|
||||||
inputFile = argv[i];
|
inputFile = argv[i];
|
||||||
if (openFile()){
|
if (openFile()){
|
||||||
@ -132,7 +136,6 @@ int main(int argc, char *argv[]){
|
|||||||
pollEvents();
|
pollEvents();
|
||||||
|
|
||||||
fpsCount++;
|
fpsCount++;
|
||||||
updateVideo();
|
|
||||||
|
|
||||||
if (!singleStep && !halt){
|
if (!singleStep && !halt){
|
||||||
for (int i = 0; i < ((float)cpuSpeed / (float)fpsStore); i++) {
|
for (int i = 0; i < ((float)cpuSpeed / (float)fpsStore); i++) {
|
||||||
@ -142,32 +145,32 @@ int main(int argc, char *argv[]){
|
|||||||
irq6502();
|
irq6502();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ticker before menu draw */
|
||||||
if ((unsigned)time(NULL) != tickTrigger){
|
if ((unsigned)time(NULL) != tickTrigger){
|
||||||
tickTrigger = (unsigned)time(NULL);
|
|
||||||
|
|
||||||
cpuHealth = (uint8_t)((cpuTicks / (float)cpuSpeed) * 100.);
|
cpuHealth = (uint8_t)((cpuTicks / (float)cpuSpeed) * 100.);
|
||||||
cpuTicks = 0;
|
cpuTicks = 0;
|
||||||
|
|
||||||
fpsStore = fpsCount; fpsCount = 0;
|
fpsStore = fpsCount; fpsCount = 0;
|
||||||
|
|
||||||
/* Refresh entire video buffer */
|
/* Refresh entire video field every second */
|
||||||
videoModified = 1;
|
updateVideo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t vStack = 16;
|
uint16_t vStack = 16;
|
||||||
|
|
||||||
if (halt) {
|
if (halt) {
|
||||||
drawString("!CPU Haltet!", renderMemory,
|
drawString("!CPU HALTET!", renderMemory,
|
||||||
SDL_X_SIZE, 0x000000FF, time(NULL) % 2 ? 0xAAAAAAFF : 0xFFFFFFFF, 16, vStack, 1);
|
SDL_X_SIZE, 0x000000FF, time(NULL) % 2 ? 0xAAAAAAFF : 0xFFFFFFFF, 16, vStack, 1);
|
||||||
|
|
||||||
vStack += (FONT_HEIGHT * 2);
|
vStack += (FONT_HEIGHT * 2);
|
||||||
} if (showDebug){
|
} 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,
|
drawString(debugString, renderMemory,
|
||||||
SDL_X_SIZE, 0x000000FF, 0xAAAAAAFF, 16, vStack, 1);
|
SDL_X_SIZE, 0x000000FF, 0xAAAAAAFF, 16, vStack, 1);
|
||||||
|
|
||||||
vStack += (FONT_HEIGHT * 4);
|
vStack += (FONT_HEIGHT * 5);
|
||||||
|
|
||||||
sprintf(debugString, "CPU: %d%% @ %s", cpuHealth, displaySpeed);
|
sprintf(debugString, "CPU: %d%% @ %s", cpuHealth, displaySpeed);
|
||||||
drawString(debugString, renderMemory,
|
drawString(debugString, renderMemory,
|
||||||
@ -196,6 +199,15 @@ int main(int argc, char *argv[]){
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
|
|
||||||
|
|
||||||
|
/* Ticker after menu draw */
|
||||||
|
if ((unsigned)time(NULL) != tickTrigger){
|
||||||
|
tickTrigger = (unsigned)time(NULL);
|
||||||
|
|
||||||
|
videoStore = videoUpdates;
|
||||||
|
videoUpdates = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
extern void scanKeyboard();
|
extern void scanKeyboard();
|
||||||
|
extern void updateVideo();
|
||||||
extern void writeVideo();
|
extern void writeVideo();
|
||||||
extern uint8_t readVideo();
|
extern uint8_t readVideo();
|
||||||
extern uint8_t videoX;
|
extern uint8_t videoX;
|
||||||
@ -64,6 +65,7 @@ void write6502(uint16_t address, uint8_t value){
|
|||||||
break;
|
break;
|
||||||
case 2: /* Video M Register */
|
case 2: /* Video M Register */
|
||||||
videoMode = value;
|
videoMode = value;
|
||||||
|
updateVideo();
|
||||||
break;
|
break;
|
||||||
case 3: /* Video A Register */
|
case 3: /* Video A Register */
|
||||||
videoA = value;
|
videoA = value;
|
||||||
|
55
src/video.c
55
src/video.c
@ -5,12 +5,10 @@
|
|||||||
#define HIGHCOLOR 255
|
#define HIGHCOLOR 255
|
||||||
#define LOWCOLOR 96
|
#define LOWCOLOR 96
|
||||||
|
|
||||||
|
extern uint32_t videoUpdates;
|
||||||
extern float displayScale;
|
extern float displayScale;
|
||||||
extern uint8_t randomize;
|
extern uint8_t randomize;
|
||||||
|
|
||||||
/* Public Variables */
|
|
||||||
int8_t videoModified;
|
|
||||||
|
|
||||||
/* Hardware-like Registers */
|
/* Hardware-like Registers */
|
||||||
uint8_t videoX;
|
uint8_t videoX;
|
||||||
uint8_t videoY;
|
uint8_t videoY;
|
||||||
@ -47,22 +45,10 @@ void updatePalette(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initVideo(){
|
void initVideo(){
|
||||||
videoModified = 1;
|
|
||||||
videoMode = 0x01;
|
videoMode = 0x01;
|
||||||
updatePalette();
|
updatePalette();
|
||||||
|
|
||||||
if (randomize) {
|
if (randomize) for (int i = 0; i < 0x8000; i++) videoMemory[i] = rand();
|
||||||
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)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPixels(uint8_t x, uint8_t y){
|
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)];
|
videoColorValue = videoMemory[(((y & 0xF8) >> 3) << 7) + (x | 0x40)];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* Bitmapped Graphics mode fetch */
|
||||||
videoValue = videoMemory[(y * 128) + x];
|
videoValue = videoMemory[(y * 128) + x];
|
||||||
videoColorValue = videoMemory[(y * 128) + (x | 0x40)];
|
videoColorValue = videoMemory[(y * 128) + (x | 0x40)];
|
||||||
}
|
}
|
||||||
@ -97,13 +84,35 @@ void setPixels(uint8_t x, uint8_t y){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateVideo(){
|
void updateVideo(){
|
||||||
if (videoModified){
|
for (uint16_t y = 0; y < 256; y++){
|
||||||
for (uint16_t y = 0; y < 256; y++){
|
for (uint8_t x = 0; x < 48; x++){
|
||||||
for (uint8_t x = 0; x < 48; x++){
|
setPixels(x, (uint8_t)y);
|
||||||
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)];
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user