Global Overlay

Source: src/global_overlay.c · 87 lines · 6 functions.

Module entry points

These functions are exposed to the rest of the project. Open one to follow its decisions and the helpers it calls.

How to read these diagrams

Each function has its own expandable diagram using the actual expressions and statements from this file. Decisions split into True and False; loop bodies are indented. Returns end the function immediately; break and continue follow their C meanings. Arrows between statements show their order when execution reaches them.

These are structural source diagrams before preprocessing, not runtime traces. Conditional compilation and macros remain source expressions. Ternary choices remain inside their statement. Calls are linked separately; callback execution and task scheduling are not inferred.

Functions in this file

globalOverlayInitialize() · source line 23
bool globalOverlayInitialize(void)
  1. Decisionpresentation_frame != NULL
    True
    1. Exit this functionreturn true;
    False

    Continue after this decision.

  2. Executepresentation_frame = heap_caps_malloc((size_t)LCD_WIDTH * LCD_HEIGHT * sizeof(*presentation_frame), MALLOC_CAP_SPIRAM | MALLOC_CAP_DMA | MALLOC_CAP_8BIT);
  3. Exit this functionreturn presentation_frame != NULL;
Read original function source
bool globalOverlayInitialize(void)
{
    if (presentation_frame != NULL) return true;
    presentation_frame = heap_caps_malloc((size_t)LCD_WIDTH * LCD_HEIGHT * sizeof(*presentation_frame),
                                          MALLOC_CAP_SPIRAM | MALLOC_CAP_DMA | MALLOC_CAP_8BIT);
    return presentation_frame != NULL;
}
globalOverlayDeinitialize() · source line 31
void globalOverlayDeinitialize(void)

Calls into this documentation:

  1. Executeheap_caps_free(presentation_frame);
  2. Executepresentation_frame = NULL;
  3. ExecuteglobalOverlayClear();
Read original function source
void globalOverlayDeinitialize(void)
{
    heap_caps_free(presentation_frame);
    presentation_frame = NULL;
    globalOverlayClear();
}
globalOverlaySetItem() · source line 38
bool globalOverlaySetItem(size_t item_index, const char *text, int x, int y, int scale,
                          uint16_t colour)
  1. Decisionitem_index >= GLOBAL_OVERLAY_ITEM_COUNT || text == NULL || text[0] == '\0' || scale <= 0
    True
      1. Exit this functionreturn false;
    False

    Continue after this decision.

  2. Executeglobal_overlay_item_t *const item = &overlay_items[item_index];
  3. Executeconst size_t text_length = strnlen(text, sizeof(item->text) - 1U);
  4. Executememcpy(item->text, text, text_length);
  5. Executeitem->text[text_length] = '\0';
  6. Executeitem->x = x;
  7. Executeitem->y = y;
  8. Executeitem->scale = scale;
  9. Executeitem->colour = colour;
  10. Executeitem->visible = true;
  11. Exit this functionreturn true;
Read original function source
bool globalOverlaySetItem(size_t item_index, const char *text, int x, int y, int scale,
                          uint16_t colour)
{
    if (item_index >= GLOBAL_OVERLAY_ITEM_COUNT || text == NULL || text[0] == '\0' || scale <= 0) {
        return false;
    }

    global_overlay_item_t *const item = &overlay_items[item_index];
    const size_t text_length = strnlen(text, sizeof(item->text) - 1U);
    memcpy(item->text, text, text_length);
    item->text[text_length] = '\0';
    item->x = x;
    item->y = y;
    item->scale = scale;
    item->colour = colour;
    item->visible = true;
    return true;
}
globalOverlayClearItem() · source line 57
void globalOverlayClearItem(size_t item_index)
  1. Decisionitem_index >= GLOBAL_OVERLAY_ITEM_COUNT
    True
    1. Exit this functionreturn;
    False

    Continue after this decision.

  2. Executeoverlay_items[item_index] = (global_overlay_item_t){0};
Read original function source
void globalOverlayClearItem(size_t item_index)
{
    if (item_index >= GLOBAL_OVERLAY_ITEM_COUNT) return;
    overlay_items[item_index] = (global_overlay_item_t){0};
}
globalOverlayClear() · source line 63
void globalOverlayClear(void)
  1. Executememset(overlay_items, 0, sizeof(overlay_items));
Read original function source
void globalOverlayClear(void)
{
    memset(overlay_items, 0, sizeof(overlay_items));
}
globalOverlayCompose() · source line 68
const uint16_t *globalOverlayCompose(const uint16_t *scene_frame)

Calls into this documentation:

  1. Decisionscene_frame == NULL || presentation_frame == NULL
    True
    1. Exit this functionreturn scene_frame;
    False

    Continue after this decision.

  2. Executebool visible_item_found = false;
  3. FOR loopsize_t item_index = 0U; item_index < GLOBAL_OVERLAY_ITEM_COUNT; ++item_index

    Repeat body while the loop condition permits; then continue below.

      1. Decisionoverlay_items[item_index].visible
        True
        1. Executevisible_item_found = true;
        False

        Continue after this decision.

  4. Decision!visible_item_found
    True
    1. Exit this functionreturn scene_frame;
    False

    Continue after this decision.

  5. Executememcpy(presentation_frame, scene_frame, (size_t)LCD_WIDTH * LCD_HEIGHT * sizeof(*presentation_frame));
  6. FOR loopsize_t item_index = 0U; item_index < GLOBAL_OVERLAY_ITEM_COUNT; ++item_index

    Repeat body while the loop condition permits; then continue below.

      1. Executeconst global_overlay_item_t *const item = &overlay_items[item_index];
      2. Decisionitem->visible
        True
        1. Executedraw_text(presentation_frame, item->x, item->y, item->text, item->scale, item->colour);
        False

        Continue after this decision.

  7. Exit this functionreturn presentation_frame;
Read original function source
const uint16_t *globalOverlayCompose(const uint16_t *scene_frame)
{
    if (scene_frame == NULL || presentation_frame == NULL) return scene_frame;

    bool visible_item_found = false;
    for (size_t item_index = 0U; item_index < GLOBAL_OVERLAY_ITEM_COUNT; ++item_index) {
        if (overlay_items[item_index].visible) visible_item_found = true;
    }
    if (!visible_item_found) return scene_frame;

    memcpy(presentation_frame, scene_frame,
           (size_t)LCD_WIDTH * LCD_HEIGHT * sizeof(*presentation_frame));
    for (size_t item_index = 0U; item_index < GLOBAL_OVERLAY_ITEM_COUNT; ++item_index) {
        const global_overlay_item_t *const item = &overlay_items[item_index];
        if (item->visible) draw_text(presentation_frame, item->x, item->y, item->text,
                                     item->scale, item->colour);
    }
    return presentation_frame;
}
Complete original file, including constants and data
/* Coded By JD(2026) */
#error "Reference listing only — not provided as build-ready source."
#include "global_overlay.h"

#include "game_graphics.h"
#include "PET2001_font.h"

#include "esp_heap_caps.h"

#include <string.h>

#define GLOBAL_OVERLAY_TEXT_LENGTH 48U

typedef struct {
    bool visible;
    char text[GLOBAL_OVERLAY_TEXT_LENGTH];
    int x;
    int y;
    int scale;
    uint16_t colour;
} global_overlay_item_t;

static global_overlay_item_t overlay_items[GLOBAL_OVERLAY_ITEM_COUNT];
static uint16_t *presentation_frame;

bool globalOverlayInitialize(void)
{
    if (presentation_frame != NULL) return true;
    presentation_frame = heap_caps_malloc((size_t)LCD_WIDTH * LCD_HEIGHT * sizeof(*presentation_frame),
                                          MALLOC_CAP_SPIRAM | MALLOC_CAP_DMA | MALLOC_CAP_8BIT);
    return presentation_frame != NULL;
}

void globalOverlayDeinitialize(void)
{
    heap_caps_free(presentation_frame);
    presentation_frame = NULL;
    globalOverlayClear();
}

bool globalOverlaySetItem(size_t item_index, const char *text, int x, int y, int scale,
                          uint16_t colour)
{
    if (item_index >= GLOBAL_OVERLAY_ITEM_COUNT || text == NULL || text[0] == '\0' || scale <= 0) {
        return false;
    }

    global_overlay_item_t *const item = &overlay_items[item_index];
    const size_t text_length = strnlen(text, sizeof(item->text) - 1U);
    memcpy(item->text, text, text_length);
    item->text[text_length] = '\0';
    item->x = x;
    item->y = y;
    item->scale = scale;
    item->colour = colour;
    item->visible = true;
    return true;
}

void globalOverlayClearItem(size_t item_index)
{
    if (item_index >= GLOBAL_OVERLAY_ITEM_COUNT) return;
    overlay_items[item_index] = (global_overlay_item_t){0};
}

void globalOverlayClear(void)
{
    memset(overlay_items, 0, sizeof(overlay_items));
}

const uint16_t *globalOverlayCompose(const uint16_t *scene_frame)
{
    if (scene_frame == NULL || presentation_frame == NULL) return scene_frame;

    bool visible_item_found = false;
    for (size_t item_index = 0U; item_index < GLOBAL_OVERLAY_ITEM_COUNT; ++item_index) {
        if (overlay_items[item_index].visible) visible_item_found = true;
    }
    if (!visible_item_found) return scene_frame;

    memcpy(presentation_frame, scene_frame,
           (size_t)LCD_WIDTH * LCD_HEIGHT * sizeof(*presentation_frame));
    for (size_t item_index = 0U; item_index < GLOBAL_OVERLAY_ITEM_COUNT; ++item_index) {
        const global_overlay_item_t *const item = &overlay_items[item_index];
        if (item->visible) drawPet2001TextTransparent(presentation_frame, item->x, item->y,
                                                       item->text, item->colour, item->scale);
    }
    return presentation_frame;
}