Personal Computer News


Basic Toolkit

 
Author: Stuart Nicholls
Published in Personal Computer News #095

Improve your programming skills with these toolkit listings from Stuart Nicholls.

Basic Toolkit

Improve your programming skills with these toolkit listings from Stuart Nicholls

This program is intended to help both Basic and machine language programmers to develop and programmers to develop and produce their working programs. It has five routines to achieve this aim.

  1. Renumber
  2. Delete lines
  3. Delete REMs
  4. Create line 0 REM
  5. Keep line 0 REM only

To call the program enter as a direct command:

RANDOMIZE USR 63400

but note that there must be a Basic program in memory before the utility is used. An error report 'Sorry... no Basic' will be printed if an attempt is made to use it without a Basic program being present.

Renumber

This option, as its name implies, will renumber a Basic program from any line number to the end of the listing, and includes all the usual keywords, GOTO, GOSUB, RESTORE, LIST, LLIST and RUN.

It starts by asking you three questions:

  • From old line no.
    This can be any number from 0 to 9999 buy defaults to 10 if Enter is pressed without entering a number. As with all inputs only numeric key presses are entered and after the entry of four figures only Delete or Enter is accepted. Numbers can be entered with or without leading zeros. The normal Break can be used at any time to return to the menu.
  • New line start no.
    This again can be in the range 0 to 9999 with a default value of 10.
  • Step between lines
    This must be in the range 1 to 9999 and has a default value of 10.

After all three inputs have been entered, a check is made on the validity of each. If an entry is not acceptable then one of the following error messages will be printed:

Old line no. too large - the old line number exceeds the last line number of the Basic program.

New no. not valid - the new number is less than the old number and will overwrite an unchanged line.

Start/step size will overrange - a combination of start and step will cause the last line to exceed the maximum allowed of 9999.

Zero steps not allowed - a zero step size was entered

Once all three values are accepted the program will be renumbered. You may see something similar to morse code on the screen; this is part of the program and should be ignored. The screen is used as a buffer to hold keyword addresses and values catering for approximately 1000 alterations to GOTO, GOSUB, etc.

After renumbering, the routine returns to Basic and automatically lists your program.

There are several points to note with this routine. If a GOTO, GOSUB, etc is calculated the routine cannot recalculate for you but will highlight that particular keyword by making it flash. This will indicate that it should be amended. Edit the line and delete the two hidden characters before and after the keyword.

If a GOTO, GOSUB etc referred to a line number that did not exist but was within the program, this will be corrected by the routine and in renumbering will refer to the next line. If a GOTO, GOSUB etc referred to a line number above the largest in the program then, because when renumbering it may refer to a renumbered line, this will be highlighted by removing the number and replacing it with a flashing OTT. The program will ignore keywords in the after REM statements and also in PRINT statements. Once you have used the renumber routine, scan the listing for any of the above points and amend as necessary before running your program. Renumbering from a specified line allows you to open holes in your listing for insertion of extra lines.

Delete Lines

Should an area of a Basic listing require deletiing, and if it is of such a size that it would be tedious to remove one line at a time, this option should be used. The input requirements are:

Delete from line no.
to line no. (inclusive)

You need a start and a finish line number, and the default is 10. It does not matter which number is entered first as the program sorts this out. However, an error message may be printed if the higher number exceeds the last Basic line number.

The lines deleted are inclusive, but note that if a line number is specified as the lower and that line does not exist then the next line will be taken, whereas a higher line number that does not exist will be taken as the previous line. So, for example, taking a program with a listing in steps of 10 from 100 to 1000 and requiring deletion lines input as 875 to 359 will delete lines 360 to 870 inclusive.

This program is instantaneous and will list your remaining program on completion.

Delete REMs

Once this option is accepted it will automatically search your program and delete all REM statements whether in a multi-statement line or on their own. REMs are helpful when producing programs but do slow down execution of Basic so it can sometimes be a benefit to remove them once a program is fully tested and working.

Create Line 0 REM

This routine is of most use to machine code programmers who use an assembler which enters code directly into first line REM statements (the McGraw-Hill Assembler for example). If your code is several hundred bytes long it can take several minutes to set up the initial REM statement even using multi statement techniques.

Using this facility, all that is necessary is to enter the number of bytes required (0 to 9999) and, providing there is sufficient memory available, you will get an instant line 0 REM statement set up and listed.

Keep Line 0 REM Only

Should you have an assembler of the McGraw-Hill type, or even a simple hexloader program, this routine can be used to remove all the Basic listing except the first line which, if it is a REM statement, will be renumbered line 0.

The Machine Code

To enter the hex dump into the Spectrum a Basic hexloader must be used, so first enter the dual purpose Basic program as in Listing 1.

GOTO 100 allows the input of hex numbers in blocks of eight, with a checksum number which is the sum of the previous eight numbers modulo 256, and will detect most errors in inputs and allow that line to be re-entered. To end the input of hex numbers enter zz after the last checksum number.

GOTO 1000 will print, either to the screen or the printer, a hex dump with checksums of any block of memory. It can be used to check memory locations should the program fail to function as described in the instructions.

Once this Basic program has been typed in we are able to enter the machine code. First enter as a direct command CLEAR 63399 to ensure that the code will be safely poked in above RAMtop, then enter the hex numbers as in the hex dump. These numbers should be entered in blocks of 18 characters, i.e. eight two-character numbers and the checksum characters.

Remember there must be no spaces between characters so the first block will be entered as:

C3ACF9000000000069 (ENTER)

Once all the hex dump has been entered, save the code using:

SAVE"UTILITY" CODE 63400,1952

Then check that the code functions correctly as per the instructions. Enter RANDOMIZE USR 63400 and check it out. If a command does not work as described use the Basic program (GOTO 1000) to compare hex dumps (the quickest way is to look at the checksum numbers) and correct any mistakes.

Stuart Nicholls

This article was converted to a web page from the following pages of Personal Computer News #095.

Personal Computer News #095 scan of page 12

Page 12

Personal Computer News #095 scan of page 13

Page 13

Personal Computer News #095 scan of page 14

Page 14