pico9918-core 1.3.0
TMS9918A / F18A video display processor emulation in C99
Loading...
Searching...
No Matches
diag.c File Reference

pico9918-core - Diagnostics overlay More...

#include "diag.h"
#include "overlay/bmp_font.h"
#include "impl/pico9918_priv.h"
#include "gpu/gpu.h"
#include <stdbool.h>
#include <string.h>
+ Include dependency graph for diag.c:

Go to the source code of this file.

Data Structures

struct  IntString
 

Macros

#define DIAG_COLOR(pramOrder)   ((PICO9918_PIXEL_T)(PICO9918_PIXEL_FROM_RGB12(pramOrder) & 0x0fff))
 
#define FONT_CHARS   96
 
#define FONT_FIRST   32
 
#define INK_WORDS   (PICO9918_DIAG_CHAR_WIDTH / PICO9918_INK_PIXELS)
 
#define INK_STRIDE   (INK_WORDS <= 4 ? 4 : 8)
 

Typedefs

typedef void(* DiagPtr) (uint16_t, PICO9918_PIXEL_T *)
 

Functions

static void clear (IntString *number)
 
static void flt2Str (float flt, int prec, IntString *out)
 
static void uint2hexStr (uint32_t number, int width, IntString *out)
 
static void glyphMaskInit (void)
 
void pico9918_diag_init (void)
 one-time initialisation of the panel value strings
 
void pico9918_diag_set_version_info (const char *hwVersion, const char *fwVersion)
 Version identity for the HWVER / FWVER rows.
 
void pico9918_diag_set_output_name (const char *name, const char *units)
 Display-mode label for the OUTPUT row, e.g.
 
void pico9918_diag_set_temperature (float tempC)
 core temperature, degrees C
 
void pico9918_diag_set_clock_hz (float clockHz)
 system clock, Hz
 
void pico9918_diag_set_frame_rate (float frameRateHz)
 Host display timing, Hz.
 
void pico9918_diag_update (pico9918_t *tms9918, uint32_t frameCount)
 recompute the panel values - call once per frame
 
int pico9918_diag_render_text (uint16_t scanline, const char *text, uint16_t x, uint16_t y, PICO9918_PIXEL_T fg, PICO9918_PIXEL_T *pixels)
 render text into the scanline buffer, if row scanline falls in the glyph band starting at y.
 
PICO9918_INLINE int renderRow (uint16_t row, const char *text, uint16_t x, PICO9918_PIXEL_T fg, PICO9918_PIXEL_T *pixels)
 
PICO9918_INLINE int renderNum (uint16_t row, IntString *str, uint16_t x, PICO9918_PIXEL_T fg, PICO9918_PIXEL_T *pixels)
 
void pico9918_diag_update_render_time (uint32_t renderTime, uint32_t frameTime)
 accumulate one scanline's render and total time, in microseconds
 
static int backgroundPixels (int xPos, int count, PICO9918_PIXEL_T *pixels)
 
static void renderLeft (const char *label, IntString *val, const char *units, uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagHwVer (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagFwVer (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagRenderTime (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagScanlineRenderTime (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagGpuTime (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagFPS (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagTemp (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagOutput (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagClock (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagNameTab (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagColorTab (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagPattTab (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagSprAttrTab (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagSprPattTab (uint16_t row, PICO9918_PIXEL_T *pixels)
 
static void diagMode (uint16_t row, PICO9918_PIXEL_T *pixels)
 
void pico9918_diag_config_updated (pico9918_t *tms9918)
 rebuild the panel row table - call whenever the PICO9918_CONF_DIAG* bytes change
 
static void renderPalette (pico9918_t *tms9918, int y, uint32_t vVirtualPixels, PICO9918_PIXEL_T *pixels)
 
void pico9918_diag_render (pico9918_t *tms9918, uint16_t y, uint32_t vVirtualPixels, PICO9918_PIXEL_T *pixels)
 render the diagnostics panels for border row y
 

Variables

IntString frameTimeStr = {0}
 
IntString renderTimePerScanlineStr = {0}
 
IntString temperatureStr = {0}
 
IntString gpuPctStr = {0}
 
IntString clockMhzStr = {0}
 
IntString modeStr = {0}
 
IntString fpsStr = {0}
 
IntString hwVerStr = {0}
 
IntString fwVerStr = {0}
 
IntString outputStr = {0}
 
static const char * outputUnitsStr = ""
 
IntString nameTabStr = {0}
 
IntString colorTabStr = {0}
 
IntString pattTabStr = {0}
 
IntString sprAttTabStr = {0}
 
IntString sprPattTabStr = {0}
 
uint32_t accumulatedRenderTime = 0
 
uint32_t accumulatedFrameTime = 0
 
uint32_t accumulatedScanlines = 0
 
uint32_t lastUpdateTime = 0
 
const PICO9918_PIXEL_T labelColor = DIAG_COLOR(0xff07)
 
const PICO9918_PIXEL_T valueColor = DIAG_COLOR(0xff0f)
 
const PICO9918_PIXEL_T unitsColor = DIAG_COLOR(0x8808)
 
static float precLookup [] = {1.0f, 10.0f, 100.0f, 1000.0f}
 
static PICO9918_INK_T glyphMask [64][INK_STRIDE]
 
const char * modeNames []
 
static float hostFrameRateHz = 0.0f
 
static const char nibbleBinStr [16][8]
 
static const uint8_t extReg []
 
const uint32_t leftXPos = 2
 
static DiagPtr const performanceDiags []
 
static DiagPtr const addressDiags []
 
static DiagPtr leftDiags [sizeof(performanceDiags)/sizeof(performanceDiags[0])+sizeof(addressDiags)/sizeof(addressDiags[0])+2] = {0}
 
static int leftDiagRows = 0
 

Detailed Description

pico9918-core - Diagnostics overlay

Copyright (c) 2024 Troy Schrapel

This code is licensed under the MIT license

https://github.com/visrealm/pico9918-core

Definition in file diag.c.

Macro Definition Documentation

◆ DIAG_COLOR

#define DIAG_COLOR (   pramOrder)    ((PICO9918_PIXEL_T)(PICO9918_PIXEL_FROM_RGB12(pramOrder) & 0x0fff))

Definition at line 91 of file diag.c.

◆ FONT_CHARS

#define FONT_CHARS   96

Definition at line 172 of file diag.c.

◆ FONT_FIRST

#define FONT_FIRST   32

Definition at line 173 of file diag.c.

◆ INK_WORDS

#define INK_WORDS   (PICO9918_DIAG_CHAR_WIDTH / PICO9918_INK_PIXELS)

Definition at line 177 of file diag.c.

◆ INK_STRIDE

#define INK_STRIDE   (INK_WORDS <= 4 ? 4 : 8)

Definition at line 178 of file diag.c.

Typedef Documentation

◆ DiagPtr

typedef void(* DiagPtr) (uint16_t, PICO9918_PIXEL_T *)

Definition at line 518 of file diag.c.

Function Documentation

◆ clear()

static void clear ( IntString number)
static

Definition at line 35 of file diag.c.

◆ flt2Str()

static void flt2Str ( float  flt,
int  prec,
IntString out 
)
static

Definition at line 100 of file diag.c.

◆ uint2hexStr()

static void uint2hexStr ( uint32_t  number,
int  width,
IntString out 
)
static

Definition at line 150 of file diag.c.

◆ glyphMaskInit()

static void glyphMaskInit ( void  )
static

Definition at line 184 of file diag.c.

◆ pico9918_diag_init()

void pico9918_diag_init ( void  )

one-time initialisation of the panel value strings

Definition at line 200 of file diag.c.

◆ pico9918_diag_set_version_info()

void pico9918_diag_set_version_info ( const char *  hwVersion,
const char *  fwVersion 
)

Version identity for the HWVER / FWVER rows.

The strings are host policy: only the host knows its board revisions and its own firmware version, and the library must not carry PICO9918 revision knowledge. Both are copied into the panel buffers, so the caller keeps no lifetime obligation. Either may be NULL to leave that row's current text alone.

Definition at line 226 of file diag.c.

◆ pico9918_diag_set_output_name()

void pico9918_diag_set_output_name ( const char *  name,
const char *  units 
)

Display-mode label for the OUTPUT row, e.g.

"480P " + "@60". The encoding of PICO9918_CONF_DISP_DRIVER is host policy (which timings a board supports), so the host supplies the label rather than the library carrying board-specific strings. name is copied; units is retained by pointer, so it must have static storage duration. Either may be NULL to leave that part alone.

Definition at line 243 of file diag.c.

◆ pico9918_diag_set_temperature()

void pico9918_diag_set_temperature ( float  tempC)

core temperature, degrees C

Definition at line 260 of file diag.c.

Referenced by pico9918_frame_end().

◆ pico9918_diag_set_clock_hz()

void pico9918_diag_set_clock_hz ( float  clockHz)

system clock, Hz

Definition at line 265 of file diag.c.

◆ pico9918_diag_set_frame_rate()

void pico9918_diag_set_frame_rate ( float  frameRateHz)

Host display timing, Hz.

The library has no clock of its own, so the FPS row is (16 - droppedFrames) * (frameRate / 16); only this term is pushed. The dropped frames come from the frame module, which owns that accounting and is read directly.

Definition at line 274 of file diag.c.

Referenced by pico9918_frame_end().

◆ pico9918_diag_update()

void pico9918_diag_update ( pico9918_t *  tms9918,
uint32_t  frameCount 
)

recompute the panel values - call once per frame

Definition at line 280 of file diag.c.

References pico9918_display_mode(), pico9918_gpu_reset_time(), pico9918_gpu_time(), and PICO9918_INST_ONLY.

Referenced by pico9918_frame_end().

◆ pico9918_diag_render_text()

int pico9918_diag_render_text ( uint16_t  scanline,
const char *  text,
uint16_t  x,
uint16_t  y,
PICO9918_PIXEL_T  fg,
PICO9918_PIXEL_T *  pixels 
)

render text into the scanline buffer, if row scanline falls in the glyph band starting at y.

Returns the x position just past the last pixel written, so calls chain. A cell's unlit pixels are darkened, not left untouched. x must be a whole number of ink words - cells are written a word at a time.

Definition at line 348 of file diag.c.

References PICO9918_DIAG_CHAR_HEIGHT.

◆ renderRow()

PICO9918_INLINE int renderRow ( uint16_t  row,
const char *  text,
uint16_t  x,
PICO9918_PIXEL_T  fg,
PICO9918_PIXEL_T *  pixels 
)

Definition at line 375 of file diag.c.

◆ renderNum()

PICO9918_INLINE int renderNum ( uint16_t  row,
IntString str,
uint16_t  x,
PICO9918_PIXEL_T  fg,
PICO9918_PIXEL_T *  pixels 
)

Definition at line 387 of file diag.c.

◆ pico9918_diag_update_render_time()

void pico9918_diag_update_render_time ( uint32_t  renderTime,
uint32_t  frameTime 
)

accumulate one scanline's render and total time, in microseconds

Definition at line 393 of file diag.c.

Referenced by pico9918_frame_scanline().

◆ backgroundPixels()

static int backgroundPixels ( int  xPos,
int  count,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 402 of file diag.c.

◆ renderLeft()

static void renderLeft ( const char *  label,
IntString val,
const char *  units,
uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 426 of file diag.c.

◆ diagHwVer()

static void diagHwVer ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 436 of file diag.c.

◆ diagFwVer()

static void diagFwVer ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 441 of file diag.c.

◆ diagRenderTime()

static void diagRenderTime ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 446 of file diag.c.

◆ diagScanlineRenderTime()

static void diagScanlineRenderTime ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 451 of file diag.c.

◆ diagGpuTime()

static void diagGpuTime ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 456 of file diag.c.

◆ diagFPS()

static void diagFPS ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 468 of file diag.c.

◆ diagTemp()

static void diagTemp ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 473 of file diag.c.

◆ diagOutput()

static void diagOutput ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 478 of file diag.c.

◆ diagClock()

static void diagClock ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 483 of file diag.c.

◆ diagNameTab()

static void diagNameTab ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 488 of file diag.c.

◆ diagColorTab()

static void diagColorTab ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 493 of file diag.c.

◆ diagPattTab()

static void diagPattTab ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 498 of file diag.c.

◆ diagSprAttrTab()

static void diagSprAttrTab ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 503 of file diag.c.

◆ diagSprPattTab()

static void diagSprPattTab ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 508 of file diag.c.

◆ diagMode()

static void diagMode ( uint16_t  row,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 513 of file diag.c.

◆ pico9918_diag_config_updated()

void pico9918_diag_config_updated ( pico9918_t *  tms9918)

rebuild the panel row table - call whenever the PICO9918_CONF_DIAG* bytes change

Definition at line 541 of file diag.c.

Referenced by pico9918_frame_raise_end_of_frame_int().

◆ renderPalette()

static void renderPalette ( pico9918_t *  tms9918,
int  y,
uint32_t  vVirtualPixels,
PICO9918_PIXEL_T *  pixels 
)
static

Definition at line 560 of file diag.c.

◆ pico9918_diag_render()

void pico9918_diag_render ( pico9918_t *  tms9918,
uint16_t  y,
uint32_t  vVirtualPixels,
PICO9918_PIXEL_T *  pixels 
)

render the diagnostics panels for border row y

Definition at line 596 of file diag.c.

References PICO9918_DIAG_CHAR_WIDTH, and PICO9918_INST.

Referenced by pico9918_frame_output_line(), and pico9918_frame_scanline().

Variable Documentation

◆ frameTimeStr

IntString frameTimeStr = {0}

Definition at line 45 of file diag.c.

◆ renderTimePerScanlineStr

IntString renderTimePerScanlineStr = {0}

Definition at line 46 of file diag.c.

◆ temperatureStr

IntString temperatureStr = {0}

Definition at line 47 of file diag.c.

◆ gpuPctStr

IntString gpuPctStr = {0}

Definition at line 48 of file diag.c.

◆ clockMhzStr

IntString clockMhzStr = {0}

Definition at line 49 of file diag.c.

◆ modeStr

IntString modeStr = {0}

Definition at line 50 of file diag.c.

◆ fpsStr

IntString fpsStr = {0}

Definition at line 51 of file diag.c.

◆ hwVerStr

IntString hwVerStr = {0}

Definition at line 55 of file diag.c.

◆ fwVerStr

IntString fwVerStr = {0}

Definition at line 56 of file diag.c.

◆ outputStr

IntString outputStr = {0}

Definition at line 57 of file diag.c.

◆ outputUnitsStr

const char* outputUnitsStr = ""
static

Definition at line 61 of file diag.c.

◆ nameTabStr

IntString nameTabStr = {0}

Definition at line 63 of file diag.c.

◆ colorTabStr

IntString colorTabStr = {0}

Definition at line 64 of file diag.c.

◆ pattTabStr

IntString pattTabStr = {0}

Definition at line 65 of file diag.c.

◆ sprAttTabStr

IntString sprAttTabStr = {0}

Definition at line 66 of file diag.c.

◆ sprPattTabStr

IntString sprPattTabStr = {0}

Definition at line 67 of file diag.c.

◆ accumulatedRenderTime

uint32_t accumulatedRenderTime = 0

Definition at line 69 of file diag.c.

◆ accumulatedFrameTime

uint32_t accumulatedFrameTime = 0

Definition at line 70 of file diag.c.

◆ accumulatedScanlines

uint32_t accumulatedScanlines = 0

Definition at line 71 of file diag.c.

◆ lastUpdateTime

uint32_t lastUpdateTime = 0

Definition at line 72 of file diag.c.

◆ labelColor

const PICO9918_PIXEL_T labelColor = DIAG_COLOR(0xff07)

Definition at line 93 of file diag.c.

◆ valueColor

const PICO9918_PIXEL_T valueColor = DIAG_COLOR(0xff0f)

Definition at line 94 of file diag.c.

◆ unitsColor

const PICO9918_PIXEL_T unitsColor = DIAG_COLOR(0x8808)

Definition at line 95 of file diag.c.

◆ precLookup

float precLookup[] = {1.0f, 10.0f, 100.0f, 1000.0f}
static

Definition at line 97 of file diag.c.

◆ glyphMask

PICO9918_INK_T glyphMask[64][INK_STRIDE]
static

Definition at line 182 of file diag.c.

◆ modeNames

const char* modeNames[]
Initial value:
= {
"GFX I", "GFX II", "TEXT", "MULTI", "80 COL",
}

Definition at line 255 of file diag.c.

◆ hostFrameRateHz

float hostFrameRateHz = 0.0f
static

Definition at line 272 of file diag.c.

◆ nibbleBinStr

const char nibbleBinStr[16][8]
static
Initial value:
= {
"((((", "((()", "(()(", "(())", "()((", "()()", "())(", "()))",
")(((", ")(()", ")()(", ")())", "))((", "))()", ")))(", "))))",
}

Definition at line 415 of file diag.c.

◆ extReg

const uint8_t extReg[]
static
Initial value:
= {10, 11, 15, 19, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
35, 36, 37, 38, 48, 49, 50, 51, 54, 55, 56, 57, 58, 59, 63}

Definition at line 421 of file diag.c.

◆ leftXPos

const uint32_t leftXPos = 2

Definition at line 424 of file diag.c.

◆ performanceDiags

DiagPtr const performanceDiags[]
static
Initial value:
= {&diagHwVer,
&diagFwVer,
&diagClock,
&diagOutput,
&diagRenderTime,
&diagScanlineRenderTime,
&diagFPS,
&diagGpuTime,
&diagTemp}

Definition at line 520 of file diag.c.

◆ addressDiags

DiagPtr const addressDiags[]
static
Initial value:
= {&diagMode, &diagNameTab, &diagColorTab,
&diagPattTab, &diagSprAttrTab, &diagSprPattTab}

Definition at line 533 of file diag.c.

◆ leftDiags

DiagPtr leftDiags[sizeof(performanceDiags)/sizeof(performanceDiags[0])+ sizeof(addressDiags)/sizeof(addressDiags[0])+2] = {0}
static

Definition at line 537 of file diag.c.

◆ leftDiagRows

int leftDiagRows = 0
static

Definition at line 539 of file diag.c.