.LOD JSR KERNALSETUP ; Set up memory so we can use the Kernal functions, ; which includes swapping the contents of zero page with ; the page at $CE00 (so the Kernal functions get a zero ; page that works for them, and any changes they make do ; not corrupt the game's zero page variables) LDA #0 ; Call the Kernal's LOAD function to load the commander LDX #LO(TAP%) ; file as follows: LDY #HI(TAP%) ; JSR KERNALLOAD ; * A = 0 to initiate a load operation ; ; * (Y X) = load address, so we load the commander to ; address TAP% PHP ; If something goes wrong with the save then the C flag ; will be set, so save this on the stack so we can check ; it below LDA #%00000001 ; Set CIA1 register $0D to enable and disable interrupts STA CIA+$D ; as follows: ; ; * Bit 0 set = configure interrupts generated by ; timer A underflow ; ; * Bits 1-4 clear = do not change configuration of ; other interrupts ; ; * Bit 7 clear = disable interrupts whose ; corresponding bits are set ; ; So this disables interrupts that are generated by ; timer A underflow, while leaving other interrupts as ; they are SEI ; Disable interrupts while we configure the VIC-II LDX #0 ; Set the raster count to 0 to initialise the raster STX RASTCT ; effects in the COMIRQ handler (such as the split ; screen) INX ; Set bit 0 of VIC register $1A and clear bits 1-3 to STX VIC+$1A ; configure the following interrupts: ; ; * Bit 0 = enable raster interrupt ; ; * Bit 1 = disable sprite-background collision ; interrupt ; ; * Bit 2 = disable sprite-sprite collision interrupt ; ; * Bit 3 = disable light pen interrupt LDA VIC+$11 ; Clear bit 7 of VIC register $11, to clear the top bit AND #%01111111 ; of the raster line that generates the interrupt (as STA VIC+$11 ; the line number is a 9-bit value, with bits 0-7 in VIC ; register $12) LDA #40 ; Set VIC register $11 to 40, so along with bit 7 of VIC STA VIC+$12 ; register $10, this sets the raster interrupt to be ; generated when the raster reaches line 40 LDA #%100 ; Call SETL1 to set the 6510 input/output port to the JSR SETL1 ; following: ; ; * LORAM = 0 ; * HIRAM = 0 ; * CHAREN = 1 ; ; This sets the entire 64K memory map to RAM ; ; See the memory map at the top of page 265 in the ; Programmer's Reference Guide CLI ; Enable interrupts again JSR SWAPPZERO ; The call to KERNALSETUP above swapped the contents of ; zero page with the page at $CE00, to ensure the Kernal ; routines ran with their copy of zero page rather than ; the game's zero page ; ; We are done using the Kernal functions, so now we swap ; them back so the Kernal's zero page is moved to $CE00 ; again, ready for next time, and the game's zero page ; variables are once again set up, ready for the game ; code to use PLP ; Retrieve the processor flags that we stashed after the ; call to KERNALLOAD above CLI ; Enable interrupts to make sure the PHP doesn't disable ; interrupts (which it could feasibly do by restoring a ; set I flag) BCS tapeerror ; If KERNALLOAD returns with the C flag set then this ; indicates that a load error occurred, so jump to ; tapeerror to print either "TAPE ERROR" or "DISK ERROR" LDA TAP% ; If the first byte of the loaded file has bit 7 set, BMI ELT2F ; jump to ELT2F, as this is an invalid commander file ; ; ELT2F contains a BRK instruction, which will force an ; interrupt to call the address in BRKV, which will ; print out the system error at ELT2F LDY #NT% ; We have successfully loaded the commander file to the ; TAP% staging area, so now we want to copy it to the ; last saved commander data block at NA%+8, so we set up ; a counter in Y to copy NT% bytes .copyme LDA TAP%,Y ; Copy the Y-th byte of TAP% to the Y-th byte of NA%+8 STA NA%+8,Y DEY ; Decrement the loop counter BPL copyme ; Loop back until we have copied all NT% bytes .LOR SEC ; Set the C flag RTS ; Return from the subroutine .ELT2F LDA #9 ; Print extended token 9 ("{cr}{all caps}ILLEGAL ELITE JSR DETOK ; II FILE{sentence case}") 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 disk access menu and return ; from the subroutine using a tail callName: LOD [Show more] Type: Subroutine Category: Save and load Summary: Load a commander fileContext: See this subroutine in context in the source code References: This subroutine is called as follows: * SVE calls LOD * GTDRV calls via LOR
The filename should be stored at INWK, terminated with a carriage return (13).
Other entry points: LOR Set the C flag and return from the subroutine
[X]
Configuration variable CIA = $DC00
Registers for the CIA1 I/O interface chip, which are memory-mapped to the 16 bytes from $DC00 to $DC0F (see page 428 of the Programmer's Reference Guide)
[X]
Subroutine DETOK (category: Text)
Print an extended recursive token from the TKN1 token table
[X]
Label ELT2F is local to this routine
[X]
Configuration variable KERNALLOAD = $FFD5
The Kernal function to load a file from a device
[X]
Subroutine KERNALSETUP (category: Save and load)
Set up memory and interrupts so we can use the Kernal functions and configure the file system device number and filename
[X]
Variable NA% (category: Save and load)
The data block for the last saved commander
[X]
Variable RASTCT (category: Drawing the screen)
The current raster count, which flips between 0 and 1 on each call to the COMIRQ1 interrupt handler (0 = space view, 1 = dashboard)
[X]
Subroutine SETL1 (category: Utility routines)
Set the 6510 input/output port register to control the memory map
[X]
Subroutine SVE (category: Save and load)
Display the disk access menu and process saving of commander files
[X]
Subroutine SWAPPZERO (category: Utility routines)
A routine that swaps zero page with the page at $CE00, so that zero page changes made by Kernal functions can be reversed
[X]
Configuration variable TAP% = $CF00
The staging area where we copy files after loading and before saving
[X]
Configuration variable VIC = $D000
Registers for the VIC-II video controller chip, which are memory-mapped to the 46 bytes from $D000 to $D02E (see page 454 of the Programmer's Reference Guide)
[X]
Label copyme is local to this routine
[X]
Subroutine tapeerror (category: Save and load)
Print either "TAPE ERROR" or "DISK ERROR"