Skip to navigation

Elite on the BBC Micro and NES

Version analysis of DFAULT / QU5

This code appears in the following versions (click to see it in the source code):

Code variations between these versions are shown below.

Code variation 1 of 11A variation in the comments only

Tap on a block to expand it, and tap it again to revert.

Name: QU5
Name: DFAULT
Type: Subroutine Category: Start and end Summary: Reset the current commander data block to the last saved commander

Code variation 2 of 11A variation in the labels only

Tap on a block to expand it, and tap it again to revert.

.QU5
.DFAULT

Code variation 3 of 11A variation in the comments only

This variation is blank in the Disc (docked), 6502 Second Processor and Master versions.

\ By the time we get here, the correct commander name \ is at NA% and the correct commander data is at NA%+8. \ Specifically: \ \ * If we loaded a commander file, then the name and \ data from that file will be at NA% and NA%+8 \ \ * If this is a brand new game, then NA% will contain \ the default starting commander name ("JAMESON") \ and NA%+8 will contain the default commander data \ \ * If this is not a new game (because they died or \ quit) and we didn't want to load a commander file, \ then NA% will contain the last saved commander \ name, and NA%+8 the last saved commander data. If \ the game has never been saved, this will still be \ the default commander

Code variation 4 of 11A variation in the comments only

This variation is blank in the Disc (docked), 6502 Second Processor, Master and Electron versions.

\JSR TTX66 \ This instruction is commented out in the original \ source; it clears the screen and draws a border

Code variation 5 of 11Specific to an individual platform

Tap on a block to expand it, and tap it again to revert.

LDX #NT% \ The size of the commander data block is NT% bytes, \ and it starts at NA%+8, so we need to copy the data \ from the "last saved" buffer at NA%+8 to the current \ commander workspace at TP. So we set up a counter in X \ for the NT% bytes that we want to copy
LDX #NT%+8 \ The size of the last saved commander data block is NT% \ bytes, and it is preceded by the 8 bytes of the \ commander name (seven characters plus a carriage \ return). The commander data block at NAME is followed \ by the commander data block, so we need to copy the \ name and data from the "last saved" buffer at NA% to \ the current commander workspace at NAME. So we set up \ a counter in X for the NT% + 8 bytes that we want to \ copy
.QUL1

Code variation 6 of 11Specific to an individual platform

Tap on a block to expand it, and tap it again to revert.

LDA NA%+7,X \ Copy the X-th byte of NA%+7 to the X-th byte of TP-1, STA TP-1,X \ (the -1 is because X is counting down from NT% to 1)
LDA NA%-1,X \ Copy the X-th byte of NA%-1 to the X-th byte of STA NAME-1,X \ NAME-1 (the -1 is because X is counting down from \ NT% + 8 to 1)
 DEX                    \ Decrement the loop counter

 BNE QUL1               \ Loop back for the next byte of the commander data
                        \ block

 STX QQ11               \ X is 0 by the end of the above loop, so this sets QQ11
                        \ to 0, which means we will be showing a view without a
                        \ boxed title at the top (i.e. we're going to use the
                        \ screen layout of a space view in the following)

                        \ If the commander check below fails, we keep jumping
                        \ back to here to crash the game with an infinite loop

Code variation 7 of 11A variation in the labels only

This variation is blank in the Cassette, Disc (docked), 6502 Second Processor and Electron versions.

.doitagain
 JSR CHECK              \ Call the CHECK subroutine to calculate the checksum
                        \ for the current commander block at NA%+8 and put it
                        \ in A

 CMP CHK                \ Test the calculated checksum against CHK

Code variation 8 of 11A variation in the labels only

Tap on a block to expand it, and tap it again to revert.

IF _REMOVE_CHECKSUMS NOP \ If we have disabled checksums, then ignore the result NOP \ of the comparison and fall through into the next part ELSE BNE P%-6 \ If the calculated checksum does not match CHK, then \ loop back to repeat the check - in other words, we \ enter an infinite loop here, as the checksum routine \ will keep returning the same incorrect value ENDIF
IF _REMOVE_CHECKSUMS NOP \ If we have disabled checksums, then ignore the result NOP \ of the comparison and fall through into the next part ELSE BNE doitagain \ If the calculated checksum does not match CHK, then \ loop back to repeat the check - in other words, we \ enter an infinite loop here, as the checksum routine \ will keep returning the same incorrect value ENDIF

Code variation 9 of 11A variation in the comments only

This variation is blank in the Cassette, Disc (docked), Master and Electron versions.

\JSR BELL \ This instruction is commented out in the original \ source. It would make a standard system beep
                        \ The checksum CHK is correct, so now we check whether
                        \ CHK2 = CHK EOR A9, and if this check fails, bit 7 of
                        \ the competition flags at COK gets set, to indicate
                        \ to Acornsoft via the competition code that there has
                        \ been some hacking going on with this competition entry

 EOR #&A9               \ X = checksum EOR &A9
 TAX

 LDA COK                \ Set A to the competition flags in COK

 CPX CHK2               \ If X = CHK2, then skip the next instruction
 BEQ tZ

 ORA #%10000000         \ Set bit 7 of A to indicate this commander file has
                        \ been tampered with

.tZ

Code variation 10 of 11Related to a standard feature

When you save a commander file, the version details get saved along with the competition flags. The flags get set as follows: the BBC Micro cassette version sets bit 1, the BBC Micro disc version sets bit 2 or 5 depending on the variant, the 6502SP version sets bit 2, and the Electron and Master versions both set bit 3.

Tap on a block to expand it, and tap it again to revert.

ORA #%00000010 \ Set bit 1 of A to denote that this is the cassette \ version
IF _STH_DISC ORA #%00100000 \ Set bit 5 of A to denote that this is the disc version \ with the refund bug fixed (in versions before the bug \ was fixed, bit 2 is set) ELIF _IB_DISC ORA #%00000100 \ Set bit 2 of A to denote that this is the disc version \ but before the refund bug was fixed (in versions after \ the bug was fixed, bit 5 is set) ENDIF
ORA #%00001000 \ Set bit 3 of A to denote that this is the Master \ version
ORA #%00000100 \ Set bit 2 of A to denote that this is the 6502 second \ processor version (which is the same bit as for the \ original disc version, before the refund bug was \ fixed)
ORA #%00001000 \ Set bit 3 of A to denote that this is the Electron \ version
 STA COK                \ Store the updated competition flags in COK

Code variation 11 of 11Minor and very low-impact

This variation is blank in the Cassette and Electron versions.

Tap on a block to expand it, and tap it again to revert.

RTS \ Return from the subroutine
\JSR CHECK2 \ These instructions are commented out in the original \CMP CHK3 \ source \BNE doitagain RTS \ Return from the subroutine