| Save routine

33010: Save Contact Sam Cruise to tape

| This is the program used to save the standard speed code block for Contact Sam Cruise.
The standard speed code block consists of two sections of data. The first section contains the 16572 bytes of data for addresses 16384-32955. The second section contains 32892 bytes of data starting at address 32976, moving forward in steps of 247 bytes (rolling back to page 127 every time the 64K boundary is reached), and ending at 33149. Note that the second section does not contain data for addresses 33396-65506 (step 247); these addresses are filled in by the routine at 33046 after the fast code block has loaded. Also note that although the byte for address 33149 is saved to tape, it is not loaded by the load routine; instead, it is also filled in by the routine at 33046.
33010 | LD SP,23806 |
33013 | LD HL,33224 | 33224 is where the game starts after loading
33016 | LD (23835),HL | Store this address where it will be popped off the stack by the load routine
33019 | EXX | Prepare BC' for saving the second section of data
33020 | LD BC,247
33023 | EXX
33024 | LD IX,16384 | 16384 to 32955 will be saved first
33028 | LD DE,16571
33031 | LD A,255 | A flag byte of 255 (the first byte saved) indicates a data block
33033 | LD HL,3224 | This constant will give a leader tone of about 2 seconds
33036 | EX AF,AF' |
33037 | INC DE | Adjust the length and start address to allow for the flag byte
33038 | DEC IX
33040 | DI | Disable interrupts
33041 | LD A,2 | MIC on, border red
33043 | LD B,A |
First create the 2-second leader tone.
33044 | DJNZ 33044 |
33046 | OUT (254),A |
33048 | XOR 15 |
33050 | LD B,164 |
33052 | DEC L |
33053 | JR NZ,33044 |
33055 | DEC B |
33056 | DEC H |
33057 | JP P,33044 |
Then create the sync pulse.
33060 | LD B,47 |
33062 | DJNZ 33062 |
33064 | OUT (254),A |
33066 | LD A,13 |
33068 | LD B,55 |
33070 | DJNZ 33070 |
33072 | OUT (254),A |
It's time to save the first byte, which will be the flag byte (255).
33074 | LD BC,15118 | B=59 (timing constant), C=14 (MIC off, border yellow)
33077 | EX AF,AF' | A=255
33078 | LD L,A | L=255
33079 | JP 33091 | Jump forward to save the flag byte
This is the main byte-saving loop.
33082 | LD A,D | In the analagous ROM routine, the second instruction here is 'OR E', to check whether it's time to save the last byte (the parity byte)
33083 | LD A,D
33084 | JR Z,33098 | This jump (to save the parity byte) is never made
33086 | LD L,(IX+0) | Fetch the next byte to be saved
33089 | LD A,H | A=current parity byte
33090 | XOR L | Update this for the next byte to be saved
33091 | LD H,A | H=new parity byte
33092 | LD A,1 | A=1 (MIC on, border blue)
33094 | SCF | Set the carry flag (which will act as the marker bit)
33095 | JP 33121 | Jump forward to save the byte
This section of code, if it were used, would save the parity byte.
33098 | LD L,H | Pick up the parity byte in L
33099 | JR 33089 | Save it
This is the bit-saving loop for the first section of data (16384-32955).
33101 | LD A,C | A=14 (MIC off, border yellow) for the second pass
33102 | BIT 7,B | Set the zero flag to indicate that this is the second pass through the loop
33104 | DJNZ 33104 |
33106 | JR NC,33112 | Jump if we are saving a '0'
33108 | LD B,66 |
33110 | DJNZ 33110 |
33112 | OUT (254),A |
33114 | LD B,62 | Set the timing constant for the second pass
33116 | JR NZ,33101 | Jump back for the second pass if we've just done the first
33118 | DEC B |
33119 | XOR A | Clear the carry flag
33120 | INC A | A=1 (MIC on, border blue)
33121 | RL L | Move the bit to be saved into the carry flag, and the marker bit leftwards
33123 | JP NZ,33104 | Jump unless we've saved all 8 bits of the byte
A byte from the first section (16384-32955) has just been saved. Are there any more left?
33126 | DEC DE | Decrease the length counter
33127 | INC IX | Move to the next byte to be saved
33129 | LD B,49 | Set the timing constant for the first bit of the next byte
33131 | LD A,127 | Return if the BREAK key is being pressed
33133 | IN A,(254)
33135 | RRA
33136 | RET NC
33137 | LD A,D | Have we saved 16384 to 32955 yet?
33138 | INC A
33139 | JP NZ,33082 | Jump back if not
Now a further 32892 bytes are saved: starting at 32976, moving forward in steps of 247 bytes, rolling back to page 127 whenever the 64K boundary is hit, and ending at 33149.
33142 | RET NZ | This return does not happen
33143 | LD DE,32892 | We need to save a further 32892 bytes
33146 | LD A,49 | Change the instruction at 32902 (in the load routine) to LD SP,23835
33148 | LD (32902),A
33151 | LD B,46 |
33153 | LD A,D | Have we saved every byte of the second section yet?
33154 | OR E
33155 | JR Z,33169 | Jump if so
33157 | LD L,(IX+20) | Otherwise pick up the next byte to save
33160 | LD A,H | A=current parity byte
33161 | XOR L | Update this for the next byte to be saved
33162 | LD H,A | H=new parity byte
33163 | LD A,1 | A=1 (MIC on, border blue)
33165 | SCF | Set the carry flag (which will act as the marker bit)
33166 | JP 33192 | Jump forward to save the byte
This is where we come when all 49464 bytes have been saved.
33169 | LD L,0 |
33171 | RET |
This is the bit-saving loop for the second section of data.
33172 | LD A,C | A=14 (MIC off, border yellow) for the second pass
33173 | BIT 7,B | Set the zero flag to indicate that this is the second pass through the loop
33175 | DJNZ 33175 |
33177 | JR NC,33183 | Jump if we are saving a '0'
33179 | LD B,66 |
33181 | DJNZ 33181 |
33183 | OUT (254),A |
33185 | LD B,62 | Set the timing constant for the second pass
33187 | JR NZ,33172 | Jump back for the second pass if we've just done the first
33189 | DEC B |
33190 | XOR A | Clear the carry flag
33191 | INC A | A=1 (MIC on, border blue)
33192 | RL L | Move the bit to be saved into the carry flag, and the marker bit leftwards
33194 | JP NZ,33175 | Jump unless we've saved all 8 bits of the byte
A byte from the second section has just been saved. Are there any more left?
33197 | DEC DE | Decrease the length counter
33198 | EXX | Move forward 247 bytes to the next byte to be saved
33199 | ADD IX,BC
33201 | EXX
33202 | LD B,47 | Set the timing constant for the first bit of the next byte
33204 | JR NC,33208 | Jump unless IX was incremented beyond the 64K boundary
33206 | LD IXh,127 | Reset the high byte of the IX register
33209 | LD A,127 | These instructions check the BREAK key but do not act on the result
33211 | IN A,(254)
33213 | RRA
33214 | NOP |
33215 | NOP |
33216 | NOP |
33217 | JP 33153 | Save the next byte