-
Notifications
You must be signed in to change notification settings - Fork 4
/
revs-oultonpark.asm
4048 lines (3486 loc) · 171 KB
/
revs-oultonpark.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 OULTON 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:
\
\ * OultonPark.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 = 128 \ 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 OULTON PARK TRACK
\
\ Produces the binary file OultonPark.bin that contains the Oulton 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 Oulton Park track
\
\ ------------------------------------------------------------------------------
\
\ Oulton Park consists of the following track sections:
\
\ 0 |<-| Lodge to Old Hall (4/4)
\ 1 -> Old Hall
\ 2 || Old Hall to Cascades (1/4)
\ 3 -> Old Hall to Cascades (2/4)
\ 4 -> Old Hall to Cascades (3/4)
\ 5 {} Old Hall to Cascades (4/4)
\ 6 <- Cascades
\ 7 || Cascades to Island Hairpin (1/2)
\ 8 |->| Cascades to Island Hairpin (2/2)
\ 9 |->| Island Hairpin
\ 10 {} Island Hairpin to Knickerbrook (1/4)
\ 11 {} Island Hairpin to Knickerbrook (2/4)
\ 12 || Island Hairpin to Knickerbrook (3/4)
\ 13 {} Island Hairpin to Knickerbrook (4/4)
\ 14 -> Knickerbrook
\ 15 |->| Knickerbrook to Druids (1/4)
\ 16 <- Knickerbrook to Druids (2/4)
\ 17 |<-| Knickerbrook to Druids (3/4)
\ 18 |<->| Knickerbrook to Druids (4/4)
\ 19 -> Druids
\ 20 |<-| Druids to Lodge (1/3)
\ 21 || Druids to Lodge (2/3)
\ 22 |->| Druids to Lodge (3/3)
\ 23 -> Lodge
\ 24 -> Lodge to Old Hall (1/4)
\ 25 <- Lodge to Old Hall (2/4)
\ 26 |<-| Lodge to Old Hall (3/4)
\
\ 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 &12 \ trackSectionData sign = 1, sectionListSize = 2
EQUB &D1 \ xTrackSectionIHi xTrackSectionI = &D120 = -12000
EQUB &12 \ yTrackSectionIHi yTrackSectionI = &1200 = 4608
EQUB &D1 \ zTrackSectionIHi zTrackSectionI = &D120 = -12000
EQUB &D0 \ xTrackSectionOHi xTrackSectionO = &D030 = -12240
EQUB 42 \ trackSectionTurn
EQUB &D1 \ zTrackSectionOHi zTrackSectionO = &D120 = -12000
EQUB 120 \ trackDriverSpeed
\ Track section 1
EQUB &21 \ trackSectionData sign = 2, sectionListSize = 1
EQUB &CE \ xTrackSectionIHi xTrackSectionI = &CEC3 = -12605
EQUB &10 \ yTrackSectionIHi yTrackSectionI = &10BB = 4283
EQUB &E6 \ zTrackSectionIHi zTrackSectionI = &E60C = -6644
EQUB &CD \ xTrackSectionOHi xTrackSectionO = &CDD5 = -12843
EQUB 27 \ trackSectionTurn
EQUB &E5 \ zTrackSectionOHi zTrackSectionO = &E5EE = -6674
EQUB 15 \ trackDriverSpeed
\ Track section 2
EQUB &23 \ trackSectionData sign = 2, sectionListSize = 3
EQUB &D2 \ xTrackSectionIHi xTrackSectionI = &D225 = -11739
EQUB &10 \ yTrackSectionIHi yTrackSectionI = &1009 = 4105
EQUB &ED \ zTrackSectionIHi zTrackSectionI = &ED6B = -4757
EQUB &D1 \ xTrackSectionOHi xTrackSectionO = &D1D5 = -11819
EQUB 255 \ trackSectionTurn
EQUB &EE \ zTrackSectionOHi zTrackSectionO = &EE4D = -4531
EQUB 255 \ trackDriverSpeed
\ Track section 3
EQUB &33 \ trackSectionData sign = 3, sectionListSize = 3
EQUB &E2 \ xTrackSectionIHi xTrackSectionI = &E27A = -7558
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0F9A = 3994
EQUB &F3 \ zTrackSectionIHi zTrackSectionI = &F333 = -3277
EQUB &E2 \ xTrackSectionOHi xTrackSectionO = &E22A = -7638
EQUB 9 \ trackSectionTurn
EQUB &F4 \ zTrackSectionOHi zTrackSectionO = &F415 = -3051
EQUB 255 \ trackDriverSpeed
\ Track section 4
EQUB &33 \ trackSectionData sign = 3, sectionListSize = 3
EQUB &ED \ xTrackSectionIHi xTrackSectionI = &ED35 = -4811
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0F52 = 3922
EQUB &F6 \ zTrackSectionIHi zTrackSectionI = &F68A = -2422
EQUB &EC \ xTrackSectionOHi xTrackSectionO = &ECF5 = -4875
EQUB 36 \ trackSectionTurn
EQUB &F7 \ zTrackSectionOHi zTrackSectionO = &F772 = -2190
EQUB 20 \ trackDriverSpeed
\ Track section 5
EQUB &42 \ trackSectionData sign = 4, sectionListSize = 2
EQUB &EF \ xTrackSectionIHi xTrackSectionI = &EFFE = -4098
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0F16 = 3862
EQUB &F6 \ zTrackSectionIHi zTrackSectionI = &F6DD = -2339
EQUB &EF \ xTrackSectionOHi xTrackSectionO = &EFFC = -4100
EQUB 18 \ trackSectionTurn
EQUB &F7 \ zTrackSectionOHi zTrackSectionO = &F7CD = -2099
EQUB 130 \ trackDriverSpeed
\ Track section 6
EQUB &53 \ trackSectionData sign = 5, sectionListSize = 3
EQUB &FA \ xTrackSectionIHi xTrackSectionI = &FA4E = -1458
EQUB &0C \ yTrackSectionIHi yTrackSectionI = &0CD6 = 3286
EQUB &F6 \ zTrackSectionIHi zTrackSectionI = &F6F3 = -2317
EQUB &FA \ xTrackSectionOHi xTrackSectionO = &FA4C = -1460
EQUB 49 \ trackSectionTurn
EQUB &F7 \ zTrackSectionOHi zTrackSectionO = &F7E3 = -2077
EQUB 26 \ trackDriverSpeed
\ Track section 7
EQUB &54 \ trackSectionData sign = 5, sectionListSize = 4
EQUB &03 \ xTrackSectionIHi xTrackSectionI = &032D = 813
EQUB &0B \ yTrackSectionIHi yTrackSectionI = &0BE0 = 3040
EQUB &04 \ zTrackSectionIHi zTrackSectionI = &0493 = 1171
EQUB &02 \ xTrackSectionOHi xTrackSectionO = &024D = 589
EQUB 255 \ trackSectionTurn
EQUB &04 \ zTrackSectionOHi zTrackSectionO = &043F = 1087
EQUB 255 \ trackDriverSpeed
\ Track section 8
EQUB &63 \ trackSectionData sign = 6, sectionListSize = 3
EQUB &F8 \ xTrackSectionIHi xTrackSectionI = &F8AD = -1875
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0F60 = 3936
EQUB &20 \ zTrackSectionIHi zTrackSectionI = &2093 = 8339
EQUB &F7 \ xTrackSectionOHi xTrackSectionO = &F7CD = -2099
EQUB 28 \ trackSectionTurn
EQUB &20 \ zTrackSectionOHi zTrackSectionO = &203F = 8255
EQUB 67 \ trackDriverSpeed
\ Track section 9
EQUB &73 \ trackSectionData sign = 7, sectionListSize = 3
EQUB &F4 \ xTrackSectionIHi xTrackSectionI = &F41D = -3043
EQUB &0E \ yTrackSectionIHi yTrackSectionI = &0EBB = 3771
EQUB &2D \ zTrackSectionIHi zTrackSectionI = &2DDE = 11742
EQUB &F3 \ xTrackSectionOHi xTrackSectionO = &F339 = -3271
EQUB 23 \ trackSectionTurn
EQUB &2D \ zTrackSectionOHi zTrackSectionO = &2D92 = 11666
EQUB 10 \ trackDriverSpeed
\ Track section 10
EQUB &83 \ trackSectionData sign = 8, sectionListSize = 3
EQUB &F8 \ xTrackSectionIHi xTrackSectionI = &F888 = -1912
EQUB &0D \ yTrackSectionIHi yTrackSectionI = &0DF4 = 3572
EQUB &30 \ zTrackSectionIHi zTrackSectionI = &30C0 = 12480
EQUB &F9 \ xTrackSectionOHi xTrackSectionO = &F95E = -1698
EQUB 255 \ trackSectionTurn
EQUB &31 \ zTrackSectionOHi zTrackSectionO = &312E = 12590
EQUB 255 \ trackDriverSpeed
\ Track section 11
EQUB &83 \ trackSectionData sign = 8, sectionListSize = 3
EQUB &01 \ xTrackSectionIHi xTrackSectionI = &0120 = 288
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0F34 = 3892
EQUB &20 \ zTrackSectionIHi zTrackSectionI = &2008 = 8200
EQUB &01 \ xTrackSectionOHi xTrackSectionO = &01F6 = 502
EQUB 255 \ trackSectionTurn
EQUB &20 \ zTrackSectionOHi zTrackSectionO = &2076 = 8310
EQUB 255 \ trackDriverSpeed
\ Track section 12
EQUB &92 \ trackSectionData sign = 9, sectionListSize = 2
EQUB &05 \ xTrackSectionIHi xTrackSectionI = &056C = 1388
EQUB &0E \ yTrackSectionIHi yTrackSectionI = &0E44 = 3652
EQUB &17 \ zTrackSectionIHi zTrackSectionI = &17AC = 6060
EQUB &06 \ xTrackSectionOHi xTrackSectionO = &0642 = 1602
EQUB 255 \ trackSectionTurn
EQUB &18 \ zTrackSectionOHi zTrackSectionO = &181A = 6170
EQUB 255 \ trackDriverSpeed
\ Track section 13
EQUB &A5 \ trackSectionData sign = 10, sectionListSize = 5
EQUB &12 \ xTrackSectionIHi xTrackSectionI = &1219 = 4633
EQUB &0D \ yTrackSectionIHi yTrackSectionI = &0DCE = 3534
EQUB &FF \ zTrackSectionIHi zTrackSectionI = &FF03 = -253
EQUB &12 \ xTrackSectionOHi xTrackSectionO = &12EF = 4847
EQUB 13 \ trackSectionTurn
EQUB &FF \ zTrackSectionOHi zTrackSectionO = &FF71 = -143
EQUB 140 \ trackDriverSpeed
\ Track section 14
EQUB &A4 \ trackSectionData sign = 10, sectionListSize = 4
EQUB &16 \ xTrackSectionIHi xTrackSectionI = &16D3 = 5843
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0F5D = 3933
EQUB &F5 \ zTrackSectionIHi zTrackSectionI = &F5D1 = -2607
EQUB &17 \ xTrackSectionOHi xTrackSectionO = &17A9 = 6057
EQUB 34 \ trackSectionTurn
EQUB &F6 \ zTrackSectionOHi zTrackSectionO = &F63F = -2497
EQUB 18 \ trackDriverSpeed
\ Track section 15
EQUB &A3 \ trackSectionData sign = 10, sectionListSize = 3
EQUB &16 \ xTrackSectionIHi xTrackSectionI = &160B = 5643
EQUB &0F \ yTrackSectionIHi yTrackSectionI = &0FD7 = 4055
EQUB &EE \ zTrackSectionIHi zTrackSectionI = &EEAD = -4435
EQUB &16 \ xTrackSectionOHi xTrackSectionO = &16DB = 5851
EQUB 28 \ trackSectionTurn
EQUB &EE \ zTrackSectionOHi zTrackSectionO = &EE35 = -4555
EQUB 255 \ trackDriverSpeed
\ Track section 16
EQUB &B3 \ trackSectionData sign = 11, sectionListSize = 3
EQUB &0A \ xTrackSectionIHi xTrackSectionI = &0AFC = 2812
EQUB &0E \ yTrackSectionIHi yTrackSectionI = &0EAA = 3754
EQUB &DD \ zTrackSectionIHi zTrackSectionI = &DD55 = -8875
EQUB &0B \ xTrackSectionOHi xTrackSectionO = &0BBC = 3004
EQUB 38 \ trackSectionTurn
EQUB &DC \ zTrackSectionOHi zTrackSectionO = &DCC7 = -9017
EQUB 12 \ trackDriverSpeed
\ Track section 17
EQUB &B3 \ trackSectionData sign = 11, sectionListSize = 3
EQUB &08 \ xTrackSectionIHi xTrackSectionI = &086B = 2155
EQUB &10 \ yTrackSectionIHi yTrackSectionI = &10E6 = 4326
EQUB &D7 \ zTrackSectionIHi zTrackSectionI = &D7D9 = -10279
EQUB &09 \ xTrackSectionOHi xTrackSectionO = &0953 = 2387
EQUB 255 \ trackSectionTurn
EQUB &D7 \ zTrackSectionOHi zTrackSectionO = &D79B = -10341
EQUB 255 \ trackDriverSpeed
\ Track section 18
EQUB &C3 \ trackSectionData sign = 12, sectionListSize = 3
EQUB &03 \ xTrackSectionIHi xTrackSectionI = &03FC = 1020
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &117A = 4474
EQUB &C3 \ zTrackSectionIHi zTrackSectionI = &C3BB = -15429
EQUB &04 \ xTrackSectionOHi xTrackSectionO = &04EA = 1258
EQUB 31 \ trackSectionTurn
EQUB &C3 \ zTrackSectionOHi zTrackSectionO = &C39D = -15459
EQUB 137 \ trackDriverSpeed
\ Track section 19
EQUB &D3 \ trackSectionData sign = 13, sectionListSize = 3
EQUB &04 \ xTrackSectionIHi xTrackSectionI = &0491 = 1169
EQUB &10 \ yTrackSectionIHi yTrackSectionI = &109B = 4251
EQUB &B2 \ zTrackSectionIHi zTrackSectionI = &B265 = -19867
EQUB &05 \ xTrackSectionOHi xTrackSectionO = &057F = 1407
EQUB 42 \ trackSectionTurn
EQUB &B2 \ zTrackSectionOHi zTrackSectionO = &B24D = -19891
EQUB 23 \ trackDriverSpeed
\ Track section 20
EQUB &E3 \ trackSectionData sign = 14, sectionListSize = 3
EQUB &FA \ xTrackSectionIHi xTrackSectionI = &FA26 = -1498
EQUB &12 \ yTrackSectionIHi yTrackSectionI = &121B = 4635
EQUB &AA \ zTrackSectionIHi zTrackSectionI = &AA75 = -21899
EQUB &FA \ xTrackSectionOHi xTrackSectionO = &FA20 = -1504
EQUB 255 \ trackSectionTurn
EQUB &A9 \ zTrackSectionOHi zTrackSectionO = &A985 = -22139
EQUB 255 \ trackDriverSpeed
\ Track section 21
EQUB &E3 \ trackSectionData sign = 14, sectionListSize = 3
EQUB &EF \ xTrackSectionIHi xTrackSectionI = &EF5E = -4258
EQUB &11 \ yTrackSectionIHi yTrackSectionI = &1132 = 4402
EQUB &AA \ zTrackSectionIHi zTrackSectionI = &AA78 = -21896
EQUB &EF \ xTrackSectionOHi xTrackSectionO = &EF72 = -4238
EQUB 255 \ trackSectionTurn
EQUB &A9 \ zTrackSectionOHi zTrackSectionO = &A988 = -22136
EQUB 255 \ trackDriverSpeed
\ Track section 22
EQUB &E1 \ trackSectionData sign = 14, sectionListSize = 1
EQUB &E0 \ xTrackSectionIHi xTrackSectionI = &E0D6 = -7978
EQUB &12 \ yTrackSectionIHi yTrackSectionI = &1287 = 4743
EQUB &A9 \ zTrackSectionIHi zTrackSectionI = &A942 = -22206
EQUB &E0 \ xTrackSectionOHi xTrackSectionO = &E0EA = -7958
EQUB 37 \ trackSectionTurn
EQUB &A8 \ zTrackSectionOHi zTrackSectionO = &A852 = -22446
EQUB 91 \ trackDriverSpeed
\ Track section 23
EQUB &F1 \ trackSectionData sign = 15, sectionListSize = 1
EQUB &CD \ xTrackSectionIHi xTrackSectionI = &CD2A = -13014
EQUB &12 \ yTrackSectionIHi yTrackSectionI = &12DB = 4827
EQUB &A8 \ zTrackSectionIHi zTrackSectionI = &A8A9 = -22359
EQUB &CC \ xTrackSectionOHi xTrackSectionO = &CCFE = -13058
EQUB 22 \ trackSectionTurn
EQUB &A7 \ zTrackSectionOHi zTrackSectionO = &A7BD = -22595
EQUB 13 \ trackDriverSpeed
\ Track section 24
EQUB &F3 \ trackSectionData sign = 15, sectionListSize = 3
EQUB &CA \ xTrackSectionIHi xTrackSectionI = &CAA8 = -13656
EQUB &12 \ yTrackSectionIHi yTrackSectionI = &12E1 = 4833
EQUB &AD \ zTrackSectionIHi zTrackSectionI = &AD0C = -21236
EQUB &C9 \ xTrackSectionOHi xTrackSectionO = &C9BE = -13890
EQUB 6 \ trackSectionTurn
EQUB &AD \ zTrackSectionOHi zTrackSectionO = &AD40 = -21184
EQUB 255 \ trackDriverSpeed
\ Track section 25
EQUB &03 \ trackSectionData sign = 0, sectionListSize = 3
EQUB &CF \ xTrackSectionIHi xTrackSectionI = &CF94 = -12396
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &14EA = 5354
EQUB &BB \ zTrackSectionIHi zTrackSectionI = &BBAC = -17492
EQUB &CE \ xTrackSectionOHi xTrackSectionO = &CEBA = -12614
EQUB 45 \ trackSectionTurn
EQUB &BC \ zTrackSectionOHi zTrackSectionO = &BC10 = -17392
EQUB 14 \ trackDriverSpeed
\ Track section 26
EQUB &03 \ trackSectionData sign = 0, sectionListSize = 3
EQUB &D0 \ xTrackSectionIHi xTrackSectionI = &D072 = -12174
EQUB &14 \ yTrackSectionIHi yTrackSectionI = &146A = 5226
EQUB &BF \ zTrackSectionIHi zTrackSectionI = &BF4D = -16563
EQUB &CF \ xTrackSectionOHi xTrackSectionO = &CF82 = -12414
EQUB 255 \ trackSectionTurn
EQUB &BF \ zTrackSectionOHi zTrackSectionO = &BF61 = -16543
EQUB 255 \ trackDriverSpeed
EQUB &06, &74 \ These bytes appear to be unused
EQUB &2A, &60
EQUB &A5, &2A
EQUB &20, &78
EQUB &34, &C9
EQUB &19, &B0
EQUB &07, &A5
EQUB &0D, &10
\ ******************************************************************************
\
\ 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
\ ******************************************************************************
\
\ Name: HookJoystick (Part 2 of 2)
\ 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
\
\ ******************************************************************************
.joys4
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 = 248 we have:
\
\ (A T) = 2 * (248/256 * x-axis) ^ 2
\ = 2 * (0.969 * x-axis) ^ 2
\ = 1.88 * x-axis ^ 2
\
\ and for A = 190 we have:
\
\ (A T) = 2 * (190/256 * x-axis) ^ 2
\ = 2 * (0.742 * x-axis) ^ 2
\ = 1.10 * 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: 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 &24 \ 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 &2F \ 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 &FE \ Sub-section 0 = &FE39 ( -455)
EQUB &00 \ Sub-section 1 = &0000 ( 0)
EQUB &FF \ Sub-section 2 = &FF87 ( -121)
EQUB &00 \ Sub-section 3 = &0000 ( 0)
EQUB &01 \ Sub-section 4 = &0161 ( 353)
EQUB &04 \ Sub-section 5 = &040A ( 1034)
EQUB &04 \ Sub-section 6 = &040A ( 1034)
EQUB &00 \ Sub-section 7 = &001E ( 30)
EQUB &01 \ Sub-section 8 = &01C7 ( 455)
EQUB &00 \ Sub-section 9 = &0000 ( 0)
EQUB &00 \ Sub-section 10 = &0000 ( 0)
EQUB &FE \ Sub-section 11 = &FE4B ( -437)
EQUB &FD \ Sub-section 12 = &FDD5 ( -555)
EQUB &FE \ Sub-section 13 = &FEFA ( -262)
EQUB &FC \ Sub-section 14 = &FC44 ( -956)
EQUB &00 \ Sub-section 15 = &0017 ( 23)
EQUB &00 \ Sub-section 16 = &0017 ( 23)
EQUB &00 \ Sub-section 17 = &0000 ( 0)
EQUB &00 \ Sub-section 18 = &0000 ( 0)
EQUB &05 \ Sub-section 19 = &0509 ( 1289)
EQUB &07 \ Sub-section 20 = &079B ( 1947)
EQUB &00 \ Sub-section 21 = &0000 ( 0)
EQUB &00 \ Sub-section 22 = &0000 ( 0)
EQUB &00 \ Sub-section 23 = &0000 ( 0)
EQUB &00 \ Sub-section 24 = &0000 ( 0)
EQUB &00 \ Sub-section 25 = &0000 ( 0)
EQUB &00 \ Sub-section 26 = &0000 ( 0)
EQUB &02 \ Sub-section 27 = &02FD ( 765)
EQUB &01 \ Sub-section 28 = &01D6 ( 470)
EQUB &00 \ Sub-section 29 = &0000 ( 0)
EQUB &00 \ Sub-section 30 = &00B0 ( 176)
EQUB &00 \ Sub-section 31 = &0000 ( 0)
EQUB &FE \ Sub-section 32 = &FECD ( -307)
EQUB &00 \ Sub-section 33 = &0000 ( 0)
EQUB &00 \ Sub-section 34 = &0000 ( 0)
EQUB &FF \ Sub-section 35 = &FFA5 ( -91)
EQUB &FF \ Sub-section 36 = &FFD2 ( -46)
EQUB &FF \ Sub-section 37 = &FF1C ( -228)
EQUB &00 \ Sub-section 38 = &0000 ( 0)
EQUB &00 \ Sub-section 39 = &00FE ( 254)
EQUB &04 \ Sub-section 40 = &04CD ( 1229)
EQUB &01 \ Sub-section 41 = &014E ( 334)
EQUB &02 \ Sub-section 42 = &020D ( 525)
EQUB &02 \ Sub-section 43 = &020D ( 525)
EQUB &00 \ Sub-section 44 = &0000 ( 0)
EQUB &FF \ Sub-section 45 = &FF7D ( -131)
EQUB &00 \ Sub-section 46 = &00E4 ( 228)
EQUB &00 \ Sub-section 47 = &0000 ( 0)
EQUB &00 \ Sub-section 48 = &0000 ( 0)
EQUB &01 \ Sub-section 49 = &018A ( 394)
EQUB &05 \ Sub-section 50 = &0574 ( 1396)
EQUB &05 \ Sub-section 51 = &0574 ( 1396)
EQUB &00 \ Sub-section 52 = &0042 ( 66)
EQUB &00 \ Sub-section 53 = &0042 ( 66)
EQUB &FE \ Sub-section 54 = &FE3F ( -449)
EQUB &00 \ Sub-section 55 = &0000 ( 0)
EQUB &FE \ Sub-section 56 = &FE39 ( -455)
EQUB &00 \ Sub-section 57 = &0000 ( 0)
\ ******************************************************************************
\
\ 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 Oulton Park track
\
\ ******************************************************************************
.trackSignData
EQUB %11010001 \ Sign 0: 11010 001 Type 8 Start flag Section 26
EQUB %00000100 \ Sign 1: 00000 100 Type 11 Right turn Section 0
EQUB %00010000 \ Sign 2: 00010 000 Type 7 Straight Section 2
EQUB %00011000 \ Sign 3: 00011 000 Type 7 Straight Section 3
EQUB %00100101 \ Sign 4: 00100 101 Type 12 Left turn Section 4
EQUB %00111000 \ Sign 5: 00111 000 Type 7 Straight Section 7
EQUB %01001011 \ Sign 6: 01001 011 Type 10 Hairpin Section 9
EQUB %01001000 \ Sign 7: 01001 000 Type 7 Straight Section 9
EQUB %01010000 \ Sign 8: 01010 000 Type 7 Straight Section 10
EQUB %01110100 \ Sign 9: 01110 100 Type 11 Right turn Section 14
EQUB %01111000 \ Sign 10: 01111 000 Type 7 Straight Section 15
EQUB %10000000 \ Sign 11: 10000 000 Type 7 Straight Section 16
EQUB %10011100 \ Sign 12: 10011 100 Type 11 Right turn Section 19
EQUB %10011000 \ Sign 13: 10011 000 Type 7 Straight Section 19
EQUB %10111100 \ Sign 14: 10111 100 Type 11 Right turn Section 23
EQUB %11001000 \ Sign 15: 11001 000 Type 7 Straight Section 25
\ ******************************************************************************
\
\ 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