Add highlighting, fixed len instructions and more
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
#include "cpustatusui.h"
|
||||
#include "font.h"
|
||||
|
||||
SDL_Texture *renderVals(CPU *cpu, BitmapFont *titleFont, BitmapFont *valueFont,
|
||||
SDL_Renderer *renderer) {
|
||||
void renderVals(CPU *cpu, BitmapFont *titleFont, BitmapFont *valueFont,
|
||||
SDL_Renderer *renderer, SDL_Texture **out) {
|
||||
|
||||
CPUStatusPart *stats = NULL;
|
||||
int statsCount = 0;
|
||||
@@ -16,12 +16,14 @@ SDL_Texture *renderVals(CPU *cpu, BitmapFont *titleFont, BitmapFont *valueFont,
|
||||
getStats(cpu, &stats, &statsCount);
|
||||
|
||||
const int padding = 4;
|
||||
const int oneFieldW = (titleFont->size + 1) * (sizeof(stats[0].value) - 1) + padding - 1;
|
||||
const int oneFieldW = (titleFont->size + 1) * (sizeof(stats[0].value)) + padding - 1;
|
||||
const int oneFieldH = (titleFont->size + 1) * 2 + (valueFont->size + 1);
|
||||
SDL_Texture *out = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,
|
||||
oneFieldW * statsCount, oneFieldH);
|
||||
if (!*out) {
|
||||
*out = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,
|
||||
oneFieldW * statsCount, oneFieldH);
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(renderer, out);
|
||||
SDL_SetRenderTarget(renderer, *out);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
@@ -61,7 +63,7 @@ SDL_Texture *renderVals(CPU *cpu, BitmapFont *titleFont, BitmapFont *valueFont,
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(renderer, NULL);
|
||||
return out;
|
||||
free(stats);
|
||||
}
|
||||
|
||||
void getStats(CPU *cpu, CPUStatusPart **cpuStatus, int *cpuStatusCount) {
|
||||
@@ -81,27 +83,27 @@ void getStats(CPU *cpu, CPUStatusPart **cpuStatus, int *cpuStatusCount) {
|
||||
|
||||
int index = 0;
|
||||
|
||||
strncpy((*cpuStatus)[index].name, "PC", sizeof((*cpuStatus)[index].name));
|
||||
strncpy((*cpuStatus)[index].name, "PCNT", sizeof((*cpuStatus)[index].name));
|
||||
(*cpuStatus)[index].value = cpu->pc;
|
||||
index++;
|
||||
|
||||
strncpy((*cpuStatus)[index].name, "SP", sizeof((*cpuStatus)[index].name));
|
||||
strncpy((*cpuStatus)[index].name, "SPTR", sizeof((*cpuStatus)[index].name));
|
||||
(*cpuStatus)[index].value = cpu->stack_ptr;
|
||||
index++;
|
||||
|
||||
strncpy((*cpuStatus)[index].name, "FLG", sizeof((*cpuStatus)[index].name));
|
||||
strncpy((*cpuStatus)[index].name, "FLAG", sizeof((*cpuStatus)[index].name));
|
||||
(*cpuStatus)[index].value = cpu->flags;
|
||||
index++;
|
||||
|
||||
strncpy((*cpuStatus)[index].name, "MOD", sizeof((*cpuStatus)[index].name));
|
||||
strncpy((*cpuStatus)[index].name, "MODE", sizeof((*cpuStatus)[index].name));
|
||||
(*cpuStatus)[index].value = cpu->mode;
|
||||
index++;
|
||||
|
||||
strncpy((*cpuStatus)[index].name, "CYC", sizeof((*cpuStatus)[index].name));
|
||||
strncpy((*cpuStatus)[index].name, "CYCL", sizeof((*cpuStatus)[index].name));
|
||||
(*cpuStatus)[index].value = cpu->cycle;
|
||||
index++;
|
||||
|
||||
for (int i = 0; i < 25; i++) {
|
||||
for (int i = 0; i < 18; i++) {
|
||||
snprintf((*cpuStatus)[index].name, sizeof((*cpuStatus)[index].name), "R%d", i);
|
||||
(*cpuStatus)[index].value = cpu->regs[i];
|
||||
index++;
|
||||
@@ -110,7 +112,7 @@ void getStats(CPU *cpu, CPUStatusPart **cpuStatus, int *cpuStatusCount) {
|
||||
*cpuStatusCount = index; // Store the actual number of status parts
|
||||
}
|
||||
|
||||
SDL_Texture *renderState(CPU *cpu, BitmapFont *titleFont, SDL_Renderer *renderer) {
|
||||
void renderState(CPU *cpu, BitmapFont *titleFont, SDL_Renderer *renderer, SDL_Texture **out) {
|
||||
|
||||
// Render the value
|
||||
char valueStr[20] = "";
|
||||
@@ -141,10 +143,12 @@ SDL_Texture *renderState(CPU *cpu, BitmapFont *titleFont, SDL_Renderer *renderer
|
||||
const int oneFieldW = (titleFont->size + 1);
|
||||
const int allFieldW = oneFieldW * strlen(valueStr);
|
||||
const int oneFieldH = (titleFont->size + 1);
|
||||
SDL_Texture *out = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,
|
||||
allFieldW, oneFieldH);
|
||||
if (!*out) {
|
||||
*out = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET,
|
||||
allFieldW, oneFieldH);
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(renderer, out);
|
||||
SDL_SetRenderTarget(renderer, *out);
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
@@ -164,5 +168,4 @@ SDL_Texture *renderState(CPU *cpu, BitmapFont *titleFont, SDL_Renderer *renderer
|
||||
}
|
||||
|
||||
SDL_SetRenderTarget(renderer, NULL);
|
||||
return out;
|
||||
}
|
Reference in New Issue
Block a user