# MathSoft/2 — 17 callable function `.inc` files (source-exact split)

**Prepared 2026-11-13. SOURCE-EXACT PASS; NATIVE BUILD NOT YET RUN.**

The library has one `fn/<function>.inc` for every public `M11_*` routine. Large engines are shared under `engine/`; no numerical instruction, operand, label, constant, RAM equate or whitespace was changed. For each of the ten prior numerical owner includes, concatenating the generated fragments reproduces the original byte-for-byte. The separate `src/mathrom_m11_v3.s` uses these includes, preserving the complete expanded source of the accepted `mathrom_m11_v2.s`. This is source equivalence, not yet HD61 ROM parity.

## Public callable `.inc` files

| Function `.inc` | Public entry | Engine dependency | Additional requirements |
|---|---|---|---|
| `fn/add.inc` | `M11_ADD` | `B9_ADD` external | `M_IN`, `M_A_INB`, `M_OUT` |
| `fn/sub.inc` | `M11_SUB` | `B9_SUB` external | same |
| `fn/mul.inc` | `M11_MUL` | `B9_MUL` external | same |
| `fn/div.inc` | `M11_DIV` | embedded `_D11_*` | `scratch/scalar_scratch.inc` |
| `fn/sqrt.inc` | `M11_SQRT` | embedded `_S11_*` | `scratch/scalar_scratch.inc` |
| `fn/exp.inc` | `M11_EXP` | embedded `_E11_*` | `scratch/scalar_scratch.inc` |
| `fn/lgt.inc`, `fn/ln.inc` | `M11_LGT`, `M11_LN` | `engine/log_engine.inc` | `scratch/scalar_scratch.inc` |
| `fn/sin.inc`, `fn/cos.inc`, `fn/tan.inc` | `M11_SIN`, etc. | `engine/trig_engine.inc` | `scratch/trig_scratch.inc` |
| `fn/sinh.inc`, `fn/cosh.inc`, `fn/tanh.inc` | `M11_SINH`, etc. | `engine/hyp_engine_before.inc` and `engine/hyp_engine_after.inc` | `scratch/hyp_scratch.inc` |
| `fn/asinh.inc`, `fn/acosh.inc`, `fn/atanh.inc` | `M11_ASINH`, etc. | `engine/invhyp_engine.inc` | `scratch/invhyp_scratch.inc` |

**Important:** these are assembly definitions, not a runtime dynamic linker. An app must include its selected function, required engine once, required scratch equates, and the fixed `M_*` buffer symbols with a valid stack, bank and `$SX/$SY`. Shared engines should never be duplicated by including more than one copy. The `hyp_engine_before/after` pair is intentionally split so the source sequence stays byte-identical to the r019 source; it is not a suggested new architectural division.

## Examples (assembly include order)

For SIN only:
```asm
#INCLUDE (lib2/mathsoft/2/scratch/trig_scratch.inc)
#INCLUDE (lib2/mathsoft/2/engine/trig_engine.inc)
#INCLUDE (lib2/mathsoft/2/fn/sin.inc)
```

For SIN and COS sharing one engine:
```asm
#INCLUDE (lib2/mathsoft/2/scratch/trig_scratch.inc)
#INCLUDE (lib2/mathsoft/2/engine/trig_engine.inc)
#INCLUDE (lib2/mathsoft/2/fn/sin.inc)
#INCLUDE (lib2/mathsoft/2/fn/cos.inc)
```

For SINH only (wrapper occurs *within* the shared engine in the frozen order):
```asm
#INCLUDE (lib2/mathsoft/2/scratch/hyp_scratch.inc)
#INCLUDE (lib2/mathsoft/2/engine/hyp_engine_before.inc)
#INCLUDE (lib2/mathsoft/2/fn/sinh.inc)
#INCLUDE (lib2/mathsoft/2/engine/hyp_engine_after.inc)
```

See `src/mathrom_m11_v3.s` for all 17 operations linked into a complete ROM in the *exact* r019 sequence. For specific consumers, include only their selected functions plus their dependencies; standalone subset linking remains to be verified by native HD61 builds.

## Contracts and limitations

- B9 is a nine-byte decimal representation; the existing donor expects `M_IN`, `M_OUT`, `M_A_INB` (when binary). The historical test app's absolute buffer locations are **not** mandatory addresses for future clients.
- Status `$0` and output-on-error behavior differ among engines; do not assume output preservation, a common pointer ABI, complete register preservation or uniform domain enforcement.
- The UA14 scratch bank is intentionally overlaid between mathematical families and B9 multiplication; **never nest or interrupt math calls** before explicit liveness qualification.
- The original r019 SIN(390°) exact-byte deviation (+4e-13) remains an accepted named exception, not a global tolerance.
- The accepted `mathrom_m11.bin` and `mathrom_m11_v2.bin` have the same SHA-256 `61be3cb8cdb989cbbdba5712fd1941150508454d8ff5f4d8c2e0ee6548f61845`. The new `v3` output is **NOT YET BUILT**.

## Verification and build

From `src/`:
```sh
python3 tests/verify_mathsoft2_fn_split.py
```

Once copied to `build/` by the normal project sync, add `mathrom_m11_v3` **as the final additional ROM name in your own `mk.cfg`** and run `./mk.sh` to rebuild all ROMs from `src/`. Compare the new ROM digest against the two existing accepted digests. Keep the donor, v2 files and `mk.cfg` unchanged until the owner build proves parity.
