mirror of
https://github.com/D-Modem/courier-emu.git
synced 2026-11-28 20:38:07 -08:00
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>
596 lines
29 KiB
C++
596 lines
29 KiB
C++
// SPDX-License-Identifier: BSD-3-Clause
|
|
// Standalone TMS320C5x core. Opcode implementation adapted from MAME's
|
|
// BSD-3-Clause tms320c5x core, copyright Ville Linde.
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <deque>
|
|
#include <string>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace courier {
|
|
|
|
// TMS320C51 on-chip memory: 1056 words of DARAM, 1K of SARAM and 8K of ROM.
|
|
// The map is confirmed by the board probes in artifacts/dsp-memory-test-2806.
|
|
//
|
|
// The guide's three maps, checked region by region against what follows:
|
|
//
|
|
// The board runs MP/MC=0 - PMST reads 00b0 - so the ROM window is live.
|
|
//
|
|
// program, MP/MC=0 0000-1FFF on-chip ROM, 8K
|
|
// 2000-23FF SARAM if PMST.RAM, else external
|
|
// 2400-FDFF external
|
|
// FE00-FFFF DARAM B0 if CNF, else external
|
|
// program, MP/MC=1 as above, but 0000-1FFF is external too
|
|
// data 0000-005F memory-mapped registers
|
|
// 0060-007F DARAM B2 0080-00FF reserved
|
|
// 0100-02FF DARAM B0, reserved when CNF
|
|
// 0300-04FF DARAM B1 0500-07FF reserved
|
|
// 0800-0BFF SARAM if PMST.OVLY, else external
|
|
// 0C00-FFFF external
|
|
//
|
|
// Two things matter for this board. The SARAM is one physical memory
|
|
// reached from both spaces, which is the point of OVLY and why the two spaces
|
|
// cannot be backed by separate storage there. And **the whole top of data
|
|
// space is external** - data space is external from 0x0C00 upward,
|
|
// and program space from 0x2400 upward with CNF clear, as
|
|
// this firmware runs it. So an external address in 0x8000-0xFEFF is an
|
|
// ordinary off-chip bus cycle in either space, and one RAM answering both is
|
|
// a board that does not separate the two strobes rather than a trick. That is
|
|
// the shared window declared below.
|
|
//
|
|
// The part is a 'C51, measured on both boards: 8K of on-chip ROM at
|
|
// 0x0000-0x1FFF and 1K of SARAM. See artifacts/dsp-memory-test-2806. MP/MC
|
|
// reads 0, so this window is mapped on the real board and is not the fixture
|
|
// it used to be - artifacts/dsp-onchip-rom-20mhz-8k has its contents.
|
|
constexpr uint16_t C5X_ROM_WORDS = 0x2000;
|
|
constexpr uint16_t C5X_B2_FIRST = 0x0060, C5X_B2_WORDS = 0x0020;
|
|
constexpr uint16_t C5X_B0_FIRST = 0x0100, C5X_B0_WORDS = 0x0200;
|
|
constexpr uint16_t C5X_B1_FIRST = 0x0300, C5X_B1_WORDS = 0x0200;
|
|
// SARAM. The 9K part's block is at 0x0800-0x2bff in *both* spaces, which is
|
|
// what this core used to assume. The 'C51 is not like that: its 1K sits at
|
|
// program 0x2000-0x23FF and data 0x0800-0x0BFF - **one physical memory at two
|
|
// different addresses**. Measured: writing data 0x0800 and data 0x0A00 reads
|
|
// back from program 0x2000 and program 0x2200
|
|
// (artifacts/dsp-memory-test-2806/sweep). So the two windows are separate
|
|
// constants and program access translates into the data-space address, which
|
|
// is the storage. Still one memory, still the point of OVLY.
|
|
constexpr uint16_t C5X_SARAM_WORDS = 0x0400;
|
|
constexpr uint16_t C5X_SARAM_DATA_FIRST = 0x0800;
|
|
constexpr uint16_t C5X_SARAM_PROGRAM_FIRST = 0x2000;
|
|
// CNF moves B0 out of data space and into the top of program space.
|
|
constexpr uint16_t C5X_B0_PROGRAM_FIRST = 0xFE00;
|
|
constexpr uint16_t C5X_DATA_EXTERNAL_FIRST = 0x0800;
|
|
// The board's own memory, not the part's. Two 32Kx8 SRAMs give 32K words at
|
|
// program 0x8000-0xffff, and that same RAM answers data space: 302's prologue
|
|
// block-moves its mailbox helper into SARAM with `bldp` from data 0x80f5,
|
|
// which only yields code if a data read there returns the downloaded program.
|
|
// The top page is not RAM - the firmware's ASIC window is DP 0x1fe/0x1ff -
|
|
// so the shared window stops below it. See docs/dsp-map-302.md.
|
|
constexpr uint16_t C5X_SHARED_FIRST = 0x8000, C5X_SHARED_LAST = 0xFEFF;
|
|
// ...but only for an image whose program actually lives there. main211.xmf
|
|
// presents a first segment at origin 0x0000 alongside one at 0x8000, and which
|
|
// of those is the real payload is unresolved (see docs/dsp-map-302.md). For
|
|
// such an image the harness cannot say where the board's RAM sits, so the
|
|
// window is disabled rather than guessed at, and its data space behaves as it
|
|
// did before the window existed.
|
|
|
|
class C5xCore {
|
|
public:
|
|
struct State {
|
|
uint16_t pc;
|
|
uint16_t op;
|
|
int32_t acc;
|
|
int32_t accb;
|
|
int32_t preg;
|
|
uint16_t treg0;
|
|
uint16_t treg1;
|
|
uint16_t treg2;
|
|
std::array<uint16_t, 8> ar;
|
|
uint16_t dp;
|
|
uint16_t arp;
|
|
uint16_t arcr;
|
|
uint16_t indx;
|
|
uint16_t flags;
|
|
bool idle;
|
|
uint64_t instructions;
|
|
uint64_t cycles;
|
|
};
|
|
|
|
struct IoEvent {
|
|
bool write;
|
|
uint16_t port;
|
|
uint16_t value;
|
|
uint16_t pc;
|
|
uint64_t instruction;
|
|
};
|
|
|
|
// Per-port totals, kept as the accesses happen. These used to be
|
|
// recovered by scanning the whole m_io_events log on every query, which
|
|
// is linear in the length of the run: the ROM-load loops in bridge.py
|
|
// ask for them once per single-step, so the cost of loading a block grew
|
|
// with how much had already been loaded. Counting here makes the query
|
|
// O(1) and independent of the event log.
|
|
struct PortStat {
|
|
uint64_t reads, writes;
|
|
uint16_t last_read, last_write;
|
|
uint16_t last_read_pc, last_write_pc;
|
|
};
|
|
|
|
struct DataEvent {
|
|
uint16_t address;
|
|
uint16_t value;
|
|
uint16_t pc;
|
|
uint64_t instruction;
|
|
};
|
|
|
|
struct SerialState {
|
|
uint16_t drr, dxr, spc;
|
|
uint64_t drr_reads, dxr_writes, spc_writes, rx_consumed, rx_queued;
|
|
uint64_t codec_rx_consumed, codec_rx_queued;
|
|
uint16_t last_drr_pc, last_dxr_pc, last_spc_pc;
|
|
uint16_t trcv, tdxr, tspc;
|
|
uint64_t trcv_reads, tdxr_writes, tspc_writes;
|
|
uint16_t last_trcv_pc, last_tdxr_pc, last_tspc_pc;
|
|
uint64_t line_tx_writes, line_tx_nonzero, line_frame_interrupts;
|
|
// How often the datapump wrote the 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.
|
|
uint64_t line_dac_writes, line_dac_frames;
|
|
uint16_t line_tx_last, line_tx_last_pc, imr, v8_rx_state, v8_rx_peak, codec_rx_peak;
|
|
uint64_t negotiation_loop_entries;
|
|
uint16_t negotiation_loop_pc, negotiation_source, negotiation_pair, negotiation_source_value, negotiation_pair_value;
|
|
int32_t negotiation_acc;
|
|
uint64_t v8_dispatches;
|
|
uint16_t v8_record, v8_handler, v8_countdown, v8_flags, v8_dispatch_pc;
|
|
uint16_t negotiation_d76, negotiation_d77, negotiation_d78, negotiation_d79;
|
|
uint16_t negotiation_d26, negotiation_indx, negotiation_arp, negotiation_pm;
|
|
// Trans-hybrid return: frames the loop delivered and the loudest one.
|
|
uint64_t hybrid_frames;
|
|
uint16_t hybrid_peak;
|
|
};
|
|
|
|
// The TLC320AC01 on the DSP's serial port. See docs/ac01-codec-protocol.md:
|
|
// the DAC word is 14 bits with two control bits in its LSBs, `11` requests a
|
|
// secondary frame, and that frame carries a control-register write. The
|
|
// conversion rate is the part's own, from the A and B registers off MCLK,
|
|
// because the firmware puts it in free-run mode.
|
|
struct CodecState {
|
|
uint16_t registers[9];
|
|
// Diagnostics for "the queue is fed but nothing is consumed": what the
|
|
// native codec queue actually holds, and where the frame driver's next
|
|
// edge sits against the cycle counter it is compared against.
|
|
uint64_t codec_rx_size, line_frame_next_cycle, cycles;
|
|
int32_t line_frame_irq;
|
|
uint32_t mclk_hz;
|
|
uint64_t sample_rate_millihz;
|
|
unsigned frame_period;
|
|
uint64_t secondary_frames, register_writes, register_reads;
|
|
uint64_t phase_shifts, primary_frames, frames_clocked;
|
|
uint16_t last_control_word;
|
|
bool rate_programmed, secondary_pending, force_secondary;
|
|
bool free_run, high_pass_enabled, loopback, sixteen_bit;
|
|
uint8_t input_gain, output_gain, monitor_gain, input_select;
|
|
};
|
|
|
|
// Where a C52 address lands. The two parts that move are the boot ROM,
|
|
// which appears at the bottom of program space only in microcomputer
|
|
// mode, and DARAM B0, which CNF swaps between data 0x0100 and program
|
|
// 0xfe00. Everything else is off-chip or reserved.
|
|
enum class Region { Rom, Daram, Saram, Registers, Reserved, Shared, External };
|
|
|
|
struct MemoryMap {
|
|
// Sampled from the pin and the mode bits, so a run can report which
|
|
// map it ran under rather than leaving it implied.
|
|
uint16_t mpmc_pin, mpmc, ovly, ram, cnf, iptr;
|
|
// The wait-state registers, which say which regions the firmware
|
|
// expects to be off-chip. This core does not delay on them; it
|
|
// records them so a run reports the board it thinks it is on.
|
|
uint16_t pdwsr, iowsr, cwsr;
|
|
bool rom_present;
|
|
uint64_t program_rom, program_daram, program_saram, program_external;
|
|
uint64_t data_registers, data_daram, data_saram, data_reserved, data_shared, data_external;
|
|
// Fetches from on-chip ROM this harness does not have. An XMF carries
|
|
// the downloaded program and nothing else, so in microcomputer mode
|
|
// every one of these is a hole rather than a byte.
|
|
uint64_t rom_holes;
|
|
};
|
|
|
|
using IoRead = std::function<uint16_t(uint16_t)>;
|
|
using IoWrite = std::function<void(uint16_t, uint16_t)>;
|
|
|
|
C5xCore();
|
|
void reset();
|
|
void load_program(const uint16_t *words, std::size_t count, uint16_t origin = 0);
|
|
void load_data(const uint16_t *words, std::size_t count, uint16_t origin = 0);
|
|
void load_rom(const uint16_t *words, std::size_t count, uint16_t origin = 0);
|
|
void set_mpmc_pin(uint16_t level);
|
|
void set_shared_window(uint16_t first, uint16_t last);
|
|
MemoryMap memory_map() const;
|
|
void set_io_callbacks(IoRead read, IoWrite write);
|
|
void set_io(uint16_t port, uint16_t value);
|
|
void configure_host_mailbox(bool enabled) { m_host_mailbox = enabled; }
|
|
uint64_t xf_falling_edges() const { return m_xf_falling_edges; }
|
|
void host_write(uint16_t address, uint16_t value);
|
|
void queue_serial_rx(const uint16_t *samples, std::size_t count);
|
|
void queue_codec_rx(const uint16_t *samples, std::size_t count);
|
|
// `return_scale` is 1/256ths of the transmit sample; `delay` is in codec
|
|
// frames. Zero scale opens the loop and drops the delay line.
|
|
void set_hybrid_return(uint32_t return_scale, uint32_t delay);
|
|
uint32_t hybrid_return() const { return m_hybrid_return; }
|
|
std::size_t hybrid_line_size() const { return m_hybrid_line.size(); }
|
|
uint64_t hybrid_frames() const { return m_hybrid_frames; }
|
|
uint16_t hybrid_peak() const { return m_hybrid_peak; }
|
|
// Quad NAC digital highway: one G.711 octet in each direction per 8 kHz
|
|
// frame. This is deliberately separate from the AC01's 16-bit words.
|
|
void configure_digital_pcm(bool enabled, uint16_t idle_codeword = 0xff,
|
|
uint32_t clock_hz = 20'160'000);
|
|
void queue_g711_rx(const uint8_t *codewords, std::size_t count);
|
|
const std::vector<uint8_t> &g711_tx() const { return m_g711_tx; }
|
|
// The boot table the ASIC clocks into the same serial port before the
|
|
// codec matters. It is not audio and must not be consumed by a frame sync,
|
|
// so the ROM loader's DRR polls drain it ahead of the sample stream.
|
|
void queue_codec_boot(const uint16_t *words, std::size_t count);
|
|
void set_v8_calling(bool enabled);
|
|
void set_v8_answering(bool enabled);
|
|
void set_bio_low(bool enabled) { m_bio_low = enabled; }
|
|
void set_line_dac_slot(uint16_t slot) { m_line_dac_slot = slot; }
|
|
// Writes to that slot, kept apart by the TDM phase they were made in. The
|
|
// ASIC bus carries about ten slots per codec sample; if the line channel
|
|
// is one of them, its samples are in one of these and averaging them all
|
|
// together is what turns a waveform into noise.
|
|
const std::vector<uint16_t> &line_phase_samples(unsigned phase) const
|
|
{ return m_line_phase_tx[phase & 3]; }
|
|
uint16_t line_dac_slot() const { return m_line_dac_slot; }
|
|
uint16_t io(uint16_t port) const;
|
|
uint16_t io_output(uint16_t port) const;
|
|
uint16_t program(uint16_t address) const;
|
|
uint16_t data(uint16_t address) const;
|
|
// Inspection only. data() returns the raw backing store, so for an address
|
|
// below 0x60 it answers with a cell no memory-mapped register keeps up to
|
|
// date - a harness reading PMST, CBCR or TDXR through it sees zero however
|
|
// the firmware has set them. This reads the register itself, and unlike
|
|
// cpuregs_r it has no side effects: DRR does not pop the codec queue and
|
|
// TRCV does not clear its ready flag.
|
|
uint16_t register_value(uint16_t offset) const;
|
|
// The 8-deep hardware stack, newest first. The firmware manipulates it
|
|
// directly (d876 is `pop ; samm @70`, a coroutine yield that discards a
|
|
// return address), so a harness that reaches an entry by a different call
|
|
// depth than the firmware does leaves it skewed, and a later RET underflows
|
|
// into whatever the C5x's shift-register stack replicates at the bottom.
|
|
uint16_t stack_entry(unsigned index) const;
|
|
void set_data(uint16_t address, uint16_t value);
|
|
void interrupt(unsigned irq);
|
|
void nmi();
|
|
void configure_line_frame_interrupt(unsigned irq, uint16_t vector);
|
|
void configure_rom_codec(bool enabled);
|
|
void set_codec_mclk(uint32_t hz);
|
|
CodecState codec_state() const;
|
|
// Conversion rate in milli-hertz, so 7578.947 Hz survives the trip.
|
|
uint64_t codec_sample_rate_millihz() const { return m_codec.sample_rate_millihz; }
|
|
void schedule_line_frame_entry(uint16_t address) { m_line_frame_entry = address; }
|
|
void schedule_call_overlay(uint16_t origin, const uint16_t *words,
|
|
std::size_t count, uint16_t entry, const uint16_t *registers,
|
|
uint16_t selector);
|
|
// The V.8 state dispatcher's address is per firmware family, not a
|
|
// constant: 2.1/2.2 runs it at c418, where 302/403 carry copies at their
|
|
// own addresses and in overlays 6 and 7. Supplied by the caller, which
|
|
// finds them by signature in the image it actually loaded.
|
|
void set_v8_dispatch_pcs(const uint16_t *pcs, std::size_t count)
|
|
{
|
|
m_v8_dispatch_pcs.clear();
|
|
for (std::size_t index = 0; index < count; ++index)
|
|
m_v8_dispatch_pcs.push_back(pcs[index]);
|
|
}
|
|
void set_call_tdm_active(bool active) { m_call_tdm_active = active; }
|
|
bool call_tdm_active() const { return m_call_tdm_active; }
|
|
void set_pc(uint16_t address) { m_pc = address; m_idle = false; }
|
|
void step();
|
|
void run(uint64_t instruction_limit);
|
|
void set_data_trace(bool enabled) { m_trace_data_writes = enabled; }
|
|
// Restrict the write trace to one cell. Unfiltered it records every
|
|
// write and the 4096-event buffer covers a few milliseconds of a run,
|
|
// which is no use for watching one cell across a whole dial.
|
|
void set_data_trace_filter(uint16_t address, bool enabled)
|
|
{
|
|
m_trace_filter = address;
|
|
m_trace_filtered = enabled;
|
|
}
|
|
void clear_data_events() { m_data_events.clear(); }
|
|
State state() const;
|
|
SerialState serial_state() const;
|
|
const std::deque<IoEvent> &io_events() const { return m_io_events; }
|
|
// The mailbox ports on their own. `m_io_events` cannot answer what the
|
|
// DSP sent: it is unfiltered and capped, and the datapump's transmit
|
|
// writes to 0x50 run to hundreds of thousands per call, so it holds
|
|
// nothing but PCM by the time anyone reads it. Polling the port stats
|
|
// instead samples an asynchronous stream and tears message boundaries -
|
|
// it pairs one message's tag with another's word. Record the writes
|
|
// where they happen.
|
|
const std::deque<IoEvent> &mailbox_events() const { return m_mailbox_events; }
|
|
const std::vector<DataEvent> &data_events() const { return m_data_events; }
|
|
uint64_t data_write_count(uint16_t address) const { return m_data_write_counts[address]; }
|
|
const PortStat &io_port_stat(uint16_t port) const { return m_io_port_stats[port]; }
|
|
const std::deque<uint32_t> &pc_trace() const { return m_pc_trace; }
|
|
// The trace windows. Two are compiled in for the call overlay and the
|
|
// low-page stub; a third is settable so a caller can watch a handler
|
|
// elsewhere - 3.1.2's mailbox tag 0x13 enters ee20, which neither
|
|
// built-in window covers.
|
|
void set_pc_trace_range(uint16_t first, uint16_t last)
|
|
{
|
|
m_trace_first = first;
|
|
m_trace_last = last;
|
|
}
|
|
const std::vector<uint16_t> &line_tx_samples() const { return m_line_tx; }
|
|
|
|
private:
|
|
struct pmst_t { uint16_t iptr, avis, ovly, ram, mpmc, ndx, trm, braf; };
|
|
struct st0_t { uint16_t dp, intm, ovm, ov, arp; };
|
|
struct st1_t { uint16_t arb, cnf, tc, sxm, c, hm, xf, pm; };
|
|
struct shadow_t {
|
|
int32_t acc, accb;
|
|
uint16_t arcr, indx;
|
|
pmst_t pmst;
|
|
int32_t preg;
|
|
st0_t st0;
|
|
st1_t st1;
|
|
int32_t treg0, treg1, treg2;
|
|
};
|
|
|
|
using opcode_func = void (C5xCore::*)();
|
|
static const opcode_func s_opcode_table[256];
|
|
static const opcode_func s_opcode_table_be[256];
|
|
static const opcode_func s_opcode_table_bf[256];
|
|
|
|
std::array<uint16_t, 65536> m_program{};
|
|
std::array<uint16_t, 65536> m_data{};
|
|
std::array<uint16_t, 65536> m_io{};
|
|
std::array<uint16_t, 3> m_mailbox_output{};
|
|
// CPU-facing ASIC inputs and DSP-facing outputs are separate holding
|
|
// registers even where they share a C51 port number.
|
|
std::array<uint16_t, 16> m_asic_output{};
|
|
std::array<uint16_t, C5X_ROM_WORDS> m_rom{};
|
|
bool m_rom_present = false;
|
|
// PMST.MPMC is preserved by this firmware's reset code rather than
|
|
// written, because on hardware it comes from a pin. Nothing in an image
|
|
// records the pin, so it is supplied here. One is what the firmware's own
|
|
// wait states argue for: it gives program 0x0000..0x7fff two of them, and
|
|
// wait states only apply off-chip, so it does not expect a boot ROM under
|
|
// the download.
|
|
uint16_t m_mpmc_pin = 1;
|
|
uint16_t m_shared_first = C5X_SHARED_FIRST, m_shared_last = C5X_SHARED_LAST;
|
|
mutable MemoryMap m_map{};
|
|
IoRead m_io_read;
|
|
IoWrite m_io_write;
|
|
std::deque<IoEvent> m_io_events;
|
|
std::deque<IoEvent> m_mailbox_events;
|
|
std::vector<DataEvent> m_data_events;
|
|
std::array<uint64_t, 65536> m_data_write_counts{};
|
|
std::array<PortStat, 65536> m_io_port_stats{};
|
|
std::deque<uint32_t> m_pc_trace;
|
|
uint16_t m_trace_first = 0xFFFF, m_trace_last = 0;
|
|
bool m_trace_data_writes = false;
|
|
uint16_t m_trace_filter = 0;
|
|
bool m_trace_filtered = false;
|
|
|
|
uint16_t m_pc = 0, m_op = 0;
|
|
int32_t m_acc = 0, m_accb = 0, m_preg = 0;
|
|
uint16_t m_treg0 = 0, m_treg1 = 0, m_treg2 = 0;
|
|
uint16_t m_ar[8]{};
|
|
int32_t m_rptc = -1;
|
|
uint16_t m_bmar = 0;
|
|
int32_t m_brcr = 0;
|
|
uint16_t m_paer = 0, m_pasr = 0, m_indx = 0, m_dbmr = 0, m_arcr = 0;
|
|
st0_t m_st0{};
|
|
st1_t m_st1{};
|
|
// Program-space SARAM addresses translate into their data-space address:
|
|
// the 'C51 sees one physical kilo-word at program 0x2000 and data 0x0800,
|
|
// and m_data is where it is stored.
|
|
static constexpr uint16_t saram_data_address(uint16_t program_address)
|
|
{
|
|
return uint16_t(program_address - C5X_SARAM_PROGRAM_FIRST
|
|
+ C5X_SARAM_DATA_FIRST);
|
|
}
|
|
|
|
pmst_t m_pmst{};
|
|
uint16_t m_ifr = 0, m_imr = 0;
|
|
std::array<uint16_t, 16> m_interrupt_vectors{};
|
|
int m_line_frame_irq = -1;
|
|
uint64_t m_line_frame_interrupts = 0;
|
|
uint64_t m_line_frame_next_cycle = 0;
|
|
bool m_rom_codec = false;
|
|
bool m_host_mailbox = false;
|
|
uint64_t m_xf_falling_edges = 0;
|
|
bool m_digital_pcm = false;
|
|
uint16_t m_g711_idle = 0x00ff;
|
|
unsigned m_line_frame_period = 258;
|
|
uint16_t m_line_frame_phase = 0;
|
|
uint32_t m_line_sample_phase = 0;
|
|
bool m_line_sample_due = false;
|
|
int64_t m_line_dac_sum = 0;
|
|
unsigned m_line_dac_count = 0;
|
|
bool m_call_tdm_active = false;
|
|
std::vector<uint16_t> m_v8_dispatch_pcs{0xc418};
|
|
uint16_t m_v8_dispatch_pc = 0;
|
|
uint16_t m_line_dac_slot = 0xfffd;
|
|
std::vector<uint16_t> m_line_phase_tx[4];
|
|
int m_line_frame_entry = -1;
|
|
uint16_t m_pending_overlay_origin = 0;
|
|
std::vector<uint16_t> m_pending_overlay;
|
|
std::array<uint16_t, 7> m_pending_call_registers{};
|
|
uint16_t m_pending_call_selector = 0;
|
|
uint16_t m_pdwsr = 0xffff, m_iowsr = 0xffff, m_cwsr = 0x000e;
|
|
uint16_t m_pcstack[8]{};
|
|
int m_pcstack_ptr = 0;
|
|
uint16_t m_rpt_start = 0, m_rpt_end = 0;
|
|
uint16_t m_cbcr = 0, m_cbsr1 = 0, m_cber1 = 0, m_cbsr2 = 0, m_cber2 = 0;
|
|
struct { int tddr = 0, psc = 0; uint16_t tim = 0, prd = 0; } m_timer;
|
|
struct {
|
|
uint16_t drr = 0, dxr = 0, spc = 0;
|
|
uint64_t drr_reads = 0, dxr_writes = 0, spc_writes = 0, rx_consumed = 0;
|
|
uint16_t last_drr_pc = 0, last_dxr_pc = 0, last_spc_pc = 0;
|
|
} m_serial;
|
|
// Datasheet section 2.20 power-up values: A and B both 18, gain register
|
|
// 0x05 (0 dB in and out, monitor squelched), analog configuration 0x01
|
|
// (IN+/IN-, high-pass in the path), frame-sync number 1.
|
|
struct Ac01 {
|
|
uint16_t registers[9] = {0, 18, 18, 0, 0x05, 0x01, 0x00, 0x00, 0x01};
|
|
// Nominal MCLK derived by the ASIC from the board oscillator. Runtime
|
|
// rate rows can scale the clock presented to the codec.
|
|
uint32_t nominal_mclk_hz = 2'880'000;
|
|
uint32_t mclk_hz = 2'880'000;
|
|
uint64_t sample_rate_millihz = 0;
|
|
uint64_t secondary_frames = 0, register_writes = 0, register_reads = 0;
|
|
uint64_t phase_shifts = 0, primary_frames = 0;
|
|
uint64_t frames_clocked = 0;
|
|
uint64_t secondary_cycle = 0;
|
|
uint16_t last_control_word = 0, readback = 0;
|
|
bool rate_programmed = false, secondary_pending = false;
|
|
bool secondary_now = false, readback_armed = false;
|
|
bool secondary_due = false, rx_ready = false;
|
|
// DXR is empty out of reset, so the first write need not wait.
|
|
bool tx_ready = true;
|
|
} m_codec;
|
|
void codec_frame(bool secondary);
|
|
void codec_transmit(uint16_t word);
|
|
void codec_apply_register(uint16_t word);
|
|
void codec_apply_asic_timing(uint16_t word);
|
|
void codec_recompute_rate();
|
|
std::deque<uint16_t> m_codec_rx;
|
|
// Trans-hybrid return. The codec's analog output reaches its own analog
|
|
// input through the hybrid, attenuated by how well the hybrid is
|
|
// terminated: near unity when the DAA is on hook and the line side is
|
|
// isolated, low once it is off hook into a terminated line. That path is
|
|
// what AT&T1 runs on - the firmware sends no loopback command and leaves
|
|
// the AC01's own register 5 at its boot value, so the loop cannot be
|
|
// keyed off anything software-visible. 256 is unity.
|
|
std::deque<int16_t> m_hybrid_line;
|
|
uint32_t m_hybrid_return = 0;
|
|
uint64_t m_hybrid_frames = 0;
|
|
uint16_t m_hybrid_peak = 0;
|
|
uint32_t m_hybrid_delay = 0;
|
|
std::deque<uint8_t> m_g711_rx;
|
|
std::vector<uint8_t> m_g711_tx;
|
|
std::deque<uint16_t> m_codec_boot;
|
|
std::deque<int16_t> m_v8_rx_window;
|
|
std::deque<uint16_t> m_line_rx;
|
|
uint16_t m_v8_rx_state = 0, m_v8_rx_peak = 0, m_codec_rx_peak = 0;
|
|
bool m_bio_low = false;
|
|
bool m_tdm_rx_ready = false;
|
|
bool m_v8_callback_ready = false;
|
|
bool m_negotiation_loop_active = false;
|
|
uint64_t m_negotiation_loop_entries = 0;
|
|
uint16_t m_negotiation_loop_pc = 0, m_negotiation_source = 0, m_negotiation_pair = 0;
|
|
uint16_t m_negotiation_source_value = 0, m_negotiation_pair_value = 0;
|
|
int32_t m_negotiation_acc = 0;
|
|
uint64_t m_v8_dispatches = 0;
|
|
uint16_t m_v8_record = 0, m_v8_handler = 0;
|
|
uint16_t m_v8_countdown = 0, m_v8_flags = 0;
|
|
uint16_t m_negotiation_d76 = 0, m_negotiation_d77 = 0;
|
|
uint16_t m_negotiation_d78 = 0, m_negotiation_d79 = 0;
|
|
uint16_t m_negotiation_d26 = 0, m_negotiation_indx = 0;
|
|
uint16_t m_negotiation_arp = 0, m_negotiation_pm = 0;
|
|
std::vector<uint16_t> m_line_tx;
|
|
uint64_t m_line_rx_consumed = 0;
|
|
uint64_t m_line_tx_nonzero = 0;
|
|
uint64_t m_line_dac_writes = 0, m_line_dac_frames = 0;
|
|
uint16_t m_line_tx_last_pc = 0;
|
|
// Which side of the call this is. The role gates the receive-side V.8
|
|
// indicator qualification below; nothing here generates a tone.
|
|
enum class V8Mode { Off, Calling, Answering };
|
|
V8Mode m_v8_mode = V8Mode::Off;
|
|
struct {
|
|
uint16_t trcv = 0, tdxr = 0, tspc = 0, tcsr = 0, trta = 0, trad = 0;
|
|
uint64_t trcv_reads = 0, tdxr_writes = 0, tspc_writes = 0, rx_consumed = 0;
|
|
uint16_t last_trcv_pc = 0, last_tdxr_pc = 0, last_tspc_pc = 0;
|
|
} m_tdm;
|
|
shadow_t m_shadow{};
|
|
bool m_idle = false;
|
|
uint64_t m_instructions = 0, m_cycles = 0;
|
|
unsigned m_step_cycles = 0;
|
|
|
|
void consume_cycles(unsigned cycles);
|
|
Region program_region(uint16_t address) const;
|
|
Region data_region(uint16_t address) const;
|
|
uint16_t fetch(uint16_t address);
|
|
uint16_t ROPCODE();
|
|
void CHANGE_PC(uint16_t new_pc);
|
|
uint16_t PM_READ16(uint16_t address);
|
|
void PM_WRITE16(uint16_t address, uint16_t value);
|
|
uint16_t DM_READ16(uint16_t address);
|
|
void DM_WRITE16(uint16_t address, uint16_t value);
|
|
uint16_t cpuregs_r(uint16_t offset);
|
|
void cpuregs_w(uint16_t offset, uint16_t data);
|
|
uint16_t IO_READ16(uint16_t port);
|
|
void IO_WRITE16(uint16_t port, uint16_t value);
|
|
void PUSH_STACK(uint16_t pc);
|
|
uint16_t POP_STACK();
|
|
int32_t SUB(uint32_t a, uint32_t b, bool shift16);
|
|
int32_t ADD(uint32_t a, uint32_t b, bool shift16);
|
|
void UPDATE_AR(int ar, int step);
|
|
void UPDATE_ARP(int nar);
|
|
uint16_t GET_ADDRESS();
|
|
bool GET_ZLVC_CONDITION(int zlvc, int zlvc_mask);
|
|
bool GET_TP_CONDITION(int tp);
|
|
int32_t PREG_PSCALER(int32_t preg);
|
|
void check_interrupts();
|
|
void save_interrupt_context();
|
|
void restore_interrupt_context();
|
|
void delay_slot(uint16_t startpc);
|
|
// SPRU056D 4.9: a delayed branch and its delay slots complete as a
|
|
// unit; no interrupt is serviced between them.
|
|
bool m_in_delay_slot = false;
|
|
|
|
void op_invalid(); void op_abs(); void op_adcb(); void op_add_mem();
|
|
void op_add_simm(); void op_add_limm(); void op_add_s16_mem(); void op_addb();
|
|
void op_addc(); void op_adds(); void op_addt(); void op_and_mem();
|
|
void op_and_limm(); void op_and_s16_limm(); void op_andb(); void op_bsar();
|
|
void op_cmpl(); void op_crgt(); void op_crlt(); void op_exar();
|
|
void op_lacb(); void op_lacc_mem(); void op_lacc_limm(); void op_lacc_s16_mem();
|
|
void op_lacl_simm(); void op_lacl_mem(); void op_lact(); void op_lamm();
|
|
void op_neg(); void op_norm(); void op_or_mem(); void op_or_limm();
|
|
void op_or_s16_limm(); void op_orb(); void op_rol(); void op_rolb();
|
|
void op_ror(); void op_rorb(); void op_sacb(); void op_sach();
|
|
void op_sacl(); void op_samm(); void op_sath(); void op_satl();
|
|
void op_sbb(); void op_sbbb(); void op_sfl(); void op_sflb();
|
|
void op_sfr(); void op_sfrb(); void op_sub_mem(); void op_sub_s16_mem();
|
|
void op_sub_simm(); void op_sub_limm(); void op_subb(); void op_subc();
|
|
void op_subs(); void op_subt(); void op_xor_mem(); void op_xor_limm();
|
|
void op_xor_s16_limm(); void op_xorb(); void op_zalr(); void op_zap();
|
|
void op_adrk(); void op_cmpr(); void op_lar_mem(); void op_lar_simm();
|
|
void op_lar_limm(); void op_ldp_mem(); void op_ldp_imm(); void op_mar();
|
|
void op_sar(); void op_sbrk(); void op_b(); void op_bacc();
|
|
void op_baccd(); void op_banz(); void op_banzd(); void op_bcnd();
|
|
void op_bcndd(); void op_bd(); void op_cala(); void op_calad();
|
|
void op_call(); void op_calld(); void op_cc(); void op_ccd();
|
|
void op_intr(); void op_nmi(); void op_retc(); void op_retcd();
|
|
void op_rete(); void op_reti(); void op_trap(); void op_xc();
|
|
void op_bldd_slimm(); void op_bldd_dlimm(); void op_bldd_sbmar(); void op_bldd_dbmar();
|
|
void op_bldp(); void op_blpd_bmar(); void op_blpd_imm(); void op_dmov();
|
|
void op_in(); void op_lmmr(); void op_out(); void op_smmr();
|
|
void op_tblr(); void op_tblw(); void op_apl_dbmr(); void op_apl_imm();
|
|
void op_cpl_dbmr(); void op_cpl_imm(); void op_opl_dbmr(); void op_opl_imm();
|
|
void op_splk(); void op_xpl_dbmr(); void op_xpl_imm(); void op_apac();
|
|
void op_lph(); void op_lt(); void op_lta(); void op_ltd();
|
|
void op_ltp(); void op_lts(); void op_mac(); void op_macd();
|
|
void op_madd(); void op_mads(); void op_mpy_mem(); void op_mpy_simm();
|
|
void op_mpy_limm(); void op_mpya(); void op_mpys(); void op_mpyu();
|
|
void op_pac(); void op_spac(); void op_sph(); void op_spl();
|
|
void op_spm(); void op_sqra(); void op_sqrs(); void op_zpr();
|
|
void op_bit(); void op_bitt(); void op_clrc_ov(); void op_clrc_ext();
|
|
void op_clrc_hold(); void op_clrc_tc(); void op_clrc_carry(); void op_clrc_cnf();
|
|
void op_clrc_intm(); void op_clrc_xf(); void op_idle(); void op_idle2();
|
|
void op_lst_st0(); void op_lst_st1(); void op_pop(); void op_popd();
|
|
void op_pshd(); void op_push(); void op_rpt_mem(); void op_rpt_limm();
|
|
void op_rpt_simm(); void op_rptb(); void op_rptz(); void op_setc_ov();
|
|
void op_setc_ext(); void op_setc_hold(); void op_setc_tc(); void op_setc_carry();
|
|
void op_setc_xf(); void op_setc_cnf(); void op_setc_intm(); void op_sst_st0();
|
|
void op_sst_st1(); void op_group_be(); void op_group_bf();
|
|
};
|
|
|
|
} // namespace courier
|