2

From the Wiki:

The final major release of BASIC-80 was version 5.x, which appeared in 1981 and added support for 40-character variable names, WHILE...WEND loops, dynamic string allocation, and several other features. BASIC 5.x removed the ability to crunch program lines.

I'm only familiar with the 6502 code for MS BASIC, which had the two-char name limit.

Does anyone know how they implemented long names? Did they simply expand the variable table? Did they separate the names to their own list? Use the 2 bytes to point to the string in the source?

  • Hmm. Not sure if that helps, but original BASICA and GWBASIC are ports of BASIC-80 V5.x – Raffzahn Jul 23 at 21:48
4

They expanded the variable table. Each entry starts with a type byte followed immediately by the full variable name.

This is based on an analysis of the Microsoft BASIC-80 5.2 source code found here. The core of the interpreter is BINTRP.MAC, which has most of the definitions used here. This includes NAMCNT (one byte) and NAMBUF (NAMLEN - 2 bytes), which are pre-allocated storage for a copy of a variable name read from the program text, and VARTAB, a pointer to the start of the area (immediately after the program text, I believe) that stores the current list of variable names and values when running.

The routine I looked at was PTRGET in BIPTRG.MAC, which reads a variable name at the current text position pointed to by HL and stores a pointer to its value in the location pointed to by DE.

The core of the variable name search is LOPTOP, which is entered with BC containing the first two chars of the variable name, DE pointing into VARTAB and storage NAMCNT and NAMBUF containing the name length count and chars beyond the first two.

LOPTOP compares the first char of the variable name (in C) with the first char of the name in VARTAB, then compares the variable type, then the second char of the name (in D). I'm guessing that this was the original full comparision routine in earlier versions of BASIC. If all of these match, it continues on with FINPTR, which compares the remaining name chars in NAMBUF with the rest of the name in VARTAB.

Postscript: I've found a disassembly of Altair Basic 3.2. The symbol names are different for obvious reasons, but its routine [GetVar] is clearly the PTRGET routine above. The start of it is almost identical, the main differences being that "read next char" is a routine called with RST rather than a MOV C,M and that the first and second characters are in B and C rather than vice versa. There are larger differences in the specific code for LOPTOP (called FindVarLoop in the disassembly), some related to the simplified variable storage (here called VAR_BASE), but the overall structure is clearly the same. The memory arrangement overview is helpful reading before diving into either this or the 5.2 source code.

  • Most excellent, I had not found that source online. Are VARTAB and NAMBUF two tables, or is NAMBUF a pointer within VARTAB? – Maury Markowitz Jul 24 at 14:13
  • @MauryMarkowitz They're completely separate; NAMEBUF is pre-allocated temporary storage for a variable name and VARTAB is the pointer to the variable table. I've updated the question to describe these better. – Curt J. Sampson Jul 24 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.