A good editor can make SuperBASIC coding and debugging much easier. In this article I also mean SBASIC since it is an extension of SuperBASIC. QD with QBASIC or Basic Linker allow a versatile editor along with Thing multitasking to provide a fine SuperBASIC development environment. Instead I like to use the TK2/SMS editor ED and the other built-in features. My reasons are:
1. Immediate syntax checking,
2. Ability to run parts of a program,
3. Good handling of GO TO and RESTORE. And
4. The option of adding various aids as desired.
Before I go any further, realize that these are personal preferences. However, I have written a lot of SuperBASIC and have used other types of programming environments. (A programming environment is jargon for a front-end program to write and debug programs; it is not the temperature in your office!) I am reluctant to use the mouse which requires good hand and eye coordination. When my eyes are blurry, I have trouble finding the pointer. Further, I can use CSIZE to make larger letters with ED; all the other editors (Please correct me if I am wrong!) use only standard size fonts. In any case, you may want to contrast my preferences by reading Tim Swenson’s “BASIC Linker – A Review” in the July/August 2000 QL Today.
EDs strengths ED checks syntax as soon as you try to enter a line. The majority of my errors are due to misspelling or other syntax mistakes. I find it daunting to have to correct all the syntax errors all at once. Plus a simple syntax error, for example in a Dimension, can cause numerous errors through out the program.
In debugging, it is nice to be able to run a fragment of a program to see if that part works. If I want to see if lines 150 and 160 work, I just temporarily add a stop at 165 and Goto 150. Indeed, this fragment running is a big reason why I prefer the QL and SuperBASIC over other any other system for program development.
I avoid GOTO in programs since they tend to make it hard to follow what is going on. But sometimes a GOTO is just the best way to do something. Plus I often use parts of other people’s code that has GOTOs. RESTORE sets the next DATA statement for read. When programs are renumbered using RENUM, the line numbers of GOTOs and RESTOREs are automatically updated to the new line numbers.
I like the ability to add keywords, ALTKEYs, or DOs to tailor the editing/debugging to my preferences. EDs weaknesses There are a lot editing facilities that are not in ED. For example, find, replace, move. However, keywords have been developed to do these things. I use Liberation Software’s QREF which can print a list of a single or all variables or procedures and at what line number they are found. Also I found Simon Goodwin’s REPLACE better then the find and change in any of the editors. For example, try replacing i to item in an editor. Every i in any word will be found. REPLACE only changes variable names. Want to edit a particular procedure but don’t know where it is in a long program? Simon’s Ed_Def% to the rescue. It lists all the procedures and functions in a temporary window, you pick one, and it automatically EDs to it.
I also use a modified version of Turbo’s demo HOW_COME which prints the calling sequence of procedures and functions. This allows you to know when a procedure bombs where it was called from. There are certain editing sequences that I find myself doing frequently. I put the commands in a DO file and when I need to do it I DO it. For example, I have a MoveIt which moves a block of code from one location to another.
I also have a ListQ which list all the lines that have a given variable name on them – very handy for finding out if you really did initialize that variable somewhere. DO files are so easy to make, I sometimes write specialized versions for a specific program. For example, in a long running simulation, I hit CTRL/space to temporarily stop the program then type DO out which prints out the values of I, J, and K which are FOR indexes which tell me how far along things are.
By using a CONTINUE at the end of the DO file, the program automatically starts rerunning. There is very little if anything an editor can do that I can not do efficiently with ED and ED aids. In separate articles, I plan to describe in detail the ED aids that I have wrote. I admit the block move took some fancy programming which is worth sharing. God bless, Al MoveIt, A DO File To Move Blocks of SuperBASIC by Al Boehm In a previous article ” ED Aids”, I explained why I like to use the TK2/SMS SuperBASIC editor ED instead of a separate editor.
There is, however, one operation that is very difficult to do using only ED. Try moving a block of SuperBASIC lines from one section to another when there are intervening lines. Pretty tough work, but very easy to do on most any editor. The trouble is that editors do not keep track of GOTO and RESTORE line numbers. Thus, you have to go back and check and correct any of these. So I kept track of the commands that I needed to move a block of code and put them into a DO file.
However, there were at least five “challenges” that I had to overcome for the MoveIt to work properly.
CHANLENGE 1: Parameters To A Do How do you get parameters (in this case the line numbers specifying the block) to the DO file? I wanted something like: DO MoveIt 500,750,1100,10 where 500 is the start of the block, 750 the last line, 1100 is where to move it to, and 10 is the gap size to leave between lines when done. All my DO files are in win1_boots_, and I use PROG_USE win1_boots_ so I don’t have to specify a drive with the DO. I don’t know how to send parameters via a DO. Please let me know if you do. You could equate numbers to the parameters: start=500:last=750,PutAt=1100:gaps=10, since variables are available in the DO file. However, this is somewhat awkward.
A better way, I think, is simply to let the DO file INPUT the values. That way you can print prompts instead of having to remember the syntax. Plus you can use unusual variable names that are unlikely to be used in your program. (If you know how to do the equivalent of LOCal variables in a DO, let me know.)
Thus, the first section of MoveIt is: REMark MoveIt moves a block of SuperBASIC. 18 Oct 2001 by A. Boehm – public domain REMark _ before names to make use in main program unlikely CLS#0:INPUT#0,’ Move lines ‘;_L;’ TO ‘;_U;’ To new location ‘;_A;’ with gap=’;gap$ IF gap$=”” THEN _Gap=10: ELSE _Gap=gap$:END IF IF _L<_A THEN DO moveitup:ELSE DO moveitdown:END IF Note the use of gap$ to let ENTER alone specify the default, gap=10. I did not add any checks on the inputs since if they are inconsistent, the program stops with error: Out of Range, and it is easy enough to start MoveIt over again.
CHALENGE 2: LONG IFs Only inline IFs are allowed in DO files. The IF in the 4th line of MoveIt works fine. However, a long structure, for example: IF a<b THEN a=b ELSE b=a END IF will not work in a DO. The 5th line IF originally had too many statements in it to keep it readable. So instead I used the chaining properties of DO to call one or the other of the DO files: MoveItup or MoveItdown.
CHALENGE 3: MOVEING LINES PAST OTHER LINES RENUM easily changes line numbers but can not change the sequence of the lines. This limitation was dealt with by first SAVEing the intervening block of lines, then DELETING them so RENUM could move the block past. Finally the intervening block is MERGEd back into place.
All GOTOs and RESTOREs are updated properly except any between the moved block and the intervening block of lines since the intervening lines are not in the program when the block is RENUMed.
MoveItup DO file: REMark Case 1 of Moveit – move a block higher REMark separate RENUMs allow known block limits no matter what gap was used RENUM _A TO;_A+_A-_L+2,1 SAVE ram1_TempLines,_U+1 TO _A-1 DLINE _U+1 TO _A-1 RENUM _L TO _U;_A,1 REMark Add to file command to run when Merged. _F=FOPEN(ram1_TempLines):PUT#_F(FLEN(#_F)) REMark PUT sets file position to end PRINT#_F,’DO MoveItEnd’ CLOSE#_F IF VER$=’HBA’ THEN MERGE ram1_TempLines REMark For non SMS, use MERGE in program only or DOs are fouled up.
CHALENGE 4: MERGE CAUSES DO TO STOP A MERGE causes a DO file to stop. How could I complete the remaining steps automatically? The process is continued by PRINTing – DO MoveItEnd – as a direct command after the lines to be MERGEd. This DO automatically activates the last section of the MoveIt files when the file is MERGEd. SAVE closes the file and leaves the file position pointer at the start. The PUT command in MoveIt’s 8th line sets the position pointer to the end of the file. Then the DO MoveItEnd is PRINTed and the file is closed.
CHALENGE 5: MERGE BUG IN JSU AND MINERVA The MERGE with the added DO MoveItEnd in the file works fine with SMS but it fouls things up when I ran it with Minerva or the JSU ROM. Apparently with these OS, when MERGE is used from a DO file or even as a direct command, no more DOs will work!!?? The workaround for this is when MoveIt stops, ENTER: 1 MERGE ram1_TempLines Then ENTER: GOTO 1 assuming line 1 is not used. This works but is not slick. If you know a better way, please let me know.
Moving a block to a lower location is similar, but the block is temporarily SAVEd and the intervening lines moved up. MoveItdown DO file: REMark case 2 of Moveit – move a block lower SAVE ram1_TempLines,_L TO _U REMark Add to file final commands to run when Merged. _F=FOPEN(ram1_TempLines):PUT#_F(FLEN(#_F)) REMark PUT sets file position to end PRINT#_F,’DO MoveItEnd’ CLOSE#_F DLINE _L TO _U RENUM _A TO;_U+1,1 IF VER$=’HBA’ THEN MERGE ram1_TempLines REMark For non SMS, use MERGE only in program or DOs are fouled up.
Cleaning Up And The Last Small Challenge
The last DO section, MoveItEnd deletes the temporarily ram file, RENUMs the block and the following program lines with the desired gap. It finishes by EDing to the new location of the block. The trouble is that sometimes you want to insert a block at an odd line number, then all following lines will have odd numbers. For example, if you insert at 513, then RENUM with a gap of 10, the line numbers will be 513, 523, 533 and so on. I’d prefer 520, 530, 540, etc. The MOD function in the 2nd line of MoveItEnd gets evenly divisible line numbers. MoveItEnd DO file: REMark MoveItEnd. Final DO file section of MoveIt RENUM _A TO;_A+_Gap-1-(_A-1) MOD _Gap,_Gap REMark Get divisible (e.g.100,110 not 111,121) numbers with MOD calculation DELETE ram1_TempLines ED _A
There is one more quirk I need to warn you about. RENUM doesn’t work if the last line of the RENUMed block is just one less then the lines above it. This minor limitation is easily taken care of by making space for the block plus two lines as in the 3rd line of MoveItup.
This article is available on the NESQLUG web site: MoveIt is freeware and you are invited to use or change it anyway you wish. However, I do hope if you make any serious changes, you will add a REMark with your name so we know who to query when it bombs!
God bless, Al