Revs on the BBC Micro

```       Name: GetDriverAddress                                        [Show more]
Type: Subroutine
Category: Text
Summary: Get the address of the specified driver's name
Context: See this subroutine in context in the source code
References: This subroutine is called as follows:

This routine calculates the address of driver A's name using the following:

(Y A) = driverNames1 + (A div 4) * &100 + (A mod 4) * 12

The names of the 20 drivers are stored in in five blocks within the main game
code. Each block of contains four names, each of which is 12 characters long.
The blocks start every &100 (256) bytes, starting with the first block at
driverNames1 and going through to driverNames5.

Given driver number A, A div 4 is the block number, while A mod 4 is the
number of the 12-character name within that block. So we have:

* (A div 4) * &100 is the address of the start of the block containing the
name of driver A

* (A mod 4) * 12 is the offset of driver A's 12-character name within that
block

The first block is at driverNames1, so we add them together to arrive at the
calculation above.

Arguments:

X                    The driver number (0 to 19)

Returns:

(Y A)                The address of the driver's 12-character name

TXA                    \ We start with the high byte of the calculation, which
LSR A                  \ is Y = HI(driverNames1) + (A div 4)
LSR A
CLC
TAY

\ And now we do the low byte calculation, which is
\ A = LO(driverNames1) + (A mod 4) * 12

TXA                    \ Set A = (A mod 4) * 4
AND #3
ASL A
ASL A

STA T                  \ Set T = A
\       = (A mod 4) * 4

ASL A                  \ Set A = (A mod 4) * 8

CLC                    \ Set A = A + T
ADC T                  \       = (A mod 4) * 8 + (A mod 4) * 4
\       = (A mod 4) * 12

ADC #LO(driverNames1)  \ Set A = LO(driverNames1) + A
\       = LO(driverNames1) + (A mod 4) * 12

RTS                    \ Return from the subroutine
```