BASIC Variable Format
From Bitchin100 DocGarden
Jump to navigationJump to search
Per Ron Wiesen, from a discussion on the Bitchin100 Mailing List:
Variable Format - (RRW) For M100: The format of BASIC variables as they appear in the variable table is shown here. Where BASIC encounters a variable name, it searches the variable table for the variable name of the appropriate variable type: numeric double-precision, numeric single-precision, numeric integer, or string. Where the name is not found, BASIC expands the table and appends the variable at the end of the variable table (i.e, defines the previously undefined variable). Where the name is found, the variable content follows in the case of numeric variable types and a descriptor of content follows in the case of the string variable type. Each varible defined within the variable table consumes a 3-byte header and from 2 to 8 more bytes depending on the variable type. The header contains a "Type" byte and a "Name" in 2-character form. The value of "Type" also serves as a skip-count (relative to first byte of content) to the next (if any) header. +-----------+----------+----------+-----------+ | DP | SP | Integer | String | | Format | Format | Format | Format | ---------------------+-----------+----------+----------+-----------+ Byte 0 Type | 8 | 4 | 2 | 3 | Byte 1 Name, 1st character | Byte 2 Name, 2nd character - NUL for 1-character names | ---------------------+-----------+----------+----------+-----------+ Byte 3<-<(VARPTR) | S & E | S & E | LSB | Len | Byte 4 | BCD M | BCD M | MSB | Addr Low | Byte 5 | BCD # | BCD # | - | Addr High | Byte 6 | BCD # | BCD L | - | - | Byte 7 | BCD # | - | - | - | Byte 8 | BCD # | - | - | - | Byte 9 | BCD # | - | - | - | Byte 10 | BCD L | - | - | - | ---------------------+-----------+----------+----------+-----------+ LSB = Least significant byte of intger. MSB = Most significant byte of integer. Bit 7 contains the sign of the integer. BCD L = Least significant BCD byte, contains least significant pair of 4-bit BCD digits. BCD H = Most significant BCD byte, contains most significant pair of 4-bit BCD digits. BCD # = Middle BCD bytes. Each digit of the number is represented by one of the 4-bit values in the two nibbles in each byte. S & E = Sign and exponent of each number. Bit 7 contains the sign of the floating point number. Bits 0-5 determine where the decimal point is to be inserted. For example, if this byte contained a 65, the sign would be positive (value 64) and the decimal point would be placed after the 1st digit (value 1), and before the second digit (#.############# in DP Format or #.##### is SP Format). The purpose of bit 6 is unknown, but it may be a marker for the "currently selected" variable. Addr = Address to string content. This can be to a string constant within a BASIC program statement (e.g., V$ = "constant") or it can be within the string area BASIC (e.g., V$ = SPACE$(2). Len = Length of string. The LEN(var$) function returns this value.