Back to Skool Routines
32815: Fast load the main code block
Continues from 23831.
32815 LD SP,33020 Put the stack somewhere safe
32818 LD IX,16384 Start loading at address 16384 (start of display area)
32822 LD DE,49152
32825 LD A,255 We expect the first (marker) byte loaded to be 255
32827 SCF Set the carry flag
32828 INC D Reset the zero flag
32829 EX AF,AF'
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
32845 RET NZ
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
32851 LD HL,1045 An edge was found; now wait a bit...
32854 DJNZ 32854
32856 DEC HL
32857 LD A,H
32858 OR L
32859 JR NZ,32854
32861 CALL 32768 ...and see if the edges are still coming
32864 JR NC,32845 Jump back if they're not
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
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 Now start looking for the first edge of the data block
32889 CP 212
32891 JR NC,32881 Jump back until it's found
32893 CALL 32783 Look for the second edge of the data block
32896 RET NC Reset the Spectrum if it can't be found
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
32903 LD B,225
32905 JR 32931 Jump forward to load the first (marker) byte of the data block
32907 EX AF,AF'
32908 JR NZ,32915 Jump if the first (marker) byte has just been collected
32910 LD (IX+0),L Load the byte read from tape into memory
32913 JR 32925
32915 RL C
32917 XOR L L=first byte of data block
32918 RET NZ Reset the Spectrum if it wasn't 255
32919 LD A,C
32920 RRA
32921 LD C,A
32922 INC DE Compensate for the DEC DE below
32923 JR 32927 Jump forward to start loading into memory
32925 INC IX IX=next address to load byte from tape into
32927 DEC DE
32928 EX AF,AF'
32929 LD B,227
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
32939 CP B The carry flag now holds the loaded bit
32940 RL L Move the loaded bit into the L register
32942 LD B,225
32944 JP NC,32933 Jump unless eight bits have been loaded
32947 LD A,H
32948 XOR L
32949 LD H,A
32950 LD A,D Note: DE never actually reaches 0
32951 OR E
32952 JR NZ,32907 Jump back to load another byte from the tape
32954 RET (We never actually 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 POKE 32902,32
32896 EXX
32897 ADD IX,BC Add 23 to IX
32899 EXX
32900 SET 7,L
After the poke at 32893:
32902 JR NZ,32929 Jump back to load next byte from tape
The last byte to be loaded is at 32902 (even though there is one more byte, 32925, left on the tape: see the save routine), which then reads:
32902 LD SP,23833
32905 LD D,H
32906 RET To (23833) = 33204