fix(attract): restore all remainder-driven cycles

The same raw Div32 pattern used by the item animation appears in every nested
idle phase: after division by 32, 40, or 16, the binary copies the remainder
from CX:BX before the second division. Readable C and Rust used quotients for
targets, word quads, the record strip, and the four-point chase, turning short
repeating chases into slow one-shot progressions.

Use `%32/2`, `%32/4`, `%40/4`, and `%16/4` for those cycles alongside the
already corrected `%144/8` items. Preserve the first-cycle phase-zero delay,
then repeat each incremental overlay state exactly. Add C and Rust coverage at
phase activation, reversal, deactivation, and wrap boundaries.

Test Plan:
- raw instruction review at `1000:01b7-063b` -- all remainder transfers confirmed
- `cargo test --workspace --all-targets --all-features` -- 125 passed
- `cargo clippy --workspace --all-targets --all-features -- -D warnings` -- passed
- `bash original/tools/test_reconstructed_c.sh` -- passed
- `python3 original/tools/audit_reconstruction.py --require-complete` -- passed with zero incomplete or unclassified units
- `cargo run -- --simulate attract --step 145 --screenshot /tmp/tdkpin-attract-remainder.png` -- passed; visually inspected at 640x460
- `rumdl check --flavor commonmark RECONSTRUCTION.md CHANGELOG.md` -- passed
- `git diff --cached --check` -- passed
This commit is contained in:
2026-08-23 20:53:12 +02:00
parent dd0299c30b
commit 7633ef9990
7 changed files with 82 additions and 39 deletions
+6 -5
View File
@@ -94,11 +94,12 @@ Wine record-57 transition `(75530,354765)/(3000,15)` to
`(77369,356597)/(1839,1832)` with exact Real48 spin `-5.28`, plus record 72
`(235348,356825)/(-3000,15)` to `(233253,358494)/(-2095,1669)` with spin
`+5.46`, seal both paths and both relative slingshot chains.
Raw `1000:061c-063b` further distinguishes the DOS divide outputs in the idle
item animation: it copies the remainder of `tick / 144` from `CX:BX` and then
divides that value by 8. The readable C and focused timer harness therefore use
`(tick % 144) / 8`, producing the repeating `0,1..9,8..1` sequence without the
previously inferred unbounded quotient.
Raw `1000:01b7-063b` further distinguishes the DOS divide outputs throughout
the idle animation: each nested phase copies the first division's remainder
from `CX:BX` before its second division. The readable C and focused timer
harness therefore use target `%32/2`, word-quad `%32/4`, record-strip `%40/4`,
four-point `%16/4`, and item `%144/8` cycles. This produces the repeating
animation rather than the previously inferred unbounded quotients.
## Reproducible gates
+1 -1
View File
@@ -69,7 +69,7 @@ address raw_name segment body_bytes status reconstructed_name module evidence no
1000:c426 FUN_1000_c426 Code1 187 verified tdkpin_save_ball_slot reconstructed/tdkpin_gameplay_helpers.c disassembly 1000:c426-c4e0; SS caller-frame receiver; reconstructed/tests/test_gameplay_helpers.c Exact inverse unchecked uint16 slot times 4/6 transfer of global position, receiver velocity/auxiliary dwords and six-byte Real48 field into packed DGROUP slot arrays, overlapping out-of-range slot behavior, and six-byte cleanup are represented and tested.
1000:c4e1 FUN_1000_c4e1 Code1 699 verified tdkpin_apply_player_sprite_effect reconstructed/tdkpin_player_state.c disassembly 1000:c4e1-c79b; verified multiply/score dependencies; exact player tables and record 399a access; reconstructed/tests/test_player_state.c Exact sprite-index dispatch 1..7, wrapping secondary-score additions 10000/20000/50000/100000/200000, unsigned-byte multiplier redraw, effect-6 multiplied transfer/reset/zero redraw, effect-7 nonzero record gate, signed-negative or unequal argument condition, receiver +be0 and global 0874 publications, and default no-op behavior are represented and branch-tested.
1000:c79c FUN_1000_c79c Code1 8981 verified tdkpin_simulate_ball_and_dispatch_collision reconstructed/tdkpin_physics.c disassembly 1000:c79c-eab0 and rz-ghidra stack-offset view; packed 83-byte records and exact 52-byte candidate layout; all integer/Real48/gameplay/GDI dependencies verified; reconstructed/tests/test_physics.c Exact RETF-2 caller-frame ABI, simulation-call counter, snapshotted ball count and substep word, multiball load/save, gravity and two ordered speed clamps, previous/predicted coordinates, board-loss/layer gates, 175-record broadphase, types 1 circle, 2 segment, 3 capture/pocket, and 4 stateful trigger, subtype normal reversal, signed cross/end-point tests, contact-state sentinels, claw/target-set/sprite/score special paths, trigger 0x4000 lifecycle and random bounce, packed improving-distance copies with fixed first-slot response, event/score dispatch, Real48 normal/tangent/spin/response/kick transform with standard dot-product tangent `tv=(vx*nx+vy*ny)/length`, opposing signed `abs(normal_velocity)*response_tangent` response (negative at zero), spin delta `tv*0.02*response_tangent`, retained-spin contribution, and deliberately zeroed intermediate, capture-age-gated ball-to-ball transfer, record 25/2 terminal/special-respawn continuation paths, ordered velocity/position publication, dynamic-record update, swept rendering, 32-bit wrap, and Borland divide/error behavior are represented. Free integration, exact 3-4-5 clamp, live line/circle tangent transitions, four trigger/capture modes, two-candidate first-slot behavior, distinct response/event/score paths, out-of-bounds, and zero-substep multiball are tested.
1000:eab1 exported_ordinal_10 Code1 4820 verified tdkpin_timer_tick reconstructed/tdkpin_timer_tick.c disassembly 1000:eab1-fd84 including RETF-8 and all annotated calls; exact Real48 claw-release table; complete verified dependency closure including 1000:c79c; reconstructed/tests/test_timer_tick.c Exact two-DWORD callback ABI with unused second argument, all nine guard conditions, busy flag, 175-record refresh, two dword counters, claw movement/release/record activation, ten exact spawn states, 175 countdowns, target rotation, multiball collapse/promotion/reset/spawn, physics gate, quotient-versus-remainder intro schedules including item phase `(tick%144)/8`, record/item/chase/status animations, complete 30x284 score-marquee GDI lifetime, panel frames 1..281, game initialization, flipper/message epilogue, busy clear, redundant tilt read, and tilt-counter decrement are represented and branch-/sequence-tested.
1000:eab1 exported_ordinal_10 Code1 4820 verified tdkpin_timer_tick reconstructed/tdkpin_timer_tick.c disassembly 1000:eab1-fd84 including RETF-8 and all annotated calls; exact Real48 claw-release table; complete verified dependency closure including 1000:c79c; reconstructed/tests/test_timer_tick.c Exact two-DWORD callback ABI with unused second argument, all nine guard conditions, busy flag, 175-record refresh, two dword counters, claw movement/release/record activation, ten exact spawn states, 175 countdowns, target rotation, multiball collapse/promotion/reset/spawn, physics gate, remainder-driven intro schedules `%32/2`, `%32/4`, `%40/4`, `%16/4`, and `%144/8`, record/item/chase/status animations, complete 30x284 score-marquee GDI lifetime, panel frames 1..281, game initialization, flipper/message epilogue, busy clear, redundant tilt read, and tilt-counter decrement are represented and branch-/sequence-tested.
1000:fd85 ne_program_entry Code1 181 verified tdkpin_ne_program_entry reconstructed/tdkpin_program_entry.c disassembly 1000:fd85-fe39; relocations 1669-1679; reconstructed/tests/test_program_entry.c Exact InitTask register handoff, eight-unit initialization order, full DX:AX GetVersion store, Windows 3.10 threshold, indirect MessageBox error path, fixed application object construction, VMT +1c Run and +08 destructor calls, dispose mode zero, and unconditional Halt(0) are represented and branch-tested.
1008:0002 FUN_1008_0002 Code2 33 verified tdkpin_play_sound_if_not_tilted reconstructed/tdkpin_sound.c disassembly 1008:0002-0022; verified 1008:1131 dependency; DGROUP game-tilted byte 07c6 and sound-enabled byte 43f2; reconstructed/tests/test_sound.c Exact Tilted==0 then Enabled!=0 short-circuit order, unchanged sound-number argument, ignored player result, two-byte Pascal cleanup, and all gate combinations are branch-tested.
1008:0023 FUN_1008_0023 Code2 191 verified tdkpin_realize_nocollapse_palette reconstructed/tdkpin_palette.c disassembly 1008:0023-00e1; exact LOGPALETTE256 layout; verified Borland allocation/free; GDI palette/DC APIs; reconstructed/tests/test_palette_gdi.c Exact null-allocation early return, 1028-byte palette, version 0300/count 256, 256 zero RGB entries with flag 4, GetDC/Create/Select(false)/Realize/Select(previous,true)/Delete/Release ordering, ignored API returns, free, and RETF 2 are branch-tested.
1 address raw_name segment body_bytes status reconstructed_name module evidence notes
69 1000:c426 FUN_1000_c426 Code1 187 verified tdkpin_save_ball_slot reconstructed/tdkpin_gameplay_helpers.c disassembly 1000:c426-c4e0; SS caller-frame receiver; reconstructed/tests/test_gameplay_helpers.c Exact inverse unchecked uint16 slot times 4/6 transfer of global position, receiver velocity/auxiliary dwords and six-byte Real48 field into packed DGROUP slot arrays, overlapping out-of-range slot behavior, and six-byte cleanup are represented and tested.
70 1000:c4e1 FUN_1000_c4e1 Code1 699 verified tdkpin_apply_player_sprite_effect reconstructed/tdkpin_player_state.c disassembly 1000:c4e1-c79b; verified multiply/score dependencies; exact player tables and record 399a access; reconstructed/tests/test_player_state.c Exact sprite-index dispatch 1..7, wrapping secondary-score additions 10000/20000/50000/100000/200000, unsigned-byte multiplier redraw, effect-6 multiplied transfer/reset/zero redraw, effect-7 nonzero record gate, signed-negative or unequal argument condition, receiver +be0 and global 0874 publications, and default no-op behavior are represented and branch-tested.
71 1000:c79c FUN_1000_c79c Code1 8981 verified tdkpin_simulate_ball_and_dispatch_collision reconstructed/tdkpin_physics.c disassembly 1000:c79c-eab0 and rz-ghidra stack-offset view; packed 83-byte records and exact 52-byte candidate layout; all integer/Real48/gameplay/GDI dependencies verified; reconstructed/tests/test_physics.c Exact RETF-2 caller-frame ABI, simulation-call counter, snapshotted ball count and substep word, multiball load/save, gravity and two ordered speed clamps, previous/predicted coordinates, board-loss/layer gates, 175-record broadphase, types 1 circle, 2 segment, 3 capture/pocket, and 4 stateful trigger, subtype normal reversal, signed cross/end-point tests, contact-state sentinels, claw/target-set/sprite/score special paths, trigger 0x4000 lifecycle and random bounce, packed improving-distance copies with fixed first-slot response, event/score dispatch, Real48 normal/tangent/spin/response/kick transform with standard dot-product tangent `tv=(vx*nx+vy*ny)/length`, opposing signed `abs(normal_velocity)*response_tangent` response (negative at zero), spin delta `tv*0.02*response_tangent`, retained-spin contribution, and deliberately zeroed intermediate, capture-age-gated ball-to-ball transfer, record 25/2 terminal/special-respawn continuation paths, ordered velocity/position publication, dynamic-record update, swept rendering, 32-bit wrap, and Borland divide/error behavior are represented. Free integration, exact 3-4-5 clamp, live line/circle tangent transitions, four trigger/capture modes, two-candidate first-slot behavior, distinct response/event/score paths, out-of-bounds, and zero-substep multiball are tested.
72 1000:eab1 exported_ordinal_10 Code1 4820 verified tdkpin_timer_tick reconstructed/tdkpin_timer_tick.c disassembly 1000:eab1-fd84 including RETF-8 and all annotated calls; exact Real48 claw-release table; complete verified dependency closure including 1000:c79c; reconstructed/tests/test_timer_tick.c Exact two-DWORD callback ABI with unused second argument, all nine guard conditions, busy flag, 175-record refresh, two dword counters, claw movement/release/record activation, ten exact spawn states, 175 countdowns, target rotation, multiball collapse/promotion/reset/spawn, physics gate, quotient-versus-remainder intro schedules including item phase `(tick%144)/8`, record/item/chase/status animations, complete 30x284 score-marquee GDI lifetime, panel frames 1..281, game initialization, flipper/message epilogue, busy clear, redundant tilt read, and tilt-counter decrement are represented and branch-/sequence-tested. Exact two-DWORD callback ABI with unused second argument, all nine guard conditions, busy flag, 175-record refresh, two dword counters, claw movement/release/record activation, ten exact spawn states, 175 countdowns, target rotation, multiball collapse/promotion/reset/spawn, physics gate, remainder-driven intro schedules `%32/2`, `%32/4`, `%40/4`, `%16/4`, and `%144/8`, record/item/chase/status animations, complete 30x284 score-marquee GDI lifetime, panel frames 1..281, game initialization, flipper/message epilogue, busy clear, redundant tilt read, and tilt-counter decrement are represented and branch-/sequence-tested.
73 1000:fd85 ne_program_entry Code1 181 verified tdkpin_ne_program_entry reconstructed/tdkpin_program_entry.c disassembly 1000:fd85-fe39; relocations 1669-1679; reconstructed/tests/test_program_entry.c Exact InitTask register handoff, eight-unit initialization order, full DX:AX GetVersion store, Windows 3.10 threshold, indirect MessageBox error path, fixed application object construction, VMT +1c Run and +08 destructor calls, dispose mode zero, and unconditional Halt(0) are represented and branch-tested.
74 1008:0002 FUN_1008_0002 Code2 33 verified tdkpin_play_sound_if_not_tilted reconstructed/tdkpin_sound.c disassembly 1008:0002-0022; verified 1008:1131 dependency; DGROUP game-tilted byte 07c6 and sound-enabled byte 43f2; reconstructed/tests/test_sound.c Exact Tilted==0 then Enabled!=0 short-circuit order, unchanged sound-number argument, ignored player result, two-byte Pascal cleanup, and all gate combinations are branch-tested.
75 1008:0023 FUN_1008_0023 Code2 191 verified tdkpin_realize_nocollapse_palette reconstructed/tdkpin_palette.c disassembly 1008:0023-00e1; exact LOGPALETTE256 layout; verified Borland allocation/free; GDI palette/DC APIs; reconstructed/tests/test_palette_gdi.c Exact null-allocation early return, 1028-byte palette, version 0300/count 256, 256 zero RGB entries with flag 4, GetDC/Create/Select(false)/Realize/Select(previous,true)/Delete/Release ordering, ignored API returns, free, and RETF 2 are branch-tested.
+4 -4
View File
@@ -378,7 +378,7 @@ static void active_ball_tick(uint16_t frame_bp, Win16FarPtr window)
static void update_intro_collision_visibility(uint16_t frame_bp, int32_t tick)
{
if (remainder_i32(tick, 2) == 0) {
int32_t phase = quotient_i32(quotient_i32(tick, 32), 2);
int32_t phase = quotient_i32(remainder_i32(tick, 32), 2);
if (phase >= 0 && phase <= 7) {
tdkpin_restore_record_or_item_a(
frame_bp, (uint16_t)(phase + 140));
@@ -388,7 +388,7 @@ static void update_intro_collision_visibility(uint16_t frame_bp, int32_t tick)
}
}
if (remainder_i32(tick, 4) == 0) {
int32_t phase = quotient_i32(quotient_i32(tick, 32), 4);
int32_t phase = quotient_i32(remainder_i32(tick, 32), 4);
if (phase == 0) {
tdkpin_restore_record_or_item_a(frame_bp, 1001);
tdkpin_restore_record_b(frame_bp, 1002);
@@ -424,7 +424,7 @@ static void update_intro_record_strip(
if (remainder_i32(tick, 4) != 0) {
return;
}
int32_t phase = quotient_i32(quotient_i32(tick, 40), 4);
int32_t phase = quotient_i32(remainder_i32(tick, 40), 4);
bool background_b = phase >= 5;
int32_t normalized = background_b ? phase - 5 : phase;
uint16_t id = (uint16_t)(normalized * 3 + 90);
@@ -450,7 +450,7 @@ static void update_intro_four_point_chase(
}
static const INT16 y[4] = {209, 214, 219, 224};
static const INT16 x[4] = {150, 164, 178, 192};
int32_t phase = quotient_i32(quotient_i32(tick, 16), 4);
int32_t phase = quotient_i32(remainder_i32(tick, 16), 4);
if (phase < 0 || phase > 3) {
return;
}
+37 -1
View File
@@ -464,7 +464,7 @@ static void test_intro_tick_32_and_marquee(void)
assert(g_restore_a_ids[2] == 153 &&
g_restore_a_ids[3] == 154 && g_restore_a_ids[4] == 6);
assert(g_restore_b_id_count == 1 && g_restore_b_ids[0] == 1002);
assert(g_region_a_calls == 2 && g_region_b_calls == 1);
assert(g_region_a_calls == 1 && g_region_b_calls == 2);
assert(g_present_calls == 3);
assert(g_item_calls == 1 && g_last_item == 4);
@@ -510,6 +510,41 @@ static void test_intro_tick_32_and_marquee(void)
}
}
static void test_intro_remainder_driven_cycles(void)
{
prepare_fixture();
win16_write_u8(win16_dgroup_pointer(0x07c9), 1);
win16_write_u32(win16_dgroup_pointer(0x0876), 0, 3);
tdkpin_timer_tick_with_frame(0x0300, g_window);
assert(g_restore_a_id_count == 2);
assert(g_restore_a_ids[0] == 142 && g_restore_a_ids[1] == 1002);
assert(g_restore_b_id_count == 1 && g_restore_b_ids[0] == 1001);
assert(g_region_a_calls == 2 && g_region_b_calls == 1);
assert(g_item_calls == 0);
prepare_fixture();
win16_write_u8(win16_dgroup_pointer(0x07c9), 1);
win16_write_u32(win16_dgroup_pointer(0x0876), 0, 15);
tdkpin_timer_tick_with_frame(0x0300, g_window);
assert(g_restore_a_id_count == 1 && g_restore_a_ids[0] == 1005);
assert(g_restore_b_id_count == 5);
assert(g_restore_b_ids[0] == 140 && g_restore_b_ids[1] == 1004);
assert(g_restore_b_ids[2] == 153 &&
g_restore_b_ids[3] == 154 && g_restore_b_ids[4] == 6);
assert(g_region_a_calls == 2 && g_region_b_calls == 1);
assert(g_item_calls == 1 && g_last_item == 2);
prepare_fixture();
win16_write_u8(win16_dgroup_pointer(0x07c9), 1);
win16_write_u32(win16_dgroup_pointer(0x0876), 0, 39);
tdkpin_timer_tick_with_frame(0x0300, g_window);
assert(g_restore_a_id_count == 2);
assert(g_restore_a_ids[0] == 144 && g_restore_a_ids[1] == 1003);
assert(g_restore_b_id_count == 1 && g_restore_b_ids[0] == 1002);
assert(g_region_a_calls == 2 && g_region_b_calls == 1);
assert(g_item_calls == 1 && g_last_item == 5);
}
static void test_panel_and_game_initialization(void)
{
prepare_fixture();
@@ -556,6 +591,7 @@ int main(void)
test_multiball_promotion();
test_multiball_spawn();
test_intro_tick_32_and_marquee();
test_intro_remainder_driven_cycles();
test_panel_and_game_initialization();
return 0;
}