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>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* _errno_set — set `errno` from an ESTEX error code (0..255 in A).
|
||||
*
|
||||
* Replaces the inline pattern
|
||||
* ld (_errno), a
|
||||
* xor a, a
|
||||
* ld (_errno+1), a ; 7 bytes per error path
|
||||
* with a single
|
||||
* call __errno_set ; 3 bytes per error path
|
||||
*
|
||||
* Saves ~4 bytes at every libc error handler that converts an ESTEX
|
||||
* code into the C-side `errno`. Helper itself is 7 bytes; with 10+
|
||||
* error paths in our libc the size win is net-positive.
|
||||
*
|
||||
* ABI:
|
||||
* in: A = ESTEX error code (0..255)
|
||||
* out: HL = A (zero-extended); errno fully overwritten so a prior
|
||||
* large value (e.g. errno = -1) can't leak its high byte.
|
||||
* clobbers: HL, AF flags. Caller must not depend on HL afterwards.
|
||||
*
|
||||
* Defensive 16-bit store — see chat 2026-06-02: if anyone ever assigns
|
||||
* errno via C (`errno = -1`), the high byte becomes 0xFF, and a partial
|
||||
* 8-bit write here would leave that 0xFF in place. Always writing the
|
||||
* full word keeps errno honest regardless of who set it last.
|
||||
*/
|
||||
|
||||
void _errno_set(unsigned char code) __naked
|
||||
{
|
||||
(void)code;
|
||||
__asm
|
||||
;; __sdcccall(1): single uint8_t arg already in A.
|
||||
;; Write the two bytes separately so HL/BC/DE/IX/IY remain
|
||||
;; untouched. Only A is clobbered: it is the input register,
|
||||
;; and ABI does not require preserving it across a void call.
|
||||
ld (_errno), a ; low byte = code
|
||||
xor a, a
|
||||
ld (_errno+1), a ; high byte = 0
|
||||
ret
|
||||
__endasm;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* errno.c — strerror / perror over the SDCC-provided `errno` global.
|
||||
*
|
||||
* The message table mirrors the one in solid-c's IO.ASM (we kept the
|
||||
* English wording for grep-ability). ESTEX returns codes 0..32 in the
|
||||
* meaningful range; anything beyond gets "Unknown error".
|
||||
*
|
||||
* Note: we deliberately do NOT define `_errno` here — SDCC's
|
||||
* z80.lib/errno.rel provides it (a single int in _DATA), and our libc
|
||||
* wrappers (read.c, open.c, etc.) just assign to `errno`. This
|
||||
* removes the "multiple definition of _errno" link warning.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Stored verbatim — pointers in the lookup table cost 2 bytes each plus
|
||||
* the message bytes themselves. Sentinel "" entries pad out gaps so
|
||||
* indexing stays direct.
|
||||
*/
|
||||
static const char *const messages[] = {
|
||||
/* 0 */ "No error",
|
||||
/* 1 */ "Invalid function",
|
||||
/* 2 */ "Invalid drive number",
|
||||
/* 3 */ "File not found",
|
||||
/* 4 */ "Path not found",
|
||||
/* 5 */ "Invalid handle",
|
||||
/* 6 */ "Too many open files",
|
||||
/* 7 */ "File already exists",
|
||||
/* 8 */ "File is read-only",
|
||||
/* 9 */ "Root directory overflow",
|
||||
/* 10 */ "No free space",
|
||||
/* 11 */ "Directory not empty",
|
||||
/* 12 */ "Can't delete current directory",
|
||||
/* 13 */ "Invalid media",
|
||||
/* 14 */ "Unknown operation",
|
||||
/* 15 */ "Directory exists",
|
||||
/* 16 */ "Invalid filename",
|
||||
/* 17 */ "Invalid EXE file",
|
||||
/* 18 */ "Not supported EXE file",
|
||||
/* 19 */ "Access denied",
|
||||
/* 20 */ "Device not ready",
|
||||
/* 21 */ "Seek error",
|
||||
/* 22 */ "Sector not found",
|
||||
/* 23 */ "CRC error",
|
||||
/* 24 */ "Write protect",
|
||||
/* 25 */ "Read error",
|
||||
/* 26 */ "Write error",
|
||||
/* 27 */ "Drive failure",
|
||||
/* 28 */ "RESERVED",
|
||||
/* 29 */ "RESERVED",
|
||||
/* 30 */ "Out of memory",
|
||||
/* 31 */ "Invalid memory block",
|
||||
/* 32 */ "Unknown error",
|
||||
};
|
||||
|
||||
const int ESTEX_MAX_ERR = sizeof(messages) / sizeof(messages[0]) - 1;
|
||||
|
||||
const char *strerror(int err)
|
||||
{
|
||||
if (err < 0 || err > ESTEX_MAX_ERR) {
|
||||
err = EUNKERR;
|
||||
}
|
||||
return messages[err];
|
||||
}
|
||||
|
||||
void perror(const char *prefix)
|
||||
{
|
||||
if (prefix && *prefix) {
|
||||
fputs(prefix, stderr);
|
||||
fputs(": ", stderr);
|
||||
}
|
||||
fputs(strerror(errno), stderr);
|
||||
fputs("\r\n", stderr);
|
||||
}
|
||||
Reference in New Issue
Block a user