|★ APPLICATIONS ★ PROGRAMMATION ★ RSX VFIND: VARIABLE FIND|COMPUTING WITH THE AMSTRAD) ★|
|Variable Dump (Computing With the Amstrad)||RSX Vfind: Variable Find (Computing with the Amstrad)|
VARIABLE Find is a machine code program to complement Roland Waddilove's Variable Dump published in the February 1987 issue of Computing with the Amstrad. Having identified mistyped variable names with |VARDUMP you can now pinpoint the offending line number using SVFIND, the RSX added by this program.
Type in Program I which is the Basic loader for the machine code. Save it before trying to run it because once you have debugged the data statements the Basic will erase itself from memory when it has installed the RSX.
The new command can be used with or without Vardump in memory and will accept upper or lower case as valid input. To use it put the variable name into a string, such as A$="FRED". It doesn't have to be A$, you could use F$ or just about anything else that takes your fancy. You should omit suffixes such as $ and % from the name otherwise they will be treated as part of the name and produce a nil return.
Then type |VFIND,@A$ and a list of line numbers will be printed out. Don't forget the (a before A$ as this is vital to the way your Amstrad extracts the variable name from the string.
The search routine has been kept fairly simple for the sake of speed, economy of memory and your fingers. Consequences of this are that the routine does not distinguish between string or numeric variable names and may print out spurious line numbers for one of two reasons.
Firstly, if your variable name also happens to be embedded at the end of a longer name then the line number containing the longer name will be listed. An example of this would be printing a line number containing OLDFRED$ when what you were really after was FRED. Of course line numbers containing FRED would also be listed out, so this is not too much of a problem.
Secondly, if your variable name is very short, particularly only one or two characters in length, it is quite likely that other bytes of program data will match the Ascii values of the name. These line numbers will be listed out for no apparent reason.
In practice you are unlikely to be searching for one or two character long variable names, and even if you are |VFIND will produce a shortlist of line numbers among that are correct lines which are easily checked.
Program II is a listing of the assembly language source code. Budding machine coders among you should find it helpful to look at the way it works, particularly the method for passing the contents of a string variable over to a machine code program, the search method and the routine for printing out a decimal.
You may know that if you make a call to a machine code routine either by RSX or direct CALL and if a parameter follows your call - such as CALL &A000,3 or CALL &A000,z where z is a numeric variable - the IX register points to the low byte of the last parameter passed and the A register contains the number of parameters.
This is easy enough to deal with if a number or numeric variable is being used but what happens if you want to pass a string? Well unfortunately you can't CALL &A000, FRED and hope that FRED will be available to your routine. You must put FRED into a string such as A$ and then CALL & A000, @A$, or in our case |VFIND,@A$.
On arrival at the machine code the A register still contains the number of parameters passed, but the IX register points to the address of the storage location of the variable A$. The (& before A$ tells your micro to pass the address of a variable rather than its value.
This address stores the location of the string descriptor block, which in turn points to the address of the contents of the string as well as giving the number of characters it holds. After sorting all that out we're finally in a position to access the string from our machine code program.
Having found the start of the string it is transferred to a store while being converted to upper case if necessary. 128 is added to the value of the last character. The stored variable name now matches the form in which it appears in the Basic program, assuming upper case. As you may have originally used lower case or may have mixed upper and lower case the search routine converts all lower case to upper case before comparison.
The search begins at address & 170 where all Basic programs start. To help you understand how this of program data. If at any stage mismatch occurs then carry on th main search where it was left of otherwise if a total match was found convert the line number to decirnal print it and continue searching on th next line.
The routine to convert a 16 bit number to decimal and print it out if fairly simple and is just the job for printing out, for example, the Score if your latest arcade masterpiece Vardurnp and Vfind together should save you hours in debugging you Basic programs. Happy hunting.