Skip to navigation

Elite on the BBC Micro

Start and end: DFAULT [Elite-A, Docked]

Name: DFAULT [Show more] Type: Subroutine Category: Start and end Summary: Reset the current commander data block to the last saved commander
Context: See this subroutine in context in the source code References: This subroutine is called as follows: * BR1 (Part 1 of 2) calls DFAULT
.DFAULT 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 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 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 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 \ --- Mod: Original Acornsoft code removed: -----------> \ \ 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 \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 \ STA COK \ Store the updated competition flags in COK \ RTS \ Return from the subroutine \ --- And replaced by: --------------------------------> JMP n_load \ Jump to n_load to load the blueprint for the current \ ship type, returning from the subroutine using a tail \ call \ --- End of replacement ------------------------------>