.SVE JSR ZEBC \ Call ZEBC to zero-fill pages &B and &C TSX \ Transfer the stack pointer to X and store it in stack, STX stack \ so we can restore it in the MEBRK routine LDA #LO(MEBRK) \ Set BRKV to point to the MEBRK routine, disabling SEI \ interrupts while we make the change and re-enabling STA BRKV \ them once we are done. MEBRK is the BRKV handler for LDA #HI(MEBRK) \ disc access operations, and replaces the standard BRKV STA BRKV+1 \ handler in BRBR while disc access operations are CLI \ 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 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 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 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 #3 \ Print extended token 3 ("COMPETITION NUMBER:") JSR DETOK 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 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 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 \ Print a newline PLA \ Restore the checksum from the stack 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 IF _SNG45 JSR DFAULT \ Call DFAULT to reset the current commander data block \ to the last saved commander ENDIF .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 callName: 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 codeContext: 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 * TT102 calls SVE
Returns: C flag Set if we loaded a new file, clear otherwise
[X]
Subroutine BPRNT (category: Text)
Print a 32-bit number, left-padded to a specific number of digits, with an optional decimal point
[X]
Subroutine BRKBK (category: Save and load)
Set the standard BRKV handler for the game
[X]
Configuration variable BRKV = &0202
The break vector that we intercept to enable us to handle and display system errors
[X]
Subroutine CAT (category: Save and load)
Catalogue a disc, wait for a key press and display the disc access menu
[X]
Subroutine CHECK (category: Save and load)
Calculate the checksum for the last saved commander data block
[X]
Variable CHK (category: Save and load)
First checksum byte for the saved commander data file
[X]
Variable CHK2 (category: Save and load)
Second checksum byte for the saved commander data file
[X]
Subroutine DELT (category: Save and load)
Catalogue a disc, ask for a filename to delete, and delete the file
[X]
Subroutine DETOK (category: Text)
Print an extended recursive token from the TKN1 token table
[X]
Subroutine DFAULT (category: Start and end)
Reset the current commander data block to the last saved commander
[X]
Subroutine GTNMEW (category: Save and load)
Fetch the name of a commander file to save or load
[X]
Subroutine LOD (category: Save and load)
Load a commander file
[X]
Subroutine MEBRK (category: Save and load)
The BRKV handler for disc access operations
[X]
Variable NA% (category: Save and load)
The data block for the last saved commander
[X]
Subroutine QUS1 (category: Save and load)
Save or load the commander file
[X]
Label SV1 is local to this routine
[X]
Label SVEX is local to this routine
[X]
[X]
Label SVL1 is local to this routine
[X]
Subroutine TRNME (category: Save and load)
Copy the last saved commander's name from INWK to NA%
[X]
Subroutine TT67 (category: Text)
Print a newline
[X]
Subroutine ZEBC (category: Utility routines)
Zero-fill pages &B and &C
[X]
Variable stack (category: Save and load)
Temporary storage for the stack pointer when switching the BRKV handler between BRBR and MEBRK