Use you ROM Norman Green in Derbyshire makes life a little easier for 16 and 48K programmers When I was a schoolboy, I was often told to use my loaf. Any day now, I expect to hear some youngster told to use his ROM! It would be sound advice, even though not a true parallel. Using one's loaf is to use one's own brains: to use your ROM would be to make use of someone else's; and if, like me, your computer is a Spectrum, the brains you would be using are those of Uncle Clive and his team of experts at Sinclair Research. The Spectrum ROM, with over sixteen thousand bytes of permanent memory, contains many very useful subroutines just waiting to be called by some grateful user (or should I say USR?). Although the ROM can be called from the keyboard using the USR key in instructions such as 'RANDOMIZE USR 0000' or 'LET l=USR 0000', the ROM routines are at their most useful when called from machine code programs, in which the pro- grammer can easily arrange for the entry conditions of any particular routine to be satisfied. In this short article, I shall limit myself to discus- sing just two of the many routines in the Spectrum ROM and then show how they may be linked together to provide a short but very powerful utility program. Readers who do not yet feel at home with machine code will nevertheless be able to key in and use the concluding program, which is written entirely in Basic with the machine code stored in a data line from which it will be transferred to a temporary home in the printer buffer section of RAM each time the program is RUN. Into the ROM The first of the aforementioned routines is situated in the Spectrum ROM at decimal address 6510. Its function is to determine the address in RAM of the first byte in a program line whose line number has been previously entered into the HL register pair. After calling 6510, the HL register will contain the required address. The other routine may be entered at 6629. Its function is to delete lines from the Basic program. [Or variables, or, less usefully for the normal programmer, channel data or any temporary data stored between the system variables and the end of the calculator stack. It will adjust pointer system variables (such as PROG) as necessary.] Before this routine is called, the address of the first byte in the lowest-numbered line of the block to be deleted must be loaded into the DE register pair, and the address of the byte following the last byte in the highest-numbered line of the block must be loaded into the HL register pair. Although they may sound complicated, use of these two routines is simplicity itself. I have seen complicated machine code programs of considerable length which take several minutes to delete a block of lines. The code which I am about to offer is a mere 19 bytes long and can delete a large chunk of unwanted program in a fraction of a second. It is more straightforward than the much-used method of corrupting the length-of-line bytes in order to fool the computer into thinking a block of lines is all one single line, and then having to delete this by keying. For those familiar with assembly language mnemonics these are printed below, alongside the 19 bytes of decimal machine code. Any line numbers are admissible, providing the first is not higher than the second. If the two are equal, then single line deletion is effected. If numbers which have not been allocated to program lines are entered, then all lines encompassed by the two numbers will be deleted. (This also applies to the number zero and to all numbers greater than 9999). I conclude with the promised Basic program. The lines are numbered 9990 to 9998 so that if transferred to tape by keying SAVE "Deletions", it may be recalled whenever required by keying MERGE "Deletions", when the high line numbers are unlikely to clash with the program being edited. When no longer required, "Deletions" may be used to delete itself; although it should be noted that the dele- tion of line 9998 by this method will produce the report "C Nonsense in BASIC, 9998:1", but on this occasion it may be ignored. ___________________________________________________________ Ld HL, 0 33, 0*, 0*, First line no. into HL. Call 6510 205,110, 25, Using your ROM. Push HL 229, Store returned address on stack. Ld HL, 0 33, 0*, 0*, Second line no. into HL. Inc HL 35, Line no. above deletion block. Call 6510 205,110, 25, Using your ROM. Pop DE 209, Reclaim address from stack to DE. Call 6629 205,229, 25, Using your ROM. Ret 201. Return to Basic. * * Line numbers are poked here in the usual way, least significant byte first. Assembly Language Listing