Commit Graph

128 Commits

Author SHA1 Message Date
snark13 eab5a2d6ac mdview2: add render-cache markdown viewer (Phases 0-4)
New examples/mdview2 — render-cache version of mdview: each logical
line is rendered into an EMM (char,attr) buffer once during file load
(interleaved with index_lines()), then scrolling draws straight from
the cache via ESTEX WINREST, with no re-parsing or fb() access in the
steady state. Horizontal scroll still uses the old live-render path
(Phase 5, not yet migrated).

Format and budget were derisked empirically first (tests/winrest):
confirmed ESTEX WINCOPY/WINREST buffer layout and measured EMM free
space, both folded into the implementation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 22:41:32 +03:00
snark13 1b39a60ff0 tests: add hello2, simple, banktest smoke tests
hello2 — stdio vs conio output API comparison (fast/no-attr vs
slower/attributed), also exercises textcolor/textbackground.
simple — packed 2-bit style array bit-twiddling smoke test.
banktest — __banked function calls across two explicit banks in huge
memory mode.

hello2.c updated to call the renamed gettextmode/settextmode (see the
conio rename in 5e5e70d).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 17:12:19 +03:00
snark13 8cfdcf307a libc: add mem_bios/mem_estex EMM page-allocation wrappers
mem_alloc_pages/mem_free_block/mem_get_page/mem_info, implemented twice:
mem_estex.c via ESTEX $3C-$3E (INFOMEM/GETMEM/FREEMEM), mem_bios.c via
the BIOS $C0/$C2-$C4/$C6 EMM_FN* calls. lib/Makefile already listed both
under LIBC_C.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 17:09:14 +03:00
snark13 49a87b4d02 libc: add Sprinter palette API (graphics + text planes)
palette.h/video/palette.c wrap BIOS $A4 PIC_SET_PAL/PIC_GET_PAL and $A6
SET_PAL_INIT for the 8 palette pages (0-3 graphics, 4-7 text planes).
gfx_palette.c and conio/text_palette.c are thin per-domain wrappers;
text_palette.c maps the text "plane" 0..3 (paper/ink/blink-paper/
blink-ink) onto BIOS pages 4..7. Covered by tests/text_palette.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 17:07:55 +03:00
snark13 5e5e70d0c8 conio: switch cursor get/set to BIOS calls, rename text-mode accessors
_get_cursor/_set_cursor now use BIOS GetCursor/SetCursor (RST 8, 08Eh/084h)
instead of ESTEX CURSOR/LOCATE; cursor position packed into a two_bytes
union. get_videotextmode/set_videotextmode renamed to gettextmode/settextmode.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 17:07:16 +03:00
snark13 016fedd94c mdview: speed up rendering via bios/text.h, fix wrap-boundary style bug
Replace per-character wrchar() loops in render_line/fill_row/help screens
with batched BIOS calls (bios_writeattr/bios_fillcharattr), and cache the
per-line index record (idx_get) instead of refetching it ~13 times per
rendered line — each refetch cost two W3 bank switches via bank_read().

Also fixes a pre-existing indexer bug: when word-wrap pushes a token that
starts with an emphasis/code marker (e.g. `_text_`) onto a new line, the
marker got re-scanned a second time during the wrap continuation, flipping
line_style back off and corrupting the rendered attribute of the next
word. Fixed by snapshotting line_style at the last seen space and rolling
back to that snapshot (both the saved continuation style and the live
scan state) when a wrap is taken.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 17:06:35 +03:00
snark13 c9d5ea35a4 libc: add bios/text.h BIOS text-output API
Direct __naked z80 wrappers over BIOS LP_PRINT_*/LP_SET_PLACE/LP_GET_PLACE
(RST 8, opcodes 081h-08Eh) for fast text rendering — a single BIOS call
replaces a wrchar() loop for constant-attribute/constant-character runs.
Covered by tests/bios_text.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-23 17:06:13 +03:00
snark13 bd116d7361 ChangeLog:
- update.
2026-06-10 10:41:03 +03:00
snark13 858e5755ad ChangeLog:
- big commit.
2026-06-10 10:35:48 +03:00
snark13 f87b52bb7f ChangeLog:
- memory optimized version.
2026-06-08 15:34:36 +03:00
snark13 07c4004bd9 ChangeLog:
- commit current version MDView.c
2026-06-08 11:22:15 +03:00
snark13 6992c1436e docs(mdview): добавить описание работы и тестовые паттерны
Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 22:39:14 +03:00
snark13 07c398a560 ChangeLog:
- Russian commentaries.
2026-06-07 22:01:13 +03:00
snark13 4bed9d3f3f fix(mdview): корректный multiline quote join в render_line
- исправлен rewind до первого non-cont сегмента для continuation
- для quote-потока newline обрабатывается как soft join с пропуском сырого ' > ' маркера
- восстановлен quote-префикс на continuation строках

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 20:26:19 +03:00
snark13 463a058f56 mdview: multiline quote paragraphs with quote-aware joining
- Quote blocks now join consecutive quote lines into one paragraph with
  soft breaks and wrap continuation under quote prefix.
- Empty quote lines ('>' / '>   ') act as quote-paragraph separators.
- Nested quote starts ('> > ...') are not merged into the parent text and
  stay separate rows.
- Keeps existing inline emphasis handling inside quote content.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 19:24:59 +03:00
snark13 8abc1d6c16 mdview: drop printf from status rendering
Replace status-line printf formatting with compact manual decimal rendering
(u16/u8 right-aligned helpers + wrchar/put_str_attr). This removes runtime
printf usage from mdview.c and keeps fixed status columns without stale digits.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 19:19:13 +03:00
snark13 982af12710 mdview: multiline list items with lazy continuation and blank-line grouping
- List items (UL/OL) can now span multiple source lines: non-marker
  lines are joined into the current item as lazy continuation.
- Continuation-line leading indentation is trimmed before joining so
  wrapped item text is separated by a single space.
- A single blank line between adjacent list markers is suppressed
  (same visual list), while 2+ blank lines still produce a separator.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 19:13:02 +03:00
snark13 394ee3a2cd mdview: blank-row block separation; tables nowrap; fix continuation marker
- Paragraph scanning no longer swallows the blank line separating it from
  the next block; runs of blank lines collapse to one row. Restores blank
  separation between paragraphs, headers and horizontal rules.
- Detect table rows (first non-space char '|') as nowrap segments; they are
  no longer merged into surrounding text or each other.
- Continuation (wrapped) rows render content as plain text and are no longer
  re-classified, so a wrapped word starting with '-'/'#'/'>' is not mis-drawn
  as a list/heading/quote marker.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 12:50:30 +03:00
snark13 47c9cd326a mdview: wide-break '\\', strikethrough, horizontal scroll bounds + '<'
- A trailing backslash before a newline now forces an in-paragraph line
  break (like two trailing spaces); render consumes the marker (non-code).
- Add ~~strikethrough~~ inline style (INIT_STYLE_STRIKE / EM_STRIKE),
  parsed in inline_scan, the paragraph merger and render, mirroring **.
- Horizontal pan is bounded by the widest nowrap segment on screen, and a
  '<' indicator marks hidden content off the left edge.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 11:55:19 +03:00
snark13 ca5f30b332 mdview: move segment index to EMM bank; inline hot byte reads
- Index is now an 8-byte record per visible segment in a dedicated EMM
  block (idx_get/idx_put), freeing ~11 KB of near RAM and lifting the
  old 2048-line cap (dynamic max_lines = index_pages * 2048).
- The per-byte scan keeps the previous segment offset in a near var
  (cur_seg_off) and mirrors the last record (cur_rec), so it never reads
  the index back from the bank.
- fb()/map_page() are inlined now that there is code headroom, removing
  per-byte call + 32-bit argument marshalling overhead.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 11:49:36 +03:00
snark13 0ad0559fc8 mdview: faster file-byte access (fb byte-decode + page cache)
Decode page/offset from the 32-bit offset's bytes to avoid SDCC z80
32-bit shift/mask helpers on the hot path; map_page() uses a cached
file_phys[] table to skip mem_get_page() on every W3 swap.
Behaviour-preserving.

Co-Authored-By: Oz <oz-agent@warp.dev>
2026-06-07 01:00:49 +03:00
snark13 035d93ab51 mdview: fix fenced code block emphasis leak and carry emphasis across wrap lines
- Add fenced code block tracking to the wrap-pass in index_lines().
  line_style is reset to PLAIN at every ``` delimiter, and all segs
  inside a fenced block get init_style=PLAIN. This prevents emphasis
  markers (e.g. _ in __var) inside code blocks from leaking into later
  normal text.
- Also carry init_style across wrap continuation segs so that a long
  bold/italic line that is wrapped continues with the correct style on
  the next segment.
- The fence bitmap pass now only updates in_code[], since init_style is
  already set correctly by the wrap pass.
2026-06-06 12:01:15 +03:00
snark13 0dedc4dac8 ChangeLog:
- prebuild.
2026-06-05 23:33:23 +03:00
snark13 737c974400 Add mdview markdown viewer, reorganize tests/examples and libc layout
- Split tests/ (libc feature tests) and examples/ (real apps); shared
  app.mk in repo root, was examples/example.mk
- libc/io/* split into libc/{conio,env,errno,file,mouse,string,sys,
  time,video}/ — clearer module boundaries
- New examples/mdview/: markdown viewer (Phases 1-5 + light nested
  lists). Headers (H1-H4), HR, ulist/olist/quote with nesting via
  leading spaces, fenced code blocks, inline emphasis (bold/italic/
  underscore/code), wrap/unwrap mode with soft wrap (F2), horizontal
  pan (← →) with '>' truncation indicator
- libc additions: scroll() in conio (ESTEX SCROLL), strlwr/strupr,
  gets() test
- Makefile updates across tests/ for the new shared app.mk path

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-04 22:23:36 +03:00
snark13 b851e22fa6 Drop print_hex.c — replaced by hex8() from hex_print.c
print_hex(uint8_t) was an early bare-metal helper doing exactly what
hex8() in the freshly-ported hex_print.c does (two-digit hex via
putchar()).  hex8() is smaller (asm cp/sbc/daa nibble trick, no LUT)
and consistent with the dec8/hex16/dec16/hex32/dec32 family.

  • Replaced print_hex() calls with hex8() in examples/banked and
    examples/bankedbg.
  • Removed libc/stdio/print_hex.c, dropped its prototype from
    sprinter.h and its entry from lib/Makefile.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-04 09:28:39 +03:00
snark13 527d4a6a18 libc review: mem/, stdio/, fixes in sprinter-cc and FILE shim
libc/mem/:
  • Split bank_io.c into bank_io_w3.c (existing W3 helpers, base 0xC000,
    port 0xE2) and bank_io_w1.c (new mirror through W1, base 0x4000,
    port 0xA2).  Two .rel files so DCE picks only the needed group:
    a W3-only user pulls ~70 bytes instead of all 134.  W1 variants are
    `--memory tiny`-only (any other mode runs code from W1 or uses W1
    for the banked-code segment, swapping it crashes).
  • mem_alloc.c: add CF=err checks for mem_free_block and mem_get_page
    (were silently ignored), per-function docstrings on alloc/free/
    get_page/info, drop the confused "wait wrong order" comment in
    mem_info.  Header sprinter_mem.h gets matching per-function doc.

libc/stdio/:
  • Add hex_print.c (hex8/hex16/hex32, ~26 bytes) and dec_print.c
    (dec8/dec16/dec32, ~170 bytes) ported from solid-c STDLIB.ASM.
    Replaces the printf("%u"/"%X") wrappers in solid_helpers.c that
    dragged in the 3-5 KB printf machinery.
    - hex* use the classic cp 10 / sbc 0x69 / daa nibble→ASCII trick;
      hex8 self-calls for the high nibble, hex16/hex32 tail-call hex8.
    - dec32 is the master routine; dec8/dec16 jump into shared entry
      points (__dec_entry3 / __dec_entry5).  32-bit subtract-power-of-10
      keeps the high 16 bits in HL alt (shadow set).
    - DISCOVERY: ESTEX PUTCHAR ($5B) on our Sprinter build preserves
      the main register set + IX but CLOBBERS the shadow set
      (BC'/DE'/HL').  solid-c's original code assumed otherwise and
      garbled output for values ≥ 6 digits.  Fix: save/restore HL alt
      around the RST 10 in _dec_emit_or_skip.  Documented in
      memory/estex_putchar_abi.md.
  • file.c: drop stdaux/stdprn (no Sprinter printer API), change
    stdin/stdout/stderr fd markers to 0/-1/-2 (positive fds clash with
    ESTEX OPEN return values), add TODO header pointing at v2 buffered
    FILE rewrite (see docs/TODO.md for the Solid-C reference struct).

bin/sprinter-cc:
  • --memory big and --memory huge now always use crt0_banked.s (was:
    only with --bank flags), matching docs/memory_modes_implemented.md.
    When the user has no --bank flags, generate a tiny stub with
    `const uint8_t n_banks = 0;` and assemble bank.s for _bank_pages.
    Without this fix, openenv with --memory big could not see the
    estex_file_handle symbol exported by crt0_banked.

examples/openenv:
  • Add usage of estex_file_handle to confirm the crt0_banked startup-
    info is reachable.  Local extern decl — keeps the symbol out of
    sprinter.h since it only exists in big/huge builds.

examples/dec_test:
  • New regression test covering hex8/16/32 and dec8/16/32 across the
    interesting boundary values.

.gitignore: add .kilo/ (editor session cache).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-04 09:26:10 +03:00
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
snark13 f542608b3f Initial commit 2026-06-03 15:50:20 +03:00