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>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Exercises SDCC's malloc / free. The library pulls in heap.rel + malloc.rel
|
||||
* from z80.lib automatically and inits the heap from crt0's _GSINIT chain.
|
||||
* Default heap size is 1023 bytes — see docs/TODO.md for plans to grow it.
|
||||
*/
|
||||
|
||||
int main(void)
|
||||
{
|
||||
puts("malloc test:");
|
||||
|
||||
/* small allocations */
|
||||
char *a = (char *)malloc(20);
|
||||
char *b = (char *)malloc(40);
|
||||
char *c = (char *)malloc(60);
|
||||
|
||||
printf(" a = %p\n", a);
|
||||
printf(" b = %p\n", b);
|
||||
printf(" c = %p\n", c);
|
||||
|
||||
if (a && b && c) {
|
||||
strcpy(a, "first");
|
||||
strcpy(b, "second-medium-length");
|
||||
strcpy(c, "third-and-the-longest-of-them-all");
|
||||
printf(" a: \"%s\"\n", a);
|
||||
printf(" b: \"%s\"\n", b);
|
||||
printf(" c: \"%s\"\n", c);
|
||||
} else {
|
||||
puts(" one of the allocations FAILED");
|
||||
}
|
||||
|
||||
/* free b, alloc smaller — should fit in the b-shaped hole */
|
||||
free(b);
|
||||
char *d = (char *)malloc(15);
|
||||
printf(" after free(b), d = %p (expected near b)\n", d);
|
||||
if (d) {
|
||||
strcpy(d, "reused");
|
||||
printf(" d: \"%s\"\n", d);
|
||||
}
|
||||
|
||||
/* drain a larger allocation to see when malloc actually says no */
|
||||
int total = 0;
|
||||
int count = 0;
|
||||
for (;;) {
|
||||
void *p = malloc(64);
|
||||
if (!p) break;
|
||||
total += 64;
|
||||
count++;
|
||||
}
|
||||
printf(" alloc'd %d x 64-byte blocks before failure (total %d bytes)\n",
|
||||
count, total);
|
||||
|
||||
free(a);
|
||||
free(c);
|
||||
free(d);
|
||||
puts("");
|
||||
puts("Press any key to exit.");
|
||||
(void)getchar();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user