Files
Sprinter-SDCC/libc/mem/bank_io.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

52 lines
1.6 KiB
C

/*
* bank_io — HOME-resident helpers to read/write a "far" page that lives
* in some physical RAM page outside the currently-mapped W3 bank.
*
* - We always run from HOME (window 1, always mapped), so we are free
* to swap W3 (port 0xE2) between the caller's bank and the data
* page, then restore it before returning.
* - The caller must not rely on W3 contents during the call — the swap
* is transparent to instruction-fetch (we execute from W1), and only
* this function touches W3.
* - DI/EI is NOT applied around the swap; ISRs in HOME are unaffected,
* and banked-call ISRs are not expected in our current design.
*/
#include <stdint.h>
#include <string.h>
#include <sprinter.h>
#include <sprinter_mem.h>
uint8_t bank_load_byte(uint8_t phys_page, uint16_t off_in_window)
{
uint8_t saved = _io_page_w3;
sprinter_page_w3(phys_page);
uint8_t v = *((volatile uint8_t *)(0xC000u + off_in_window));
sprinter_page_w3(saved);
return v;
}
void bank_store_byte(uint8_t phys_page, uint16_t off_in_window, uint8_t v)
{
uint8_t saved = _io_page_w3;
sprinter_page_w3(phys_page);
*((volatile uint8_t *)(0xC000u + off_in_window)) = v;
sprinter_page_w3(saved);
}
void bank_read(uint8_t phys_page, uint16_t off, void *dst, uint16_t n)
{
uint8_t saved = _io_page_w3;
sprinter_page_w3(phys_page);
memcpy(dst, (const void *)(0xC000u + off), n);
sprinter_page_w3(saved);
}
void bank_write(uint8_t phys_page, uint16_t off, const void *src, uint16_t n)
{
uint8_t saved = _io_page_w3;
sprinter_page_w3(phys_page);
memcpy((void *)(0xC000u + off), src, n);
sprinter_page_w3(saved);
}