LIB2 / FILE VIEW

ARITH_API.md

DOWNLOAD ORIGINAL ↓

# B9 elementary ADD and SUB candidate API

`B9_ADD` and `B9_SUB` are two independent public entrypoints sharing one numerical kernel in `b9_arith.inc`. Source derives from accepted private Math 1.0 ADD/SUB algorithms; source identity is intentionally different. `math10_add.inc` and `math10_sub.inc` must remain unchanged.

Call arguments are RAM pointers in the UA14 bank (all 9-byte B9 values): `$10/$11` = A; `$12/$13` = B; `$14/$15` = destination. `$0` = status 0 success, 1 invalid encoding, 2 range. r009 decodes A and B directly from the read-only caller buffers; non-overlapping destination and exact aliasing are supported, partial overlaps are unsupported. Failed calls leave destination unchanged. Other CPU register and flags may be clobbered. Non-reentrant.

Dependencies: `B9_COPY` (`lib/b9/b9_value.inc`), valid stack, initialized `$SX=0`, `$SY=1`. **No resident firmware mathematical service.** Fixed scratch 3000h..31ECh (32 fewer bytes than r008); caller buffers must be outside that scratch, plus existing B9 converter scratch 2E40h..2EC4h when the app also includes the converter. Confirm RAM bank accessibility and no overlap for each future client.

Current single test ROM: `src/b9-test01.s` has independent TEST1 (50 historical cases, 7 pages), TEST2 (12 MUL cases, 2 pages) and TEST3 (14 M11 ADD/SUB + alias cases, 2 pages), with VT23 for page transport. It checks exact result bytes/status, both operands, and destination sentinel on errors. This initial set is a smoke/regression gate, not exhaustive precision or rounding qualification.

r009 status: SOURCE/STATIC CHECKED, not yet accepted on target; native HD61 assembly, 64KiB size, actual computational PASS, exact ROM SHA and emulator/physical run remain **OPEN**.

## r009 direct-input boundary

Both inputs are read without pre-copy and remain unmodified. This optimization requires the caller to keep the nine-byte input objects outside `B9A_*` private scratch (`3000h..31ECh`). Exact destination alias with A or B remains supported because output is produced privately, copied only on success. Partial overlaps remain unsupported. The two Test3 alias cases explicitly exercise this contract.