Skip to navigation

Elite on the BBC Micro

Save and load: SVE [Electron version]

Name: SVE [Show more] Type: Subroutine Category: Save and load Summary: Save the commander file Deep dive: Commander save files The competition code
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: * TT102 calls SVE
.SVE JSR GTNME \ Clear the screen and ask for the commander filename \ to save, storing the name at INWK JSR TRNME \ Transfer the commander filename from INWK to NA% JSR ZERO \ Zero-fill pages &9, &A, &B, &C and &D, which clears \ the ship data blocks, the ship line heap, the ship \ slots for the local bubble of universe, and various \ flight and ship status variables LSR SVC \ Halve the save count value in SVC LDX #NT% \ We now want to copy the current commander data block \ from location TP to the last saved commander block at \ NA%+8, so set a counter in X to copy the NT% bytes in \ the commander data block \ \ We also want to copy the data block to another \ location &0B00, which is normally used for the ship \ lines heap .SVL1 LDA TP,X \ Copy the X-th byte of TP to the X-th byte of &0900 STA &0900,X \ and NA%+8 STA NA%+8,X DEX \ Decrement the loop counter BPL SVL1 \ Loop back until we have copied all the bytes in the \ commander data block JSR CHECK \ Call CHECK to calculate the checksum for the last \ saved commander and return it in A STA CHK \ Store the checksum in CHK, which is at the end of the \ last saved commander block PHA \ Store the checksum on the stack ORA #%10000000 \ Set K = checksum with bit 7 set STA K EOR COK \ Set K+2 = K EOR COK (the competition flags) STA K+2 EOR CASH+2 \ Set K+1 = K+2 EOR CASH+2 (the third cash byte) STA K+1 EOR #&5A \ Set K+3 = K+1 EOR &5A EOR TALLY+1 (the high byte of EOR TALLY+1 \ the kill tally) STA K+3 JSR BPRNT \ Print the competition number stored in K to K+3. The \ value of U might affect how this is printed, and as \ it's a temporary variable in zero page that isn't \ reset by ZERO, it might have any value, but as the \ competition code is a 10-digit number, this just means \ it may or may not have an extra space of padding JSR TT67 \ Call TT67 twice to print two newlines JSR TT67 PLA \ Restore the checksum from the stack STA &0900+NT% \ Store the checksum in the last byte of the save file \ at &0900 (the equivalent of CHK in the last saved \ block) EOR #&A9 \ Store the checksum EOR &A9 in CHK2, the penultimate STA CHK2 \ byte of the last saved commander block STA &08FF+NT% \ Store the checksum EOR &A9 in the penultimate byte of \ the save file at &0900 (the equivalent of CHK2 in the \ last saved block) LDY #&9 \ Set up an OSFILE block at &0A00, containing: STY &0A0B \ INY \ Start address for save = &00000900 in &0A0A to &0A0D STY &0A0F \ \ End address for save = &00000A00 in &0A0E to &0A11 \ \ Y is left containing &A which we use below LDA #0 \ Call QUS1 with A = 0, Y = &C to save the commander JSR QUS1 \ file with the filename we copied to INWK at the start \ of this routine JMP BAY \ Go to the docking bay (i.e. show Status Mode)