fix(physics): use predicted magnetic gate bounds

Correct the readable 1000:9b69 reconstruction to read DGROUP 07db/07df and name the helper for its predicted-position role. Rust magnetic rectangles now enter only from an old position inside the record and deactivate when the recomputed prediction exits any edge, replacing the prior swept approximation.

Test Plan:
- bash original/tools/test_reconstructed_c.sh
- python3 original/tools/audit_reconstruction.py --require-complete
- cargo test --all-targets
- cargo clippy --all-targets --all-features -- -D warnings
- rumdl check original/C_RECONSTRUCTION_FINAL_AUDIT.md tdkpin-rs/CHANGELOG.md tdkpin-rs/RECONSTRUCTION.md tdkpin-rs/README.md
- git diff --check
This commit is contained in:
2026-08-23 18:25:23 +02:00
parent 8c51094b31
commit 742b8b7981
9 changed files with 66 additions and 22 deletions
+5
View File
@@ -71,6 +71,11 @@ the original Borland compiler.
multiball, and scoring. Static/host evidence is not mislabeled as Wine.
12. **Phase boundary:** no Rust source or Cargo manifest/lockfile was modified.
Post-audit evidence correction (2026-08-23): raw `1000:9b69` reads predicted
DGROUP coordinates `1028:07db/07df`, not current `07d3/07d7`. The readable
helper and its harness now reflect that distinction; the complete C test and
ledger gates below still pass.
## Reproducible gates
```sh
@@ -661,8 +661,8 @@ uint16_t tdkpin_receiver_point_in_bounds(
x, y, maximum_y, maximum_x, minimum_y, minimum_x);
}
/* 1000:9b69 -- same inclusive rectangle test for the global ball position. */
uint16_t tdkpin_ball_in_bounds(
/* 1000:9b69 -- test the predicted 1028:07db/07df position against bounds. */
uint16_t tdkpin_predicted_ball_in_bounds(
uint16_t ignored_static_link,
int32_t maximum_y,
int32_t maximum_x,
@@ -671,8 +671,8 @@ uint16_t tdkpin_ball_in_bounds(
{
(void)ignored_static_link;
return point_in_bounds_with_residue(
g_ball_x_milli,
g_ball_y_milli,
(int32_t)win16_read_u32(win16_dgroup_pointer(0x07db)),
(int32_t)win16_read_u32(win16_dgroup_pointer(0x07df)),
maximum_y,
maximum_x,
minimum_y,
@@ -36,7 +36,7 @@ uint16_t tdkpin_receiver_point_in_bounds(
int32_t maximum_x,
int32_t minimum_y,
int32_t minimum_x); /* 1000:9ae0 */
uint16_t tdkpin_ball_in_bounds(
uint16_t tdkpin_predicted_ball_in_bounds(
uint16_t ignored_static_link,
int32_t maximum_y,
int32_t maximum_x,
+2 -2
View File
@@ -223,7 +223,7 @@ static int32_t clamp_motion_speed(
static bool broadphase_contains_predicted_ball(
const TdkpinCollisionRecord *record, uint16_t caller_bp)
{
return (uint8_t)tdkpin_ball_in_bounds(
return (uint8_t)tdkpin_predicted_ball_in_bounds(
caller_bp,
record->bounds_max_y_milli,
record->bounds_max_x_milli,
@@ -686,7 +686,7 @@ static void handle_trigger_record(
0x07db, add_wrap(ball_x, motion->velocity_x));
write_dgroup_i32(
0x07df, add_wrap(ball_y, motion->velocity_y));
if ((uint8_t)tdkpin_ball_in_bounds(
if ((uint8_t)tdkpin_predicted_ball_in_bounds(
0,
record->point2_y_milli,
record->point2_x_milli,
@@ -235,9 +235,13 @@ int main(void)
assert(tdkpin_receiver_point_in_bounds(
0x0100, 0x6000, 0x2000, 0x5000, 0x1300) == 0x1200);
g_ball_x_milli = 0x1234;
g_ball_y_milli = 0x56ab;
assert(tdkpin_ball_in_bounds(
win16_write_u32(win16_dgroup_pointer(0x07db), 0, 0x00001234u);
win16_write_u32(win16_dgroup_pointer(0x07df), 0, 0x000056abu);
assert(tdkpin_predicted_ball_in_bounds(
0, 0x6000, 0x2000, 0x5000, 0x1000) == 0x5601);
g_ball_x_milli = 0;
g_ball_y_milli = 0;
assert(tdkpin_predicted_ball_in_bounds(
0, 0x6000, 0x2000, 0x5000, 0x1000) == 0x5601);
g_ball_x_milli = 100000;
+1 -1
View File
@@ -180,7 +180,7 @@ static bool in_bounds(
y >= minimum_y && y <= maximum_y;
}
uint16_t tdkpin_ball_in_bounds(
uint16_t tdkpin_predicted_ball_in_bounds(
uint16_t ignored_static_link,
int32_t maximum_y,
int32_t maximum_x,
+3
View File
@@ -10,6 +10,9 @@ and this project adheres to
### Fixed
- 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.
- Decay the 16-bit tilt counter once per selected 50/40/30/20/10 ms detail
callback, replacing an invented independent 30 ms accumulator.
- Match the multiball nudge path's saved-slot behavior: consume the active
+1 -1
View File
@@ -25,7 +25,7 @@ implementation.
| 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. 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. 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. 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. |
| Physics arithmetic | Recovered Real48 core | Production movement uses the original 10 ms millipixel substep, `+15` vertical acceleration, Real48 `3800/speed` clamp, type-2 distance/cross gates, type-1 midpoint normal, surface-distance candidate ordering, persistent Real48 spin, and the common impulse response. 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. 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 transfer normal impulse to the other ball before applying `normal_velocity-1000` to the moving ball; 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, wheel-reset target, seven-way effect selector/consumer including multiball, permanent 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; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. 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-callback DAT600 target rotation with exact 91x90 frames/target points and rotates the five contact/item values at state 6. Completing all five lock holes 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. Turn changes mirror the original save/load of all 175 collision record states: wheel/top targets, active/contact slots, selected effect, and multiball readiness remain attached to their player. 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 field pulls the ball upward until it exits and then deactivates. The claw state machine and release table have live differential coverage for all four random terminals. |
| 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, wheel-reset target, seven-way effect selector/consumer including multiball, permanent 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; the following completed bank enables double scoring, and later completions add 100,000 to the per-player secondary score. 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-callback DAT600 target rotation with exact 91x90 frames/target points and rotates the five contact/item values at state 6. Completing all five lock holes 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. Turn changes mirror the original save/load of all 175 collision record states: wheel/top targets, active/contact slots, selected effect, and multiball readiness remain attached to their player. 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. 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, and each add operation can advance at most one media threshold. |
| 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 name screen before the table is shown and play resumes. Persisted updates use portable JSON rather than rewriting the Win16 file. |
| Configuration | Behaviorally compatible | Sound, language, and five detail levels are retained. Storage moves from a local Win16 INI file to the platform user-data directory. |
+42 -10
View File
@@ -1430,15 +1430,10 @@ impl Game {
if !self.object_active[object_id] {
continue;
}
let predicted = old_position.add(*velocity);
let sweep_min_x = old_position.x.min(predicted.x);
let sweep_max_x = old_position.x.max(predicted.x);
let sweep_min_y = old_position.y.min(predicted.y);
let sweep_max_y = old_position.y.max(predicted.y);
if sweep_max_x < min_x
|| sweep_min_x > max_x
|| sweep_max_y < min_y
|| sweep_min_y > max_y
if old_position.x < min_x
|| old_position.x > max_x
|| old_position.y < min_y
|| old_position.y > max_y
{
continue;
}
@@ -1453,7 +1448,12 @@ impl Game {
.multiply(vertical_factor)
.round_i32()
.wrapping_neg();
if old_position.add(*velocity).y < min_y {
let predicted = old_position.add(*velocity);
if predicted.x < min_x
|| predicted.x > max_x
|| predicted.y < min_y
|| predicted.y > max_y
{
self.object_active[object_id] = false;
}
}
@@ -2944,6 +2944,38 @@ mod tests {
assert_eq!(game.player().score, 1_000);
}
#[test]
fn magnetic_rectangles_use_old_position_for_entry_and_prediction_for_exit() {
let mut game = Game::new_with_seed(1, 7);
game.object_active[153] = true;
let seed_before = game.random.seed();
let mut entering_from_outside = MilliVec { x: 0, y: -3_000 };
game.apply_magnetic_fields(
MilliVec {
x: 15_000,
y: 390_000,
},
&mut entering_from_outside,
);
assert_eq!(entering_from_outside, MilliVec { x: 0, y: -3_000 });
assert_eq!(game.random.seed(), seed_before);
assert!(game.object_active[153]);
let mut exiting_sideways = MilliVec { x: -2_000, y: 0 };
game.apply_magnetic_fields(
MilliVec {
x: 1_000,
y: 350_000,
},
&mut exiting_sideways,
);
assert_eq!(exiting_sideways.x, -1_800);
assert!(!game.object_active[153]);
}
#[test]
fn wheel_holes_accumulate_and_transfer_the_per_player_secondary_score() {
let mut game = Game::new(1);