![]() |
Load routines |
| Prev: 32768 | Up: Map |
|
Continues from 23831.
|
||||
| 32815 | LD SP,33020 | Put the stack somewhere safe | ||
| 32818 | LD IX,16384 | The fast code block starts loading at address 16384 (the start of the display file) | ||
| 32822 | LD DE,49152 | Set DE (the byte counter) to a high enough value that it won't reach 0 before the first 16570 bytes (16384-32953) have been loaded | ||
| 32825 | LD A,255 | We expect the first byte loaded (the flag byte) to be 255 | ||
| 32827 | SCF | In the analogous ROM routine, setting the carry flag would indicate that we want to LOAD rather than VERIFY; here, this flag is not used | ||
| 32828 | INC D | Reset the zero flag, indicating that we haven't loaded the first byte of the data block (the flag byte) yet | ||
| 32829 | EX AF,AF' | Save these flags | ||
| 32830 | DEC D | Restore the value of DE | ||
| 32831 | DI | Disable interrupts | ||
| 32832 | LD A,15 | BORDER 7 | ||
| 32834 | OUT (254),A | |||
| 32836 | IN A,(254) | Collect an initial EAR port reading into bit 6 of A | ||
| 32838 | RRA | Move it to bit 5 of A | ||
| 32839 | AND 32 | Clear the extraneous bits (0-4 and 6-7) | ||
| 32841 | OR 2 | The border will turn red when the first edge is found | ||
| 32843 | LD C,A | C will hold the border colour | ||
| 32844 | CP A | Set the zero flag to avoid returning at the next instruction | ||
| 32845 | RET NZ | In the analogous ROM routine, this instruction would return if the BREAK key is being pressed; here, the zero flag is always set | ||
| 32846 | CALL 32783 | Listen for an edge | ||
| 32849 | JR NC,32845 | Jump back to listen again if no edge was found within the time limit | ||
|
An edge was found. Wait a bit and then listen again.
|
||||
| 32851 | LD HL,1045 | Wait for about one second | ||
| 32854 | DJNZ 32854 | |||
| 32856 | DEC HL | |||
| 32857 | LD A,H | |||
| 32858 | OR L | |||
| 32859 | JR NZ,32854 | |||
| 32861 | CALL 32768 | Are the edges still coming? | ||
| 32864 | JR NC,32845 | Jump back if not | ||
|
Check whether the signal is a leader tone.
|
||||
| 32866 | LD B,156 | 256 double edges arriving within a specific time limit constitute a valid leader tone | ||
| 32868 | CALL 32768 | |||
| 32871 | JR NC,32845 | |||
| 32873 | LD A,198 | |||
| 32875 | CP B | |||
| 32876 | JR NC,32846 | |||
| 32878 | INC H | |||
| 32879 | JR NZ,32866 | |||
|
This looks like a leader tone. Now listen for the first edge of the data block.
|
||||
| 32881 | LD B,201 | Is the leader tone still there? | ||
| 32883 | CALL 32783 | |||
| 32886 | JR NC,32845 | Jump back if not | ||
| 32888 | LD A,B | Have we found the first edge of the data block? | ||
| 32889 | CP 212 | |||
| 32891 | JR NC,32881 | Jump back if not | ||
|
The first edge of the data block has been detected.
|
||||
| 32893 | CALL 32783 | Look for the second edge of the data block | ||
| 32896 | RET NC | Reset the Spectrum if it can't be found | ||
|
Prepare to load the data block.
|
||||
| 32897 | LD A,C | The border will alternate between blue and yellow for the data block | ||
| 32898 | XOR 3 | |||
| 32900 | LD C,A | |||
| 32901 | LD H,0 | Initialise the parity byte to 0 | ||
| 32903 | LD B,225 | Set the timing constant for the flag byte | ||
| 32905 | JR 32931 | Jump forward to load the flag byte | ||
|
This is the byte-loading loop. The first byte loaded is the flag byte.
|
||||
| 32907 | EX AF,AF' | Restore the flags | ||
| 32908 | JR NZ,32915 | Jump if the first byte (the flag byte) has just been collected | ||
| 32910 | LD (IX+0),L | Load the byte read from tape into memory | ||
| 32913 | JR 32925 | |||
| 32915 | RL C | Save the carry flag in bit 0 of C temporarily | ||
| 32917 | XOR L | L=first byte of the data block (the flag byte) | ||
| 32918 | RET NZ | Reset the Spectrum if it wasn't 255 | ||
| 32919 | LD A,C | Restore the carry flag | ||
| 32920 | RRA | |||
| 32921 | LD C,A | Restore C | ||
| 32922 | INC DE | Compensate for the 'DEC DE' below | ||
| 32923 | JR 32927 | Jump forward to start loading bytes into memory | ||
| 32925 | INC IX | IX=next address to load the byte from tape into | ||
| 32927 | DEC DE | Decrease the byte counter | ||
| 32928 | EX AF,AF' | Save the flags (the zero flag is now set) | ||
|
This inner loop loads the eight bits of a byte one-by-one from the tape into the L register.
|
||||
| 32929 | LD B,227 | Set the timing constant | ||
| 32931 | LD L,1 | Get ready to load eight bits from the tape | ||
| 32933 | CALL 32768 | Load one bit from the tape | ||
| 32936 | RET NC | Reset the Spectrum if there was a loading error | ||
| 32937 | LD A,237 | Set the carry flag if a '1' was read from the tape, or reset it if a '0' was read | ||
| 32939 | CP B | |||
| 32940 | RL L | Move the bit into the L register | ||
| 32942 | LD B,225 | Set the timing constant for the next bit | ||
| 32944 | JP NC,32933 | Jump unless eight bits have been loaded | ||
|
A full byte has just been read from the tape.
|
||||
| 32947 | LD A,H | Update the (ultimately unused) parity byte against the byte just read from the tape | ||
| 32948 | XOR L | |||
| 32949 | LD H,A | |||
| 32950 | LD A,D | Set the zero flag if the the byte counter has reached 0 (which never happens) | ||
| 32951 | OR E | |||
| 32952 | JR NZ,32907 | Jump back to load another byte from the tape | ||
| 32954 | RET | (We never get here) | ||
|
When the computer has loaded up to 32953, the instruction at 32952 is changed thus:
|
||||
| 32952 | JR NZ,32893 | |||
|
At this stage, 32893 reads as follows:
|
||||
| 32893 | LD (IX-52),L | Effectively LD (32902),32 | ||
| 32896 | EXX | |||
| 32897 | ADD IX,BC | Add 23 to IX | ||
| 32899 | EXX | |||
| 32900 | SET 7,L | |||
|
The instruction at 32893 above changes the instruction at 32902 from 'LD SP,23833' to:
|
||||
| 32902 | JR NZ,32929 | Jump forward to load the next byte from the tape | ||
|
Now 65536 more bytes are loaded, the last of which is at 32902 (even though there is one more byte, 32925, left on the tape: see the save routine). Then 32902 reads as follows:
|
||||
| 32902 | LD SP,23833 | Point the stack pointer at the game start address that was placed at 23833 by the save routine | ||
| 32905 | LD D,H | |||
| 32906 | RET | To (23833)=33204 | ||
| Prev: 32768 | Up: Map |