Skip to navigation


Start and end: QU5

[Acorn Electron version]

Name: QU5 [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 Variations: See code variations for this subroutine in the different versions References: This subroutine is called as follows: * BR1 (Part 1 of 2) calls QU5
.QU5 \ 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 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 .QUL1 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) 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 \ 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 ORA #%00001000 \ Set bit 3 of A to denote that this is the Electron \ version STA COK \ Store the updated competition flags in COK