-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrevs-brandshatch.asm
4057 lines (3495 loc) · 173 KB
/
revs-brandshatch.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 BRANDS HATCH 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:
\
\ * BrandsHatch.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 = 136 \ 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
Multiply8x8 = &0C00
Absolute16Bit = &0E40
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
xVergeRightLo = &5E40
xVergeLeftLo = &5E68
xVergeRightHi = &5E90
xVergeLeftHi = &5EB8
yVergeRight = &5F20
yVergeLeft = &5F48
\ ******************************************************************************
\
\ REVS BRANDS HATCH TRACK
\
\ Produces the binary file BrandsHatch.bin that contains the Brands Hatch 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 Brands Hatch track
\
\ ------------------------------------------------------------------------------
\
\ Brands Hatch consists of the following track sections:
\
\ 0 -> Clearways to Paddock Bend (3/3)
\ 1 -> Paddock Bend
\ 2 |->| Paddock Bend to Druids (1/2)
\ 3 {} Paddock Bend to Druids (2/2)
\ 4 |->| Druids
\ 5 || Druids to Graham Hill Bend
\ 6 <- Graham Hill Bend
\ 7 || Graham Hill Bend to Surtees (1/3)
\ 8 <- Graham Hill Bend to Surtees (2/3)
\ 9 <- Graham Hill Bend to Surtees (3/3)
\ 10 <- Surtees
\ 11 {} Surtees to Hawthorns Bend (1/4)
\ 12 |->| Surtees to Hawthorns Bend (2/4)
\ 13 {} Surtees to Hawthorns Bend (3/4)
\ 14 {} Surtees to Hawthorns Bend (4/4)
\ 15 -> Hawthorns Bend
\ 16 || Hawthorns Bend to Westfield
\ 17 -> Westfield
\ 18 {} Westfield to Dingle Dell Corner (1/3)
\ 19 -> Westfield to Dingle Dell Corner (2/3)
\ 20 || Westfield to Dingle Dell Corner (3/3)
\ 21 -> Dingle Dell Corner
\ 22 || Dingle Dell Corner to Stirlings
\ 23 <- Stirlings
\ 24 {} Stirlings to Clearways (1/2)
\ 25 {} Stirlings to Clearways (2/2)
\ 26 -> Clearways
\ 27 -> Clearways to Paddock Bend (1/3)
\ 28 -> Clearways to Paddock Bend (2/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 &01 \ trackSectionData sign = 0, sectionListSize = 1
EQUB &D1 \ xTrackSectionIHi xTrackSectionI = &D120 = -12000
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &1400 = 5120
EQUB &0F \ zTrackSectionIHi zTrackSectionI = &0FA0 = 4000
EQUB &D0 \ xTrackSectionOHi xTrackSectionO = &D021 = -12255
EQUB 52 \ trackSectionTurn
EQUB &0F \ zTrackSectionOHi zTrackSectionO = &0FA0 = 4000
EQUB 127 \ trackDriverSpeed
\ Track section 1
EQUB &13 \ trackSectionData sign = 1, sectionListSize = 3
EQUB &D4 \ xTrackSectionIHi xTrackSectionI = &D4DC = -11044
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &1487 = 5255
EQUB &2A \ zTrackSectionIHi zTrackSectionI = &2A5C = 10844
EQUB &D3 \ xTrackSectionOHi xTrackSectionO = &D3F6 = -11274
EQUB 41 \ trackSectionTurn
EQUB &2A \ zTrackSectionOHi zTrackSectionO = &2AC8 = 10952
EQUB 28 \ trackDriverSpeed
\ Track section 2
EQUB &22 \ trackSectionData sign = 2, sectionListSize = 2
EQUB &E0 \ xTrackSectionIHi xTrackSectionI = &E052 = -8110
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0F2B = 3883
EQUB &2D \ zTrackSectionIHi zTrackSectionI = &2DE3 = 11747
EQUB &E0 \ xTrackSectionOHi xTrackSectionO = &E0B5 = -8011
EQUB 255 \ trackSectionTurn
EQUB &2E \ zTrackSectionOHi zTrackSectionO = &2ECC = 11980
EQUB 255 \ trackDriverSpeed
\ Track section 3
EQUB &31 \ trackSectionData sign = 3, sectionListSize = 1
EQUB &EA \ xTrackSectionIHi xTrackSectionI = &EA2B = -5589
EQUB &0E \ yTrackSectionIHi yTrackSectionI = &0EDE = 3806
EQUB &29 \ zTrackSectionIHi zTrackSectionI = &2996 = 10646
EQUB &EA \ xTrackSectionOHi xTrackSectionO = &EAAA = -5462
EQUB 22 \ trackSectionTurn
EQUB &2A \ zTrackSectionOHi zTrackSectionO = &2A73 = 10867
EQUB 73 \ trackDriverSpeed
\ Track section 4
EQUB &31 \ trackSectionData sign = 3, sectionListSize = 1
EQUB &F3 \ xTrackSectionIHi xTrackSectionI = &F3EB = -3093
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &116C = 4460
EQUB &23 \ zTrackSectionIHi zTrackSectionI = &23F6 = 9206
EQUB &F4 \ xTrackSectionOHi xTrackSectionO = &F46A = -2966
EQUB 24 \ trackSectionTurn
EQUB &24 \ zTrackSectionOHi zTrackSectionO = &24D3 = 9427
EQUB 6 \ trackDriverSpeed
\ Track section 5
EQUB &43 \ trackSectionData sign = 4, sectionListSize = 3
EQUB &F1 \ xTrackSectionIHi xTrackSectionI = &F171 = -3727
EQUB &0D \ yTrackSectionIHi yTrackSectionI = &0D53 = 3411
EQUB &1E \ zTrackSectionIHi zTrackSectionI = &1E53 = 7763
EQUB &F1 \ xTrackSectionOHi xTrackSectionO = &F100 = -3840
EQUB 21 \ trackSectionTurn
EQUB &1D \ zTrackSectionOHi zTrackSectionO = &1D6D = 7533
EQUB 255 \ trackDriverSpeed
\ Track section 6
EQUB &44 \ trackSectionData sign = 4, sectionListSize = 4
EQUB &E6 \ xTrackSectionIHi xTrackSectionI = &E60D = -6643
EQUB &08 \ yTrackSectionIHi yTrackSectionI = &0843 = 2115
EQUB &23 \ zTrackSectionIHi zTrackSectionI = &23EA = 9194
EQUB &E5 \ xTrackSectionOHi xTrackSectionO = &E59C = -6756
EQUB 31 \ trackSectionTurn
EQUB &23 \ zTrackSectionOHi zTrackSectionO = &2304 = 8964
EQUB 18 \ trackDriverSpeed
\ Track section 7
EQUB &53 \ trackSectionData sign = 5, sectionListSize = 3
EQUB &DE \ xTrackSectionIHi xTrackSectionI = &DE2F = -8657
EQUB &05 \ yTrackSectionIHi yTrackSectionI = &05EB = 1515
EQUB &21 \ zTrackSectionIHi zTrackSectionI = &2120 = 8480
EQUB &DE \ xTrackSectionOHi xTrackSectionO = &DEF0 = -8464
EQUB 1 \ trackSectionTurn
EQUB &20 \ zTrackSectionOHi zTrackSectionO = &207A = 8314
EQUB 255 \ trackDriverSpeed
\ Track section 8
EQUB &54 \ trackSectionData sign = 5, sectionListSize = 4
EQUB &DA \ xTrackSectionIHi xTrackSectionI = &DA39 = -9671
EQUB &05 \ yTrackSectionIHi yTrackSectionI = &05EB = 1515
EQUB &1C \ zTrackSectionIHi zTrackSectionI = &1C81 = 7297
EQUB &DA \ xTrackSectionOHi xTrackSectionO = &DAFA = -9478
EQUB 39 \ trackSectionTurn
EQUB &1B \ zTrackSectionOHi zTrackSectionO = &1BDB = 7131
EQUB 19 \ trackDriverSpeed
\ Track section 9
EQUB &53 \ trackSectionData sign = 5, sectionListSize = 3
EQUB &D8 \ xTrackSectionIHi xTrackSectionI = &D836 = -10186
EQUB &05 \ yTrackSectionIHi yTrackSectionI = &05EB = 1515
EQUB &16 \ zTrackSectionIHi zTrackSectionI = &16CE = 5838
EQUB &D9 \ xTrackSectionOHi xTrackSectionO = &D930 = -9936
EQUB 43 \ trackSectionTurn
EQUB &16 \ zTrackSectionOHi zTrackSectionO = &16A1 = 5793
EQUB 117 \ trackDriverSpeed
\ Track section 10
EQUB &62 \ trackSectionData sign = 6, sectionListSize = 2
EQUB &D9 \ xTrackSectionIHi xTrackSectionI = &D90A = -9974
EQUB &05 \ yTrackSectionIHi yTrackSectionI = &05EB = 1515
EQUB &01 \ zTrackSectionIHi zTrackSectionI = &0152 = 338
EQUB &DA \ xTrackSectionOHi xTrackSectionO = &DA00 = -9728
EQUB 40 \ trackSectionTurn
EQUB &01 \ zTrackSectionOHi zTrackSectionO = &018F = 399
EQUB 20 \ trackDriverSpeed
\ Track section 11
EQUB &61 \ trackSectionData sign = 6, sectionListSize = 1
EQUB &E5 \ xTrackSectionIHi xTrackSectionI = &E558 = -6824
EQUB &0A \ yTrackSectionIHi yTrackSectionI = &0ADF = 2783
EQUB &FC \ zTrackSectionIHi zTrackSectionI = &FC7C = -900
EQUB &E4 \ xTrackSectionOHi xTrackSectionO = &E496 = -7018
EQUB 1 \ trackSectionTurn
EQUB &FD \ zTrackSectionOHi zTrackSectionO = &FD21 = -735
EQUB 123 \ trackDriverSpeed
\ Track section 12
EQUB &73 \ trackSectionData sign = 7, sectionListSize = 3
EQUB &EF \ xTrackSectionIHi xTrackSectionI = &EF18 = -4328
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &1173 = 4467
EQUB &07 \ zTrackSectionIHi zTrackSectionI = &07DC = 2012
EQUB &EE \ xTrackSectionOHi xTrackSectionO = &EE56 = -4522
EQUB 255 \ trackSectionTurn
EQUB &08 \ zTrackSectionOHi zTrackSectionO = &0881 = 2177
EQUB 255 \ trackDriverSpeed
\ Track section 13
EQUB &82 \ trackSectionData sign = 8, sectionListSize = 2
EQUB &06 \ xTrackSectionIHi xTrackSectionI = &0661 = 1633
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &1132 = 4402
EQUB &1B \ zTrackSectionIHi zTrackSectionI = &1B7F = 7039
EQUB &05 \ xTrackSectionOHi xTrackSectionO = &05C5 = 1477
EQUB 255 \ trackSectionTurn
EQUB &1C \ zTrackSectionOHi zTrackSectionO = &1C4B = 7243
EQUB 255 \ trackDriverSpeed
\ Track section 14
EQUB &81 \ trackSectionData sign = 8, sectionListSize = 1
EQUB &12 \ xTrackSectionIHi xTrackSectionI = &1261 = 4705
EQUB &0E \ yTrackSectionIHi yTrackSectionI = &0E12 = 3602
EQUB &24 \ zTrackSectionIHi zTrackSectionI = &249F = 9375
EQUB &11 \ xTrackSectionOHi xTrackSectionO = &11C5 = 4549
EQUB 19 \ trackSectionTurn
EQUB &25 \ zTrackSectionOHi zTrackSectionO = &256B = 9579
EQUB 142 \ trackDriverSpeed
\ Track section 15
EQUB &90 \ trackSectionData sign = 9, sectionListSize = 0
EQUB &1B \ xTrackSectionIHi xTrackSectionI = &1B61 = 7009
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &11C0 = 4544
EQUB &2B \ zTrackSectionIHi zTrackSectionI = &2B77 = 11127
EQUB &1A \ xTrackSectionOHi xTrackSectionO = &1AC5 = 6853
EQUB 46 \ trackSectionTurn
EQUB &2C \ zTrackSectionOHi zTrackSectionO = &2C43 = 11331
EQUB 23 \ trackDriverSpeed
\ Track section 16
EQUB &92 \ trackSectionData sign = 9, sectionListSize = 2
EQUB &2A \ xTrackSectionIHi xTrackSectionI = &2AA6 = 10918
EQUB &15 \ yTrackSectionIHi yTrackSectionI = &15DC = 5596
EQUB &2A \ zTrackSectionIHi zTrackSectionI = &2AF6 = 10998
EQUB &2B \ xTrackSectionOHi xTrackSectionO = &2B63 = 11107
EQUB 50 \ trackSectionTurn
EQUB &2B \ zTrackSectionOHi zTrackSectionO = &2BA2 = 11170
EQUB 127 \ trackDriverSpeed
\ Track section 17
EQUB &A1 \ trackSectionData sign = 10, sectionListSize = 1
EQUB &3C \ xTrackSectionIHi xTrackSectionI = &3C0D = 15373
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14C9 = 5321
EQUB &17 \ zTrackSectionIHi zTrackSectionI = &17D7 = 6103
EQUB &3C \ xTrackSectionOHi xTrackSectionO = &3CCA = 15562
EQUB 37 \ trackSectionTurn
EQUB &18 \ zTrackSectionOHi zTrackSectionO = &1883 = 6275
EQUB 18 \ trackDriverSpeed
\ Track section 18
EQUB &A3 \ trackSectionData sign = 10, sectionListSize = 3
EQUB &3A \ xTrackSectionIHi xTrackSectionI = &3A6B = 14955
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14A8 = 5288
EQUB &0C \ zTrackSectionIHi zTrackSectionI = &0C7C = 3196
EQUB &3B \ xTrackSectionOHi xTrackSectionO = &3B17 = 15127
EQUB 21 \ trackSectionTurn
EQUB &0B \ zTrackSectionOHi zTrackSectionO = &0BBE = 3006
EQUB 255 \ trackDriverSpeed
\ Track section 19
EQUB &A2 \ trackSectionData sign = 10, sectionListSize = 2
EQUB &2D \ xTrackSectionIHi xTrackSectionI = &2D35 = 11573
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &1128 = 4392
EQUB &00 \ zTrackSectionIHi zTrackSectionI = &0076 = 118
EQUB &2D \ xTrackSectionOHi xTrackSectionO = &2DE1 = 11745
EQUB 40 \ trackSectionTurn
EQUB &FF \ zTrackSectionOHi zTrackSectionO = &FFB8 = -72
EQUB 20 \ trackDriverSpeed
\ Track section 20
EQUB &A1 \ trackSectionData sign = 10, sectionListSize = 1
EQUB &29 \ xTrackSectionIHi xTrackSectionI = &29E7 = 10727
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &11AC = 4524
EQUB &FE \ zTrackSectionIHi zTrackSectionI = &FEC6 = -314
EQUB &2A \ xTrackSectionOHi xTrackSectionO = &2A28 = 10792
EQUB 21 \ trackSectionTurn
EQUB &FD \ zTrackSectionOHi zTrackSectionO = &FDCF = -561
EQUB 123 \ trackDriverSpeed
\ Track section 21
EQUB &B1 \ trackSectionData sign = 11, sectionListSize = 1
EQUB &1D \ xTrackSectionIHi xTrackSectionI = &1D37 = 7479
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14A0 = 5280
EQUB &FB \ zTrackSectionIHi zTrackSectionI = &FB62 = -1182
EQUB &1D \ xTrackSectionOHi xTrackSectionO = &1D78 = 7544
EQUB 24 \ trackSectionTurn
EQUB &FA \ zTrackSectionOHi zTrackSectionO = &FA6B = -1429
EQUB 12 \ trackDriverSpeed
\ Track section 22
EQUB &B3 \ trackSectionData sign = 11, sectionListSize = 3
EQUB &18 \ xTrackSectionIHi xTrackSectionI = &18F2 = 6386
EQUB &15 \ yTrackSectionIHi yTrackSectionI = &1509 = 5385
EQUB &FC \ zTrackSectionIHi zTrackSectionI = &FC9E = -866
EQUB &18 \ xTrackSectionOHi xTrackSectionO = &1834 = 6196
EQUB 33 \ trackSectionTurn
EQUB &FB \ zTrackSectionOHi zTrackSectionO = &FBF1 = -1039
EQUB 108 \ trackDriverSpeed
\ Track section 23
EQUB &C2 \ trackSectionData sign = 12, sectionListSize = 2
EQUB &0C \ xTrackSectionIHi xTrackSectionI = &0CEC = 3308
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &1497 = 5271
EQUB &09 \ zTrackSectionIHi zTrackSectionI = &09D4 = 2516
EQUB &0C \ xTrackSectionOHi xTrackSectionO = &0C2E = 3118
EQUB 27 \ trackSectionTurn
EQUB &09 \ zTrackSectionOHi zTrackSectionO = &0927 = 2343
EQUB 13 \ trackDriverSpeed
\ Track section 24
EQUB &C1 \ trackSectionData sign = 12, sectionListSize = 1
EQUB &05 \ xTrackSectionIHi xTrackSectionI = &05D0 = 1488
EQUB &15 \ yTrackSectionIHi yTrackSectionI = &1599 = 5529
EQUB &0A \ zTrackSectionIHi zTrackSectionI = &0A0B = 2571
EQUB &06 \ xTrackSectionOHi xTrackSectionO = &067E = 1662
EQUB 255 \ trackSectionTurn
EQUB &09 \ zTrackSectionOHi zTrackSectionO = &0950 = 2384
EQUB 255 \ trackDriverSpeed
\ Track section 25
EQUB &D3 \ trackSectionData sign = 13, sectionListSize = 3
EQUB &F9 \ xTrackSectionIHi xTrackSectionI = &F970 = -1680
EQUB &19 \ yTrackSectionIHi yTrackSectionI = &1923 = 6435
EQUB &FE \ zTrackSectionIHi zTrackSectionI = &FE83 = -381
EQUB &FA \ xTrackSectionOHi xTrackSectionO = &FA1E = -1506
EQUB 47 \ trackSectionTurn
EQUB &FD \ zTrackSectionOHi zTrackSectionO = &FDC8 = -568
EQUB 125 \ trackDriverSpeed
\ Track section 26
EQUB &E2 \ trackSectionData sign = 14, sectionListSize = 2
EQUB &E5 \ xTrackSectionIHi xTrackSectionI = &E5D8 = -6696
EQUB &19 \ yTrackSectionIHi yTrackSectionI = &193C = 6460
EQUB &EC \ zTrackSectionIHi zTrackSectionI = &EC41 = -5055
EQUB &E6 \ xTrackSectionOHi xTrackSectionO = &E686 = -6522
EQUB 42 \ trackSectionTurn
EQUB &EB \ zTrackSectionOHi zTrackSectionO = &EB86 = -5242
EQUB 24 \ trackDriverSpeed
\ Track section 27
EQUB &E1 \ trackSectionData sign = 14, sectionListSize = 1
EQUB &DB \ xTrackSectionIHi xTrackSectionI = &DB15 = -9451
EQUB &16 \ yTrackSectionIHi yTrackSectionI = &16E6 = 5862
EQUB &ED \ zTrackSectionIHi zTrackSectionI = &EDCA = -4662
EQUB &DA \ xTrackSectionOHi xTrackSectionO = &DA64 = -9628
EQUB 255 \ trackSectionTurn
EQUB &ED \ zTrackSectionOHi zTrackSectionO = &ED11 = -4847
EQUB 125 \ trackDriverSpeed
\ Track section 28
EQUB &F2 \ trackSectionData sign = 15, sectionListSize = 2
EQUB &D3 \ xTrackSectionIHi xTrackSectionI = &D398 = -11368
EQUB &17 \ yTrackSectionIHi yTrackSectionI = &179A = 6042
EQUB &F7 \ zTrackSectionIHi zTrackSectionI = &F7D9 = -2087
EQUB &D2 \ xTrackSectionOHi xTrackSectionO = &D2A5 = -11611
EQUB 255 \ trackSectionTurn
EQUB &F7 \ zTrackSectionOHi zTrackSectionO = &F78C = -2164
EQUB 255 \ trackDriverSpeed
EQUB &00, &00 \ These bytes appear to be unused
EQUB &00, &00
EQUB &00, &34
EQUB &00, &7F
\ ******************************************************************************
\
\ Name: Hook80Percent
\ Type: Subroutine
\ Category: Extra tracks
\ Summary: Set the horizonTrackWidth to 80% of the width of the track on the
\ horizon
\ Deep dive: Secrets of the extra tracks
\ Code hooks in the extra tracks
\
\ ------------------------------------------------------------------------------
\
\ This routine is called from GetTrackAndMarkers to set the horizonTrackWidth to
\ 80% of the width of the track on the horizon.
\
\ ******************************************************************************
.Hook80Percent
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
EQUB &00 \ This byte appears to be unused
\ ******************************************************************************
\
\ 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
EQUB &00, &00 \ These bytes appear to be unused
\ ******************************************************************************
\
\ 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 padded out to be 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 &00 \ This byte pads the block out to exactly 20 bytes
\ ******************************************************************************
\
\ 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 padded out to be 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 &00 \ This byte pads the block out to exactly 20 bytes
\ ******************************************************************************
\
\ 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 = &0023 ( 35)
EQUB &00 \ Sub-section 1 = &0048 ( 72)
EQUB &00 \ Sub-section 2 = &00CB ( 203)
EQUB &01 \ Sub-section 3 = &01AC ( 428)
EQUB &05 \ Sub-section 4 = &055C ( 1372)
EQUB &01 \ Sub-section 5 = &019D ( 413)
EQUB &00 \ Sub-section 6 = &0000 ( 0)
EQUB &02 \ Sub-section 7 = &02AB ( 683)
EQUB &00 \ Sub-section 8 = &0000 ( 0)
EQUB &00 \ Sub-section 9 = &0000 ( 0)
EQUB &00 \ Sub-section 10 = &0000 ( 0)
EQUB &06 \ Sub-section 11 = &063D ( 1597)
EQUB &00 \ Sub-section 12 = &0000 ( 0)
EQUB &FC \ Sub-section 13 = &FC0A (-1014)
EQUB &FD \ Sub-section 14 = &FDDE ( -546)
EQUB &FC \ Sub-section 15 = &FC17 (-1001)
EQUB &FE \ Sub-section 16 = &FEF8 ( -264)
EQUB &FF \ Sub-section 17 = &FF4A ( -182)
EQUB &FF \ Sub-section 18 = &FFE1 ( -31)
EQUB &FF \ Sub-section 19 = &FF16 ( -234)
EQUB &FD \ Sub-section 20 = &FD46 ( -698)
EQUB &FE \ Sub-section 21 = &FE52 ( -430)
EQUB &FD \ Sub-section 22 = &FD5C ( -676)
EQUB &FB \ Sub-section 23 = &FBBC (-1092)
EQUB &00 \ Sub-section 24 = &0000 ( 0)
EQUB &00 \ Sub-section 25 = &0000 ( 0)
EQUB &00 \ Sub-section 26 = &0000 ( 0)
EQUB &01 \ Sub-section 27 = &016C ( 364)
EQUB &00 \ Sub-section 28 = &0000 ( 0)
EQUB &00 \ Sub-section 29 = &0000 ( 0)
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 = &0132 ( 306)
EQUB &01 \ Sub-section 34 = &019A ( 410)
EQUB &01 \ Sub-section 35 = &01FB ( 507)
EQUB &04 \ Sub-section 36 = &0417 ( 1047)
EQUB &01 \ Sub-section 37 = &01A3 ( 419)
EQUB &03 \ Sub-section 38 = &0311 ( 785)
EQUB &01 \ Sub-section 39 = &015A ( 346)
EQUB &00 \ Sub-section 40 = &0000 ( 0)
EQUB &00 \ Sub-section 41 = &0000 ( 0)
EQUB &02 \ Sub-section 42 = &0272 ( 626)
EQUB &03 \ Sub-section 43 = &037C ( 892)
EQUB &05 \ Sub-section 44 = &057A ( 1402)
EQUB &FC \ Sub-section 45 = &FCBB ( -837)
EQUB &FB \ Sub-section 46 = &FBF8 (-1032)
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 &05 \ Sub-section 51 = &0555 ( 1365)
EQUB &02 \ Sub-section 52 = &0211 ( 529)
EQUB &02 \ Sub-section 53 = &0211 ( 529)
EQUB &00 \ Sub-section 54 = &0060 ( 96)
EQUB &01 \ Sub-section 55 = &01B0 ( 432)
EQUB &00 \ Sub-section 56 = &0078 ( 120)
EQUB &00 \ Sub-section 57 = &0020 ( 32)
\ ******************************************************************************
\
\ 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 Brands Hatch track
\
\ ******************************************************************************
.trackSignData
EQUB %00001100 \ Sign 0: 00001 100 Type 11 Right turn Section 1
EQUB %00010000 \ Sign 1: 00010 000 Type 7 Straight Section 2
EQUB %00100011 \ Sign 2: 00100 011 Type 10 Hairpin Section 4
EQUB %00100000 \ Sign 3: 00100 000 Type 7 Straight Section 4
EQUB %00111000 \ Sign 4: 00111 000 Type 7 Straight Section 7
EQUB %01001101 \ Sign 5: 01001 101 Type 12 Left turn Section 9
EQUB %01011000 \ Sign 6: 01011 000 Type 7 Straight Section 11
EQUB %01100000 \ Sign 7: 01100 000 Type 7 Straight Section 12
EQUB %01101100 \ Sign 8: 01101 100 Type 11 Right turn Section 13
EQUB %10001100 \ Sign 9: 10001 100 Type 11 Right turn Section 17
EQUB %10100100 \ Sign 10: 10100 100 Type 11 Right turn Section 20
EQUB %10110101 \ Sign 11: 10110 101 Type 12 Left turn Section 22
EQUB %11000000 \ Sign 12: 11000 000 Type 7 Straight Section 24
EQUB %11010100 \ Sign 13: 11010 100 Type 11 Right turn Section 26
EQUB %11100000 \ Sign 14: 11100 000 Type 7 Straight Section 28
EQUB %00000001 \ Sign 15: 00000 001 Type 8 Start flag Section 0
\ ******************************************************************************
\
\ 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
\ and axes for the segment vector
LDA yawAngleLo \ Set A = (yawAngleHi yawAngleLo) << 1
ASL A \
LDA yawAngleHi \ Keeping the high byte only and rotating bit 7 into
ROL A \ the C flag
PHA \ Push the high byte in A onto the stack, so the stack
\ contains the high byte of yawAngle << 1
ROL A \ Set bits 0-2 of U to bits 5-7 of yawAngleHi (i.e. the
ROL A \ top three bits), so this is equivalent to:
ROL A \
AND #%00000111 \ U = (yawAngleHi yawAngleLo) DIV 8192
STA U \
\ We will use U to work out the direction of the track
\ that we are building
\ We now work out the index into the xTrackCurve and
\ zTrackCurve tables for the curve that matches the
\ direction of the track, putting the result in X
\
\ The curve tables contain coordinates for a curve that
\ covers one-eighth of a circle, or 45 degrees, so we
\ first reduce the yaw angle into that range by reducing
\ our 32-bit angle into this range
\
\ The 32-bit angle in (yawAngleHi yawAngleLo) cover a
\ whole circle, so 0 to 65536 represents 0 to 360
\ degrees, so one-eighth of a circle, or 45 degrees, is
\ represented by 65536 / 8 = 8192
\
\ So we reduce the 32-bit value into the range 0 to 8192
\ so we can map it to the curve in the curve tables
LSR A \ Set the C flag to bit 0 of A, i.e. bit 5 of yawAngleHi
PLA \ Retrieve the high byte that we pushed onto the stack,
\ i.e. the high byte of yawAngle << 1
AND #%00111111 \ Clear bits 6 and 7 of A, so A now contains two zeroes,
\ then bits 4, 3, 2, 1, 0 of yawAngleHi, then bit 7 of
\ yawAngleLo
\ By this point, we have:
\
\ X = (yawAngleHi yawAngleLo) MOD 8192
\
\ This is the corresponding point in the curve tables
\ for the track direction, reduced to one-eighth of a
\ circle, or 0 to 45 degrees
\
\ The next eighth of the circle (i.e. from 45 to 90
\ degrees) will map to the curve tables, but in reverse,
\ so we can extend our calculation to quarter circle by
\ flipping the index in X for this range of yaw angle
\ (i.e. if we are in the second eighth of the circle,
\ from 45 to 90 degrees, which is when bit 5 of the high
\ byte is clear)
BCC vect1 \ If the C flag, i.e. bit 5 of yawAngleHi, is clear,
\ jump to vect1 to skip the following
EOR #%00111111 \ Negate A using two's complement (the ADC adds 1 as the
ADC #0 \ C flag is set)
.vect1
\ By this point, A contains the index of the curve
\ within the curve tables that corresponds to the angle
\ in which the track is pointing, reduced to the first
\ quarter of a circle (0 to 90 degrees)
\
\ We can now fetch the vector for that point on the
\ curve, which will give us the vector of the curve at
\ that point (i.e. the direction of the curve for the
\ track segment we are building)
TAX \ Set X = A
LDY xTrackCurve,X \ Set Y = X-th entry in xTrackCurve
LDA zTrackCurve,X \ Set X = X-th entry in zTrackCurve
TAX
\ The vector in X and Y now contains the correct values
\ for the curve vector, but because we reduced it to the
\ first quarter in the circle, the signs may not be
\ correct, and we may need to swap the x-coordinate and
\ z-coordinate
\
\ We now use the value of U to set the vector properly,
\ as the value of U determines which eighth of the
\ circle corresponds to the track direction
LDA U \ If bit 1 of U + 1 is set, i.e. U ends in %01 or %10,
CLC \ i.e. bits 5 and 6 of yawAngleHi are different, then
ADC #1 \ jump to vect2 to set V and W the other way round
AND #%00000010
BNE vect2
STY V \ Set V = Y
STX W \ Set W = X
BEQ vect3 \ Jump to vect3 (this BEQ is effectively a JMP as we
\ passed through a BNE above)
.vect2
STX V \ Set V = X
STY W \ Set W = Y