Skip to navigation


Save and load: LOD

[Acorn Electron version]

Name: LOD [Show more] Type: Subroutine Category: Save and load Summary: Load a commander file
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 LOD

The filename should be stored at INWK, terminated with a carriage return (13).
.LOD LDX #2 \ Enable the ESCAPE key and clear memory if the BREAK JSR FX200 \ key is pressed (*FX 200,2) JSR ZERO \ Zero-fill pages &9, &A, &B, &C and &D, which clears \ the ship data blocks, the ship line heap, the ship \ slots for the local bubble of universe, and various \ flight and ship status variables LDY #&9 \ Set up an OSFILE block at &0A00, containing: STY &0A03 \ INC &0A0B \ Load address = &00000900 in &0A02 to &0A05 \ \ Length of file = &00000100 in &0A0A to &0A0D INY \ Increment Y to &A, which we use next LDA #&FF \ Call QUS1 with A = &FF, Y = &C to load the commander JSR QUS1 \ file to address &0B00 LDA &0900 \ If the first byte of the loaded file has bit 7 set, BMI SPS1+1 \ jump to SPS+1, which is the second byte of an LDA #0 \ instruction, i.e. a BRK instruction, which will force \ an interrupt to call the address in BRKV, which is set \ to BR1... so this instruction restarts the game from \ the title screen. Valid commander files for the \ cassette version of Elite only have 0 for the first \ byte, as there are no missions in this version, so \ having bit 7 set is invalid anyway LDX #NT% \ We have successfully loaded the commander file at \ &0B00, so now we want to copy it to the last saved \ commander data block at NA%+8, so we set up a counter \ in X to copy NT% bytes .LOL1 LDA &0900,X \ Copy the X-th byte of &0900 to the X-th byte of NA%+8 STA NA%+8,X DEX \ Decrement the loop counter BPL LOL1 \ Loop back until we have copied all NT% bytes LDX #3 \ Fall through into FX200 to disable the ESCAPE key and \ clear memory if the BREAK key is pressed (*FX 200,3) \ and return from the subroutine there