Skip to navigation

Elite on the BBC Micro

Save and load: SVE [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 * BRBR calls SVE * DELT calls SVE * LOD calls SVE * TT102 calls SVE
.SVE TSX \ Transfer the stack pointer to X and store it in stack, STX stack \ so we can restore it in the BRBR routine JSR TRADE \ 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 LD1 to load a new BEQ LD1 \ commander CMP #'2' \ Option 2 was chosen, so jump to LD1 to save the BEQ SV1 \ current commander CMP #'3' \ Option 3 was chosen, so jump to CAT to catalogue a BEQ CAT \ disc CMP #'4' \ If option 4 wasn't chosen, skip the next two BNE P%+8 \ 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 CMP #'5' \ If option 5 wasn't chosen, skip to exit to exit the BNE exit \ menu LDA #224 \ Print extended token 224 ("ARE YOU SURE?") JSR DETOK JSR GETYN \ Call GETYN to wait until either "Y" or "N" is pressed BCC exit \ If "N" was pressed, jump to exit 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 .exit CLC \ Option 5 was chosen, so clear the C flag to indicate \ that nothing was loaded RTS \ Return from the subroutine .CAT 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 .LD1 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 drive number from the keyboard \ in A, setting the C flag if an invalid drive number \ was entered BCS LDdone \ 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 LDLI+6 \ Store the ASCII drive number in LDLI+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 .LDdone 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 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 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 LDY #NT% \ We now want to copy the current commander data block \ to location &0791 so we can do a file save operation, \ so set a counter in X to copy the NT% bytes in the \ commander data block .SVL2 LDA NA%+8,Y \ Copy the X-th byte of NA% to the X-th byte of &0791 STA &0791,Y DEY \ Decrement the loop counter BPL SVL2 \ Loop back until we have copied all the bytes in the \ commander data block IF _SNG47 JSR GTDRV \ Get an ASCII disc drive drive number from the keyboard \ in A, setting the C flag if an invalid drive number \ was entered BCS P%+8 \ If the C flag is set, then an invalid drive number was \ entered, so skip the next two instructions STA SVLI+6 \ Store the ASCII drive number in SVLI+6, which is the \ drive character of the save filename string ":1.E." ENDIF JSR SAVE \ Call SAVE to save the commander file JSR DFAULT \ Call DFAULT to reset the current commander data \ block to the last saved commander CLC \ Clear the C flag to indicate that no new commander \ file was loaded RTS \ Return from the subroutine