Files
Sprinter-SDCC/examples/hello/hello.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

66 lines
1.9 KiB
C

/*
* hello — smoke test for the two output APIs:
*
* stdio (printf/puts/putchar) — FAST, no attribute (ambient colour)
* conio (cprintf/cputs/putch) — SLOWER, applies textcolor/textbackground
*
* Demonstrates textcolor/textbackground (Turbo-C-compatible names).
*/
#include <stdio.h>
#include <conio.h>
#include <gfx.h>
#include <sprinter.h>
#include <sprinter_exit.h>
#include <errno.h>
int main(void)
{
errno = -1;
int16_t a0 = 0, a1 = 0;
a0 = get_text_attr();
uint8_t vMode = get_videotextmode();
set_videotextmode(TEXT_MODE_80x32);
/* Wipe the screen with a known attribute so stdio printf/puts inherit
* a clean colour for the cursor. */
clrscr_attr(COLOR(COLOR_LIGHTGRAY, COLOR_BLACK));
/* --- stdio set: fast, no attribute ------------------------------- */
puts("hello (stdio) - fast PCHARS, ambient colour");
printf("printf: a0=%d (initial attr)\n", a0);
/* --- conio set: applies textcolor / textbackground --------------- */
textcolor(COLOR_YELLOW);
textbackground(COLOR_BLUE);
cputs("conio: yellow on blue\r\n");
textcolor(COLOR_LIGHTRED);
textbackground(COLOR_BLACK);
cprintf("cprintf %d %d %s\r\n", 42, -7, "args");
/* set_text_attr / textattr replace the whole byte. */
textattr(COLOR(COLOR_LIGHTGREEN, COLOR_BLACK));
cputs("conio: light-green via textattr\r\n");
/* Opting out of attribute control — conio falls back to fast path. */
set_text_attr(KEEP_EXIST_ATTR);
cputs("conio with KEEP_EXIST_ATTR (fast path)\r\n");
a1 = get_text_attr();
/* Back to a normal attribute so the goodbye reads cleanly. */
textattr(COLOR(COLOR_LIGHTGRAY, COLOR_BLACK));
printf("a0=%d a1=%d now=%d errno=%d\n",
a0, a1, get_text_attr(), errno);
#ifdef DEBUG_RT
printf("w2_self_allocated = %u\n", w2_self_allocated);
#endif
cputs("Press any key to exit...");
(void)getchar();
set_videotextmode(vMode);
return 0;
}