Skip to navigation

Elite on the BBC Micro and NES

Save and load: SVE

[BBC Master version]

Name: SVE [Show more] Type: Subroutine Category: Save and load Summary: Display the disc access menu and process saving of commander files 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: * BR1 (Part 1 of 2) calls SVE * DELT calls SVE * LOD calls SVE * NEWBRK calls SVE * TT102 calls SVE
.SVE TSX \ Transfer the stack pointer to X and store it in STX stackpt \ stackpt, so we can restore it in the NEWBRK routine JSR TRADEMODE2 \ Set the palette for trading screens and switch the \ current colour to white LDA #1 \ Print extended token 1, the disc access menu, which JSR DETOK \ presents these options: \ \ 1. Load New Commander \ 2. Save Commander {commander name} \ 3. Catalogue \ 4. Delete A File \ 5. Default JAMESON \ 6. Exit JSR t \ Scan the keyboard until a key is pressed, returning \ the ASCII code in A and X CMP #'1' \ Option 1 was chosen, so jump to loading to load a new BEQ loading \ commander CMP #'2' \ Option 2 was chosen, so jump to SV1 to save the BEQ SV1 \ current commander CMP #'3' \ Option 3 was chosen, so jump to feb10 to catalogue a BEQ feb10 \ disc CMP #'4' \ If option 4 wasn't chosen, skip the next two BNE jan18 \ instructions JSR DELT \ Option 4 was chosen, so call DELT to delete a file JMP SVE \ Jump to SVE to display the disc access menu again and \ return from the subroutine using a tail call .jan18 CMP #'5' \ If option 5 wasn't chosen, skip to feb13 to exit the BNE feb13 \ menu LDA #224 \ Print extended token 224 ("ARE YOU SURE?") JSR DETOK JSR YESNO \ Call YESNO to wait until either "Y" or "N" is pressed BCC feb13 \ If "N" was pressed, jump to feb13 JSR JAMESON \ Otherwise "Y" was pressed, so call JAMESON to set the \ last saved commander to the default "JAMESON" \ commander JMP DFAULT \ Jump to DFAULT to reset the current commander data \ block to the last saved commander, returning from the \ subroutine using a tail call .feb13 CLC \ Option 5 was chosen, so clear the C flag to indicate \ that nothing was loaded RTS \ Return from the subroutine .feb10 JSR CATS \ Call CATS to ask for a drive number (or a directory \ name on the Master Compact) and catalogue that disc \ or directory JSR t \ Scan the keyboard until a key is pressed, returning \ the ASCII code in A and X JMP SVE \ Jump to SVE to display the disc access menu and return \ from the subroutine using a tail call .loading JSR GTNMEW \ If we get here then option 1 (load) was chosen, so \ call GTNMEW to fetch the name of the commander file \ to load (including drive number and directory) into \ INWK IF _SNG47 JSR GTDRV \ Get an ASCII disc drive number from the keyboard in A, \ setting the C flag if an invalid drive number was \ entered BCS jan2186 \ If the C flag is set, then an invalid drive number was \ entered, so return from the subroutine (as DELT-1 \ contains an RTS) STA lodosc+6 \ Store the ASCII drive number in lodosc+6, which is the \ drive character of the load filename string ":1.E." ENDIF JSR LOD \ Call LOD to load the commander file JSR TRNME \ Transfer the commander filename from INWK to NA% SEC \ Set the C flag to indicate we loaded a new commander .jan2186 RTS \ Return from the subroutine .SV1 JSR GTNMEW \ If we get here then option 2 (save) was chosen, so \ call GTNMEW to fetch the name of the commander file \ to save (including drive number and directory) into \ INWK JSR TRNME \ Transfer the commander filename from INWK to NA% LSR SVC \ Halve the save count value in SVC LDA #4 \ Print extended token 4, which is blank (this was where JSR DETOK \ the competition number was printed in older versions, \ but the competition was long gone by the time of the \ BBC Master version 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 .SVL1 LDA TP,X \ Copy the X-th byte of TP to the X-th byte of NA%+8 \STA &0B00,X \ STA NA%+8,X \ The STA is commented out in the original source DEX \ Decrement the loop counter BPL SVL1 \ Loop back until we have copied all the bytes in the \ commander data block \JSR CHECK2 \ These instructions are commented out in the original \STA CHK3 \ source 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 CLC \ Clear the C flag so the call to BPRNT does not include \ a decimal point JSR TT67 \ Call TT67 twice to print two newlines JSR TT67 PLA \ Restore the checksum from the stack EOR #&A9 \ Store the checksum EOR &A9 in CHK2, the penultimate STA CHK2 \ byte of the last saved commander block \ We now copy the current commander data block into the \ TAP% staging area, though this has no effect as we \ then ignore the result (this code is left over from \ the Commodore 64 version) LDY #NT% \ Set a counter in X to copy the NT% bytes in the \ commander data block .copyme2 LDA NA%+8,Y \ Copy the X-th byte of NA% to the X-th byte of TAP% STA TAP%,Y DEY \ Decrement the loop counter BPL copyme2 \ Loop back until we have copied all the bytes in the \ commander data block IF _SNG47 JSR GTDRV \ Get an ASCII disc drive number from the keyboard in A, \ setting the C flag if an invalid drive number was \ entered BCS SVEX9 \ If the C flag is set, then an invalid drive number was \ entered, so skip the next two instructions STA savosc+6 \ Store the ASCII drive number in savosc+6, which is the \ drive character of the save filename string ":1.E." ENDIF JSR wfile \ Call wfile to save the commander file .SVEX9 JSR DFAULT \ Call DFAULT to reset the current commander data \ block to the last saved commander .SVEX CLC \ Clear the C flag to indicate that no new commander \ file was loaded RTS \ Return from the subroutine