-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrevs-doningtonpark.asm
4184 lines (3592 loc) · 175 KB
/
revs-doningtonpark.asm
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
\ ******************************************************************************
\
\ REVS DONINGTON PARK TRACK SOURCE
\
\ Revs was written by Geoffrey J Crammond and is copyright Acornsoft 1985
\
\ The code on this site has been reconstructed from a disassembly of the
\ original game binaries
\
\ The commentary is copyright Mark Moxon, and any misunderstandings or mistakes
\ in the documentation are entirely my fault
\
\ The terminology and notations used in this commentary are explained at
\ https://revs.bbcelite.com/terminology
\
\ The deep dive articles referred to in this commentary can be found at
\ https://revs.bbcelite.com/deep_dives
\
\ ------------------------------------------------------------------------------
\
\ This source file produces the following binary file:
\
\ * DoningtonPark.bin
\
\ ******************************************************************************
GUARD &7C00 \ Guard against assembling over screen memory
\ ******************************************************************************
\
\ Configuration variables
\
\ ******************************************************************************
CODE% = &5300 \ The assembly address of the track data
LOAD% = &70DB \ The load address of the track binary
trackWidth = 134 \ Track width
\ ******************************************************************************
\
\ Addresses in the main game code
\
\ ******************************************************************************
thisSectionFlags = &0001
thisVectorNumber = &0002
yStore = &001B
horizonLine = &001F
frontSegmentIndex = &0024
directionFacing = &0025
segmentCounter = &0042
playerPastSegment = &0043
xStore = &0045
vergeBufferEnd = &004B
horizonListIndex = &0051
playerSpeedHi = &0063
currentPlayer = &006F
T = &0074
U = &0075
V = &0076
W = &0077
topTrackLine = &007F
blockOffset = &0082
objTrackSection = &06E8
objSectionSegmt = &0880
Multiply8x8 = &0C00
Absolute16Bit = &0E40
MovePlayerForward = &12F3
UpdateVectorNumber = &13E0
MovePlayerBack = &140B
CheckVergeOnScreen = &1933
gseg13 = &2490
gtrm2 = &2535
Absolute8Bit = &3450
MultiplyHeight = &4610
xTrackSegmentI = &5400
yTrackSegmentI = &5500
zTrackSegmentI = &5600
xTrackSegmentO = &5700
zTrackSegmentO = &5800
trackSectionFrom = &5905
xVergeRightHi = &5E90
xVergeLeftHi = &5EB8
yVergeRight = &5F20
yVergeLeft = &5F48
backgroundColour = &5F60
playerDrift = &62FB
\ ******************************************************************************
\
\ REVS DONINGTON PARK TRACK
\
\ Produces the binary file DoningtonPark.bin that contains the Donington Park
\ track.
\
\ ******************************************************************************
ORG CODE%
.trackData
\ ******************************************************************************
\
\ Name: Track section data (Part 1 of 2)
\ Type: Variable
\ Category: Extra tracks
\ Summary: Data for the track sections
\ Deep dive: The track data file format
\ The extra tracks data file format
\ The Donington Park track
\
\ ------------------------------------------------------------------------------
\
\ Donington Park consists of the following track sections:
\
\ 0 || Coppice to Park Chicane (1/2)
\ 1 {} Coppice to Park Chicane (2/2)
\ 2 |->| Park Chicane (1/2)
\ 3 <- Park Chicane (2/2)
\ 4 {} Park Chicane to Redgate (1/2)
\ 5 |->| Park Chicane to Redgate (2/2)
\ 6 -> Redgate
\ 7 |->| Redgate to Craner Curves
\ 8 -> Craner Curves
\ 9 {} Craner Curves to The Old Hairpin (1/3)
\ 10 <- Craner Curves to The Old Hairpin (2/3)
\ 11 |->| Craner Curves to The Old Hairpin (3/3)
\ 12 -> The Old Hairpin
\ 13 || The Old Hairpin to Macleans (1/6)
\ 14 <- The Old Hairpin to Macleans (2/6)
\ 15 |<-| The Old Hairpin to Macleans (3/6)
\ 16 || The Old Hairpin to Macleans (4/6)
\ 17 <- The Old Hairpin to Macleans (5/6)
\ 18 -> The Old Hairpin to Macleans (6/6)
\ 19 -> Macleans
\ 20 {} Macleans to Coppice (1/2)
\ 21 {} Macleans to Coppice (2/2)
\ 22 -> Coppice (1/3)
\ 23 -> Coppice (2/3)
\ 24 -> Coppice (3/3)
\
\ where each section is one of the following shapes:
\
\ || is a straight section that doesn't curve to the left or right, and has
\ the same gradient throughout the whole section
\
\ {} is a straight section in the sense that it doesn't curve to the left or
\ right, but the gradient can differ between sub-sections
\
\ -> consists of sub-sections that all curve to the right
\
\ <- consists of sub-sections that all curve to the left
\
\ |->| consists of sub-sections that are either straight or curve to the right
\
\ |<-| consists of sub-sections that are either straight or curve to the left
\
\ |<->| consists of sub-sections that are either straight or curve to the left
\ or right
\
\ This part defines the following aspects of these track sections:
\
\ trackSectionData Various data for the track section:
\
\ * Bits 0-2: Size of the track section list
\
\ Defines the number of entries that we store in the
\ track section list for this section, which is used
\ to calculate the coordinates of the track verges
\ (higher numbers mean more sections are calculated,
\ so higher numbers are used for more complex parts
\ of the track)
\
\ This value is given in the bottom nibble of the
\ track section data byte (bit 3 is ignored), i.e. the
\ second digit in the hexadecimal value
\
\ * Bits 4-7: Sign number
\
\ The number of the road sign (0 to 15) to show when
\ we enter this section, but only if the sign number
\ is different to the number in the previous section
\
\ This value is given in the top nibble of the track
\ section data byte, i.e. the first digit in the
\ hexadecimal value
\
\ xTrackSectionIHi High byte of the x-coordinate of the starting point of
\ the inner verge of each track section
\
\ yTrackSectionIHi High byte of the y-coordinate of the starting point of
\ the inner verge of each track section
\
\ zTrackSectionIHi High byte of the z-coordinate of the starting point of
\ the inner verge of each track section
\
\ xTrackSectionOHi High byte of the x-coordinate of the starting point of
\ the outside verge of each track section
\
\ trackSectionTurn The number of the segment towards the end of the section
\ where non-player cars should start turning in
\ preparation for the next section
\
\ zTrackSectionOHi High byte of the z-coordinate of the starting point of
\ the outside verge of each track section
\
\ trackDriverSpeed The maximum speed for non-player drivers on the next
\ section of the track
\
\ ******************************************************************************
\ Track section 0
EQUB &D3 \ trackSectionData sign = 13, sectionListSize = 3
EQUB &D1 \ xTrackSectionIHi xTrackSectionI = &D120 = -12000
EQUB &1E \ yTrackSectionIHi yTrackSectionI = &1E00 = 7680
EQUB &D1 \ zTrackSectionIHi zTrackSectionI = &D120 = -12000
EQUB &D0 \ xTrackSectionOHi xTrackSectionO = &D024 = -12252
EQUB 255 \ trackSectionTurn
EQUB &D1 \ zTrackSectionOHi zTrackSectionO = &D120 = -12000
EQUB 255 \ trackDriverSpeed
\ Track section 1
EQUB &E1 \ trackSectionData sign = 14, sectionListSize = 1
EQUB &D1 \ xTrackSectionIHi xTrackSectionI = &D120 = -12000
EQUB &1C \ yTrackSectionIHi yTrackSectionI = &1CC4 = 7364
EQUB &F6 \ zTrackSectionIHi zTrackSectionI = &F628 = -2520
EQUB &D0 \ xTrackSectionOHi xTrackSectionO = &D024 = -12252
EQUB 63 \ trackSectionTurn
EQUB &F6 \ zTrackSectionOHi zTrackSectionO = &F628 = -2520
EQUB 81 \ trackDriverSpeed
\ Track section 2
EQUB &F3 \ trackSectionData sign = 15, sectionListSize = 3
EQUB &D1 \ xTrackSectionIHi xTrackSectionI = &D120 = -12000
EQUB &19 \ yTrackSectionIHi yTrackSectionI = &196C = 6508
EQUB &15 \ zTrackSectionIHi zTrackSectionI = &1590 = 5520
EQUB &D0 \ xTrackSectionOHi xTrackSectionO = &D024 = -12252
EQUB 8 \ trackSectionTurn
EQUB &15 \ zTrackSectionOHi zTrackSectionO = &1590 = 5520
EQUB 0 \ trackDriverSpeed
\ Track section 3
EQUB &F2 \ trackSectionData sign = 15, sectionListSize = 2
EQUB &D3 \ xTrackSectionIHi xTrackSectionI = &D372 = -11406
EQUB &19 \ yTrackSectionIHi yTrackSectionI = &196C = 6508
EQUB &18 \ zTrackSectionIHi zTrackSectionI = &1833 = 6195
EQUB &D3 \ xTrackSectionOHi xTrackSectionO = &D352 = -11438
EQUB 18 \ trackSectionTurn
EQUB &19 \ zTrackSectionOHi zTrackSectionO = &192C = 6444
EQUB 10 \ trackDriverSpeed
\ Track section 4
EQUB &04 \ trackSectionData sign = 0, sectionListSize = 4
EQUB &D7 \ xTrackSectionIHi xTrackSectionI = &D742 = -10430
EQUB &19 \ yTrackSectionIHi yTrackSectionI = &196C = 6508
EQUB &1B \ zTrackSectionIHi zTrackSectionI = &1B9A = 7066
EQUB &D6 \ xTrackSectionOHi xTrackSectionO = &D648 = -10680
EQUB 255 \ trackSectionTurn
EQUB &1B \ zTrackSectionOHi zTrackSectionO = &1BB5 = 7093
EQUB 255 \ trackDriverSpeed
\ Track section 5
EQUB &13 \ trackSectionData sign = 1, sectionListSize = 3
EQUB &DB \ xTrackSectionIHi xTrackSectionI = &DB04 = -9468
EQUB &15 \ yTrackSectionIHi yTrackSectionI = &1544 = 5444
EQUB &3E \ zTrackSectionIHi zTrackSectionI = &3E00 = 15872
EQUB &DA \ xTrackSectionOHi xTrackSectionO = &DA0A = -9718
EQUB 45 \ trackSectionTurn
EQUB &3E \ zTrackSectionOHi zTrackSectionO = &3E1B = 15899
EQUB 91 \ trackDriverSpeed
\ Track section 6
EQUB &23 \ trackSectionData sign = 2, sectionListSize = 3
EQUB &DE \ xTrackSectionIHi xTrackSectionI = &DE28 = -8664
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14CC = 5324
EQUB &54 \ zTrackSectionIHi zTrackSectionI = &54A8 = 21672
EQUB &DD \ xTrackSectionOHi xTrackSectionO = &DD41 = -8895
EQUB 25 \ trackSectionTurn
EQUB &55 \ zTrackSectionOHi zTrackSectionO = &550A = 21770
EQUB 15 \ trackDriverSpeed
\ Track section 7
EQUB &23 \ trackSectionData sign = 2, sectionListSize = 3
EQUB &E3 \ xTrackSectionIHi xTrackSectionI = &E302 = -7422
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14CC = 5324
EQUB &57 \ zTrackSectionIHi zTrackSectionI = &5729 = 22313
EQUB &E3 \ xTrackSectionOHi xTrackSectionO = &E34D = -7347
EQUB 255 \ trackSectionTurn
EQUB &58 \ zTrackSectionOHi zTrackSectionO = &5817 = 22551
EQUB 138 \ trackDriverSpeed
\ Track section 8
EQUB &35 \ trackSectionData sign = 3, sectionListSize = 5
EQUB &ED \ xTrackSectionIHi xTrackSectionI = &ED4C = -4788
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14CC = 5324
EQUB &50 \ zTrackSectionIHi zTrackSectionI = &50AD = 20653
EQUB &ED \ xTrackSectionOHi xTrackSectionO = &EDDA = -4646
EQUB 255 \ trackSectionTurn
EQUB &51 \ zTrackSectionOHi zTrackSectionO = &517C = 20860
EQUB 255 \ trackDriverSpeed
\ Track section 9
EQUB &45 \ trackSectionData sign = 4, sectionListSize = 5
EQUB &F5 \ xTrackSectionIHi xTrackSectionI = &F597 = -2665
EQUB &0D \ yTrackSectionIHi yTrackSectionI = &0DF4 = 3572
EQUB &39 \ zTrackSectionIHi zTrackSectionI = &39E9 = 14825
EQUB &F6 \ xTrackSectionOHi xTrackSectionO = &F68E = -2418
EQUB 6 \ trackSectionTurn
EQUB &39 \ zTrackSectionOHi zTrackSectionO = &39BD = 14781
EQUB 255 \ trackDriverSpeed
\ Track section 10
EQUB &55 \ trackSectionData sign = 5, sectionListSize = 5
EQUB &F4 \ xTrackSectionIHi xTrackSectionI = &F41D = -3043
EQUB &0B \ yTrackSectionIHi yTrackSectionI = &0B24 = 2852
EQUB &31 \ zTrackSectionIHi zTrackSectionI = &319D = 12701
EQUB &F5 \ xTrackSectionOHi xTrackSectionO = &F514 = -2796
EQUB 30 \ trackSectionTurn
EQUB &31 \ zTrackSectionOHi zTrackSectionO = &3171 = 12657
EQUB 10 \ trackDriverSpeed
\ Track section 11
EQUB &54 \ trackSectionData sign = 5, sectionListSize = 4
EQUB &F5 \ xTrackSectionIHi xTrackSectionI = &F5AB = -2645
EQUB &09 \ yTrackSectionIHi yTrackSectionI = &0926 = 2342
EQUB &2A \ zTrackSectionIHi zTrackSectionI = &2AE7 = 10983
EQUB &F6 \ xTrackSectionOHi xTrackSectionO = &F682 = -2430
EQUB 35 \ trackSectionTurn
EQUB &2B \ zTrackSectionOHi zTrackSectionO = &2B68 = 11112
EQUB 120 \ trackDriverSpeed
\ Track section 12
EQUB &64 \ trackSectionData sign = 6, sectionListSize = 4
EQUB &FE \ xTrackSectionIHi xTrackSectionI = &FE29 = -471
EQUB &06 \ yTrackSectionIHi yTrackSectionI = &0648 = 1608
EQUB &19 \ zTrackSectionIHi zTrackSectionI = &19BF = 6591
EQUB &FF \ xTrackSectionOHi xTrackSectionO = &FF13 = -237
EQUB 19 \ trackSectionTurn
EQUB &1A \ zTrackSectionOHi zTrackSectionO = &1A16 = 6678
EQUB 13 \ trackDriverSpeed
\ Track section 13
EQUB &64 \ trackSectionData sign = 6, sectionListSize = 4
EQUB &FD \ xTrackSectionIHi xTrackSectionI = &FD6F = -657
EQUB &06 \ yTrackSectionIHi yTrackSectionI = &0664 = 1636
EQUB &16 \ zTrackSectionIHi zTrackSectionI = &16B0 = 5808
EQUB &FE \ xTrackSectionOHi xTrackSectionO = &FE33 = -461
EQUB 32 \ trackSectionTurn
EQUB &16 \ zTrackSectionOHi zTrackSectionO = &1612 = 5650
EQUB 255 \ trackDriverSpeed
\ Track section 14
EQUB &73 \ trackSectionData sign = 7, sectionListSize = 3
EQUB &EF \ xTrackSectionIHi xTrackSectionI = &EFF5 = -4107
EQUB &09 \ yTrackSectionIHi yTrackSectionI = &0944 = 2372
EQUB &05 \ zTrackSectionIHi zTrackSectionI = &05CC = 1484
EQUB &F0 \ xTrackSectionOHi xTrackSectionO = &F0B9 = -3911
EQUB 29 \ trackSectionTurn
EQUB &05 \ zTrackSectionOHi zTrackSectionO = &052E = 1326
EQUB 14 \ trackDriverSpeed
\ Track section 15
EQUB &73 \ trackSectionData sign = 7, sectionListSize = 3
EQUB &EE \ xTrackSectionIHi xTrackSectionI = &EEEA = -4374
EQUB &09 \ yTrackSectionIHi yTrackSectionI = &09A4 = 2468
EQUB &03 \ zTrackSectionIHi zTrackSectionI = &0337 = 823
EQUB &EF \ xTrackSectionOHi xTrackSectionO = &EFE1 = -4127
EQUB 255 \ trackSectionTurn
EQUB &03 \ zTrackSectionOHi zTrackSectionO = &030B = 779
EQUB 255 \ trackDriverSpeed
\ Track section 16
EQUB &73 \ trackSectionData sign = 7, sectionListSize = 3
EQUB &ED \ xTrackSectionIHi xTrackSectionI = &ED58 = -4776
EQUB &0D \ yTrackSectionIHi yTrackSectionI = &0D0E = 3342
EQUB &F8 \ zTrackSectionIHi zTrackSectionI = &F81B = -2021
EQUB &EE \ xTrackSectionOHi xTrackSectionO = &EE53 = -4525
EQUB 14 \ trackSectionTurn
EQUB &F8 \ zTrackSectionOHi zTrackSectionO = &F823 = -2013
EQUB 255 \ trackDriverSpeed
\ Track section 17
EQUB &83 \ trackSectionData sign = 8, sectionListSize = 3
EQUB &ED \ xTrackSectionIHi xTrackSectionI = &EDC8 = -4664
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &11DE = 4574
EQUB &EA \ zTrackSectionIHi zTrackSectionI = &EAFB = -5381
EQUB &EE \ xTrackSectionOHi xTrackSectionO = &EEC3 = -4413
EQUB 33 \ trackSectionTurn
EQUB &EB \ zTrackSectionOHi zTrackSectionO = &EB03 = -5373
EQUB 0 \ trackDriverSpeed
\ Track section 18
EQUB &83 \ trackSectionData sign = 8, sectionListSize = 3
EQUB &F0 \ xTrackSectionIHi xTrackSectionI = &F0F9 = -3847
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14A8 = 5288
EQUB &E3 \ zTrackSectionIHi zTrackSectionI = &E34B = -7349
EQUB &F1 \ xTrackSectionOHi xTrackSectionO = &F1C2 = -3646
EQUB 15 \ trackSectionTurn
EQUB &E3 \ zTrackSectionOHi zTrackSectionO = &E3E3 = -7197
EQUB 114 \ trackDriverSpeed
\ Track section 19
EQUB &93 \ trackSectionData sign = 9, sectionListSize = 3
EQUB &F5 \ xTrackSectionIHi xTrackSectionI = &F583 = -2685
EQUB &17 \ yTrackSectionIHi yTrackSectionI = &1728 = 5928
EQUB &DB \ zTrackSectionIHi zTrackSectionI = &DB2C = -9428
EQUB &F6 \ xTrackSectionOHi xTrackSectionO = &F675 = -2443
EQUB 27 \ trackSectionTurn
EQUB &DB \ zTrackSectionOHi zTrackSectionO = &DB6F = -9361
EQUB 17 \ trackDriverSpeed
\ Track section 20
EQUB &A3 \ trackSectionData sign = 10, sectionListSize = 3
EQUB &F3 \ xTrackSectionIHi xTrackSectionI = &F3B0 = -3152
EQUB &18 \ yTrackSectionIHi yTrackSectionI = &189B = 6299
EQUB &D5 \ zTrackSectionIHi zTrackSectionI = &D5CF = -10801
EQUB &F4 \ xTrackSectionOHi xTrackSectionO = &F440 = -3008
EQUB 255 \ trackSectionTurn
EQUB &D5 \ zTrackSectionOHi zTrackSectionO = &D501 = -11007
EQUB 255 \ trackDriverSpeed
\ Track section 21
EQUB &A3 \ trackSectionData sign = 10, sectionListSize = 3
EQUB &EA \ xTrackSectionIHi xTrackSectionI = &EA1E = -5602
EQUB &1A \ yTrackSectionIHi yTrackSectionI = &1AA9 = 6825
EQUB &CF \ zTrackSectionIHi zTrackSectionI = &CF12 = -12526
EQUB &EA \ xTrackSectionOHi xTrackSectionO = &EAAE = -5458
EQUB 27 \ trackSectionTurn
EQUB &CE \ zTrackSectionOHi zTrackSectionO = &CE44 = -12732
EQUB 111 \ trackDriverSpeed
\ Track section 22
EQUB &B3 \ trackSectionData sign = 11, sectionListSize = 3
EQUB &DC \ xTrackSectionIHi xTrackSectionI = &DC56 = -9130
EQUB &1E \ yTrackSectionIHi yTrackSectionI = &1E96 = 7830
EQUB &C5 \ zTrackSectionIHi zTrackSectionI = &C55E = -15010
EQUB &DC \ xTrackSectionOHi xTrackSectionO = &DCE6 = -8986
EQUB 18 \ trackSectionTurn
EQUB &C4 \ zTrackSectionOHi zTrackSectionO = &C490 = -15216
EQUB 8 \ trackDriverSpeed
\ Track section 23
EQUB &B3 \ trackSectionData sign = 11, sectionListSize = 3
EQUB &DA \ xTrackSectionIHi xTrackSectionI = &DA15 = -9707
EQUB &1E \ yTrackSectionIHi yTrackSectionI = &1E8C = 7820
EQUB &C5 \ zTrackSectionIHi zTrackSectionI = &C547 = -15033
EQUB &D9 \ xTrackSectionOHi xTrackSectionO = &D9C1 = -9791
EQUB 6 \ trackSectionTurn
EQUB &C4 \ zTrackSectionOHi zTrackSectionO = &C45A = -15270
EQUB 118 \ trackDriverSpeed
\ Track section 24
EQUB &C3 \ trackSectionData sign = 12, sectionListSize = 3
EQUB &D7 \ xTrackSectionIHi xTrackSectionI = &D717 = -10473
EQUB &1E \ yTrackSectionIHi yTrackSectionI = &1E70 = 7792
EQUB &C6 \ zTrackSectionIHi zTrackSectionI = &C69E = -14690
EQUB &D6 \ xTrackSectionOHi xTrackSectionO = &D6A3 = -10589
EQUB 37 \ trackSectionTurn
EQUB &C5 \ zTrackSectionOHi zTrackSectionO = &C5BD = -14915
EQUB 14 \ trackDriverSpeed
EQUB &03, &CF \ These bytes appear to be unused
EQUB &14, &BB
EQUB &CE, &FF
EQUB &BC, &FF
\ ******************************************************************************
\
\ Name: Multiply80Percent
\ Type: Subroutine
\ Category: Extra tracks
\ Summary: Calculate (A T) = 0.80 * A
\
\ ******************************************************************************
.Multiply80Percent
STA U \ Set U = A
LDA #205 \ Set A = 205
JMP Multiply8x8 \ Set (A T) = A * U
\ = 205 * A
\
\ returning from the subroutine using a tail call
\
\ This calculates the following in A:
\
\ A = (A T) / 256
\ = 205 * A / 256
\ = 0.80 * A
\ ******************************************************************************
\
\ Name: HookFlipAbsolute
\ Type: Subroutine
\ Category: Extra tracks
\ Summary: Set the sign of A according to the direction we are facing along
\ the track
\ Deep dive: Secrets of the extra tracks
\ Code hooks in the extra tracks
\
\ ------------------------------------------------------------------------------
\
\ This routine is called from MovePlayerOnTrack so that the yaw angle of the
\ closest segment retains the correct sign, like this:
\
\ * If we are facing forwards along the track, set A = |A|
\
\ * If we are facing backwards along the track, set A = -|A|
\
\ ******************************************************************************
.HookFlipAbsolute
EOR directionFacing \ Flip the sign bit of A if we are facing backwards
\ along the track
\
\ The Absolute8Bit routine does the following:
\
\ * If A is positive leave it alone
\
\ * If A is negative, set A = -A
\
\ So if bit 7 of directionFacing is set (i.e. we are
\ facing backwards along the track), this flips bit 7 of
\ A, which changes the Absolute8Bit routine to the
\ following (if we consider the original value of A):
\
\ * If A is negative leave it alone
\
\ * If A is positive, set A = -A
\
\ So this sets set A = -|A| instead of A = |A|
JMP Absolute8Bit \ Set A = |A|, unless we are facing backwards along the
\ track, in which case set A = -|A|, and return from the
\ subroutine using a tail call
\ ******************************************************************************
\
\ Name: HookJoystick (Part 3 of 3)
\ Type: Subroutine
\ Category: Extra tracks
\ Summary: Apply enhanced joystick steering to specific track sections
\ Deep dive: Secrets of the extra tracks
\ Code hooks in the extra tracks
\
\ ******************************************************************************
.joys12
\ By this point, Y contains the scale factor to apply to
\ the steering, which is one of the following values:
\
\ * 181 for a scale factor of 1.00
\
\ * 188 for a scale factor of 1.08
\
\ * 205 for a scale factor of 1.28
\
\ * 215 for a scale factor of 1.41
TYA \ Set A = Y
\
\ So A is 181, 188, 205 or 215
JSR Multiply8x8 \ Set (A T) = A * U
\ = A * x-axis
STA U \ Set U = A
\ = high byte of A * x-axis
JSR Multiply8x8 \ Set (A T) = A * U
\ = A * A
\ = (A * x-axis) ^ 2
ASL T \ Set (A T) = (A T) * 2
ROL A \ = 2 * (A * x-axis) ^ 2
\ So for A = 215 we have:
\
\ (A T) = 2 * (215/256 * x-axis) ^ 2
\ = 2 * (0.840 * x-axis) ^ 2
\ = 1.41 * x-axis ^ 2
\
\ and for A = 205 we have:
\
\ (A T) = 2 * (205/256 * x-axis) ^ 2
\ = 2 * (0.8012 * x-axis) ^ 2
\ = 1.28 * x-axis ^ 2
\
\ and for A = 188 we have:
\
\ (A T) = 2 * (188/256 * x-axis) ^ 2
\ = 2 * (0.734 * x-axis) ^ 2
\ = 1.08 * x-axis ^ 2
\
\ and for A = 181 we have:
\
\ (A T) = 2 * (181/256 * x-axis) ^ 2
\ = 2 * (0.707 * x-axis) ^ 2
\ = 1.00 * x-axis ^ 2
RTS \ Return from the subroutine
\ ******************************************************************************
\
\ Name: HookForward
\ Type: Subroutine
\ Category: Extra tracks
\ Summary: Move the player forward by an extra segment when edgeSegmentNumber
\ is 10
\ Deep dive: Secrets of the extra tracks
\ Code hooks in the extra tracks
\
\ ------------------------------------------------------------------------------
\
\ This routine is called from MovePlayerSegment to move the player forward by an
\ extra segment if required.
\
\ ------------------------------------------------------------------------------
\
\ Arguments:
\
\ A The value of edgeSegmentNumber
\
\ ******************************************************************************
.HookForward
CMP #11 \ If edgeSegmentNumber >= 11, then the player is either
BCS move1 \ in the same segment, or has moved backwards, so jump
\ to move1
\ If we get here then edgeSegmentNumber < 11, so
\ edgeSegmentNumber must be 10, so we move the player
\ forwards by two segments
JSR MovePlayerForward \ Move the player forwards by one segment
.move1
JMP MovePlayerForward \ Move the player forwards by one segment, returning
\ from the subroutine using a tail call
\ ******************************************************************************
\
\ Name: ModifyGameCode (Part 4 of 4)
\ Type: Subroutine
\ Category: Extra tracks
\ Summary: Modify the game code to support the extra track data
\
\ ------------------------------------------------------------------------------
\
\ The code modifications are done in four parts.
\
\ ******************************************************************************
.mods4
STA &4F55 \ ?&4F55 = 22 (argument in a CMP #22 instruction)
STA &4F59 \ ?&4F59 = 22 (argument in a CMP #22 instruction)
RTS \ Return from the subroutine
\ ******************************************************************************
\
\ Name: subSection
\ Type: Variable
\ Category: Extra tracks
\ Summary: The number of the current sub-section
\
\ ******************************************************************************
.subSection
EQUB 0
\ ******************************************************************************
\
\ Name: trackSubCount
\ Type: Variable
\ Category: Extra tracks
\ Summary: The total number of sub-sections in the track
\
\ ******************************************************************************
.trackSubCount
EQUB 58
\ ******************************************************************************
\
\ Name: yawAngleLo
\ Type: Variable
\ Category: Extra tracks
\ Summary: Low byte of the current yaw angle of the track, i.e. the angle at
\ which the track is pointing along the ground
\
\ ******************************************************************************
.yawAngleLo
EQUB 0
\ ******************************************************************************
\
\ Name: yawAngleHi
\ Type: Variable
\ Category: Extra tracks
\ Summary: High byte of the current yaw angle of the track, i.e. the angle at
\ which the track is pointing along the ground
\
\ ******************************************************************************
.yawAngleHi
EQUB 0
\ ******************************************************************************
\
\ Name: segmentSlope
\ Type: Variable
\ Category: Extra tracks
\ Summary: The height above ground of the current track sub-section
\
\ ******************************************************************************
.segmentSlope
EQUB 0
\ ******************************************************************************
\
\ Name: subSectionSegment
\ Type: Variable
\ Category: Extra tracks
\ Summary: The number of the segment within the current sub-section, counting
\ from the start of the sub-section
\
\ ******************************************************************************
.subSectionSegment
EQUB 0
\ ******************************************************************************
\
\ Name: modifyAddressLo
\ Type: Variable
\ Category: Extra tracks
\ Summary: Low byte of the location in the main game code where we modify a
\ two-byte address
\
\ ------------------------------------------------------------------------------
\
\ This is also where the xTrackSegmentI table is built, once the modifications
\ have been done. The block is exactly 20 bytes long, so along with the
\ modifyAddressHi block, there's one byte for each inner segment x-coordinate.
\
\ ******************************************************************************
.modifyAddressLo
EQUB &49 \ !&1249 = HookSectionFrom
EQUB &8A \ !&128A = HookFirstSegment
EQUB &CA \ !&13CA = HookSegmentVector
EQUB &27 \ !&1427 = HookSegmentVector
EQUB &FC \ !&12FC = HookDataPointers
EQUB &1B \ !&261B = HookUpdateHorizon
EQUB &8C \ !&248C = HookFieldOfView
EQUB &39 \ !&2539 = HookFixHorizon
EQUB &94 \ !&1594 = HookJoystick
EQUB &D1 \ !&4CD1 = xTrackSignVector
EQUB &C9 \ !&4CC9 = yTrackSignVector
EQUB &C1 \ !&4CC1 = zTrackSignVector
EQUB &D6 \ !&44D6 = trackSteering
EQUB &D7 \ !&4CD7 = trackSignData
EQUB &E1 \ !&4CE1 = trackSignData
EQUB &47 \ !&1947 = HookFlattenHills
EQUB &F3 \ !&24F3 = HookMoveBack
EQUB &2C \ !&462C = HookFlipAbsolute
EQUB &43 \ !&2543 = Hook80Percent
EQUB &24 \ !&2F24 = HookBackground
\ ******************************************************************************
\
\ Name: modifyAddressHi
\ Type: Variable
\ Category: Extra tracks
\ Summary: High byte of the location in the main game code where we modify a
\ two-byte address
\
\ ------------------------------------------------------------------------------
\
\ This is also where the xTrackSegmentI table is built, once the modifications
\ have been done. The block is exactly 20 bytes long, so along with the
\ modifyAddressLo block, there's one byte for each inner segment x-coordinate.
\
\ ******************************************************************************
.modifyAddressHi
EQUB &12 \ !&1249 = HookSectionFrom
EQUB &12 \ !&128A = HookFirstSegment
EQUB &13 \ !&13CA = HookSegmentVector
EQUB &14 \ !&1427 = HookSegmentVector
EQUB &12 \ !&12FC = HookDataPointers
EQUB &26 \ !&261B = HookUpdateHorizon
EQUB &24 \ !&248C = HookFieldOfView
EQUB &25 \ !&2539 = HookFixHorizon
EQUB &15 \ !&1594 = HookJoystick
EQUB &4C \ !&4CD1 = xTrackSignVector
EQUB &4C \ !&4CC9 = yTrackSignVector
EQUB &4C \ !&4CC1 = zTrackSignVector
EQUB &44 \ !&44D6 = trackSteering
EQUB &4C \ !&4CD7 = trackSignData
EQUB &4C \ !&4CE1 = trackSignData
EQUB &19 \ !&1947 = HookFlattenHills
EQUB &24 \ !&24F3 = HookMoveBack
EQUB &46 \ !&462C = HookFlipAbsolute
EQUB &25 \ !&2543 = Hook80Percent
EQUB &2F \ !&2F24 = HookBackground
\ ******************************************************************************
\
\ Name: trackYawDeltaHi
\ Type: Variable
\ Category: Extra tracks
\ Summary: High byte of the change in yaw angle that we apply to each segment
\ in the specified sub-section when building the track
\
\ ******************************************************************************
.trackYawDeltaHi
EQUB &00 \ Sub-section 0 = &0000 ( 0)
EQUB &00 \ Sub-section 1 = &0000 ( 0)
EQUB &00 \ Sub-section 2 = &0000 ( 0)
EQUB &00 \ Sub-section 3 = &0000 ( 0)
EQUB &00 \ Sub-section 4 = &0000 ( 0)
EQUB &00 \ Sub-section 5 = &0000 ( 0)
EQUB &10 \ Sub-section 6 = &104B ( 4171)
EQUB &03 \ Sub-section 7 = &0371 ( 881)
EQUB &FE \ Sub-section 8 = &FE94 ( -364)
EQUB &FA \ Sub-section 9 = &FA73 (-1421)
EQUB &00 \ Sub-section 10 = &0000 ( 0)
EQUB &00 \ Sub-section 11 = &0000 ( 0)
EQUB &00 \ Sub-section 12 = &0000 ( 0)
EQUB &00 \ Sub-section 13 = &0000 ( 0)
EQUB &00 \ Sub-section 14 = &00A9 ( 169)
EQUB &01 \ Sub-section 15 = &01C7 ( 455)
EQUB &02 \ Sub-section 16 = &0294 ( 660)
EQUB &05 \ Sub-section 17 = &0588 ( 1416)
EQUB &01 \ Sub-section 18 = &0183 ( 387)
EQUB &00 \ Sub-section 19 = &0000 ( 0)
EQUB &01 \ Sub-section 20 = &0153 ( 339)
EQUB &01 \ Sub-section 21 = &016E ( 366)
EQUB &00 \ Sub-section 22 = &00B6 ( 182)
EQUB &00 \ Sub-section 23 = &00AD ( 173)
EQUB &00 \ Sub-section 24 = &00B2 ( 178)
EQUB &00 \ Sub-section 25 = &00FD ( 253)
EQUB &00 \ Sub-section 26 = &0000 ( 0)
EQUB &00 \ Sub-section 27 = &0000 ( 0)
EQUB &FD \ Sub-section 28 = &FDDE ( -546)
EQUB &FE \ Sub-section 29 = &FE46 ( -442)
EQUB &00 \ Sub-section 30 = &0000 ( 0)
EQUB &00 \ Sub-section 31 = &0000 ( 0)
EQUB &00 \ Sub-section 32 = &0000 ( 0)
EQUB &01 \ Sub-section 33 = &013F ( 319)
EQUB &00 \ Sub-section 34 = &0000 ( 0)
EQUB &06 \ Sub-section 35 = &0605 ( 1541)
EQUB &FC \ Sub-section 36 = &FC9F ( -865)
EQUB &00 \ Sub-section 37 = &0000 ( 0)
EQUB &00 \ Sub-section 38 = &0000 ( 0)
EQUB &FE \ Sub-section 39 = &FEC1 ( -319)
EQUB &FE \ Sub-section 40 = &FE2A ( -470)
EQUB &FE \ Sub-section 41 = &FED8 ( -296)
EQUB &00 \ Sub-section 42 = &005B ( 91)
EQUB &01 \ Sub-section 43 = &0166 ( 358)
EQUB &02 \ Sub-section 44 = &0272 ( 626)
EQUB &04 \ Sub-section 45 = &04BE ( 1214)
EQUB &04 \ Sub-section 46 = &044B ( 1099)
EQUB &00 \ Sub-section 47 = &0000 ( 0)
EQUB &00 \ Sub-section 48 = &0000 ( 0)
EQUB &00 \ Sub-section 49 = &0000 ( 0)
EQUB &00 \ Sub-section 50 = &0000 ( 0)
EQUB &00 \ Sub-section 51 = &0000 ( 0)
EQUB &00 \ Sub-section 52 = &0000 ( 0)
EQUB &07 \ Sub-section 53 = &07DD ( 2013)
EQUB &00 \ Sub-section 54 = &00BC ( 188)
EQUB &02 \ Sub-section 55 = &0224 ( 548)
EQUB &01 \ Sub-section 56 = &0162 ( 354)
EQUB &01 \ Sub-section 57 = &01A4 ( 420)
\ ******************************************************************************
\
\ Name: trackSignData
\ Type: Variable
\ Category: Track data
\ Summary: Base coordinates and object types for 16 road signs
\ Deep dive: The track data file format
\ The extra tracks data file format
\ The Donington Park track
\
\ ******************************************************************************
.trackSignData
EQUB %00100001 \ Sign 0: 00100 001 Type 8 Start flag Section 4
EQUB %00110100 \ Sign 1: 00110 100 Type 11 Right turn Section 6
EQUB %01000000 \ Sign 2: 01000 000 Type 7 Straight Section 8
EQUB %01001000 \ Sign 3: 01001 000 Type 7 Straight Section 9
EQUB %01010101 \ Sign 4: 01010 101 Type 12 Left turn Section 10
EQUB %01100100 \ Sign 5: 01100 100 Type 11 Right turn Section 12
EQUB %01110101 \ Sign 6: 01110 101 Type 12 Left turn Section 14
EQUB %10001101 \ Sign 7: 10001 101 Type 12 Left turn Section 17
EQUB %10011100 \ Sign 8: 10011 100 Type 11 Right turn Section 19
EQUB %10100000 \ Sign 9: 10100 000 Type 7 Straight Section 20
EQUB %10110100 \ Sign 10: 10110 100 Type 11 Right turn Section 22
EQUB %11000000 \ Sign 11: 11000 000 Type 7 Straight Section 24
EQUB %00000000 \ Sign 12: 00000 000 Type 7 Straight Section 0
EQUB %00001000 \ Sign 13: 00001 000 Type 7 Straight Section 1
EQUB %00010011 \ Sign 14: 00010 011 Type 10 Chicane Section 2
EQUB %00010000 \ Sign 15: 00010 000 Type 7 Straight Section 2
\ ******************************************************************************
\
\ Name: CalcSegmentVector
\ Type: Subroutine
\ Category: Extra tracks
\ Summary: Calculate the segment vector for the current segment
\ Deep dive: Dynamic track generation in the extra tracks
\
\ ------------------------------------------------------------------------------
\
\ This routine calculates the segment vector for the current segment, by
\ converting the direction of the track at this point, which is stored in the
\ yaw angle in (yawAngleHi yawAngleLo), into a direction vector to store in the
\ (xTrackSegmentI yTrackSegmentI zTrackSegmentI) tables in the track data file.
\
\ We also calculate the outer track segment vector (i.e. the vector across the
\ track) and store it in the (xTrackSegmentO yTrackSegmentI zTrackSegmentO)
\ tables in the track data file.
\
\ Note that the track segment vector tables overwrite the modification routines,
\ as those are no longer used, and the main game code still thinks that's where
\ the segment vector tables are stored as part of the track data file (which
\ they are, it's just that they are dynamically generated in the extra track
\ files, rather than being full of static data).
\
\ ******************************************************************************
.CalcSegmentVector
\ This routine calculates the segment vector for the
\ current segment within the current sub-section
\
\ The segment vector contains two vectors:
\
\ * (xTrackSegmentI yTrackSegmentI zTrackSegmentI) is
\ the vector along the inside of the track from the
\ previous segment to the current segment
\
\ * (xTrackSegmentO yTrackSegmentI zTrackSegmentO) is
\ the vector from the inner edge of the track to the
\ outer edge of the track for the current segment
\
\ We start by analysing the track's yaw angle to see in
\ which direction the track that we're building is
\ currently pointing, so we can set the correct signs