103. Super-fast relocate ~~~~~~~~~~~~~~~~~~~ We published a very simple and effective relocate for disc users back in September 1983. This was added to your Basic program, and automatically moved it down to a lower value of PAGE. For those who don't know, the Beeb DFS 'pinches' some user memory as workspace for itself, and these relocate programs are to claim it back again after the program is loaded. This overcomes the problem of some long programs only running on Cassette-based Beebs. The only drawback is that the published relocate is a trifle slow, and can take up to 5 seconds on very long programs. My new routine below uses machine-code for the critical section, with a bit of Basic for economy of programming. It can relocate a 25k program in less than 0.4 seconds, which is fast enough for anyone! It is written in the form of a dummy Procedure, which tacks onto the end of your program, and is called by line 0. The line numbers used have been chosen so as not to clash with line numbers in your own program. Your program can start anywhere after line 0, and must finish before line 32000. Be sure to add an END to stop the program running into the Procedure by accident. A convenient way to add this routine is to *SPOOL it off onto disc, and then *EXEC it back in again to merge with your own program. Those of you with utilities like *MERGE will find life made even easier. This routine automatically switches the DFS off if you try to relocate below &1100, which is the lowest value of PAGE where limited use of the DFS is possible. You simply set the variable D% in line 0 to the address you want PAGE resetting to; &E00 in this example. Please note that the Procedure is a dummy one, and is terminated with END, rather than ENDPROC. This is quite deliberate, so don't change it back again. The routine uses integer variables D%, (for Destination), and P%, (for Program counter). If you want to avoid using D% for any reason, then change it to a different resident integer variable. You cannot substitute for P% in this way, but it is quite OK to use it in your own program as well, without any clash. Some workspace on Zero Page is used, from &70 up to &8C, as this area isn't used by Basic, and is in any case freed again as soon as the program has been relocated. There are no spaces within the listing, and you can omit the ones immediately after the line numbers. To those of you not familiar with machine-code, this must look very weird indeed, but just type it in very carefully, exactly as it is, but note that the two blank lines with colons are only to make the listing more clear. If you want to relocate a program which has data or machine code stored in memory locations above TOP, then you can substitute the length of the whole file in place of TOP-PAGE on line 32010; eg. &4B53+256. This Hex number can be found by using *INFO on the file, after you have added this routine. (Put any 4-digit Hex number in at first, just to simulate the true length.) 0 D%=&E00:IFPAGE>D%THENPROCmove 10 : 20 REM Your program goes somewhere about here. 5000 END:REM Most important. 5010 : 32000 DEFPROCmove:IFD%<&1100THEN*TAPE 32010 !&70=D%:!&72=PAGE:!&74=TOP-PAGE+256 32020 P%=&76:[OPT2:LDX&74:LDY#0 32030 LDA(&72),Y:STA(&70),Y:INY:BNE&85:INC&71:INC&73 32040 DEX:BNE&7A:DEC&75:BNE&7A:RTS:] 32050 VDU21:*KEY9CALL&76|MPAGE=D%|MNEW|MOLD|MRUN|F|M 32060 *FX138,0,137 32070 END