library-newlib

Guides z88dk newlib CRT driver instantiation, stdio heap sizing, and disk fcntl wiring.

1.1k|206|Updated Mar 16, 2016
One-click install
npx skills add https://github.com/z88dk/z88dk --skill library-newlib-z88dk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: library-newlib
Source: https://github.com/z88dk/z88dk/tree/main/.agents/skills/library-newlib
Command: npx skills add https://github.com/z88dk/z88dk --skill library-newlib-z88dk

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Migrating z88dk targets to newlib or adding serial and disk drivers often fails with opaque symptoms like undefined asm_target_open_p1 symbols, fopen returning EMFILE, or corrupted FDSTRUCTs from mis-sized stdio heap blocks. This Skill documents the CRT m4 instantiation model, heap sizing formulas, and CRT config knobs so those failures can be diagnosed and fixed directly. ## Core Features & Use Cases - Serial FILE instantiation*: Explains character_00 vs console_01 driver layers, CRT m4 wiring of stdin/stdout/stderr, multi-port ttyin/ttyout patterns, and CP/M IOBYTE seeding for dual-port consoles. - Static stdio heap sizing: Provides the committed = header + body formula with per-driver byte counts and map-span verification to prevent heap underflow corrupting adjacent FDSTRUCTs. - Disk fcntl setup: Covers asm_target_open_p1/p2 requirements, open_max/stdio_heap_size/fopen_max sizing, and FCB vs FatFs dual-stack policy. - Use Case: When adding a CP/M disk driver to a new target, follow the checklist to place cpm_01_file in the library list, force a lib rebuild, and prove linkage with z88dk-z80nm and map file inspection. ## Quick Start Ask the agent to diagnose why fopen fails with EMFILE on a +cpm -clib=new build and to check the CRT open_max, stdio_heap_size, and fopen_max settings.

Frequently Asked Questions about library-newlib

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix undefined symbol asm_target_open_p1 in z88dk newlib?

The undefined asm_target_open_p1 error means the target library lacks a disk fcntl driver such as cpm_01_file. Add the driver to the target library list, force a rebuild by deleting the target .lib files, and verify with z88dk-z80nm that the symbol is present.

Why does fopen return EMFILE while open works in newlib?

fopen fails with EMFILE when fopen_max is not greater than the number of static FILE structures instantiated by the CRT, leaving the FILE freelist empty. Increase fopen_max in crt_config.inc, for example to 10 when six static streams exist.

What is the difference between character_00 and console_01 drivers?

console_01 provides line-edited terminal streams with echo and CR/LF cooking and is the default on most CRTs. character_00 is a thin byte-stream driver suited to multi-port setups like RDR/PUN/LST, instantiated via CRT m4 macros with m4_file_dup for error streams.

Does z88dk classic library support getline for serial input?

No, getline and getdelim are newlib-only POSIX APIs. Classic targets use fgets on stdin backed by fgets_cons for cooked line input, or fgetc_cons for raw input where the application must implement line editing.

Why does open corrupt stdout after adding a newlib driver?

Heap corruption happens when a static driver m4 sets the committed size larger than header plus FDSTRUCT body, causing free-space underflow. Verify map spans between __i_fcntl_heap_N blocks equal the formula, for example $3+27 for cpm_00_input_cons.

Can FatFs f_* functions replace CP/M FCB open in newlib?

No, f_* is never an alias for FCB fcntl; the two volumes stay independent. Plain +cpm -clib=new needs only the BDOS FCB driver, while hardware -subtype=cpm builds may optionally add -lff as a dual stack.