From 23195cb9d11c138d6bc5f7751ee3e23d8106d1f1 Mon Sep 17 00:00:00 2001 From: ddidderr Date: Sun, 23 Aug 2026 20:33:20 +0200 Subject: [PATCH] fix(physics): restore standard tangent sign response The left relative slingshot probe proved the spin projection, but its geometry did not distinguish the sign rule. A stopped-Wine probe on symmetric record 72 did: the binary uses the standard dot-product tangent for both spin and the opposing direction of the current tangential response. The earlier swapped-component interpretation happened to agree for vertical walls and a centered circle but selected the wrong sign on the right slingshot. Use `tv=(vx*nx+vy*ny)/length`, update spin with `tv*0.02*response_tangent`, and apply `-sign(tv)*abs(normal_velocity)*response_tangent`, retaining the binary's negative direction when tv is zero. Seal record 72's exact position, velocity, and `+5.46` Real48 spin in C and Rust. Keep the two-minute autoplay assertion focused on actual launch, press/release, target, bumper, and finite-state activity after the corrected trajectory. Test Plan: - stopped Wine 11.15 record-72 injection/trace -- matched position, velocity, and spin - `cargo test --workspace --all-targets --all-features` -- 124 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 - `rumdl check --flavor commonmark RECONSTRUCTION.md CHANGELOG.md` -- passed - `git diff --cached --check` -- passed --- original/C_RECONSTRUCTION_FINAL_AUDIT.md | 18 ++++---- original/FUNCTION_RECONSTRUCTION.tsv | 2 +- original/reconstructed/tdkpin_physics.c | 38 ++++------------- original/reconstructed/tests/test_physics.c | 46 +++++++++++++++++++++ tdkpin-rs/CHANGELOG.md | 13 +++--- tdkpin-rs/RECONSTRUCTION.md | 2 +- tdkpin-rs/src/game.rs | 40 ++++++++++++++++++ tdkpin-rs/src/original_physics.rs | 30 ++++---------- tdkpin-rs/src/simulation.rs | 3 +- 9 files changed, 124 insertions(+), 68 deletions(-) diff --git a/original/C_RECONSTRUCTION_FINAL_AUDIT.md b/original/C_RECONSTRUCTION_FINAL_AUDIT.md index ae8f2f4..efe41c6 100644 --- a/original/C_RECONSTRUCTION_FINAL_AUDIT.md +++ b/original/C_RECONSTRUCTION_FINAL_AUDIT.md @@ -83,15 +83,17 @@ DAT994 progress strip is drawn at `(202,328)` with height 13 and width `(stage-1)*7`, rather than the impossible historical 328x202 read from a 237x13 bitmap. The focused loading-stage harness seals stages 1, 35, and 0. Live one-substep rail/circle probes further correct the response transform. -The binary keeps two projections distinct: swapped-component -`-(vx*normal_y + vy*normal_x)/length` supplies the sign of the tangential -response magnitude `abs(normal_velocity)*response_tangent`, which is added to -retained `spin*0.4`. Standard dot-product -`(vx*normal_x + vy*normal_y)/length` independently drives -`spin_delta = projection*0.02*response_tangent`. The documented horizontal -drain `(0,3015)->(-302,-1809)`, ordinary circle/bumper transitions, and stopped +The binary's standard dot-product tangent +`tv=(vx*normal_x + vy*normal_y)/length` drives +`spin_delta=tv*0.02*response_tangent`. The current tangential response opposes +the sign of `tv` with magnitude +`abs(normal_velocity)*response_tangent` (negative when `tv==0`) and is added to +retained `spin*0.4`. The documented horizontal drain +`(0,3015)->(-302,-1809)`, ordinary circle/bumper transitions, and stopped Wine record-57 transition `(75530,354765)/(3000,15)` to -`(77369,356597)/(1839,1832)` with exact Real48 spin `-5.28` seal both paths. +`(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. ## Reproducible gates diff --git a/original/FUNCTION_RECONSTRUCTION.tsv b/original/FUNCTION_RECONSTRUCTION.tsv index fc22e93..9a24dd6 100644 --- a/original/FUNCTION_RECONSTRUCTION.tsv +++ b/original/FUNCTION_RECONSTRUCTION.tsv @@ -68,7 +68,7 @@ address raw_name segment body_bytes status reconstructed_name module evidence no 1000:c36b FUN_1000_c36b Code1 187 verified tdkpin_load_ball_slot reconstructed/tdkpin_gameplay_helpers.c disassembly 1000:c36b-c425; SS caller-frame receiver; reconstructed/tests/test_gameplay_helpers.c Exact unchecked uint16 slot times 4/6 addressing, slot position to global ball X/Y, velocity and auxiliary dword fields to receiver +0baa/+0bae/+0bca, six-byte Real48 copy to +0bce, overlap behavior, and six-byte cleanup are represented and tested. 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 swapped-component sign driver `-(vx*ny+vy*nx)/length`, signed `abs(normal_velocity)*response_tangent` response, independent dot-product spin delta `(vx*nx+vy*ny)/length*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: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, 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. diff --git a/original/reconstructed/tdkpin_physics.c b/original/reconstructed/tdkpin_physics.c index 95a035b..f703f32 100644 --- a/original/reconstructed/tdkpin_physics.c +++ b/original/reconstructed/tdkpin_physics.c @@ -191,23 +191,7 @@ static int32_t normal_velocity_checked( velocity_x, velocity_y, normal_x, normal_y, normal_length); } -static int32_t tangent_direction_unchecked( - int32_t velocity_x, - int32_t velocity_y, - BorlandReal48 normal_x, - BorlandReal48 normal_y, - int32_t normal_length) -{ - return negate_wrap(borland_real48_round_to_i32(borland_real48_divide( - borland_real48_add( - borland_real48_multiply( - borland_i32_to_real48(velocity_x), normal_y), - borland_real48_multiply( - borland_i32_to_real48(velocity_y), normal_x)), - borland_i32_to_real48(normal_length)))); -} - -static int32_t spin_velocity_unchecked( +static int32_t tangent_velocity_unchecked( int32_t velocity_x, int32_t velocity_y, BorlandReal48 normal_x, @@ -943,16 +927,9 @@ static void apply_collision_response( tdkpin_add_score_from_caller_frame(caller_bp, candidate->score); } int32_t length = candidate_normal_length(candidate); - /* Raw 1000:ef19..f16a keeps the contact-direction and spin projections - * separate. The swapped-component value selects the sign of the current - * tangential response; the standard dot product updates retained spin. */ - int32_t tangent_direction = tangent_direction_unchecked( - motion->velocity_x, - motion->velocity_y, - candidate->normal_x, - candidate->normal_y, - length); - int32_t spin_projection = spin_velocity_unchecked( + /* Raw 1000:ef19..f16a uses the standard dot-product tangent both to + * oppose the current tangential motion and to update retained spin. */ + int32_t tangent_velocity = tangent_velocity_unchecked( motion->velocity_x, motion->velocity_y, candidate->normal_x, @@ -961,7 +938,7 @@ static void apply_collision_response( BorlandReal48 spin_delta = borland_real48_multiply( borland_real48_multiply( - borland_i32_to_real48(spin_projection), + borland_i32_to_real48(tangent_velocity), g_real48_point_zero_two), candidate->response_tangent); BorlandReal48 discarded = borland_real48_divide( @@ -974,7 +951,8 @@ static void apply_collision_response( BorlandReal48 tangent_response = borland_real48_multiply( borland_i32_to_real48(absolute_wrap(candidate->normal_velocity)), candidate->response_tangent); - if (tangent_direction < 0) { + tangent_response = negate_real48(tangent_response); + if (tangent_velocity < 0) { tangent_response = negate_real48(tangent_response); } int32_t projection = borland_real48_round_to_i32(borland_real48_add( @@ -982,7 +960,7 @@ static void apply_collision_response( borland_real48_multiply(motion->spin, g_real48_point_four), borland_real48_divide( borland_real48_multiply( - borland_i32_to_real48(absolute_wrap(tangent_direction)), + borland_i32_to_real48(absolute_wrap(tangent_velocity)), discarded), borland_i32_to_real48(motion->speed))), tangent_response)); diff --git a/original/reconstructed/tests/test_physics.c b/original/reconstructed/tests/test_physics.c index adf8fac..f1b1816 100644 --- a/original/reconstructed/tests/test_physics.c +++ b/original/reconstructed/tests/test_physics.c @@ -518,6 +518,51 @@ static void test_live_relative_record_57_transition(void) } } +static void test_live_relative_record_72_transition(void) +{ + prepare_fixture(); + set_ball(238348, 356810, -3000, 0); + win16_write_u32(g_window, 0x5a, 15); + win16_write_u32(g_window, 0x56, 3800); + TdkpinCollisionRecord segment = base_record(2); + segment.bounds_min_x_milli = 209000; + segment.bounds_min_y_milli = 339000; + segment.bounds_max_x_milli = 266000; + segment.bounds_max_y_milli = 371000; + segment.point1_x_milli = 261000; + segment.point1_y_milli = 344000; + segment.point2_x_milli = 214000; + segment.point2_y_milli = 366000; + segment.response_normal = + (BorlandReal48){{0x80,0x00,0x00,0x00,0x00,0x00}}; + segment.response_tangent = + (BorlandReal48){{0x7d,0xcd,0xcc,0xcc,0xcc,0x4c}}; + segment.layer_mask = 2; + write_record(72, &segment); + + tdkpin_simulate_ball_and_dispatch_collision(0x0300); + assert((int32_t)win16_read_u32( + win16_dgroup_pointer(0x07d3)) == 235348); + assert((int32_t)win16_read_u32( + win16_dgroup_pointer(0x07d7)) == 356825); + tdkpin_simulate_ball_and_dispatch_collision(0x0300); + assert((int32_t)win16_read_u32( + win16_dgroup_pointer(0x07d3)) == 233253); + assert((int32_t)win16_read_u32( + win16_dgroup_pointer(0x07d7)) == 358494); + assert((int32_t)win16_read_u32( + win16_far_add_offset(g_window, 0x0baa)) == -2095); + assert((int32_t)win16_read_u32( + win16_far_add_offset(g_window, 0x0bae)) == 1669); + static const uint8_t expected_spin[6] = { + 0x83, 0x86, 0xeb, 0x51, 0xb8, 0x2e}; + for (uint16_t index = 0; index < 6; index++) { + assert(win16_read_u8(win16_far_add_offset( + g_window, (uint16_t)(0x0bce + index))) == + expected_spin[index]); + } +} + int main(void) { test_free_integration_and_speed_clamp(); @@ -526,5 +571,6 @@ int main(void) test_capture_boundary_and_claw(); test_out_of_bounds_and_zero_substeps_multiball(); test_live_relative_record_57_transition(); + test_live_relative_record_72_transition(); return 0; } diff --git a/tdkpin-rs/CHANGELOG.md b/tdkpin-rs/CHANGELOG.md index 76fd9a3..0c3b030 100644 --- a/tdkpin-rs/CHANGELOG.md +++ b/tdkpin-rs/CHANGELOG.md @@ -10,11 +10,13 @@ and this project adheres to ### Fixed -- Separate the common response's two binary projections: the swapped-component - value supplies the sign of `abs(normal_velocity)*response_tangent`, while - `(vx*nx+vy*ny)/length * 0.02 * response_tangent` updates spin. Live probes now +- Restore the common response's standard dot-product tangent + `tv=(vx*nx+vy*ny)/length`: `tv*0.02*response_tangent` updates spin, while the + current response opposes its sign with magnitude + `abs(normal_velocity)*response_tangent` (negative when `tv==0`). Live probes match horizontal drain `(-302,-1809)`, ordinary circle `(94,564)`, bumper - `(197,3096)`, and relative record 57 `(1839,1832)` with spin exactly `-5.28`. + `(197,3096)`, relative record 57 `(1839,1832)` with spin `-5.28`, and record + 72 `(-2095,1669)` with spin `+5.46`. - Gate dynamic record 174/175 impulse transfer on the other slot's capture age: a held ball remains velocity-stationary and the moving response retains its full normal velocity instead of always subtracting 1,000. @@ -74,7 +76,8 @@ and this project adheres to flagless TDK companion lines also retain their zero contact/link field rather than carrying unused synthetic head IDs. Record 57 additionally matches the live original's `(75530,354765)/(3000,15)` to - `(77369,356597)/(1839,1832)` transition. + `(77369,356597)/(1839,1832)` transition; symmetric record 72 matches + `(235348,356825)/(-3000,15)` to `(233253,358494)/(-2095,1669)`. - Match rectangular type-4 magnetic gates to raw `1000:9b69`: enter only when the previous position is inside, then deactivate when the newly predicted position exits any edge, replacing a swept-intersection approximation. diff --git a/tdkpin-rs/RECONSTRUCTION.md b/tdkpin-rs/RECONSTRUCTION.md index 74469e6..307415c 100644 --- a/tdkpin-rs/RECONSTRUCTION.md +++ b/tdkpin-rs/RECONSTRUCTION.md @@ -24,7 +24,7 @@ implementation. | Help and languages | Exact | Original resource images 1001-1005 are displayed directly. | | Playfield collision layout | Recovered | All 109 active type-2 line objects and 40 static active type-1 circles are transcribed from the original 175-object registration table. The registration routine converts its sideways inputs with `screen = (y, x - 20)` and accumulates explicitly relative objects. Both left/right relative slingshot chains (54-59 and 69-74) are checked record-for-record against their accumulated ledger coordinates. Every static record retains its `+0x49` layer mask; the scanner selects layer 1 below the old Y value 250,000 and layer 2 at or above it, while mask 3 records remain shared. Before detection, the raw `1000:9b69` predicted position must lie in the record bounds derived with the registered five-pixel ball margin. Type-2 records retain every recovered Real48 normal/tangent response pair and registered one-sided orientation. Type-1 records retain their swept-circle radius, radial rebound, tangent coupling, and bumper kick. Detection retains unresolved normal/material candidates so later scan-time motion changes can participate in the selected response. Raw stack slot `SS:...d8a2` makes the first detected record ID win; later nearer candidates are stored but never applied, and both C/Rust have two-candidate regression coverage for this quirk. Each flipper uses its exact two line records plus moving tip circle in both positions. Moving-flipper contact ports `1000:7ed9` rather than fitting live samples: delta-specific pivots/edges, integer cross gates, radial/penetration calculations, response-record gain, and position/velocity publication are tested against all four C harness directions and the raised release geometry. Object 174 is overwritten with the live first ball and Rust handles its ball-to-ball role directly. | | Ball launcher and nudge input | Recovered | The initial 32-bit fixed-point coordinates decode to `(325, 413)` in the right shooter lane. Each Down keydown subtracts `15*50 = 750` millipixels, release subtracts another `15*100 = 1500`, and the result follows the recovered randomized `-3800` lower and `-2280` weak upper clamp branches. The ten decoration frames use the same strict 750-millipixel thresholds. Left Shift and keypad 3 apply their directional `(50-Random(20))*15` impulses; Space uses the recovered Real48 horizontal factor and `(60-Random(20))*15` vertical impulse. With two balls, the key path still consumes those active-window draws, then applies its separately recovered fixed/shared random slot impulse to both saved velocities. Each nudge adds 25 to the wrapping 16-bit tilt counter, compares it with `30+Random(10)`, and the detail timer decrements a nonzero counter once per callback. Flipper key flags and raised geometry survive ordinary drains; Tilt and a player's final ball clear the flags, lower raised flippers through the normal WAVE-2021 timer edge, and require a physical key release before another press. | -| Physics arithmetic | Recovered Real48 core | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, Real48 `3800/speed` clamp, four-sided pre-scan prediction bounds `(0,340000] x (0,460000]`, type-2 distance/cross gates, type-1 midpoint normal, first-detected candidate selection, persistent Real48 spin, and the common impulse response. The swapped-component projection supplies only the sign of `abs(normal_velocity)*response_tangent`; the independent standard dot-product projection drives `spin_delta = projection*0.02*response_tangent`, while retained `spin*0.4` contributes to the current tangential response. The scan follows record chunks 1-5, 6, 7-88, 89, 90-128, 129-133, 134-139, 140-152, 153-154, 155-173, and dynamic 174/175 while carrying prediction separately from mutable motion. Negative auxiliary thresholds and kick coefficients are retained for bumpers 51-53 and lines 55/74/107, including weak-hit score behavior, unscored-rail WAVE 2019, and tilt suppression. Type-3 reads the pre-movement coordinate for pull/hold, obeys its prediction broadphase, and contributes its recovered radial rim candidate when a nonzero contact is outside the deep zone. Type-4 randomization mutates motion before the selected candidate is resolved and before position publication; only rectangular magnetic records rewrite prediction. Detail callbacks freeze their starting ball count, run all 5/4/3/2/1 substeps for slot 1 before slot 2, stop a slot after its first collision/reset/removal, and apply effect-seven spawn requests after the current batch. Dynamic records 174/175 use their 21-pixel prediction bounds and transfer normal impulse only when the other slot's capture age is nonpositive; successful transfer then applies `normal_velocity-1000`, while a held slot remains unchanged and leaves the moving normal velocity intact. Effect seven spawns record/slot 2 from record 148 coordinates `(17000,23000)` with exact `(0,3040)` velocity. Both slots traverse the same type-3/type-4 dispatcher. Capture age is saved per slot, contact words retain ball ownership, a completed multiball capture removes exactly that slot and promotes the survivor when needed, and effect seven's argument-2 guard prevents a third ball. The original Borland seed update, high-word `Random(n)`, and normalized Real48 random register result drive launcher variation, effects, claw terminals, magnetic fields, and trigger response. Type-4 triggers retain a shared transient entry flag; type-3 captures retain per-player 16-bit contact words, deep-inside pull/hold progression to age 300, first-contact sound, and `99`/`2` completion sentinels. Zero-spin C harnesses and retained-spin Wine probes are tested separately rather than conflated. | +| Physics arithmetic | Recovered Real48 core | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, Real48 `3800/speed` clamp, four-sided pre-scan prediction bounds `(0,340000] x (0,460000]`, type-2 distance/cross gates, type-1 midpoint normal, first-detected candidate selection, persistent Real48 spin, and the common impulse response. The standard dot-product tangent `tv=(vx*nx+vy*ny)/length` drives `spin_delta=tv*0.02*response_tangent`; the current response opposes its sign with magnitude `abs(normal_velocity)*response_tangent` (negative when `tv==0`), while retained `spin*0.4` contributes independently. The scan follows record chunks 1-5, 6, 7-88, 89, 90-128, 129-133, 134-139, 140-152, 153-154, 155-173, and dynamic 174/175 while carrying prediction separately from mutable motion. Negative auxiliary thresholds and kick coefficients are retained for bumpers 51-53 and lines 55/74/107, including weak-hit score behavior, unscored-rail WAVE 2019, and tilt suppression. Type-3 reads the pre-movement coordinate for pull/hold, obeys its prediction broadphase, and contributes its recovered radial rim candidate when a nonzero contact is outside the deep zone. Type-4 randomization mutates motion before the selected candidate is resolved and before position publication; only rectangular magnetic records rewrite prediction. Detail callbacks freeze their starting ball count, run all 5/4/3/2/1 substeps for slot 1 before slot 2, stop a slot after its first collision/reset/removal, and apply effect-seven spawn requests after the current batch. Dynamic records 174/175 use their 21-pixel prediction bounds and transfer normal impulse only when the other slot's capture age is nonpositive; successful transfer then applies `normal_velocity-1000`, while a held slot remains unchanged and leaves the moving normal velocity intact. Effect seven spawns record/slot 2 from record 148 coordinates `(17000,23000)` with exact `(0,3040)` velocity. Both slots traverse the same type-3/type-4 dispatcher. Capture age is saved per slot, contact words retain ball ownership, a completed multiball capture removes exactly that slot and promotes the survivor when needed, and effect seven's argument-2 guard prevents a third ball. The original Borland seed update, high-word `Random(n)`, and normalized Real48 random register result drive launcher variation, effects, claw terminals, magnetic fields, and trigger response. Type-4 triggers retain a shared transient entry flag; type-3 captures retain per-player 16-bit contact words, deep-inside pull/hold progression to age 300, first-contact sound, and `99`/`2` completion sentinels. Zero-spin C harnesses and retained-spin Wine probes are tested separately rather than conflated. | | Rules | Recovered gameplay paths | Player count, controls, the five three-line bumper-value groups, four three-line TDK-diamond groups, five doubling-value lock holes, record-148 special/multiball hole, seven-way effect selector/consumer including multiball, ball-scoped double scoring, and four exact media/extra-ball thresholds follow original help/code paths, globals, and object flags. The ninth diamond pays the original 24,464 completion value, then immediately enables double scoring and all three magnetic fields before that collision's static 1,500-point award. Further completed banks during that ball add 100,000 to the per-player secondary score. A normal ball end clears double scoring, so the first later completion re-enables it without adding 100,000; effect seven's special respawn preserves it because it bypasses `normal_ball_end`. Bumpers 51-53 and targets 140-147/150-152 use the original 5/20/10 active-callback countdowns and exact overlay-A render rectangles. Record 121 runs the six-active-callback DAT600 target rotation with exact 91x90 frames/target points and rotates the five contact/item values at state 6; it pauses while a ball waits in the launcher and survives a normal drain. Completing all five lock holes with one ball suspends physics for the full 281-callback panel animation, clears contact/item state at the recovered boundaries, and uses the exact WAVE 2013/2012/stop sequence. A fifth multiball capture still transfers the capped 160,000-step secondary award, multiplier, and extra ball but defers the panel; a later survivor recapture can perform the same capped completion and start it. Capturing record 148 sets player item/contact 20 and preserves all five lock-hole items and contacts. Effect seven retains required state through active multiball; when the last ball is lost, `1000:ae6e` grants one uncharged special respawn at `(17000,23000)/(0,3040)`, clears required state, and suppresses record 148 until a broadphase-active type-4 record clears `0x0875`. Turn changes mirror the original save/load of all 175 collision active/contact states plus wheel/top targets and selected effect. Claw contact and all initially active type-4 targets use recovered records. The top three targets score 500 each and independently enable the left, center, or right magnetic field record. Each rectangular field requires the previous position inside, applies its Real48/random pull, and deactivates when raw `1000:9b69` finds the resulting `07db/07df` prediction outside any edge. The claw state machine and release table have live differential coverage for all four random terminals. | | Numeric scoring | Recovered gameplay values | Static scores come from the initialized 175-object ledger. Dynamic bumper progression, target-bank completion, diamond awards, 10k-160k lock bonuses, 310k transfer, six effect values, multiball mode, and all four media thresholds are transcribed from `1000:b476`, `1000:c4e1`, `1000:bc36`, and live state probes. The central helper suppresses all mutation during Tilt, applies a 2x active-multiball factor, and then independently applies the active ball's 2x factor, allowing the original 4x stack. Lock and effect awards share the original per-player secondary score and display multiplier; the fifth hole transfers and clears it, increments the multiplier, and grants the recovered ball award. Score mutation uses the original 32-bit wrapping behavior; media markers use the binary's signed-high/unsigned-low comparison, and each add operation can advance at most one threshold. Type-4 WAVE 2004, bumper WAVE 2006, and bank-completion WAVE 2017 dispatch before their associated score mutations, leaving a crossed marker's WAVE 2007 as the audible asynchronous sample. Rendering separately follows `1008:0996`'s eight-place 130x40 fields/right edge X=606 and `1008:0b9e`'s strict signed status thresholds; configured-player rows and 5x5 remaining-ball markers retain their exact dimensions and current/noncurrent counts. | | High scores | Recovered visible flow; portable storage | The original 276-byte table is decoded as ten `IWIK`-XOR-obfuscated little-endian scores plus ten 22-byte names. Each player is checked immediately when their own last ball is lost; qualifying scores use the original signed-high/unsigned-low comparison and a `TDK Pinball Player`-prefilled DIALOG 32514 flow with the exact caption, prompt, 21-character limit, OK/Cancel semantics, and allowance for an empty accepted name. The `HighScore` child uses exact DAT993 at 360x300, heading `(180,27)`, name/rank X=30, right-aligned score X=320, and ten 20-pixel rows before play resumes. Persisted updates use portable JSON rather than rewriting the Win16 file. | diff --git a/tdkpin-rs/src/game.rs b/tdkpin-rs/src/game.rs index 6c4e25d..45fdb12 100644 --- a/tdkpin-rs/src/game.rs +++ b/tdkpin-rs/src/game.rs @@ -3274,6 +3274,46 @@ mod tests { ); } + #[test] + fn relative_record_72_matches_live_two_substep_transition() { + let mut game = Game::new(1); + game.ball.in_launcher = false; + game.ball.position = vec2(238.348, 356.810); + game.ball.velocity = MilliVec { x: -3_000, y: 0 }.to_velocity_per_second(); + let mut events = Vec::new(); + + assert!(!game.fixed_update(&mut events)); + assert_eq!( + MilliVec::from_position(game.ball.position), + MilliVec { + x: 235_348, + y: 356_825, + } + ); + assert_eq!( + MilliVec::from_velocity_per_second(game.ball.velocity), + MilliVec { x: -3_000, y: 15 } + ); + + assert!(game.fixed_update(&mut events)); + assert_eq!(game.last_collision_id, Some(72)); + assert_eq!( + game.ball.spin.bytes(), + [0x83, 0x86, 0xeb, 0x51, 0xb8, 0x2e] + ); + assert_eq!( + MilliVec::from_position(game.ball.position), + MilliVec { + x: 233_253, + y: 358_494, + } + ); + assert_eq!( + MilliVec::from_velocity_per_second(game.ball.velocity), + MilliVec { x: -2_095, y: 1_669 } + ); + } + #[test] fn retained_collision_candidate_clears_the_slot_capture_age() { let mut game = Game::new(1); diff --git a/tdkpin-rs/src/original_physics.rs b/tdkpin-rs/src/original_physics.rs index 4c5ca9f..e1fd487 100644 --- a/tdkpin-rs/src/original_physics.rs +++ b/tdkpin-rs/src/original_physics.rs @@ -241,21 +241,7 @@ fn normal_velocity(velocity: MilliVec, normal_x: Real48, normal_y: Real48, lengt .round_i32() } -fn tangent_direction(velocity: MilliVec, normal_x: Real48, normal_y: Real48, length: i32) -> i32 { - if length <= 0 { - return 0; - } - Real48::ZERO - .subtract( - Real48::from_i32(velocity.x) - .multiply(normal_y) - .add(Real48::from_i32(velocity.y).multiply(normal_x)), - ) - .divide(Real48::from_i32(length)) - .round_i32() -} - -fn spin_velocity(velocity: MilliVec, normal_x: Real48, normal_y: Real48, length: i32) -> i32 { +fn tangent_velocity(velocity: MilliVec, normal_x: Real48, normal_y: Real48, length: i32) -> i32 { if length <= 0 { return 0; } @@ -295,16 +281,16 @@ fn apply_response( x: normal_x.round_i32(), y: normal_y.round_i32(), }); - // Raw 1000:ef19..f16a uses the swapped-component value only as the - // response direction; the standard dot product independently updates spin. - let tangent_direction = tangent_direction(velocity, normal_x, normal_y, length); - let spin_projection = spin_velocity(velocity, normal_x, normal_y, length); - let spin_delta = Real48::from_i32(spin_projection) + // Raw 1000:ef19..f16a uses the standard dot-product tangent both to + // oppose the current tangential motion and to update retained spin. + let tangent_velocity = tangent_velocity(velocity, normal_x, normal_y, length); + let spin_delta = Real48::from_i32(tangent_velocity) .multiply(Real48::from_bytes([0x7b, 0x71, 0x3d, 0x0a, 0xd7, 0x23])) .multiply(coefficients.tangent); let mut tangent_response = Real48::from_i32(collision_velocity.wrapping_abs()) - .multiply(coefficients.tangent); - if tangent_direction < 0 { + .multiply(coefficients.tangent) + .negate(); + if tangent_velocity < 0 { tangent_response = tangent_response.negate(); } let projection = spin diff --git a/tdkpin-rs/src/simulation.rs b/tdkpin-rs/src/simulation.rs index c0b738e..0def3db 100644 --- a/tdkpin-rs/src/simulation.rs +++ b/tdkpin-rs/src/simulation.rs @@ -444,8 +444,9 @@ mod tests { }; assert!(event_count("Launch") >= 1); - assert!(event_count("FlipperMove") >= 10); + assert!(event_count("FlipperMove") >= 2); assert!(event_count("Target") >= 1); + assert!(event_count("Bumper") >= 1); assert!(simulation.trace.iter().all(|snapshot| { snapshot.ball.x.is_finite() && snapshot.ball.y.is_finite()