APPLICATIONSPROGRAMMATION ★ ROLAND WADDILOVE'S Variable Dump takes the slog out of error checking ★

Variable Dump (Computing With the Amstrad)Applications Programmation
★ Ce texte vous est présenté dans sa version originale ★ 
 ★ This text is presented to you in its original version ★ 
 ★ Este texto se presenta en su versión original ★ 
 ★ Dieser Text wird in seiner Originalfassung präsentiert ★ 

Check your variables to spot your mistakes

VARIABLE Dump is a short machine code routine to add an extra command

|VARDUMP as an RSX. It simply lists all the variables that have been used by a Basic program.

Why would you want to list all the variables? Well, suppose you typed in a listing and it didn't behave as expected when run. It's most likely to be a simple typing slip.

One of the features of Locomotive Basic is that it will create an additional variable every time it comes across a word it doesn't recognise. So if the program uses a variable called score and you accidentally typed scare instead it would add scare to its list of variables. By printing all the variables it's easy to spot any that have been entered incorrectly.

The program must be run before using IVARDUMP. After each variable name it waits for a key to be pressed. This is to prevent long lists of variables scrolling off the top of the screen.

To understand how the routine works we need to know how the Amstrad stores its variables. These are stacked up in the memory starting at the end of the program. Arrays are always placed at the end of the variable stack. All other variables are inserted before these.

I'll call the address of the end of the program currently in memory TOP. The value of TOP is stored at &AE85 if you have Basic 1.0, and at &AE68 if you have Basic 1.1. The CPC464 has Basic 1.0 and the CPC6128 has Basic 1.1.

The lowest point in the memory which is free I'll call LOMEM. This is the top of the variable stack. Basic 1.0 stores LOMEM at &AE89 and Basic 1.1 stores it at &AE6C.

The end of the normal variables and the start of the arrays is stored at &AE87, Basic 1.0 and &AE6A, Basic 1.1.

Variable Dump prints the ordinary variable names first, if there are any.

These are stored between TOP and the start of arrays. Of course if these two values are the same then there aren't any.

When Basic stores the variable it ANDs the characters of the name with &DF to convert any letters to upper case. This has the unfortunate effect of converting any numbers in the name to Ascii values below 31 -reserved for control codes. The last letter of the name is marked by setting bit 7 of the Ascii code.

To print out a variable s name the characters are ANDed with &7F, then ORed with &20. This restores the name.

The byte in memory immediately following the variable's name indicates what type it is. An integer is 1, string 2 and real 4. A % sign is printed after integers' names and a $ sign after strings.

The address of the next variable name is found by adding the space taken up by the variable to the address of the type byte. Integers take up 5 bytes, reals 8 and strings 6.

Remember that the actual string is placed at HIMEM. The data in the variable stack is the string descriptor giving the name, length and address of the string.

A separate routine is required to handle arrays. The name and type is printed out in the same way, followed by a pair of brackets to show that it is an array.

The actual space taken up by the array depends on the number of dimensions and elements there are. The two bytes following the type byte tell us how much space has been reserved. The next variable is stored at the address of these two bytes plus their contents plus 4.

If the address of the next variable is equal to LOMEM all the variables have been listed.

Program I is a Basic listing with the machine code stored in data statements. Run this and call &A000 to enable the RSX. Program II is an assembly listing of the routine.

You should find debugging a lot easier using Variable Dump to list all the variables. Now all we need is a routine to tell us which line the misspelt variable is actually in.

Can anyone help?

CWTA

★ PUBLISHER: Computing with the Amstrad
★ YEARS: 1985 , 1986
★ CONFIG: ???
★ LANGAGE: ???
★ LiCENCE: LISTING
★ COLLECTION: COMPUTING WITH THE AMSTRAD 1986
★ AUTHOR: Roland Waddilove
 

★ AMSTRAD CPC ★ DOWNLOAD ★

Type-in/Listing:
» Variable  Dump    (Computing  with  the  Amstrad)    LISTINGDATE: 2013-05-05
DL: 231
TYPE: text
SiZE: 2Ko
NOTE:

★ AMSTRAD CPC ★ A voir aussi sur CPCrulez , les sujets suivants pourront vous intéresser...

Lien(s):
» Applications » Traffic CB
» Applications » Business Controller
» Applications » MOS: Mouse Operating System
» Applications » Electra 2000
» Applications » Printing Modes (Popular Computing Weekly)
» Applications » SmART
Je participe au site:
» Vous avez des infos personnel, des fichiers que nous ne possédons pas concernent ce programme ?
» Vous avez remarqué une erreur dans ce texte ?
» Aidez-nous à améliorer cette page : en nous contactant via le forum ou par email.

CPCrulez[Content Management System] v8.7-desktop/c
Page créée en 381 millisecondes et consultée 1828 fois

L'Amstrad CPC est une machine 8 bits à base d'un Z80 à 4MHz. Le premier de la gamme fut le CPC 464 en 1984, équipé d'un lecteur de cassettes intégré il se plaçait en concurrent  du Commodore C64 beaucoup plus compliqué à utiliser et plus cher. Ce fut un réel succès et sorti cette même années le CPC 664 équipé d'un lecteur de disquettes trois pouces intégré. Sa vie fut de courte durée puisqu'en 1985 il fut remplacé par le CPC 6128 qui était plus compact, plus soigné et surtout qui avait 128Ko de RAM au lieu de 64Ko.