Repository navigation
Expand file tree
/
Copy pathtest_rig.diff
More file actions
5741 lines (5265 loc) · 261 KB
/
Copy pathtest_rig.diff
File metadata and controls
5741 lines (5265 loc) · 261 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Every source change since the replay rig — one commit at a time
Generated by `scripts/gen_rig_diff.sh`; regenerate after adding commits.
Base: `7eaaa63` (2026-09-03), the first TESTS.md.
The rig itself, docs and scripts are excluded — this is what the GAME does
differently. `docs/TESTS.md` has the reasoning and the asm citations; this
file is the code, so a change can be reviewed without going commit hunting.
CLASS says whether a commit can alter **Amiga-mode play**, which is what the
game ships in and what the DOS corpus cannot test:
AMIGA changes shipped play — the reviewable surface
DOS behind `_gDosGameplay`, Amiga arm byte-identical
VIEW a literal rewritten as f(view); identical at 336x272
FLAG behind an opt-in -D; default build unchanged
RIG inert unless --replay-test
NOOP no behaviour change
## Index
| commit | class | what |
|---|---|---|
| `43fa201` | **DOS+RIG** | DOS constants + rig hooks; Amiga values and paths unchanged |
| `3399d34` | **VIEW** | introduces _sim_view_*; defaults to the render width, so a no-op then |
| `22f370a` | **AMIGA** | splits onScreen from the render cull and pins the sim view to 336 |
| `47bb535` | **FLAG** | SWOS_ORIGINAL_TACTICS variants; default build unchanged |
| `0aa401f` | **VIEW** | bench-slide window as f(view); identical at 272 lines |
| `f2195e8` | **FLAG** | SWOS_DOS_TACTICS variants; default build unchanged |
| `bb88140` | **DOS** | goalkeeper-sub cursor; Amiga arm unchanged |
| `af8fd04` | **DOS** | extra ApplyGameStyle call; writes the same constants on Amiga |
| `2247d74` | **AMIGA** | ball-quadrant leading bound + clr.w on sprite z (SetBallPosition) |
| `f3e9bc5` | **DOS** | bench comment/constant; Amiga arm unchanged |
| `beb74a9` | **DOS** | IsThisPlayerOkToSelect offset + DOS bench camera 55 |
| `cbb2d2a` | **DOS** | player-down timer 55 on DOS, 50 on Amiga |
| `6ce24b7` | **AMIGA** | five nearest-player scans now walk the table forwards |
| `e24f55f` | **AMIGA** | goalie catch reads GoalieSkill 0x2A/0x2C; tackling timer >= -2 |
| `f337e13` | **AMIGA** | InitUserTactics writes through _teamTacticsTable; no-op by default |
| `04f8f01` | **AMIGA** | AI fire gates, angle tolerance, dead $FFFF arm, 478 bound |
| `3e4a754` | **RIG** | replay runs silent; no gameplay path |
| `d355a28` | **DOS** | goalie reach index differs per release |
| `f343cca` | **DOS** | throw-in hide-result gate 55 on DOS, 50 on Amiga |
| `5e058fe` | **DOS** | goalie/header recompilation differences |
| `41ba466` | **DOS** | second stoppage gate 55 on DOS, 50 on Amiga |
| `25b90e6` | **DOS** | --dos-gameplay switches the formation set |
| `b5b850c` | **AMIGA** | a2 is the ball (parameter, not a local); CPU-only position block |
| `9a7bc65` | **AMIGA** | tst.l spans longPass+longSpinPass in three tests |
| `24159a6` | **AMIGA** | near-goal slowdown is four shifts (/16), not five |
| `6155a4a` | **DOS+VIEW** | stoppage reloads scale on DOS; referee entry as f(view) |
| `7a08d16` | **AMIGA** | an AI tackle clears pl1FireCounter (shared asm tail) |
| `6c1aa1a` | **AMIGA** | unmatched end-game state falls through to the stoppage countdown |
| `a535e50` | **VIEW** | end-of-game / highlights camera as f(view); identical at 336x272 |
| `757b933` | **DOS** | stats overlay freezes the clock on Amiga only; Amiga arm unchanged |
| `a58a2a1` | **DOS** | DOS alternates teams on its own counter; Amiga keeps frameCount |
| `59a65a1` | **AMIGA** | goalpost deflection has three arms |
| `98bb0e3` | **NOOP** | drops three includes left over from tracing |
| `6f59733` | **DOS** | penalty keeper frames scale; DOS ends a shoot-out differently |
| `75abd23` | **DOS** | final-whistle freeze; Amiga arm unchanged |
| `91dd1e3` | **DOS** | DOS second-yellow table runs off its end |
| `310c1a6` | **AMIGA** | animation follows the render view (widescreen only) |
| `28f8204` | **AMIGA** | camera pan range is the simulation constant, not the render width |
| `97dd23a` | **AMIGA** | render origin split from the game camera (widescreen only) |
| `0624126` | **AMIGA** | HUD + bench menus anchor on the render origin (widescreen only) |
## Amiga-affecting commits only
- `22f370a` fix: onScreen culled to the render width, and was overwrit — splits onScreen from the render cull and pins the sim view to 336
- `2247d74` sim: four more bugs the sprite level found, and the bench — ball-quadrant leading bound + clr.w on sprite z (SetBallPosition)
- `6ce24b7` sim: five "nearest player" scans walked the sprite table b — five nearest-player scans now walk the table forwards
- `e24f55f` goalie: the catch gate read GoalieSkill offsets 0 and 2, n — goalie catch reads GoalieSkill 0x2A/0x2C; tackling timer >= -2
- `f337e13` tactics: the DOS "rewritten forward rows" are dead data †— InitUserTactics writes through _teamTacticsTable; no-op by default
- `04f8f01` ai: three fire gates in AI_SetControlsDirection read the w — AI fire gates, angle tolerance, dead $FFFF arm, 478 bound
- `b5b850c` ai: a block the DOS build does not have, and a register th — a2 is the ball (parameter, not a local); CPU-only position block
- `9a7bc65` pass: a `tst.l` on a two-byte field spans the next one — tst.l spans longPass+longSpinPass in three tests
- `24159a6` tackle: four shifts, not five — the comment said /32 and — near-goal slowdown is four shifts (/16), not five
- `7a08d16` controls: the AI team's tackle clears PLAYER 1's fire coun — an AI tackle clears pl1FireCounter (shared asm tail)
- `6c1aa1a` timers: a held fire button froze the stoppage countdown — unmatched end-game state falls through to the stoppage countdown
- `59a65a1` ball: the goalpost deflection has three arms, and the port — goalpost deflection has three arms
- `310c1a6` anim: sprites in the widescreen margin were drawn but neve — animation follows the render view (widescreen only)
- `28f8204` camera: the widescreen camera stopped 148px short and left — camera pan range is the simulation constant, not the render width
- `97dd23a` camera: split the render origin from the game camera — t — render origin split from the game camera (widescreen only)
- `0624126` hud: the score panel and the match clock anchored on the w — HUD + bench menus anchor on the render origin (widescreen only)
## Cumulative diff stat
```
include/display.h | 68 ++++++++++
include/game_types.h | 17 +++
include/menu_data.h | 4 +
include/sprites.h | 5 +
include/swos_io.h | 30 +++++
include/swos_platform.h | 36 ++++++
include/tactics_data.h | 7 +
src/SWOS.c | 8 ++
src/adverts.c | 4 +-
src/ai.c | 97 ++++++++++----
src/animated_patterns.c | 4 +-
src/ball_physics.c | 198 +++++++++++++++++------------
src/ball_possession.c | 11 +-
src/bench_subs.c | 156 ++++++++++++++++++-----
src/camera.c | 25 +++-
src/display.c | 28 +++-
src/dos_gameplay.c | 124 +++++++++++++++++-
src/game_hud.c | 2 +-
src/game_init.c | 13 ++
src/game_loop.c | 29 ++++-
src/game_state.c | 46 +++----
src/game_timers.c | 29 +++--
src/goalkeeper.c | 62 ++++++++-
src/headers.c | 28 +++-
src/highlight.c | 48 ++++++-
src/image_cmd.c | 14 +-
src/input_sdl.c | 74 +++++++++++
src/interrupts.c | 40 +++++-
src/main.c | 142 ++++++++++++++++++++-
src/match_setup.c | 96 ++++++++++++--
src/math68k.c | 22 +++-
src/menu_data.c | 23 +++-
src/menu_load_json.c | 5 +-
src/menu_symbols.c | 10 ++
src/menus.c | 76 ++++++++++-
src/move_camera.c | 31 +++--
src/pitch.c | 4 +-
src/platform_switch.cpp | 40 ++++++
src/player_anim.c | 11 +-
src/random.c | 22 +++-
src/referee.c | 59 ++++++++-
src/resload.c | 39 ++++--
src/sprites.c | 107 ++++++++++++----
src/string_symbols.c | 5 +-
src/swos_amiga_ptr_imports.c | 12 ++
src/swos_amiga_strings.c | 5 +
src/swos_globals.c | 8 ++
src/swos_io.c | 177 ++++++++++++++++++++++++--
src/swos_settings.c | 5 +
src/tackle_foul.c | 9 +-
src/tactics_data.c | 297 ++++++++++++++++++++++++++++++++++++++++++-
src/tactics_load_json.c | 5 +-
src/team_control.c | 66 ++++++++--
src/translations.c | 4 +-
src/update_players.c | 56 ++++++--
55 files changed, 2221 insertions(+), 322 deletions(-)
```
## Per-commit diffs
---
### 43fa201 [DOS+RIG] tests: the recorded-game replay rig — and four defects it found
_2026-09-03_
```diff
diff --git a/src/SWOS.c b/src/SWOS.c
index b83926f..e438415 100644
--- a/src/SWOS.c
+++ b/src/SWOS.c
@@ -343,6 +343,14 @@ skip_title_screens: ;
/* ---- Phase 9: Enter front-end loop (or arcade attract loop) ---- */
#ifdef SWOS_SDL_BUILD
+ {
+ extern int ReplayTest_Armed(void);
+ extern void ReplayTest_Run(void);
+ if (ReplayTest_Armed()) {
+ ReplayTest_Run(); /* replays a recording, then exits the process */
+ return;
+ }
+ }
{
extern int _gArcadeMode;
extern void ArcadeMainLoop(void);
diff --git a/src/dos_gameplay.c b/src/dos_gameplay.c
index 49c9826..c552793 100644
--- a/src/dos_gameplay.c
+++ b/src/dos_gameplay.c
@@ -33,6 +33,13 @@ int16_t _gsBallOutOfGameTimer = 500; /* GS_550_500 game_timers.c ball-out-o
int16_t _gsResultAutoAdvance = 600; /* GS_660_600 ai.c half/fulltime result dismiss */
int16_t _gsKickoffStoppage = 750; /* GS_825_750 game_timers.c kickoff stoppage */
int16_t _gsStoppageEventReload = 50; /* GS_GK_55_50 game_timers.c stoppageEvent reload */
+/* The two result-banner display lengths ShowResult (game_state.c) maps its magic
+ * 30000/31000 markers to. Found by the recorded-game replay rig: a DOS recording
+ * sets resultTimer to 165 at a stoppage where we set 150 (docs/TESTS.md). They fit
+ * the same x1.1 DOS:Amiga family as every GS_* above, and swos-2020's DOS source
+ * hard-codes 275 (game.cpp:13024). */
+int16_t _gsResultHalftimeLength = 250; /* GS_275_250 game_state.c 30000 -> banner length */
+int16_t _gsResultBreakLength = 150; /* GS_165_150 game_state.c 31000 -> banner length */
/* ---- speed_factor — the per-frame movement-delta scale (docs/DOS_GAMEPLAY.md §8.3).
* Reproduces swos-2020's CalculateDeltaXAndY_125 hook (symbols.txt:2083 ->
@@ -46,9 +53,15 @@ int16_t _gsStoppageEventReload = 50; /* GS_GK_55_50 game_timers.c stoppageEv
int16_t _gMoveDeltaScaleNum = 1; /* DOS 41 / Amiga 1 (future Amiga-60: 50) */
int16_t _gMoveDeltaScaleDen = 1; /* DOS 64 / Amiga 1 (future Amiga-60: 60) */
-/* GS_54_49: the doc keeps the authentic ORIGINAL DOS value 54 as the default, and
- * exposes swos-2020's deliberate retune of 69 as a tweak. Flip this to test. */
-#define GS_FRAMES_PER_GAME_SECOND_DOS 54 /* original DOS = 54; swos-2020 = 69 */
+/* GS_54_49 — MEASURED, not chosen. docs/DOS_GAMEPLAY.md originally took 54 from
+ * swos-2020's `GS_54_49 = 69; // original = 54`, but a DOS recording settles it:
+ * zkz-12065730 reaches game-minute 1 at frame 702 and minute 2 at frame 842, i.e.
+ * 140 frames per game-minute. The accumulator subtracts gameLenSecondsTable[0] = 30
+ * per frame and reloads by this constant, so seconds advance at 30/N per frame and
+ * 60 seconds take 2*N frames: N = 70. (54 would give 108 frames/minute, 69 would
+ * give 138.) swos-port agrees — gameTime.cpp kPcTicksPerGameSeconds = 70 — and its
+ * replay of this same corpus passes. The Amiga 49 is unchanged and untouched. */
+#define GS_FRAMES_PER_GAME_SECOND_DOS 70 /* was 54 (swos-2020 comment); see above */
#define GS_FRAMES_PER_GAME_SECOND_AMIGA 49
int DosGameplay_TargetFps(void)
@@ -90,6 +103,8 @@ void ApplyGameStyle(void)
_gsResultAutoAdvance = dos ? 660 : 600;
_gsKickoffStoppage = dos ? 825 : 750;
_gsStoppageEventReload = dos ? 55 : 50;
+ _gsResultHalftimeLength = dos ? 275 : 250;
+ _gsResultBreakLength = dos ? 165 : 150;
/* --- Movement speed_factor (swos-2020 CalculateDeltaXAndY_125, §8.3) ---
* DOS/PC 70fps scales the per-frame movement deltas by 41/64 so players don't
diff --git a/src/game_init.c b/src/game_init.c
index de44f91..41bacc7 100644
--- a/src/game_init.c
+++ b/src/game_init.c
@@ -738,6 +738,19 @@ void SetupPlayers(TeamFileEx *team1, TeamFileEx *team2, int16_t maxSubs,
_careerTeamCoachOnly = 0;
#ifdef SWOS_SDL_BUILD
+ {
+ /* Recorded-game replay: the two ShowPlayMatchMenu prompts are
+ * replaced by the control assignment the recording's header carries
+ * (docs/TESTS.md 5b), mirroring the reference rig's menu callback. */
+ extern int ReplayTest_Armed(void);
+ extern void ReplayTest_SetupPlayers(TeamFileEx *t1, TeamFileEx *t2);
+ if (ReplayTest_Armed()) {
+ _careerTeamCoachOnly = 0;
+ ReplayTest_SetupPlayers(team1, team2);
+ (void)maxSubs; (void)excludeFlags; (void)allowSquadChanges; (void)mode; (void)d0;
+ return;
+ }
+ }
{
extern int _gArcadeMode;
if (_gArcadeMode) {
diff --git a/src/game_loop.c b/src/game_loop.c
index 7076ea2..0b182c9 100644
--- a/src/game_loop.c
+++ b/src/game_loop.c
@@ -623,6 +623,12 @@ GameLoop(void)
goto wait_for_vblank_sync;
vblank_return_dispatch:
+#ifdef SWOS_SDL_BUILD
+ /* Recorded-game replay: take this frame's record and inject its stick
+ * state before anything reads input (docs/TESTS.md 5b). No-op unless the
+ * rig is running. */
+ { extern void ReplayTest_FrameStart(void); ReplayTest_FrameStart(); }
+#endif
ReadTimerDelta();
/* Pause spin loop */
@@ -733,6 +739,14 @@ vblank_return_dispatch:
_goalCameraMode = 0;
}
+#ifdef SWOS_SDL_BUILD
+ /* ... and compare the state this frame produced against the record. The
+ * branches above that jump straight to wait_for_vblank_sync deliberately
+ * skip this — the rig reports such a frame rather than silently reusing
+ * its record. */
+ { extern void ReplayTest_FrameEnd(void); ReplayTest_FrameEnd(); }
+#endif
+
wait_for_vblank_sync:
waitVBlankSync(0xCFD1F9BDu, 0x165Au);
#ifdef DETERMINISTIC_DUMP_FRAME
diff --git a/src/game_state.c b/src/game_state.c
index 0abab12..5df1347 100644
--- a/src/game_state.c
+++ b/src/game_state.c
@@ -93,6 +93,8 @@ extern uint16_t _timeVar;
extern uint16_t _timeDelta;
extern int16_t _gsFramesPerGameSecond; /* GS_54_49 clock reload — dos_gameplay.c */
extern int16_t _gsEndGameCounter; /* GS_55_50 endGameCounter reload — dos_gameplay.c */
+extern int16_t _gsResultHalftimeLength; /* GS_275_250 result banner — dos_gameplay.c */
+extern int16_t _gsResultBreakLength; /* GS_165_150 result banner — dos_gameplay.c */
extern uint16_t _gameStatePl;
extern uint16_t _playingPenalties;
extern int16_t _extraTimeState;
@@ -404,12 +406,12 @@ void ShowResult(void)
/* --- timer init phase: map magic values to countdown values --- */
if (_resultTimer == 30000)
{
- _resultTimer = 250;
+ _resultTimer = _gsResultHalftimeLength; /* Amiga 250 / DOS 275 */
goto show_sprites;
}
if (_resultTimer == 31000)
{
- _resultTimer = 150;
+ _resultTimer = _gsResultBreakLength; /* Amiga 150 / DOS 165 */
goto show_sprites;
}
if (_resultTimer == 32000)
diff --git a/src/input_sdl.c b/src/input_sdl.c
index 855f728..672f5b8 100644
--- a/src/input_sdl.c
+++ b/src/input_sdl.c
@@ -553,6 +553,11 @@ void InputSDL_ClearKeyState(void)
void InputSDL_PostFrame(void)
{
+ /* The replay rig writes joy0Dat/joy1Dat/ciaa_pra itself, once per game
+ * loop iteration. Recomputing them from the real keyboard/pads here
+ * would overwrite the recorded stick with whatever is physically held. */
+ { extern int ReplayTest_Running(void); if (ReplayTest_Running()) return; }
+
/* Player 1: keyboard + pad 0 (combined). */
int p1_up = s_kbd_up, p1_down = s_kbd_down, p1_left = s_kbd_left, p1_right = s_kbd_right;
int p1_fire = s_kbd_fire;
diff --git a/src/interrupts.c b/src/interrupts.c
index f537287..387a247 100644
--- a/src/interrupts.c
+++ b/src/interrupts.c
@@ -232,11 +232,27 @@ void _Int3TimerHandler(void)
/* debugMode LINE-A trap skipped (dead code in non-debug builds) */
/* isr_update_ticks_and_input */
+#ifdef SWOS_SDL_BUILD
+ /* On Amiga this IS the VBlank interrupt, so BOTH counters advance exactly
+ * once per game-loop iteration. On SDL they are driven from a wall clock by
+ * two threads — fine for play, but gameplay reads them (currentTick gates
+ * the ball-control speed bonus in ball_possession.c, currentGameTick gates
+ * most of the AI's phase decisions), so a replay would not reproduce. The
+ * rig takes both over and advances them itself, once per frame. */
+ { extern int ReplayTest_OwnsGameTick(void);
+ if (!ReplayTest_OwnsGameTick()) _currentTick++; }
+#else
_currentTick++;
+#endif
if (_showingUserStats == 0 && _paused == 0)
{
+#ifdef SWOS_SDL_BUILD
+ { extern int ReplayTest_OwnsGameTick(void);
+ if (!ReplayTest_OwnsGameTick()) _currentGameTick++; }
+#else
_currentGameTick++;
+#endif
/* Key repeat logic: keyDelay is negative when counting down */
if (_keyDelay < 0)
diff --git a/src/main.c b/src/main.c
index 2edf6a0..dc5f9b9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,6 +36,7 @@
#include "save_format_json.h" /* DataJson_SelfTest */
#include "dos_mode.h" /* gDosGraphics/gDosGameplay — defined in dos_graphics.c */
#include "display.h" /* _screen_width, WIDESCREEN_WIDTH, SCREEN_WIDTH */
+#include "replay_test.h" /* --replay-test: recorded-game regression rig */
#define WIN_SCALE 3
@@ -139,6 +140,23 @@ static void print_usage(const char *argv0)
" tuning). PC-only extra.\n"
" --dos-dir=<folder> Folder (under bin/) to load DOS assets from.\n"
" Default: grafs_dos.\n"
+ " --replay-test=<file.swr> Replay a recorded match and assert every frame\n"
+ " against the recording (docs/TESTS.md). Skips the\n"
+ " front end, runs unpaced, and exits 0 on a full\n"
+ " match, 2 on the first divergence. Build a .swr\n"
+ " with scripts/rgd_convert.py --emit.\n"
+ " --replay-level=<scalars|teams|info|sprites>\n"
+ " How much of each frame to compare. Default: the\n"
+ " level the .swr was emitted at.\n"
+ " --replay-selftest Check CalculateDeltaXAndY against swos-port's\n"
+ " reference vectors and exit. No recording needed.\n"
+ " --replay-skip=<a,b,...> Mute every field whose name contains one of these\n"
+ " substrings, e.g. '.starting_direction' (all 33\n"
+ " sprites) or 'top_info.'.\n"
+ " --replay-max-errors=<N> Keep going past a divergence and report up to N\n"
+ " mismatching fields. Default: 1 (stop at the\n"
+ " first — gameplay is chaotic, so everything after\n"
+ " it is noise).\n"
" -h, --help Show this help and exit.\n",
argv0 ? argv0 : "SWOS");
}
@@ -217,6 +235,8 @@ int main(int argc, char **argv)
snprintf(opts.arcade_key_p2_start, sizeof opts.arcade_key_p2_start, "%s", "2");
snprintf(opts.arcade_key_service, sizeof opts.arcade_key_service, "%s", "F2");
snprintf(opts.dos_dir, sizeof opts.dos_dir, "%s", "grafs_dos");
+ const char *replay_file = NULL, *replay_level = NULL, *replay_skip = NULL;
+ int replay_max_errors = 1;
snprintf(opts.language, sizeof opts.language, "%s", "en");
snprintf(opts.currency, sizeof opts.currency, "%s", "pound");
@@ -298,6 +318,20 @@ int main(int argc, char **argv)
}
} else if ((v = match_kv(a, "dos-dir")) != NULL) {
snprintf(opts.dos_dir, sizeof opts.dos_dir, "%s", v);
+ } else if ((v = match_kv(a, "replay-test")) != NULL) {
+ replay_file = v;
+ } else if ((v = match_kv(a, "replay-level")) != NULL) {
+ replay_level = v;
+ } else if (strcmp(a, "--replay-selftest") == 0) {
+ return ReplayTest_MathSelfTest();
+ } else if ((v = match_kv(a, "replay-skip")) != NULL) {
+ replay_skip = v;
+ } else if ((v = match_kv(a, "replay-max-errors")) != NULL) {
+ replay_max_errors = atoi(v);
+ if (replay_max_errors < 1) {
+ fprintf(stderr, "Invalid --replay-max-errors value '%s' (expected >= 1)\n", v);
+ return 1;
+ }
} else if (strcmp(a, "-h") == 0 || strcmp(a, "--help") == 0) {
print_usage(argv[0]);
return 0;
@@ -308,6 +342,26 @@ int main(int argc, char **argv)
}
}
+ /* A replay test is a batch run: unpace the frame loop (the game clock is
+ * driven per-iteration by the rig, not by the wall clock), skip the loader
+ * intro, and keep the log on the terminal where the test output belongs.
+ * Both are read inside Platform_Init, so they must be set before it. */
+ if (replay_file) {
+#ifdef _WIN32
+ _putenv("SWOS_HARNESS_TURBO=1");
+ _putenv("SWOS_NO_LOG=1");
+#else
+ setenv("SWOS_HARNESS_TURBO", "1", 1);
+ setenv("SWOS_NO_LOG", "1", 1);
+#endif
+ opts.dos_gameplay = 1; /* the corpus is DOS gameplay (docs/TESTS.md 5c) */
+ /* Replay at the port's OWN native view, not the tester's monitor:
+ * SWOS's camera constants are all derived from the view size, so a
+ * widescreen render puts the camera somewhere else entirely. */
+ opts.res_w = SCREEN_WIDTH;
+ opts.res_h = SCREEN_HEIGHT;
+ }
+
/* Publish DOS-mode flags for the game code (default = Amiga graphics). */
_gDosGraphics = opts.dos_graphics;
{ extern int _gArcadeMode; _gArcadeMode = opts.arcade; }
@@ -411,6 +465,15 @@ int main(int argc, char **argv)
}
_menu_draw_x_offset = WIDE_MARGIN;
+ /* Arm the replay rig before the bootstrap: SWOS.c enters it in place of
+ * the front-end loop once the game data is loaded. Parsing here means a
+ * bad path or a stale .swr fails immediately, not after the intro. */
+ if (replay_file &&
+ ReplayTest_Load(replay_file, replay_level, replay_max_errors, replay_skip) != 0) {
+ SDL_Quit();
+ return 1;
+ }
+
if (Platform_Init(&opts) != 0) {
fprintf(stderr, "Platform_Init failed\n");
SDL_Quit();
diff --git a/src/math68k.c b/src/math68k.c
index 1270118..e7aa510 100644
--- a/src/math68k.c
+++ b/src/math68k.c
@@ -239,11 +239,23 @@ uint16_t CalculateDeltaXAndY(int16_t destX, int16_t destY,
* frame rate doesn't play faster — reproduces swos-2020's CalculateDeltaXAndY_125
* hook, injected at this routine's tail (symbols.txt:2083 -> render.cpp:4682).
* DOS/PC 70fps = 41/64; Amiga 50fps = 1/1 (no-op, so the Amiga build and normal
- * 50fps play are byte-for-byte unchanged). Integer `* num / den` matches
- * swos-2020's truncation. Callers reading only `dir` (AI goal-angle, tactics
- * arrows) are unaffected; every mover using the deltas is scaled, as in
- * swos-2020. See docs/DOS_GAMEPLAY.md §8.3. */
- if (_gMoveDeltaScaleNum != _gMoveDeltaScaleDen) {
+ * 50fps play are byte-for-byte unchanged). Callers reading only `dir` (AI
+ * goal-angle, tactics arrows) are unaffected. See docs/DOS_GAMEPLAY.md §8.3.
+ *
+ * 41/64 is done as a chain of ARITHMETIC SHIFTS, not `* 41 / 64`:
+ * x - x/4 - x/16 - x/32 - x/64 == x * (64-16-4-2-1)/64 == x * 41/64
+ * Each shift floors, while C division truncates toward zero, so the two
+ * disagree by one on negative deltas — and that one unit compounds into a
+ * different trajectory within a few frames. swos-port hit the same thing
+ * (updateSprite.cpp: "shifts have to be used explicitly, divisions end up
+ * with slightly different result"), and the replay rig caught ours:
+ * delta_x -93531 where the recording had -93530. `--replay-selftest` runs
+ * the reference vectors for this routine. */
+ if (_gMoveDeltaScaleNum == 41 && _gMoveDeltaScaleDen == 64) {
+ int32_t dx = *outDeltaX, dy = *outDeltaY;
+ *outDeltaX = dx - (dx >> 2) - (dx >> 4) - (dx >> 5) - (dx >> 6);
+ *outDeltaY = dy - (dy >> 2) - (dy >> 4) - (dy >> 5) - (dy >> 6);
+ } else if (_gMoveDeltaScaleNum != _gMoveDeltaScaleDen) {
*outDeltaX = *outDeltaX * _gMoveDeltaScaleNum / _gMoveDeltaScaleDen;
*outDeltaY = *outDeltaY * _gMoveDeltaScaleNum / _gMoveDeltaScaleDen;
}
diff --git a/src/random.c b/src/random.c
index 0c6d360..ac85157 100644
--- a/src/random.c
+++ b/src/random.c
@@ -7,6 +7,18 @@
#include "deterministic.h"
#include "game_types.h"
+#ifdef SWOS_SDL_BUILD
+/* Recorded-game replay pins BOTH generators to the recording's
+ * fixedRandomValue (docs/TESTS.md 5c) — without it nothing is reproducible.
+ * -1 (the default) leaves the real PRNGs alone. Defined in replay_test.c. */
+extern int _replayFixedRandom;
+#define REPLAY_FIXED_RAND() do { \
+ if (_replayFixedRandom >= 0) return (uint16_t)_replayFixedRandom; \
+} while (0)
+#else
+#define REPLAY_FIXED_RAND() do { } while (0)
+#endif
+
/* ---- External globals (all live in SWOS2.s) ---- */
extern uint8_t _kRandomTable[]; /* 257-byte lookup table */
extern uint8_t _seed; /* primary PRNG seed/counter (in code section) */
@@ -28,7 +40,10 @@ extern void PanicHaltLoop(void) __attribute__((noreturn));
__attribute__((used, externally_visible))
uint16_t Rand(void)
{
- uint16_t d0 = _seed & 0xFFu;
+ uint16_t d0;
+
+ REPLAY_FIXED_RAND();
+ d0 = _seed & 0xFFu;
if (d0 == 0)
{
@@ -50,7 +65,10 @@ uint16_t Rand(void)
__attribute__((used, externally_visible))
uint16_t Rand2(void)
{
- uint16_t d0 = _seed2 & 0xFFu;
+ uint16_t d0;
+
+ REPLAY_FIXED_RAND();
+ d0 = _seed2 & 0xFFu;
if (d0 == 0)
{
```
---
### 3399d34 [VIEW] sim view: replay at the recording's own geometry, and run headless
_2026-09-03_
```diff
diff --git a/include/display.h b/include/display.h
index 5a8a62e..c200c38 100644
--- a/include/display.h
+++ b/include/display.h
@@ -404,6 +404,53 @@ extern int _screen_width;
#define FRONTBUFFER_MAX_STRIDE_BYTES ROW_STRIDE_BYTES
#define FRONTBUFFER_ROW_STRIDE_BYTES ROW_STRIDE_BYTES
#endif
+
+/* ---- The SIMULATION view --------------------------------------------------
+ * SWOS's gameplay reads the view size, not just the renderer: the `onScreen`
+ * cull decides which players auto-selection may pick (GAMEPLAY.md §5, §25.2),
+ * and every camera constant is derived from the view —
+ *
+ * kick-off centre X (672 - viewW) / 2 168 at 336, 176 at 320
+ * bottom start Y 664 - (viewH - 200) 592 at 272, 664 at 200
+ * camera centre Y viewH / 2 136 at 272, 100 at 200
+ * pan range 672 - viewW 336 at 336, 352 at 320
+ * target Y clamp 664 - (viewH - 200) 592 at 272, 664 at 200
+ * position Y clamp 880 - viewH 608 at 272, 680 at 200
+ * (= swos-port's kCameraMaxY)
+ *
+ * — which is why the port's hard-coded 168/592/0x88/0x250 are all f(336, 272),
+ * and why the same formulas reproduce the DOS release's own constants at
+ * (320, 200). Keeping that size separate from the RENDER width lets the
+ * recorded-game replay rig (docs/TESTS.md) simulate at the geometry a
+ * recording was made in while still drawing at whatever the display wants.
+ *
+ * Default: exactly today's behaviour — the live render width and the fixed
+ * 272 line count — so nothing changes for a player unless something sets it.
+ * (GAMEPLAY.md §25.4 notes that pinning this to 336x272 regardless of the
+ * render width is the fix for widescreen changing CPU player selection; that
+ * is a deliberate gameplay change and is NOT what the default does.) */
+#ifdef SWOS_SDL_BUILD
+extern int16_t _sim_view_width;
+extern int16_t _sim_view_height;
+#else
+/* Amiga has no widescreen and no replay rig, so the simulation view IS the
+ * hardware view — fold to compile-time constants and the m68k codegen for
+ * every site below is byte-for-byte what it was before this existed. */
+#define _sim_view_width SCREEN_WIDTH
+#define _sim_view_height SCREEN_HEIGHT
+#endif
+
+/* The camera constants above, as functions of the simulation view. */
+#define SIM_CAMERA_CENTRE_X ((int16_t)((0x2A0 - _sim_view_width) / 2))
+#define SIM_CAMERA_PAN_RANGE ((int16_t)(0x2A0 - _sim_view_width))
+#define SIM_CAMERA_CENTRE_Y ((int16_t)(_sim_view_height / 2))
+/* The camera DESTINATION clamp (where MoveCamera may aim). */
+#define SIM_CAMERA_MAX_Y ((int16_t)(664 - (_sim_view_height - 200)))
+#define SIM_CAMERA_MAX_Y_TRN ((int16_t)(616 - (_sim_view_height - 200)))
+/* The camera POSITION clamp — keeps the view inside the 880-tall pitch. 0x260
+ * at 272 lines; swos-port's kCameraMaxY = 680 at 200. */
+#define SIM_CAMERA_POS_MAX_Y ((int16_t)(880 - _sim_view_height))
+
#define FRONTBUFFER_VISIBLE_LINES SCREEN_HEIGHT
#define FRONTBUFFER_TOTAL_LINES (SCREEN_HEIGHT + 1)
/* AGA block-B elimination: ONLY the two display frontbuffers (base/alt) are 2x
diff --git a/src/camera.c b/src/camera.c
index ace57f0..d347071 100644
--- a/src/camera.c
+++ b/src/camera.c
@@ -79,14 +79,17 @@ void MoveView(int16_t newScreenX, int16_t newScreenY)
if (_playHighlightFlag != 0) {
/* X: 0x2A0 (pitch world width) - _screen_width is the max camera X — the
* same clamp SetCameraCoordinates applies. No-op at 4:3 / on Amiga. */
- int16_t panRange = (int16_t)(0x2A0 - _screen_width);
+ int16_t panRange = SIM_CAMERA_PAN_RANGE;
if (panRange < 0) panRange = 0;
if (newScreenX < 0) newScreenX = 0;
else if (newScreenX > panRange) newScreenX = panRange;
/* Y: the live camera's vertical range [0x10, 0x260]. A DOS HIL captured
* in a 200px-tall view reaches ~0x295, which on our taller (272px)
- * playback view would pan past the bottom into the green surround. */
+ * playback view would pan past the bottom into the green surround.
+ * This one stays keyed to the PLAYBACK view (0x260), not the
+ * simulation view: it exists precisely to re-fit a foreign recording
+ * to the window we are drawing in. */
if (newScreenY < 0x10) newScreenY = 0x10;
else if (newScreenY > 0x260) newScreenY = 0x260;
}
diff --git a/src/game_loop.c b/src/game_loop.c
index 0b182c9..a51ab0c 100644
--- a/src/game_loop.c
+++ b/src/game_loop.c
@@ -599,15 +599,20 @@ GameLoop(void)
_fadeAndSaveHighlightScene = 0;
_spaceReplayTimer = 0;
+ /* Training starts at a fixed (168, 313) in both releases. A match starts
+ * centred horizontally on one of the two goal ends, and both of those are
+ * functions of the SIMULATION view (display.h): 168/592 at the port's own
+ * 336x272, and 176/664 — swos-port's kCenterX / kBottomStartLocationY — at
+ * the DOS release's 320x200. */
d1 = 168;
d2 = 313;
if (_trainingGame == 0) {
uint16_t r = Rand();
if (r & 1)
- d2 = 592;
+ d2 = SIM_CAMERA_MAX_Y; /* bottom end: 592 at 272 lines */
else
- d2 = 16;
- d1 = 168;
+ d2 = 16; /* top end: the same in both */
+ d1 = SIM_CAMERA_CENTRE_X; /* 168 at 336 wide */
}
ReplayUpdateCameraAndSwapBuffers(d1, d2);
diff --git a/src/main.c b/src/main.c
index dc5f9b9..21d30b0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -148,6 +148,9 @@ static void print_usage(const char *argv0)
" --replay-level=<scalars|teams|info|sprites>\n"
" How much of each frame to compare. Default: the\n"
" level the .swr was emitted at.\n"
+ " --replay-window Open a window during --replay-test. Off by\n"
+ " default: a replay is a batch run and a full\n"
+ " matrix would open one window per cell.\n"
" --replay-selftest Check CalculateDeltaXAndY against swos-port's\n"
" reference vectors and exit. No recording needed.\n"
" --replay-skip=<a,b,...> Mute every field whose name contains one of these\n"
@@ -237,6 +240,7 @@ int main(int argc, char **argv)
snprintf(opts.dos_dir, sizeof opts.dos_dir, "%s", "grafs_dos");
const char *replay_file = NULL, *replay_level = NULL, *replay_skip = NULL;
int replay_max_errors = 1;
+ int replay_window = 0;
snprintf(opts.language, sizeof opts.language, "%s", "en");
snprintf(opts.currency, sizeof opts.currency, "%s", "pound");
@@ -322,6 +326,8 @@ int main(int argc, char **argv)
replay_file = v;
} else if ((v = match_kv(a, "replay-level")) != NULL) {
replay_level = v;
+ } else if (strcmp(a, "--replay-window") == 0) {
+ replay_window = 1;
} else if (strcmp(a, "--replay-selftest") == 0) {
return ReplayTest_MathSelfTest();
} else if ((v = match_kv(a, "replay-skip")) != NULL) {
@@ -350,9 +356,19 @@ int main(int argc, char **argv)
#ifdef _WIN32
_putenv("SWOS_HARNESS_TURBO=1");
_putenv("SWOS_NO_LOG=1");
+ if (!replay_window && !getenv("SDL_VIDEODRIVER"))
+ _putenv("SDL_VIDEODRIVER=dummy");
#else
setenv("SWOS_HARNESS_TURBO", "1", 1);
setenv("SWOS_NO_LOG", "1", 1);
+ /* Headless by default: a replay is a batch run, and a full matrix opens
+ * one window per cell. The dummy video driver keeps every buffer and
+ * blit real — the game still renders into the frontbuffer, which is
+ * what the simulation reads back — it just never opens a window.
+ * --replay-window opts back in to watching it. Respect an
+ * SDL_VIDEODRIVER the caller set explicitly. */
+ if (!replay_window && !getenv("SDL_VIDEODRIVER"))
+ setenv("SDL_VIDEODRIVER", "dummy", 1);
#endif
opts.dos_gameplay = 1; /* the corpus is DOS gameplay (docs/TESTS.md 5c) */
/* Replay at the port's OWN native view, not the tester's monitor:
@@ -463,6 +479,15 @@ int main(int argc, char **argv)
fprintf(stderr, "[video] render %dx%d (screen %d/%d, resolution %dx%d, %.2f:1)\n",
_screen_width, SCREEN_HEIGHT, opts.screen, nd, dw, dh, (double)dw / dh);
}
+ /* Keep the SIMULATION view (display.h) equal to the render width, which is
+ * exactly what the gameplay culls and camera math used before it existed —
+ * so this is a no-op for a player. Only the replay rig overrides it.
+ * (GAMEPLAY.md §25.4: pinning it to SCREEN_WIDTH x SCREEN_HEIGHT instead
+ * would stop a widescreen render from changing CPU player selection. That
+ * is a deliberate gameplay change, not this line.) */
+ _sim_view_width = (int16_t)_screen_width;
+ _sim_view_height = SCREEN_HEIGHT;
+
_menu_draw_x_offset = WIDE_MARGIN;
/* Arm the replay rig before the bootstrap: SWOS.c enters it in place of
diff --git a/src/move_camera.c b/src/move_camera.c
index cc98d13..4918022 100644
--- a/src/move_camera.c
+++ b/src/move_camera.c
@@ -292,8 +292,11 @@ bench_camera_target_and_zero_vel:
offset_and_clamp_to_view:
/* Center the view: subtract half screen dimensions */
- targetX -= (_screen_width / 2); /* half the view width: 168 (336) / 192 (384 widescreen) */
- targetY -= 0x88; /* 136 */
+ /* Centre the view on the target. Both halves come from the SIMULATION view
+ * (display.h), not the render width: 168/136 at the port's own 336x272,
+ * 160/100 at the DOS release's 320x200. */
+ targetX -= (_sim_view_width / 2);
+ targetY -= SIM_CAMERA_CENTRE_Y;
/* Apply camera velocity */
targetX += (int16_t)_cameraXVelocity;
@@ -305,7 +308,7 @@ offset_and_clamp_to_view:
* view on the pitch (=0x150 at 336). On wide/ultrawide displays the view nears
* the pitch width and this range collapses or inverts — then just center the
* view on the pitch (the whole pitch is visible; the camera can't pan). */
- int16_t panRange = (int16_t)(0x2A0 - _screen_width);
+ int16_t panRange = SIM_CAMERA_PAN_RANGE;
int16_t xMax = panRange - boundsMargin;
if (xMax <= boundsMargin) {
targetX = (int16_t)(panRange / 2);
@@ -321,13 +324,13 @@ offset_and_clamp_to_view:
if (_trainingGame != 0) {
if (targetY <= 0x50)
targetY = 0x50;
- if (targetY >= 0x220)
- targetY = 0x220;
+ if (targetY >= SIM_CAMERA_MAX_Y_TRN) /* 0x220 = 544 at 272 lines */
+ targetY = SIM_CAMERA_MAX_Y_TRN;
} else {
if (targetY <= 0x10)
targetY = 0x10;
- if (targetY >= 0x250)
- targetY = 0x250;
+ if (targetY >= SIM_CAMERA_MAX_Y) /* 0x250 = 592 at 272 lines */
+ targetY = SIM_CAMERA_MAX_Y;
}
/* ---- Compute fixed-point delta from current camera position ---- */
@@ -385,13 +388,13 @@ offset_and_clamp_to_view:
/* Final clamp of integer position */
if (newIntX < 0)
newIntX = 0;
- if (newIntX >= (int16_t)(0x2A0 - _screen_width)) /* pitchWidth - viewWidth */
- newIntX = (int16_t)(0x2A0 - _screen_width);
+ if (newIntX >= SIM_CAMERA_PAN_RANGE) /* pitchWidth - viewWidth */
+ newIntX = SIM_CAMERA_PAN_RANGE;
if (newIntY < 0x10)
newIntY = 0x10;
- if (newIntY >= 0x260)
- newIntY = 0x260;
+ if (newIntY >= SIM_CAMERA_POS_MAX_Y) /* 0x260 = 880 - 272 lines */
+ newIntY = SIM_CAMERA_POS_MAX_Y;
SetCameraCoordinates(newIntX, newIntY);
_cameraCoordinatesValid = 0;
diff --git a/src/sprites.c b/src/sprites.c
index 84a7ead..6f67367 100644
--- a/src/sprites.c
+++ b/src/sprites.c
@@ -2342,8 +2342,12 @@ void BuildSpriteBandAndGeneralRenderStacks(void)
int16_t d2 = a1->y.s.i - a0->centerY - _cameraY.s.i;
d2 -= a1->z.s.i;
- /* Cull if off-screen */
- if (d1 >= _screen_width || d2 >= SCREEN_HEIGHT) {
+ /* Cull if off-screen. This is a GAMEPLAY decision as well as a render
+ * one — UpdateControlledPlayer will not auto-select a player whose
+ * onScreen is clear (GAMEPLAY.md §5, §25.2) — so it keys off the
+ * SIMULATION view, which defaults to the render width but which the
+ * replay rig sets to the geometry a recording was made in. */
+ if (d1 >= _sim_view_width || d2 >= _sim_view_height) {
a1->onScreen = 0;
d7--;
if (d7 < 0) break;
diff --git a/src/swos_globals.c b/src/swos_globals.c
index bc71f17..97705af 100644
--- a/src/swos_globals.c
+++ b/src/swos_globals.c
@@ -104,6 +104,14 @@ SWOS_CHIP_BSS uint8_t _frontbufferMaskBuffer[FRONTBUFFER_ALLOC_TOTAL_BYTES];
/* Live frontbuffer stride / visible width: SCREEN_WIDTH (336) or WIDESCREEN_WIDTH,
* set once at startup from gWidescreen (main.c). 336 = unchanged behaviour. */
int _screen_width = SCREEN_WIDTH;
+#ifdef SWOS_SDL_BUILD
+/* The SIMULATION view (display.h). Defaults to the port's own geometry; main.c
+ * follows _screen_width into it so behaviour is unchanged, and the replay rig
+ * overrides it to the geometry a recording was made in. On Amiga these are
+ * compile-time constants (display.h), so there is nothing to define. */
+int16_t _sim_view_width = SCREEN_WIDTH;
+int16_t _sim_view_height = SCREEN_HEIGHT;
+#endif
#endif
/* Per-draw X shift for centering 336-wide menu content in a widescreen frame. Set to
* WIDE_MARGIN only around the menu entry-draw loop; 0 everywhere else (and on Amiga). */
```
---
### 22f370a [AMIGA] fix: onScreen culled to the render width, and was overwritten after enqueue
_2026-09-03_
```diff
diff --git a/src/image_cmd.c b/src/image_cmd.c
index 1c40806..a5a71c0 100644
--- a/src/image_cmd.c
+++ b/src/image_cmd.c
@@ -10,7 +10,8 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
-int _debug_sprite_load = 0; /* flip to 1 in gdb to trace extracts */
+#include <stdlib.h> /* getenv — SWOS_DEBUG_SPRITE_LOAD */
+int _debug_sprite_load = 0; /* flip to 1 in gdb, or set SWOS_DEBUG_SPRITE_LOAD=1 */
__attribute__((constructor))
static void unbuf_stderr(void) { setbuf(stderr, NULL); }
#endif
@@ -132,8 +133,8 @@ static void blitDispatch(uint16_t spriteIndex, uint16_t xOffset, uint16_t yOffse
{
extern int _debug_sprite_load;
if (_debug_sprite_load) {
- fprintf(stderr, "[sprite] extract idx=0x%03X w=%u h=%u at 0x%08x src=%s\n",
- spriteIndex, width, height, (unsigned)(uintptr_t)headerBase,
+ fprintf(stderr, "[sprite] extract idx=0x%03X (%u) w=%u h=%u cx=%d cy=%d src=%s\n",
+ spriteIndex, spriteIndex, width, height, (int)dstX, (int)dstY,
src == (uint8_t *)0 ? "CHECKERBOARD" : "buf");
}
}
@@ -410,6 +411,13 @@ update_cursor:
__attribute__((used, externally_visible, optimize("no-tree-loop-distribute-patterns")))
void ProcessImageCommandStream(const uint16_t *cmdBuffer, uint8_t *workBuffer)
{
+#ifdef SWOS_SDL_BUILD
+ /* SWOS_DEBUG_SPRITE_LOAD=1 traces every extract with its hotspot, which is
+ * what the onScreen cull reads — useful for comparing our bank's metrics
+ * against another release's (docs/TESTS.md). */
+ { static int probed; if (!probed) { probed = 1;
+ if (getenv("SWOS_DEBUG_SPRITE_LOAD")) _debug_sprite_load = 1; } }
+#endif
const uint8_t *a0 = (const uint8_t *)cmdBuffer;
uint16_t opcode, opcodeType;
uint16_t spriteIndex, xOff, yOff, w, h, maskSel;
diff --git a/src/main.c b/src/main.c
index 21d30b0..1f4b34a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -479,13 +479,15 @@ int main(int argc, char **argv)
fprintf(stderr, "[video] render %dx%d (screen %d/%d, resolution %dx%d, %.2f:1)\n",
_screen_width, SCREEN_HEIGHT, opts.screen, nd, dw, dh, (double)dw / dh);
}
- /* Keep the SIMULATION view (display.h) equal to the render width, which is
- * exactly what the gameplay culls and camera math used before it existed —
- * so this is a no-op for a player. Only the replay rig overrides it.
- * (GAMEPLAY.md §25.4: pinning it to SCREEN_WIDTH x SCREEN_HEIGHT instead
- * would stop a widescreen render from changing CPU player selection. That
- * is a deliberate gameplay change, not this line.) */
- _sim_view_width = (int16_t)_screen_width;
+ /* The SIMULATION view (display.h) is the port's own fixed geometry, NOT the
+ * render width. SWOS reads the view size from inside the simulation — the
+ * onScreen cull decides which players auto-selection may pick — so tying
+ * it to the render width made a widescreen display change CPU behaviour:
+ * a 650-wide view admits men the Amiga culls, and the nearest-to-the-ball
+ * choice changes. Pinning it here means every display plays the same game
+ * and the renderer simply draws wider (GAMEPLAY.md §25.4/§25.5).
+ * The replay rig overrides it to the geometry a recording was made in. */
+ _sim_view_width = SCREEN_WIDTH;
_sim_view_height = SCREEN_HEIGHT;
_menu_draw_x_offset = WIDE_MARGIN;
diff --git a/src/sprites.c b/src/sprites.c
index 6f67367..2142585 100644
--- a/src/sprites.c
+++ b/src/sprites.c
@@ -2342,30 +2342,39 @@ void BuildSpriteBandAndGeneralRenderStacks(void)
int16_t d2 = a1->y.s.i - a0->centerY - _cameraY.s.i;
d2 -= a1->z.s.i;
- /* Cull if off-screen. This is a GAMEPLAY decision as well as a render
- * one — UpdateControlledPlayer will not auto-select a player whose
- * onScreen is clear (GAMEPLAY.md §5, §25.2) — so it keys off the
- * SIMULATION view, which defaults to the render width but which the
- * replay rig sets to the geometry a recording was made in. */
- if (d1 >= _sim_view_width || d2 >= _sim_view_height) {
- a1->onScreen = 0;
- d7--;
- if (d7 < 0) break;
- continue;
- }
+ /* Two culls, deliberately: one decides GAMEPLAY, the other DRAWING.
+ *
+ * `onScreen` is a simulation input — UpdateControlledPlayer will not
+ * auto-select a player whose onScreen is clear (GAMEPLAY.md §5, §25.2)
+ * — so it must NOT depend on the display. Keying it off the live
+ * render width meant a widescreen player faced a different CPU: a
+ * 650-wide view admits men the Amiga culls, one of them is nearer the
+ * ball, and the selection changes. GAMEPLAY.md §25.4.
+ *
+ * The window is 336 wide and _sim_view_height tall, and the width is a
+ * CONSTANT rather than the view: measured against the DOS recordings,
+ * whose visible screen is 320 wide, a sprite is recorded onScreen out
+ * to camera-relative x 335 and off from 336 (42032 samples across
+ * zkz-12065730, per-image centerX/pixWidth taken from the DOS banks —
+ * clean separation, no overlap). Both releases cull to a 336-wide
+ * buffer; only the height follows the display (200 DOS, 272 Amiga),
+ * which is also what the same measurement gives: on out to y 199.
+ *
+ * Whether to ENQUEUE the sprite is a rendering question and keys off
+ * the render width, so a wide display still draws everything it can
+ * fit — the renderer draws wider than the simulation sees, which is
+ * exactly what §25.5 prescribes. The render view is never narrower
+ * than the simulation view (main.c clamps _screen_width to at least
+ * SCREEN_WIDTH), so this only ever draws MORE, never less. */
{
int16_t negW = -a0->pixWidth;
- if (d1 <= negW) {
- a1->onScreen = 0;
- d7--;
- if (d7 < 0) break;
- continue;
- }
- }
- {
int16_t negH = -a0->nlines;
- if (d2 <= negH) {
- a1->onScreen = 0;
+ int onScreen = !(d1 >= SCREEN_WIDTH || d2 >= _sim_view_height ||
+ d1 <= negW || d2 <= negH);
+ int inRenderView = !(d1 >= _screen_width || d2 >= SCREEN_HEIGHT ||
+ d1 <= negW || d2 <= negH);
+ a1->onScreen = (int16_t)onScreen;
+ if (!inRenderView) {
d7--;
if (d7 < 0) break;
continue;
@@ -2490,8 +2499,12 @@ post_enqueue:
a3[rightBucket >> 1] = d2;
}
- /* Mark sprite as on-screen */
- a1->onScreen = 1;
+ /* onScreen was already decided by the SIMULATION cull above, and this
+ * used to overwrite it with 1 for anything that reached the enqueue.
+ * That was harmless while the two culls were the same test, and wrong
+ * the moment they are not: a sprite outside the simulation's window
+ * but inside the render view gets drawn (correct) and must still read
+ * as off-screen to the game (which this line was undoing). */
#if defined(DETERMINISTIC_MODE) && DETERMINISTIC_SPRITE_LIMIT > 0
spritesEnqueued++;
#endif
```
---
### 47bb535 [FLAG] tactics: make the four corrected formations build-selectable
_2026-09-03_
```diff
diff --git a/src/tactics_data.c b/src/tactics_data.c
index 76c0b2b..9bf698d 100644
--- a/src/tactics_data.c
+++ b/src/tactics_data.c
@@ -285,10 +285,119 @@ extern TeamTactics _teamTacticsUSERF;
* Pointer table for all 19 tactics (18 formations + editor copy)