Skip to navigation


Save and load: SVE

[Elite-A, Parasite]

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 References: This subroutine is called as follows: * BR1 (Part 1 of 2) calls SVE * DELT calls SVE * TT102 calls SVE
.SVE JSR ZEBC \ Call ZEBC to zero-fill pages &B and &C TSX \ Transfer the stack pointer to X and store it in STX MEBRK+1 \ MEBRK+1, which modifies the LDX #&FF instruction at \ the start of MEBRK so that it sets X to the value of \ the stack pointer LDA #LO(MEBRK) \ Set BRKV to point to the MEBRK routine, which is the STA BRKV \ BRKV handler for disc access operations, and replaces LDA #HI(MEBRK) \ the standard BRKV handler in BRBR while disc access STA BRKV+1 \ operations are happening 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. Exit JSR t \ Scan the keyboard until a key is pressed, returning \ the ASCII code in A and X CMP #'1' \ If A < ASCII "1", jump to SVEX to exit as the key BCC SVEX \ press doesn't match a menu option CMP #'4' \ If "4" was pressed, jump to DELT to process option 4 BEQ DELT \ (delete a file) BCS SVEX \ If A >= ASCII "4", jump to SVEX to exit as the key \ press is either option 5 (exit), or it doesn't match a \ menu option (as we already checked for "4" above) CMP #'2' \ If A >= ASCII "2" (i.e. save or catalogue), skip to BCS SV1 \ SV1 \ If we get here then option 1 (load) was chosen LDA #0 \ If save_lock = &FF, then there are unsaved changes, so JSR confirm \ ask for confirmation before proceeding with the load, BNE SVEX \ jumping to SVEX to exit if confirmation is not given JSR GTNMEW \ Call GTNMEW to fetch the name of the commander file \ to load (including drive number and directory) into \ INWK 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 BCS SVEX+1 \ file, and return from the subroutine (as SVEX+1 \ contains an RTS) .SV1 BNE CAT \ We get here following the CMP #'2' above, so this \ jumps to CAT if option 2 was not chosen - in other \ words, if option 3 (catalogue) was chosen \ If we get here then option 2 (save) was chosen LDA #&FF \ If save_lock = 0, then there are no unsaved changes, JSR confirm \ so ask for confirmation before proceeding with the BNE SVEX \ save, jumping to SVEX to exit if confirmation is not \ given JSR GTNMEW \ 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% 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 &0B00 STA &0B00,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 STA &0B00+NT% \ Store the checksum in the last byte of the save file \ at &0B00 (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 &0AFF+NT% \ Store the checksum EOR &A9 in the penultimate byte of \ the save file at &0B00 (the equivalent of CHK2 in the \ last saved block) LDY #&B \ Set up an OSFILE block at &0C00, containing: STY &0C0B \ INY \ Start address for save = &00000B00 in &0C0A to &0C0D STY &0C0F \ \ End address for save = &00000C00 in &0C0E to &0C11 \ \ Y is left containing &C 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 .SVEX CLC \ Clear the C flag to indicate we didn't just load a new \ commander file JMP BRKBK \ Jump to BRKBK to set BRKV back to the standard BRKV \ handler for the game, and return from the subroutine \ using a tail call