Commit Graph
90 Commits
Author SHA1 Message Date
Cryan209andClaude Opus 5.5 11df97b2c2 SATH shifts right by 16 on TREG1 bit 4, not left by bits 3-0
op_sath shifted ACC left by TREG1(3:0) and saturated. SPRU056D 6-229: it
shifts right 16 when TREG1 bit 4 is set and otherwise leaves ACC alone,
SXM picking the fill; SATL is the 0-15 half of the same 0-31 bit shift.

Overlay 6's V.34 phase-3 transmit sequencer (0xb0c5) takes its next state
as nibble[state] of 0x00102540 through samm @0d / sath / satl. From state
3 it must reach 2; the left shift saturated to 0x7fffffff and gave 15, so
the answerer's TRN never ended and its control code at 0x9d5d, waiting for
state 5, waited for the rest of the call. With the fix the answerer leaves
TRN after about 1.7 s; the caller still misses J, so training now retrains
instead of hanging.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 12:27:40 +12:00
Cryan209andClaude Opus 5 5f01b218fa BANZD's address modify belongs before its delay slots
delay_slot() overwrites m_op, and GET_ADDRESS() reads its addressing mode
out of m_op, so taking the modify afterwards applied the last delay-slot
instruction's field instead of the branch's own. op_bd and op_calld already
order it correctly; op_banzd was the outlier.

MICA's datapump is what found it. Its cooperative yield ends in
`banzd 4f6e, *` (no modify) with `lar ar7, *+` (post-increment) in the delay
slot, so AR2 came out one word high and the task restore read its resume PC
out of the forward link rather than the task's stack. Every yield returned to
program 0x0000 and restarted the DSP.

Also implement sfrb, which the datapump reaches once it stays up: the mirror
of sflb, with ACC's LSB into ACCB's MSB, the bit leaving the bottom of ACCB
into the carry, and ACC shifting as SFR does under SXM.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 11:49:33 +12:00
Cryan209 1870fee438 dsp work 2026-09-21 00:13:20 +12:00
Cryan209 ac4962829d Support C51 DSP model and document memory maps 2026-09-20 23:51:55 +12:00
Cryan209 945f9ff7c5 c5 core work 2026-09-20 21:36:58 +12:00
Cryan209andClaude Opus 5 c3d1e8ec6d TIM counts CLKOUT, not retired instructions
The on-chip timer was ticked once per instruction, so it ran slow by the
average cycles-per-instruction, roughly 2.5x. Firmware that measures a
hardware period against TIM read the wrong answer.

The MICA portware's frame-rate check is what exposed it. At program 0x80cd
it reloads TIM from PRD, waits one serial frame, averages 256 readings and
requires 0x137e +/- 0x2ca cycles per frame. With the frame period set to
5000 cycles TIM reported 2000, so the check rejected every clock rate and
the datapump never left that loop.

The core already tracks real cycles in m_cycles for the TDM frame clock, so
drive the timer from the same counter. TINT now fires at its true rate,
which is faster than before for any firmware that uses the timer - the
Courier residents leave it counting via splk @26, #0020.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 20:22:19 +12:00
Cryan209 a12a9dff8f dsp core fixes 2026-09-20 18:22:37 +12:00
Cryan209andClaude Opus 5 4754e35470 The frame interrupt is the transmitter's, and both halves latch on one edge
Every Courier-family C5x resident programs the primary port identically - 403
and 302 at 0x8090, 2.1.1 at 0x80bd, 2.3.31 at 0x109d - and the sequence says
what the model has to do. SPC goes 0x0008 then 0x40c8, so MCM = 0 and TXM = 0
and the frame edge is external; DXR is primed and the part spins on XRDY
waiting for that edge; IFR is write-1-cleared; and then IMR is written with
0x002a: INT2, TINT and XINT. RINT, bit 4, is not enabled, and `samm @04` - the
only write certain to reach IMR, since `splk @04` is DP-relative - appears
exactly once in each of the 403 and 302 residents.

A cold start confirms it. Parked at 0x813c the 403 has IMR = 002a, SPC = 40c8,
and the mask ROM's dispatch cells hold @65 = 8178 for XINT against @64 = 819d
for RINT, the same unused stub @6a holds for NMI. Only XINT has a handler.

So `serial_receive_interrupt` was raising the right IFR bit for the wrong
reason and gating it on SPC.RRST, the receiver's reset bit, which the 403
never consults. The 2.x residents then show why naming one bit is wrong at
all: they test data 0x012f and, if set, `lamm @04 ; and #ffcf ; or #0010 ;
samm @04` - same frame, service moved to RINT. One edge now latches both, each
behind its own half of the port's reset, and IMR and INTM decide recognition
where the part leaves them.

Three more things the residents reach that the core did not do:

- Recognition ran only from `interrupt()` and the INTM controls, so a flag
  that became eligible without a fresh source edge waited for the next one.
  The 2.x rewrite of IMR above happens with INTM already clear, and RETE
  clears INTM on its way out of a handler. It is checked at every instruction
  boundary now, and taking a vector is its own step.
- A repeated instruction was interruptible. RPTC and the repeat pointers are
  not in the context shadow, so a vector out of the middle of a block lost the
  rest of it; check_nmi has always refused for that reason.
- NMI vectored to a literal 0x0024. Its slot is offset 0x24 inside the same
  IPTR-relocated table as every other vector; 0x0024 is only right because the
  mask ROM runs with IPTR zero.

And the timer ignored TCR.TSS, so a stopped timer still raised TINT - which
matters here because TINT is the other thing 0x002a enables, and it is what
wakes the IDLE at 0x813b when no frame has arrived yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 12:42:08 +12:00
Cryan209andClaude Opus 5 c08409b53c The V.8 capture read the wrong data page, and DP was reported pre-shifted
Two reporting defects in the same quantity, and the diagnostics needed to
tell where DP actually comes from.

m_st0.dp is held pre-shifted - LDP stores DP<<7 and GET_ADDRESS ORs it
straight into the offset - but two readers treated it as a raw DP:

  - The V.8 dispatch capture computed `(m_st0.dp & 0x1ff) << 7`, which keeps
    only (DP & 3) << 7 and then shifts that again, landing on a page the
    dispatcher never runs on. v8_handler, v8_countdown and v8_flags came back
    0 from every dispatch for that reason - 133,790 of them on the answering
    end alone - which reads exactly like a state machine spinning on an unset
    vector. With the page right, the handler is af12 on the answering end and
    ae7d on the originating one.

  - state() exported m_st0.dp raw, so every consumer printing `dp` was
    printing DP<<7. The answering end's "dp=896" was DP 7.

Added alongside: shadow_dp, the DP an interrupt return is about to reinstate;
last_dp_pc/value/source, where DP was last written and by which instruction;
and stray_cala_pc/target/dp, latching the first CALA whose target leaves the
loaded images, with the DP and target it ran with.

That last one exists because DP cannot be read after the fact here. The
originating end's crash is a CALA to program 0000, and the mask ROM it lands
in rewrites DP itself - `LST #0` at 0676 - so a DP sampled at the end of the
run describes the ROM, not the call. Latched where it happens, the call is:

    9f3a  cala  -> 0000, with DP = 6

so the vector it read is @2f on page 6, data 032f, which holds 0000 on both
ends. The answering end never reaches this call and never makes a stray one.

Why 032f is never written is not answered here.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 12:15:33 +12:00
Cryan209andClaude Opus 5 e63293ea8d RPTC idles at 0, not -1, so an unrepeated TBLR actually transfers
Both ends of a leased pair transmitted pure silence, and had since well before
this branch - 0925e22 and f59a824 both record it. The cause is one initialiser.

Fifteen opcodes in the repeatable block-transfer family - TBLR, TBLW, the BLDD
and BLPD forms, MACD and the rest - share this idiom:

    while (m_rptc > -1) { ...; m_rptc--; }

which executes RPTC+1 times. But `reset()` and the member default both set
RPTC to -1, and the loop leaves it at -1 when it finishes. So after a reset,
and after every repeat, RPTC was -1 and every one of those instructions was a
silent no-op: no transfer, no write, no fault. Only once some RPT had run and
step()'s block-repeat tail happened to leave RPTC at 0 did they start working.

On the part RPTC reads 0 whenever no RPT is in force, an unrepeated
instruction runs once, and a repeated one runs RPTC+1 times - both ending at
0. So the loops become do/while and reset to 0.

What this cost: the C51 resident's command dispatcher at 83b5 reads a command
byte from ff5e, bounds-checks it, and does `tblr @7c ; lacc @7c ; bacc` over a
table based at 8401. The resident had downloaded perfectly - 286 words sampled
across it, none differing, and 8402 holding its true entry 8003 - but the TBLR
transferred nothing, so @7c kept its initial 0 and the BACC branched to
program 0000. That is the C51's mask ROM: the part fell through the vector
table into the ROM's serial bootstrap spin at 06dc and waited there for a
word no one was ever going to send. No datapump overlay was ever requested,
because the DSP that would request one was gone.

It was path-dependent, which is why one harness path looked healthy: a run
that happened to execute an RPT before reaching the dispatcher left RPTC at 0
and dispatched correctly.

Measured on `--dip-preset dedicated-line --at 'AT&T1'`, the invocation
docs/datapump-dispatch-gate.md gives, before and after:

    overlay_downloads   0        ->  2  (id 8, verified)
    line_tx_nonzero     0        ->  6732
    dxr_writes          36       ->  16715
    dsp pc              06dc     ->  a2b7

and a leased pair over the socket line now carries audio both ways - each
end's transmit matches the other's receive, rms 2201, peak 16160, with tones
at 1801 and 2199 Hz. Cut-through moves from frame 518 to 93, because the DSP
now reaches the state that answers instead of dying at frame 0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 11:42:00 +12:00
Cryan209andClaude Opus 5 23b41322f4 The call has one state, and it belongs to the line rather than to either end
Three corrections to the sound path.

The switched call now has a single state that both subscribers share.  Each
end used to decide for itself whether the path was through, from a counter
only it could have: the calling end watched the rings it was sending, the
answering end watched the ring bursts it was receiving, and a leased pair
matched neither rule on the answering side, so B never cut through at all.
The two ends could therefore disagree, which is a half-connected call - one
end transmitting into a cut loop.  `call_state` now crosses the line in every
frame; each end advertises the furthest point it knows of and adopts the later
of its own view and the peer's.  Every transition has exactly one end that can
make it - only the calling end can seize and ring, only the called end can
answer - so this converges instead of oscillating, and `_cut_through` is now a
derived property rather than a per-end flag.

RS is shared with the AC01, and a reset pin cannot change the board.  The
reset already returned the codec's registers to power-up but took the MCLK
back to the 2.88 MHz default with them, so every generation after the first
ran at a clock the board never presents; it also left the frame period at the
rate the previous generation had programmed, while the divider registers it
was supposedly derived from had gone back to A = B = 18.  Carry the configured
MCLK across and restart the frame period with the registers.

IRQ5 is the serial port's receive interrupt, not the frame scheduler's.
SPRU056D 5.3: RINT is raised when RSR transfers into DRR, and a receiver held
in reset shifts nothing and raises nothing.  The frame clock itself is
genuinely external - the ASIC is the frame master and keeps running while the
DSP is inside an overlay - but all four sites that load DRR now end at one
port-level entry point that applies the RRST gate.  Suppressions are counted
and exported as `serial_rint_suppressed`, because a receiver left in reset is
otherwise indistinguishable from a frame clock that stopped.  The gate has not
been exercised against a completed call: the C51 ROM loader does not reach its
ASIC poll on either the 302 or the 403 image, which is a fault ahead of it and
predates this change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-20 10:54:46 +12:00
Cryan209 1f78be8ce5 fixes 2026-09-20 10:43:02 +12:00
Cryan209 f60e434cec work 2026-09-20 01:53:33 +12:00
Cryan209andClaude Opus 5 3b7d47dd14 Aim @48 at the page the dispatcher runs on, and admit a dialed call
Two instrument faults on the way to the doc's "next question, singular".

_maybe_start_originate_engine returned unless daa.operation was "originate".
Its docstring says why - it was written for the leased line, where the
originating end never dials - and the socket path's new digit receiver moves
the operation to "dialing" on the first digit, so the originating end stopped
arming at all. That was a regression from the dial-tone commit. A dialing
seizure now qualifies once the called party has answered, which is when an
originating modem starts V.8 instead of putting CM under its own digits.

And the core read m_data[0x48] for @48. A direct operand resolves to
(DP << 7) | offset, so that asserted DP 0. Measured at the dispatch DP is
0x180, which puts @48 at 0xc048 and @4a/@4d at 0xc04a/0xc04d: every report of
a null handler was reading a cell the firmware does not use. v8_dispatch_dp is
now reported so the page is never assumed again.

The static question the doc asked is answered: the 403 resident segment has 57
sites storing to @48, 26 to @4a and 58 to @4d, and almost every @48 site is
splk @48, #<address two words on>, so @48 is a continuation vector resumed by
lacl @48 ; bacc - the same arrangement as 2.1/2.2. The signature match is not
a false friend for want of writers.

With both faults fixed @48 still reads zero at every dispatch on both ends,
including B, which emits a full 2.98 s answer tone through 62,759 dispatches
of that routine. A routine whose vector is null on the side that is
negotiating is not the one negotiating, so 0xba0b is not the live V.8 state
machine on 403 and none of these counters mean V.8 progress here.

What does separate the ends is the mailbox stream: A originates 0008:* and B
0016:*, overlapping only on three tags. The audio is unchanged by any of this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-19 23:11:47 +12:00
Cryan209andClaude Opus 5 f97b451512 Aim the V.8 counter at the loaded image, gate the overlay publication
The core no longer hard-codes 2.1/2.2's c418: Bridge._v8_dispatch_addresses
finds every copy of the dispatcher by signature over the resident bank and
each declared overlay, and set_v8_dispatch_pcs hands them to the core, which
now also reports which one fired as v8_dispatch_pc.

_find_call_overlay requires the candidate to be pre-linked for the
destination - first branch target == 0xc418 + 0x0d. 2.1/2.2's stored copy
satisfies it; the self-linked resident copies on 302/403 do not, so nothing
is published there any more.

Measured on a 403 linked pair against the old behaviour as a control: every
V.8 number identical, only call_overlay_available moves, so the gate changed
nothing observable. The dispatcher does run, at 0xba0b, 22,471 times - but
@48, @4a and @4d are all zero, so every entry branches to program 0, and
v8_rx_peak and the audio rms are zero on both sides in the baseline too.

Artifacts in artifacts/v8-dispatcher-403-01/.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-19 12:53:08 +12:00
Cryan209andClaude Opus 5 dd6c5bc086 Record the DSP's mailbox writes where they happen
`dsp_originated_tags` polls `io_port_stats` once a batch and then reads
whatever `io_output` holds, which samples an asynchronous stream: it
counts polls that saw a change, not messages, and can pair one
message's tag with another's word. The general I/O event log cannot
stand in for it either - it is unfiltered and capped at 8192, and the
datapump's transmit writes to port 0x50 run to half a million per call,
so it holds nothing but PCM by the time anyone reads it.

Keep a separate log of the writes to 0x5e..0x60 in the core, and decode
it in the bridge on the resident sender's own boundary: the tag goes to
0x5e and the words follow on 0x5f (0x83eb, 0x83ee, 0x83f6), so a write
to 0x5e opens a message. `status().dsp_mailbox_log` is the ordered
result, with the pc and instruction count of each send.

On a leased pair it confirms what the poll had reported, so the poll was
not in fact tearing here: the answerer sends exactly two messages in
150M instructions and the originator one.

  a  92,860,533  tag 006b  words 0000 4321
  a 112,636,450  tag 0034  words 0000 0005
  b  99,940,384  tag 006b  words 0000 4321

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 12:51:39 +12:00
Cryan209 7e7f3390e2 work 2026-09-17 21:18:58 +12:00
Cryan209andClaude Opus 4.6 0992f43687 Cap the DSP I/O event log at 8192 entries
m_io_events was an unbounded std::vector that grew by one entry per
DSP I/O operation — millions per second of simulated time. Over a
long interactive session this alone consumed tens of gigabytes and
triggered the macOS OOM killer. Switch to a std::deque with a rolling
window; the per-port aggregate stats in PortStat are unaffected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-09-17 15:57:30 +12:00
Cryan209andClaude Opus 5 20133c60ee Do not service interrupts inside a delayed branch's delay slots
op_clrc_intm() calls check_interrupts() inline, which is right at an
instruction boundary and wrong inside a delay slot: it pushed the return
address and set the PC to the vector, and then the enclosing op_calld's
CHANGE_PC(pma) overwrote the PC and left the push behind. One orphaned
stack entry per execution.

SPRU056D 4.9 has a delayed branch and its delay slots complete as a unit,
with no interrupt serviced between them, so the pending interrupt should
simply be taken at the next boundary.

This firmware guards every host-port access with the same idiom -

    setc intm ; calld 80e8 ; lar ar1, #xx ; clrc intm

at 80eb, 8103, 82c6, 82d5, 8323 and 83c4, so the stack drifted a level on
every port read. The visible damage was in the datapump's receive delivery:
8320's RETD at 8330 popped the stale 8327 its own CALLD had pushed, re-
entering the routine at 8327 with ARP still 1 from the `sacl *+, ar1`. AR1
holds 0x6f there, so the delivery wrote the assembled character over @6f -
its own flag word - clearing bit 3 and disabling receive delivery, after
reading that same cell as if it were the host status port.

With the FSK loopback running the firmware's own loop, that is the
difference between 14 characters delivered and 1211, and @6f now reaches
008c - carrier, receive delivery and transmit data all enabled - instead of
being knocked back to 0007.

Also adds stack_entry()/NativeC5x.stack(), which is what made the orphaned
push visible.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 22:12:04 +12:00
Cryan209andClaude Opus 5 cf84decd47 Read memory-mapped registers through the registers, not the backing store
C5xCore::data() answers from m_data, which for an address below 0x60 is a
cell that no memory-mapped register keeps up to date. DM_READ16 routes those
through cpuregs_r; the inspection accessor never did. So every harness that
reached for a register got zero however the firmware had set it, and said so
confidently:

  PMST  reads 0000, is 00b0   - iptr 0, MP/MC 0, OVLY, RAM and AVIS all set
  CBSR1 reads 0000, is 0bc0   - the datapump's output buffer
  CBER1 reads 0000, is 0bdf
  CBCR  reads 0000, is 00ef   - circular buffer 1, AR7, enabled, 32 words
  TDXR  reads 0000            - whatever INTR 17's handler has been writing

Reading those four was what led to "the firmware never sets up a circular
buffer" and "TDXR never changes". Both were the accessor, not the firmware.

register_value() answers from the register and has no side effects, which is
the difference that matters for an inspection path: cpuregs_r pops the codec
queue on DRR and clears the ready flag on TRCV. data() keeps its meaning, so
nothing that already treats low addresses as scratch changes behaviour.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 21:46:40 +12:00
Cryan209andClaude Opus 5 3146b47a05 The hybrid returns the codec's output to its own input
AT&T1 is local analogue loopback: the codec's transmit comes back to its
own receive, and the DSP modulates and demodulates against itself to
exercise the analogue side. It is not meant to reach the line, so the
on-hook DAA in the last run was correct and the silence on the socket was
never the fault.

The loop was simply not modelled. c5x_core decoded the AC01's loopback
bit from register 5 and reported it, and the receive sample came from
m_codec_rx unconditionally, so a run with no peer fed the datapump
silence. docs/ac01-codec-protocol.md already said the setting "does not
yet alter the samples".

Nor is there anything to key it off. Running AT&T0, AT&T1 and AT&T8
standalone, &T1 and &T8 send byte-identical mailbox sequences - the same
33 messages in the same order, ending 0071:0003 0077:0000 0076:0000
0002:9d00 0002:dc00 0004:0000 0010:5001 001f:0000 0019:0000 - and leave
register 5 at its boot 0x05, IN+/IN- selected, loopback bit clear. Only
the B register moves, 20 -> 18, which is overlay 6 selecting 10266.67 Hz
from the negotiated symbol rate. The hardware capture agrees: the four
ports asic_ports.py records as moving between idle and &T8 are the
mailbox status pair and live signal, not a path select.

So the return is the analogue front end, not a command. The codec's
output reaches its own input through the hybrid, attenuated by how well
the hybrid is terminated: on hook the DAA isolates the line and the
hybrid looks into an open, so nearly all of it comes back, which is the
path &T1 tests and why it needs no bit of its own.

Modelled core-side, flat, with a short delay. codec_transmit taps the
analogue output into a delay line; codec_frame sums it into the analogue
input ahead of the input gain, so it shares the gain with the line. The
scale is set from hook state by the bridge - 240/256 on hook, 26/256 off,
the latter a stand-in for a real hybrid's 20 dB trans-hybrid loss and not
a measurement of this board - and applied outside the line guard, because
a standalone &T1 has no line and is the case that needs it.

Measured, AT&T1 standalone at 200M instructions:

  hybrid_frames        445,781      loop carries every primary frame
  hybrid_peak           12,123      against a transmit peak of 12,135
  codec_rx_peak         24,246      after the +6 dB input gain, no clip
  drr_reads            379,805      the ISR is consuming it

&T1 has no start-up to complete: it is a data-mode test, the modulator
sending a sequence into the loop and the demodulator recovering it. There
is no handshake to wait on and no originate/answer role, so an earlier
draft of this message that guessed at one is withdrawn.

What closing the loop changes is one extra DSP-to-host report, 0004:0000,
present with the loop closed and absent with it open against an otherwise
identical run at 200M. The demodulator sees the signal and says something
about it.

Nothing else moves. Queuing 16 bytes of data behind the command leaves
serial_input_remaining at 16 - the firmware never takes them, so the DTE
data path is never opened - and serial_text is empty, so not even a
result code comes back. CD stays off. The HS LED does light, at
i=35,293,183, but it lights identically with the loop open, so it says
nothing about the loop; checked against 144c95c rather than assumed.

So the loop is closed and carries the modulator at a sane level, the
demodulator consumes it and reports once, and the firmware does not
declare the test up. Whether the demodulator recovers the sequence is
still unmeasured. Next: what tag 04 is, and what the supervisor waits for
before it opens the DTE path.

47 tests pass; the leased pair is unchanged, both ends still loading
['9d00', 'dc00'] with 0 unreadable.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 11:56:48 +12:00
Cryan209 ab59d705af dsp work 2026-09-15 19:28:39 +12:00
Cryan209 daa51e0c6a Correct codec clock modeling and leased-line defaults 2026-09-15 17:06:58 +12:00
Cryan209 21661e3e54 Accelerate x86 interpreter with guarded native execution 2026-09-15 16:33:54 +12:00
Cryan209andClaude Opus 5 c063e1a73f Clock the C52 at the board's 20.16 MHz, not 25
Scott confirms the board clocks the DSP at 20.16 MHz. The core carried
25 MHz, picked to reproduce a shipped frame-period constant of 3472
cycles rather than measured from anything.

The sample rate is unaffected - the clock cancels out of
MCLK / (2 x A x B) - so this moves no frequency and is not the 1.2 in
codec-sample-rates.md. What it moves is the frame period: 2520 cycles
where the board has 2520, against 3125 before. The DSP had been getting
24% more compute per sample than the part it models.

The pre-programming stand-in goes from 3472 to 2800, which is the same
7200 Hz it always meant, now at the right clock.

Behaviour is unchanged where it can be compared: the 302
`--exchange-hotline` run still loads overlay 8 and still transmits
continuously at the same level, and the leased pair still holds its
tones. Captures get longer for a given instruction budget, because more
frames now fit in one, so recorded sample counts and hashes move.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 15:17:19 +12:00
Cryan209andClaude Opus 5 6862ed0164 Count the datapump's writes to the line DAC slot
Two counters: how often the datapump wrote the ASIC line-DAC slot, and
how many codec frames collected those writes. Their ratio is how many
datapump samples the model folds into one line sample.

They answer that immediately, and not the way the code reads: across a
whole leased-pair run both are zero. The branch whose comment says "the
line slot carries the datapump's own DAC accumulation and nothing else"
never executes on this route - it is gated on call-TDM being active, and
it is not. Every line sample is pushed from the generic write hook
instead, at C52 program 0x818f, one per line-frame interrupt.

So the accumulate-and-average DAC model does not produce the line on the
path that matters, and the 1.2 in codec-sample-rates.md is not hiding in
it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 14:24:47 +12:00
Cryan209andClaude Opus 5 2303403749 Do not let the DSP reset disarm the write trace
`--dsp-write-watch` recorded nothing on 302 or 403. The bridge arms the
trace when it builds the core, and these images then reset the core
during boot - which cleared the flag. Every watch since has been
reporting an empty list rather than "no writes".

What is traced, and which cell, is the caller's diagnostic, not device
state the reset line owns.

With it kept, watching 0x39a shows the answering end of a leased pair
re-running its own init mid-handshake, which is how the transmit
teardown was found.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:03:32 +12:00
Cryan209andClaude Opus 5 f00993b176 Implement SUBB, and give SUBC its own arithmetic
The answering end of a leased pair killed its C52 two and a half seconds
into the handshake: `TMS320C5x: unimplemented op subb at 0000A7D1`. The
core stops there, so `frames_clocked` stops, so the audio-only line -
which paces its frames off the codec clock - never services the socket
again. The peer then spins to its instruction limit waiting for a frame
that cannot arrive, which is why 400M instructions produced no more line
audio than 120M did. With SUBB implemented the pair runs to the limit:
186 frames becomes 992, and 148,800 samples becomes 793,600.

SUBB is the mirror of ADDC, subtracting the inverted carry as a borrow.

Its body already existed - in `op_subc`, which is a different
instruction. SUBC is the conditional-subtract divide step, and it is
reached at program 0x9444 on every run of this firmware, so the resident
has been running a borrow subtract where it asked for a division step.
It now follows SPRU056D 6-137.

That correction changes no output here: both ends' line audio and the
302 `--exchange-hotline` transmit capture are byte-identical across it.
What it changes is that the instruction computes the right function.

Both ends still fall silent about 2.5 s after the carrier starts, while
holding the line off hook for the rest of the run. That is a separate
stop and is not this.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 12:42:36 +12:00
Cryan209andClaude Opus 5 02bd4da27a Take the DSP program origins from the supervisor, not from constants
The XMF layout in xmf.py placed main211's first segment at program 0x0000,
and the mask-ROM reasoning in three documents was built on that. The origin
was never measured. The supervisor names its own destination at the download
call site, and it says 8000; its overlay table puts the other 2.1/2.2 rows at
9d00, af50 and dc00. Every branch target in the payload has bit 15 set, which
needs no explaining at that origin and needed masking off at 0x0000.

Recover all four segments the way rom.py does, matching the call site and the
table and identifying the resident as the fall-through row that reproduces
what the call site independently said. That also separates the two families:
2.1.1 and 2.2.05 occupy 8000..ffff, the board's 32K of external RAM, leaving
0000..1fff to the C51's mask ROM; 2.3.x occupies 0000..7fff instead, with its
resident at 1000 and one overlay at program 0000, which no part running mask
ROM there can host.

Three consumers carried the layout too: bridge.py's bootstrap length and its
TDM vector, and c5x_runner.cpp, which held the whole map as C++ defaults and
entered at PC 0. All three now derive it, the runner taking --segment
OFFSET:BYTES:ORIGIN. Both loaders published every segment into the core at
construction, which with correct origins would lay the overlays over resident
code; they load the resident alone, as the board has it at reset.

bootstrap_match stays true at 60344 bytes, and all seven XMFs now boot from
their own origin to the same relative idle.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 08:18:49 +12:00
Cryan209andClaude Opus 5 67f6a7e172 Count the C5x's I/O accesses as they happen, not by scanning the log
courier_c5x_get_io_port_stats answered every query by walking the whole
m_io_events vector once per port. That vector is only cleared at reset, so
the scan was linear in the length of the run, and the bridge's ROM-load and
overlay-commit loops ask for the stats once per single-step: the cost of
committing a block grew with how much had already been committed.

Keep the six figures per port in IO_READ16 and IO_WRITE16 instead, the way
m_data_write_counts already does for data writes, and make the query an
array lookup. Replaying the event log over a five-million-instruction run
reproduces the new counters exactly, and a twenty-million-instruction run
of MAIN_2.3.31 gives byte-identical output.

At 139k events the sixteen-port query drops from 599us to 21us and stops
growing; a step(1) loop that samples one port goes from 0.12 to 0.52M
instructions per second.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 22:06:22 +12:00
Cryan209 0c43c564a4 cpu > asic > dsp work 2026-09-14 00:39:33 +12:00
Cryan209 c8b4195fb1 Correct C5x memory mapping and ROM validation 2026-09-13 23:56:24 +12:00
Cryan209 19313a03ef Model C51 8K boot ROM and split SARAM mapping 2026-09-13 23:10:10 +12:00
Cryan209 800e5fa098 Improve SIP real-time audio pacing 2026-09-13 08:42:27 +12:00
Cryan209andClaude Opus 5 2844b8ab0a Bind TREG1, TREG2 and DBMR for reading, and the B channel comes alive
The flag hunt at e8ba has a driver at e63a that sets TREG2 = 15 and @7c = 7
before calling it, so the hunt eats the byte one bit per call and trips its
pop/ret - discarding the bit helper's return address to land on the driver's -
when TREG2 reaches @7c. The per-frame cycle is the resident splitting a
received word, calling the handler the overlay installed at 088c/088d, that
handler at eb39 bit-reversing the octet, the hunt eating eight bits, and the
pop/ret bringing control home.

It never came home because TREG2 was only half a register here. cpuregs_w
bound TREG1, TREG2 and DBMR; cpuregs_r bound TREG0 and stopped - the exact
split the comment above case 0x0c warns about, left half-applied. lamm @0e
read a dead cell, so sub @7c was never equal, and samm @0e wrote ffff back
every time: bitt tested bit 15 for 3,186,292 iterations while the counter it
waited on never moved.

With the read side bound, the modem answers, synchronises on the far end's
flags and idles the link with 6,937 of its own - HDLC 7e, not noise - the 5e
command is consumed, and the whole call runs to a clean l4_DISCONN and NO
CARRIER once the far end proves to have nothing above framing to say. The DSP
ends at IDLE with the mailbox drained 39 of 39.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 20:33:32 +12:00
Cryan209andClaude Opus 5 2f1c268136 Clock two peripheral-port time slots per frame, as SPC says to
The DSP's serial port is in sixteen-bit word format - the firmware writes
SPC = 40c8 and FO is bit 2, the same bit docs/quad-dsp-pcm-path.md already
separates the two products on. Sixteen bits every 125 us is 128 kbit/s: two
eight-bit peripheral-port time slots, where one B channel is 64. The core had
a comment claiming byte format and clocked one octet per frame into the low
byte, leaving the high byte - the half the firmware's own splitter at
80db..80de reads for this call - permanently zero.

The core now reads FO out of SPC rather than assuming it. FO=1 keeps one octet
per frame, which is the Quad's path (SPC = 40cc) and is unchanged. FO=0
exchanges a whole word, MSB first, so the frame's first slot is the high byte
at both ends - which is what decides the mapping rather than a preference.

Am79C30.peripheral_slots() says which channel is in which slot, taking them in
the order the MCRs list their connections. PPCR1 and PPCR2 are recorded and
not decoded: nothing in the image has shown what their fields mean.
ImodemDsp._sync_pcm exchanges one MUX frame per pair of octets, so B1 still
carries one octet per 125 us.

A call programs MCR1 = 16h and nothing else, so B1 takes the first slot and
the second is unconnected. DRR now reads 7eff against a flag-carrying far end:
the B-channel octet in the high half from Bd, idle in the low half from a slot
the MUX has nothing on. The deadlock at e8ba is unmoved, as expected - but the
byte it is stuck on is now the right byte.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 20:16:57 +12:00
Cryan209andClaude Opus 5 0396e6b4dc The loop at e8ba is an HDLC flag hunt, deadlocked against its own caller
Read back out of the core - NativeC5x.program() is new, because a downloaded
overlay exists nowhere else - the loop is a bit-serial hunt for 01111110, nine
flags before it declares sync, structured as a coroutine with its resume
address in @7d.

Its bits come from the helper at e8d7, which walks TREG2 from 15 down to 8
across the top half of a sixteen-bit word at 0x0889 and unwinds when the byte
is spent. 0x0889 is filled by the resident's splitter at 80d9..80de, on the
same background path as the mailbox dispatcher - and that path stops the
moment the overlay loop starts. Across the whole call after the 5e command the
cell takes no writes at all, while the interrupt side goes on filling a ring
at 0x0bd0 that a 7e input turns entirely to 7e. The bytes arrive; nothing
carries one to the cell the hunt reads, because that is the loop's own caller.

The ff on the wire is the overlay's own choice of mark idle, at e8e9/e909.

Found on the way: the firmware programs SPC = 40c8, so FO is 0 and the port is
in sixteen-bit word format. The core's comment claims the opposite, and the
splitter taking two octets out of one word agrees with the firmware. Which
half carries which peripheral-port slot is not settled, so nothing is changed
on that yet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 20:09:57 +12:00
Cryan209 d82e170e3c Model ISDN bearer audio and reliable LAPD timing 2026-09-12 17:49:41 +12:00
Cryan209 089056e3e0 i modem work 2026-09-11 19:25:28 +12:00
Cryan209 df5d70971b emu work 2026-09-11 14:03:02 +12:00
Cryan209 0748551a07 Implement Quad C50 digital PCM and stock DSP audio paths 2026-09-10 15:26:16 +12:00
Cryan209andClaude Opus 5 735d5fa941 Instrument the core: the C52 is not running at all
Added codec_rx_size, line_frame_irq, frame_period, line_frame_next_cycle and
cycles to codec_state(), and surfaced the core's codec state as `core_codec` on
the bridge status, which nothing reported before. One instrumented dial answers
what three commits of reading the code could not:

  line_frame_irq          5
  frame_period         3472
  line_frame_next_cycle 3472
  cycles                  0
  codec_rx_size      228480
  frames_clocked          0
  pc / instructions    0 / 0
  active              False
  bootstraps              1

m_cycles is zero because the C52 never executes an instruction. The frame
driver compares m_cycles against m_line_frame_next_cycle, 0 >= 3472 is never
true, codec_frame() never runs, and the queue fills to 228,480 undrained.

The reason is bridge.py:1327. A DSP reset closes the core, builds a fresh
NativeC5x and sets active = False; active only returns when a re-download
reaches bootstrap_target_size, and that second download never comes -
bootstraps stays at 1 - so the part is held dead for the rest of the dial.
Under ATX0 the supervisor skips the wait, loads the call overlay, and the DSP
comes back, which is why that path has always worked.

So the dial-tone failure is not a missing detector, not a missing flag and not
a gated ISR. Three separate conclusions in this document said otherwise and all
three were reached by reading code rather than by asking the core what it was
doing. The instrumentation is kept for that reason.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-09 00:29:28 +12:00
Cryan209andClaude Opus 5 797ed28378 Delete the harness tone generator; the DSP is the whole audio path
The core carried hand-written sin() in C++ that stood in for the datapump's
DAC output: a DTMF pair generator, a 1300 Hz V.8 calling indicator and a
2100 Hz ANSam approximation, armed from the bridge through set_dtmf_digits
and gated by set_synthetic_line. While it ran it also *discarded* the C52's
own DAC accumulation to make room, so the assist did not merely supplement
the firmware, it displaced it.

It is gone. dtmf_sample(), m_dtmf_digits, m_synthetic_line and the three
substitution sites (the 0xb2e5 write guard, the call-TDM V.8 branch and the
idle branch) are removed, along with the C API exports, the Python bindings
and the bridge's arming calls. V8Mode stays: the role still gates the
receive-side indicator qualification, which observes the line rather than
driving it.

Nothing is lost on the image that matters. Rerunning the 3.0.13 capture with
the generator deleted produces line audio byte-identical to the reference
(sha256 ccad9c62...), and decoding it independently at 7200 Hz returns
5551212 - the number the firmware was asked to dial. The C52 was already
doing the work; only the stand-in's presence obscured that.

The three tests that covered the generator went with it. They asserted on
main211, which is not modelled well enough to be a behavioural reference.
The bridge tests that used core.dtmf as a proxy for reaching the dial phase
now assert on bridge.dial_digits and daa.operation instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-08 08:27:31 +12:00
Cryan209andClaude Opus 5 9f97d97e4c Watch 39a during a digit: the generator runs, the silence is after it
--dsp-write-watch ADDR records every write to one C52 data cell with the
program address that made it. The write trace was unfiltered and its
4096-event buffer covers milliseconds; the read side also traces a fixed
set of cells and floods the buffer on its own. Both honour the filter now.

Watching 39a across a 403 dial gives four arm/restore pairs, one per
digit: ee2b writes 8743, and about 2.3M instructions later - roughly the
tone's duration - 86dc restores 8128. That is a one-shot callback
lifetime, not a clobber, so the end-of-run 8128 was just the idle state.

Watching 3c0 inside one of those windows shows the phase advancing by
0x2f81 per sample, exactly the increment tblr loaded into 3f2. The
oscillator runs at the right rate from the right table entry.

So the mailbox-to-oscillator path is sound and the tone is generated but
never reaches the line. What is left is the mixer's output path: the
work pointer at 390 reads 0bd8 in the full-board run where audio312,
which does produce output from this ROM, supplies 0bc0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 23:44:01 +12:00
Cryan209andClaude Opus 5 6a78c03bbe Widen the C52 trace window: ee20 runs and arms the tone correctly
The core's PC trace was two hardcoded ranges. set_pc_trace_range adds a
third, settable one, exposed as --dsp-trace-range FIRST:LAST. Pointed at
ee00:ef00 it catches 3.1.2's tag 0x13 handler four times in a dial, once
per digit, and the handler is correct: it indexes the frequency table at
ee34, loads both increments, installs 8743 - the DTMF pair generator -
in the mixer's callback slot at 39a, sets the amplitude and clears both
phases. Every cell is one answer-tone.md already named.

So the silence is downstream of the handler. --dsp-peek reads C52 data
cells at the end of a run, and after a 403 dial the increments are still
loaded while 39a holds 8128 rather than 8743. Whether that is the
firmware restoring a silence generator after the tone or something
writing one cell low is not separable from an end-of-run value; it needs
39a sampled while a tone plays.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 23:29:06 +12:00
Cryan209 0b08dd7a94 emu work 2026-09-07 19:35:05 +12:00
Cryan209andClaude Opus 5 df8aa0a3ab Expose ARCR and INDX in the core state, and confirm ARCR is never written
Adds arcr/indx to State so the auxiliary-register compare that gates the
resident's block-level work can be observed rather than inferred.

With them visible: over a 600,000-instruction warm start, ARCR changes exactly
once - the reset to zero - and is never written again. AR7 meanwhile cycles the
mailbox ring 0x0bd0-0x0bde under the circular-buffer registers, so cmpr eq at
0x80d1 can never match and the block holding the mailbox poll never runs.

CMPR itself is confirmed correct in the core: it compares m_ar[arp] against
m_arcr, and ARP is 7 there, set by the mar *, ar7 before the loop's delayed
branch.

Also records what the idle state actually is, which was misread earlier as the
DSP being stuck: 0x822b sets @1a to 0x8139, a bare ret, and @1b to 0x8138, which
is intr 17 - vectoring through ROM 0x0022 to @69 = 0x81b7. That accounts for the
two largest slices of the PC histogram. A dozen sites across the resident reset
@1a to idle when a task ends, so the cells are a task pointer and the firmware
is idling by design, waiting to be given work.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 12:59:37 +12:00
Cryan209andClaude Opus 5 48fd048f69 Make XRDY follow the frame clock, and record why the boot table shares the port
XRDY says DXR can accept another word, which becomes true when a frame sync
moves the last one into the transmit shift register. It was reported set
whenever XRST was set, so the firmware's reset handshake at 0x8097 - write DXR,
spin on XRDY, write again - fell straight through instead of waiting a frame.
It now clears on a DXR write, sets on a frame sync, and is released by a 0 -> 1
edge on XRST.

Scoped to the AC01 path: the legacy TDM path models no framing on this port, so
nothing there would set XRDY again after a write and a spin would never end.
That is a limit of this model rather than hardware behaviour, and it is
commented as such.

Also records what the boot table sharing the port actually rests on. TI's
application guide puts the AC01 on the primary serial port and leaves the TDM
port pulled to COM, which the firmware agrees with; the ROM loader is on that
same port and is receive-only. The datasheet holds DOUT in high impedance until
the eighth primary frame sync, and the firmware issues exactly eight primary
frames first - two priming writes plus six register writes - so the ASIC can
drive DR with the boot table unopposed until the codec is fully programmed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 11:12:01 +12:00
Cryan209andClaude Opus 5 6f75c0ac3a Clock the codec's audio per the datasheet instead of on demand
DRR was filled lazily, when the firmware happened to read it, so a run whose
receive queue was empty returned the same stale word every frame - 28,212 reads
of one value in the survey run.

codec_frame now runs at every frame sync:

- one ADC word per primary frame (section 2.4, "one word for each primary
  communication interval"), delivering a zero for a quiet line rather than
  repeating the last word;
- no sample on a secondary frame, which carries the addressed register when a
  read was requested and zeros otherwise, so a readback arrives with the frame
  rather than with the host's read;
- the secondary frame sync half a frame period after the primary that asked for
  it, which is Figure 2-1's (B/2) FCLK periods given fs = FCLK/B;
- RRDY following a word having been clocked in.

The ROM boot table shares the port but is not the sample stream: a frame sync
consuming those words breaks the download. queue_codec_boot keeps them in their
own queue, drained only by the loader's polls.

302 boot measures 1911 frame syncs and 1911 samples consumed, one each, with
DRR carrying live audio.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 11:00:09 +12:00
Cryan209andClaude Opus 5 ae6e9eaf82 Model the AC01 codec and derive the sample rate from its B register
The rate was hardcoded: 3472 cycles in the core and 9600 Hz in every generator
that filled the receive queue. The firmware retunes register 2 at runtime for
each V.34 symbol rate, so a constant is wrong by construction - and the two
figures disagreed with each other, making the DSP hear every frequency scaled
by 4/3.

C5xCore now decodes DXR the way the part does. Which kind of frame a word
belongs to is decided by the previous frame's control bits, which replaces a
test against two hardcoded ISR addresses that recognised the samples of two
known builds and nothing else. Secondary words are parsed into a nine-register
file; writing register 1 or 2 recomputes fs = MCLK/(2 x A x B) and the frame
period with it. Register reads, the no-op register, forced secondary and
software reset are handled.

bridge.LineToCodec resamples line audio to whatever rate the codec currently
reports, so the harness can keep carrying the line at a fixed rate without that
rate reaching the DSP. A 2100 Hz tone now measures 2100 Hz after conversion
instead of 1575.

Booting 302 through the ROM recovers the six reset registers, 7200 Hz, and a
frame period of 3472 - the constant it replaces, now derived.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-07 10:48:03 +12:00