Skip to navigation


Save and load: SVE

[Apple II version]

Name: SVE [Show more] Type: Subroutine Category: Save and load Summary: Display the disk 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 References: This subroutine is called as follows: * BR1 (Part 1 of 2) calls SVE * diskerror calls SVE * LOD calls SVE * TT102 calls SVE
.SVE LDA #1 ; Print extended token 1, the disk access menu, which JSR DETOK ; presents these options: ; ; 1. Load New Commander ; 2. Save Commander {commander name} ; 3. Default JAMESON ; 4. 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' ; If option 3 wasn't chosen, jump to feb13 to exit the ;BEQ feb10 ; menu ;CMP #'4' ; BNE feb13 ; The instructions in the middle are commented out in ; the original source LDA #224 ; Option 3 was chosen, so print extended token 224 JSR DETOK ; ("ARE YOU SURE?") 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 ; These instructions are commented out in the original ; ; source ;LDA DISK ;EOR #$FF ;STA DISK ; ;JMP SVE .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 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 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 ("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 .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 ; Call CHECK2 to calculate the third checksum for the ; last saved commander and return it in A STA CHK3 ; Store the checksum in CHK3, which is at the end of the ; last saved commander 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 ; 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 JSR COPYNAME ; Copy the last saved commander's name from INWK+5 to ; comnam and pad out the rest of comnam with spaces, so ; we can use it as the filename to write in wfile ; We now copy the current commander data block into the ; TAP% staging area 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 JSR wfile ; Write the commander file in the buffer at comfil ; (which contains the TAP% buffer) to a DOS disk BCS diskerror ; If the C flag is set then there was a disk error, so ; jump to diskerror to print the disk error (whose ; number is now in A), make a beep and wait for a key ; press JSR DFAULT ; Call DFAULT to reset the current commander data block ; to the last saved commander JSR t ; Scan the keyboard until a key is pressed, returning ; the ASCII code in A and X .SVEX CLC ; Clear the C flag to indicate we didn't just load a new ; commander file RTS ; Return from the subroutine