mirror of
https://github.com/D-Modem/courier-emu.git
synced 2026-11-28 12:38:04 -08:00
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>
This commit is contained in:
1 parent
ba0dfa6ab1
commit
11df97b2c2
2 files changed
+52
-10
No files matched your search
+9
-10
@@ -768,18 +768,17 @@ void C5xCore::op_samm()
|
||||
CYCLES(1);
|
||||
}
|
||||
|
||||
// SPRU056D 6-229: right by 16 if TREG1 bit 4 is set, otherwise untouched;
|
||||
// SXM picks the fill, and neither C nor OV is affected. SATL supplies the
|
||||
// 0-15 half of the same 0-31 bit shift.
|
||||
void C5xCore::op_sath()
|
||||
{
|
||||
int count = m_treg1 & 0xf;
|
||||
int64_t shifted = int64_t(m_acc) * (int64_t(1) << count);
|
||||
if (shifted > INT32_MAX) {
|
||||
m_st0.ov = 1;
|
||||
m_acc = INT32_MAX;
|
||||
} else if (shifted < INT32_MIN) {
|
||||
m_st0.ov = 1;
|
||||
m_acc = INT32_MIN;
|
||||
} else {
|
||||
m_acc = int32_t(shifted);
|
||||
if (m_treg1 & 0x10)
|
||||
{
|
||||
if (m_st1.sxm)
|
||||
m_acc = (int32_t)(m_acc) >> 16;
|
||||
else
|
||||
m_acc = (uint32_t)(m_acc) >> 16;
|
||||
}
|
||||
CYCLES(1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import struct
|
||||
|
||||
from courier_emu.dsp import NativeC5x
|
||||
|
||||
|
||||
def program(*words: int) -> bytes:
|
||||
return struct.pack(f"<{len(words)}H", *words)
|
||||
|
||||
|
||||
def run(*words: int, steps: int) -> dict:
|
||||
with NativeC5x.from_program(0, program(*words), rebuild=True) as core:
|
||||
core.step(steps)
|
||||
return core.state()
|
||||
|
||||
|
||||
def test_sath_satl_pick_a_nibble_the_way_the_v34_sequencer_does():
|
||||
# Overlay 6's phase-3 transmit sequencer at 0xb0c5 takes its next state as
|
||||
# nibble[state] of 0x00102540. State 3 must become 2. With SATH shifting
|
||||
# left and saturating it became 0x7fffffff >> 12 & f = 15, a state the
|
||||
# answerer's control code (0x9d5d, waiting for 5) can never leave.
|
||||
state = run(
|
||||
0xB90C, # lacl #0c 4 x state 3
|
||||
0x880D, # samm @0d -> TREG1
|
||||
0xBF8F, 0x0020, # lacc #0020, 15 = 0x00100000
|
||||
0xBF90, 0x2540, # add #2540
|
||||
0xBE5A, # sath TREG1 bit 4 clear: unchanged
|
||||
0xBE5B, # satl >> 12
|
||||
steps=6,
|
||||
)
|
||||
assert state["acc"] & 0xFFFFFFFF == 0x102
|
||||
|
||||
|
||||
def test_sath_shifts_right_sixteen_only_when_treg1_bit4_is_set():
|
||||
# SPRU056D 6-229/6-230, examples 1 and 2 in spirit: bit 4 moves the
|
||||
# accumulator right by 16, and SXM decides the fill.
|
||||
positive = run(0xB910, 0x880D, 0xBF8F, 0x0020, 0xBE5A, steps=4)
|
||||
assert positive["acc"] & 0xFFFFFFFF == 0x0010
|
||||
|
||||
signed = run(0xBE47, 0xB910, 0x880D, 0xBF8F, 0x8000, 0xBE5A, steps=5)
|
||||
assert signed["acc"] & 0xFFFFFFFF == 0xFFFFC000
|
||||
|
||||
unsigned = run(0xBE46, 0xB910, 0x880D, 0xBF8F, 0x8000, 0xBE5A, steps=5)
|
||||
assert unsigned["acc"] & 0xFFFFFFFF == 0x00004000
|
||||
Reference in new issue
Block a user