Files
Sprinter-SDCC/examples/gfx_text/gfx_text.c
T
snark13 c71e249a4e Add full compiler toolchain, libc, examples and reference docs
First substantive commit: the entire Sprinter C compiler tree on top of
the bare README+gitignore initial commit.

What's in here:
  bin/sprinter-cc        — driver script invoking SDCC + linker + mkexe
  libc/                  — Sprinter-specific libc layer over ESTEX/BIOS
                           (conio, gfx, io, mem, stdio + headers)
  runtime/               — crt0 variants (default/small/banked/minimal)
                           + heap + bank trampolines
  toolchain/             — mkexe (SprintEXE packer, C + tests)
  examples/              — 30 demo programs (gfx, file I/O, env, time, …)
  lib/Makefile           — builds the libc archive (sprinter.lib)
  docs/                  — converted Sprinter manuals + asm reference samples
  third_party/           — solid-c reference compiler dump + sdcc setup script
  release_docs/          — packaging / release notes

gitignore overhaul:
  • Drop dangerous blanket patterns: *.asm (would hide docs/samples/*.asm)
    and *.exe (case-insensitive match was hiding third_party/solid-c/*.EXE
    on macOS APFS).  Replaced with examples/*/*.{asm,exe,…} and lib/*.lib.
  • Restore tracking of toolchain/mkexe/tests/{one,big}.bin — those are
    INPUT fixtures, not build outputs.
  • Collapse the duplicated SDCC/C/Sdcc sections into one section per
    concern (build outputs / vendored / OS-junk).
  • Add .sprinter-cc-*/, build/ (catches lib/build/ too), .claude/.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-03 16:13:21 +03:00

114 lines
3.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* gfx_text_demo — bitmap-font text rendering test.
*
* Stages (press a key to advance):
* 1. 320×256×256 mode — text in multiple colors using BIOS default font.
* 2. 640×256×16 mode — same text with the 16-color palette.
* Verifies the same font renders correctly in both pixel formats.
*/
#include <stdio.h>
#include <conio.h>
#include <gfx.h>
#include <stdint.h>
static uint8_t pal256[256 * 4];
static uint8_t pal16[16 * 4];
static void wait_key(void)
{
__asm
ld c, #0x30
rst #0x10
__endasm;
}
int main(void)
{
/* Grey ramp for 256-color mode. */
for (int i = 0; i < 256; i++) {
pal256[i * 4 + 0] = (uint8_t)i;
pal256[i * 4 + 1] = (uint8_t)i;
pal256[i * 4 + 2] = (uint8_t)i;
pal256[i * 4 + 3] = 0;
}
/* Simple 16-color palette: 0=black, 1=red, 2=green, ..., 7=white,
* 8..15 = dimmed variants. */
static const uint8_t bgr16[16][3] = {
{0x00,0x00,0x00}, {0x00,0x00,0xFF}, {0x00,0xFF,0x00}, {0xFF,0x00,0x00},
{0x00,0xFF,0xFF}, {0xFF,0x00,0xFF}, {0xFF,0xFF,0x00}, {0xFF,0xFF,0xFF},
{0x40,0x40,0x40}, {0x40,0x40,0xFF}, {0x40,0xFF,0x40}, {0xFF,0x40,0x40},
{0x40,0xFF,0xFF}, {0xFF,0x40,0xFF}, {0xFF,0xFF,0x40}, {0xA0,0xA0,0xA0},
};
for (int i = 0; i < 16; i++) {
pal16[i*4+0] = bgr16[i][0];
pal16[i*4+1] = bgr16[i][1];
pal16[i*4+2] = bgr16[i][2];
pal16[i*4+3] = 0;
}
/* --- Stage 1: text in 320×256×256 ----------------------------- */
uint8_t prev = gfx_init(GFX_MODE_320x256x256, 0);
gfx_pal_load(0, 0, 0, pal256);
gfx_clear256(0x20);
gfx_text256(8, 8, "Hello from Sprinter!", 0xFF, 0x20);
gfx_text256(8, 24, "320x256x256 mode", 0xC0, 0x20);
gfx_text256(8, 40, "Bitmap font from BIOS WIN_GET_ZG", 0x80, 0x20);
/* Color showcase — same string in 8 different greys. */
for (int i = 0; i < 8; i++) {
char buf[16] = "Color ramp test";
gfx_text256(8, 64 + i * 12, buf, (uint8_t)(0x40 + i * 24), 0x20);
}
/* Adjacent FG/BG variants. */
gfx_text256(8, 176, "FG=white BG=red", 0xFF, 0x30);
gfx_text256(8, 192, "FG=black BG=white", 0x00, 0xFF);
gfx_text256(8, 208, "Negative space:", 0xFF, 0x20);
/* Large block to test grid-aligned text. */
for (int row = 0; row < 3; row++)
for (int col = 0; col < 8; col++) {
char ch[2] = { (char)('A' + row * 8 + col), 0 };
gfx_text256(176 + col * 16, 176 + row * 16, ch, 0xFF, 0x20);
}
wait_key();
/* --- Stage 2: text in 640×256×16 ------------------------------ */
gfx_done(prev);
prev = gfx_init(GFX_MODE_640x256x16, 0);
gfx_pal_load(0, 0, 16, pal16);
gfx_clear16(0);
gfx_text16(8, 8, "Hello from Sprinter!", 7, 0);
gfx_text16(8, 24, "640x256x16 mode (16 colours)", 6, 0);
gfx_text16(8, 40, "Same font, packed two pixels/byte", 4, 0);
/* Color demo: each line in a different palette index. */
for (int i = 1; i < 16; i++) {
char buf[20];
/* Simple manual itoa to avoid stdio bloat. */
buf[0] = 'C'; buf[1] = 'o'; buf[2] = 'l'; buf[3] = 'o'; buf[4] = 'r';
buf[5] = ' '; buf[6] = (char)('0' + (i / 10));
buf[7] = (char)('0' + (i % 10));
buf[8] = 0;
gfx_text16(8, 64 + (i - 1) * 12, buf, (uint8_t)i, 0);
}
/* Show on right side — paragraph in white-on-black, then inverted. */
gfx_text16(280, 64, "ABCDEFGHIJKLMNOP", 7, 0);
gfx_text16(280, 76, "QRSTUVWXYZ", 7, 0);
gfx_text16(280, 92, "abcdefghijklmnop", 7, 0);
gfx_text16(280, 104, "qrstuvwxyz", 7, 0);
gfx_text16(280, 120, "0123456789", 7, 0);
gfx_text16(280, 132, "!@#$%^&*()_+-=", 7, 0);
gfx_text16(280, 148, "Inverted text", 0, 7);
gfx_text16(280, 164, "FG=red BG=cyan", 1, 6);
wait_key();
gfx_done(prev);
puts("done");
return 0;
}