Skip to content

Commit bd4cc67

Browse files
committed
configurable left-panel diagnostics
1 parent b656645 commit bd4cc67

File tree

5 files changed

+48
-24
lines changed

5 files changed

+48
-24
lines changed

configtool/src/menu-main.bas

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,6 @@ configMenuData:
411411
DATA BYTE CONF_DIAG_PALETTE, "Palette ", 0, 2, " Show palettes "
412412
DATA BYTE CONF_MENU_CANCEL, "<<< Main menu ", 0, 0, " "
413413

414-
415-
416-
417414
' -----------------------------------------------------------------------------
418415
' Pico9918Option values. Indexed from options()
419416
' -----------------------------------------------------------------------------

src/config.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ void applyConfig()
9999
tms9918->config[CONF_DIAG_PALETTE] ||
100100
tms9918->config[CONF_DIAG_PERFORMANCE] ||
101101
tms9918->config[CONF_DIAG_REGISTERS];
102-
103102
}
104103

105104
#define CONFIG_FLASH_OFFSET (0x200000 - 0x1000) // in the top 4kB of a 2MB flash

src/diag.c

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "pico/divider.h"
2121

2222
#include <stdbool.h>
23+
#include <string.h>
2324

2425
#define CHAR_WIDTH 6
2526
#define CHAR_HEIGHT 6
@@ -364,31 +365,52 @@ static void diagMode(uint16_t row, uint16_t* pixels)
364365
renderLeft("MODE : ", &modeStr, "", row, pixels);
365366
}
366367

367-
static void diagEmpty(uint16_t row, uint16_t* pixels)
368-
{
369-
}
370-
371368
typedef void (*DiagPtr)(uint16_t, uint16_t*);
372369

373-
DiagPtr leftDiags[] =
374-
{
370+
DiagPtr leftDiags[32] = {0};
371+
int leftDiagRows = 0;
372+
373+
DiagPtr performanceDiags[] = {
375374
&diagClock,
376375
&diagRenderTime,
377376
&diagGpuTime,
378-
&diagTemp,
379-
&diagEmpty,
377+
&diagTemp};
378+
379+
DiagPtr addressDiags[] = {
380380
&diagMode,
381381
&diagNameTab,
382382
&diagColorTab,
383383
&diagPattTab,
384384
&diagSprAttrTab,
385-
&diagSprPattTab
386-
};
385+
&diagSprPattTab};
386+
387+
void diagnosticsConfigUpdated()
388+
{
389+
memset(leftDiags, 0, sizeof(leftDiags));
390+
391+
leftDiagRows= 0;
392+
if (tms9918->config[CONF_DIAG_PERFORMANCE])
393+
{
394+
for (int j = 0; j < sizeof(performanceDiags) / sizeof(void*); ++j)
395+
{
396+
leftDiags[leftDiagRows++] = performanceDiags[j];
397+
}
398+
leftDiagRows++;
399+
}
400+
401+
if (tms9918->config[CONF_DIAG_ADDRESS])
402+
{
403+
for (int j = 0; j < sizeof(addressDiags) / sizeof(void*); ++j)
404+
{
405+
leftDiags[leftDiagRows++] = addressDiags[j];
406+
}
407+
leftDiagRows++;
408+
}
409+
}
387410

388411
static void renderPalette(int y, uint16_t *pixels)
389412
{
390413
divmod_result_t dmResult = divmod_u32u32(y, 6);
391-
int regIndex = to_quotient_u32(dmResult);
392414
int row = to_remainder_u32(dmResult);
393415

394416
int palette = (y - 216) / 6;
@@ -421,10 +443,11 @@ void renderDiagnostics(uint16_t y, uint16_t* pixels)
421443
{
422444
y -= 1; // vertical border
423445

446+
// palette
424447
if (tms9918->config[CONF_DIAG_PALETTE] && (y > 213)) renderPalette(y + 2, pixels);
425448

426449
divmod_result_t dmResult = divmod_u32u32(y, 6);
427-
int regIndex = to_quotient_u32(dmResult);
450+
int diagRow = to_quotient_u32(dmResult);
428451
int row = to_remainder_u32(dmResult);
429452

430453
int maxReg = 8;
@@ -433,26 +456,28 @@ void renderDiagnostics(uint16_t y, uint16_t* pixels)
433456
maxReg += sizeof(extReg) / sizeof(int);
434457
}
435458

436-
if (tms9918->config[CONF_DIAG_PERFORMANCE] && (regIndex < sizeof(leftDiags) / sizeof(DiagPtr)))
459+
// left panels
460+
if (diagRow < leftDiagRows)
437461
{
438-
leftDiags[regIndex](row, pixels);
462+
if (leftDiags[diagRow]) leftDiags[diagRow](row, pixels);
439463
}
440464

441-
if (tms9918->config[CONF_DIAG_REGISTERS] && (regIndex < maxReg))
465+
// registers
466+
if (tms9918->config[CONF_DIAG_REGISTERS] && (diagRow < maxReg))
442467
{
443-
if (regIndex >= 8)
468+
if (diagRow >= 8)
444469
{
445-
regIndex = extReg[regIndex - 8];
470+
diagRow = extReg[diagRow - 8];
446471
}
447472

448-
dmResult = divmod_u32u32(regIndex, 10);
473+
dmResult = divmod_u32u32(diagRow, 10);
449474
int xPos = 636 - (CHAR_WIDTH * 13);
450475
char buf[] = "R00:"; buf[1] = '0' + to_quotient_u32(dmResult); buf[2] = '0' + to_remainder_u32(dmResult);
451476
xPos = renderText(row, buf, xPos, 0, labelColor, 0, pixels);
452477
xPos = backgroundPixels(xPos, 2, pixels);
453-
xPos = renderText(row, nibbleBinStr[TMS_REGISTER(tms9918, regIndex) >> 4], xPos, 0, valueColor, 0, pixels);
478+
xPos = renderText(row, nibbleBinStr[TMS_REGISTER(tms9918, diagRow) >> 4], xPos, 0, valueColor, 0, pixels);
454479
xPos = backgroundPixels(xPos, 2, pixels);
455-
xPos = renderText(row, nibbleBinStr[TMS_REGISTER(tms9918, regIndex) & 0xf], xPos, 0, valueColor, 0, pixels);
480+
xPos = renderText(row, nibbleBinStr[TMS_REGISTER(tms9918, diagRow) & 0xf], xPos, 0, valueColor, 0, pixels);
456481
}
457482

458483
}

src/diag.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ void diagSetTemperature(float tempC);
1919

2020
void diagSetClockHz(float clockHz);
2121

22+
void diagnosticsConfigUpdated();
23+
2224
void updateDiagnostics(uint32_t frameCount);
2325

2426
void updateRenderTime(uint32_t renderTime, uint32_t frameTime);

src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ static void eofInterrupt()
227227
{
228228
tms9918->configDirty = false;
229229
applyConfig(); // apply config option to device now
230+
diagnosticsConfigUpdated();
230231
}
231232
}
232233

0 commit comments

Comments
 (0)