# z80:Floating-Point Variables

It's great to be able to do integer math, but at some point, the limitations of 8/16-bit math won't meet your program's needs, especially for programs dealing with math/science (it is a calculator, after all). So how does TI perform that fancy math? The answer is with floating point variables. Each floating point variable (Op1, Op2, ... Op6) is a 9-bytes section of RAM used by the OS to perform operations. In this section, we will learn how to interface with these variables.

## Contents

# Variable Structure

Because the floating point variables are 9 bytes, their must be a standard layout for processing them in an 8-bit processor. It is as such:

## Byte 0: Type

This is for all the "definitions" of what's contained in the variable. Floating point variables are used for more than just math, they are also used to reference objects (programs, real/complex vars, matrices, etc.). So, this byte defines what is being looked at.

Bit 0-4: Object type Bit 5/6: Not used? Bit 7: Sign. 1 = negative, 0 = positive

The object type is a 5-bit that has been pre-defined by the OS. Here's a table of known definitions and their equates. Chances are you'll never use most of these, and some of these should never be used.

! Objects | Equate | Notes |
---|---|---|

RealObj | $00 | Real number |

ListObj | $01 | Real List |

MatObj | $02 | Matrix |

EquObj | $03 | Equation (Y=...) |

StrngObj | $04 | String |

ProgObj | $05 | Program |

ProtProgObj | $06 | Protected Program |

PictObj | $07 | Picture |

GDBObj | $08 | Graphical Database |

UnknownObj | $09 | ? |

UnknownEquObj | $0A | ? |

NewEquObj | $0B | ? |

CplxObj | $0C | Complex Number |

CListObj | $0D | Complex List |

UndefObj | $0E | ? |

WindowObj | $0F | ? |

ZStoObj | $10 | ? |

TblRngObj | $11 | ? |

LCDObj | $12 | ? |

BackupObj | $13 | ? |

AppObj | $14 | application, only used in menus/link |

AppVarObj | $15 | application variable |

TempProgObj | $16 | program, home deletes when finished |

GroupObj | $17 | group |

Depending on the type of object held, the rest of the objects are used differently. Below we will explore the most common objects.

## Real Objects

### Byte 1: Exponent

This holds the exponent of the object. The byte is treated as a signed 8-bit integer, except in a strange fashion. $80 is zero, $81-$FF are positive exponents ($81 = 1, $FF = 127), and $00-$7F are negative exponents ($00 = -128, $7F = -1).

### Byte 2-8: Data

The rest of the bytes are used to hold the data. Each nibble represents the "decimal" digit. The value is treated in scientific notation.

Ex.: $00,$80,$31,$41,$59,$26,$54,$00 represents a real value 3.14159265400

## Complex Objects

Complex objects take up two floating point variables. The first one is the real part, and the second one (immediately following) is the complex part. Both must contain the complex object token. For data structuring, see above (real objects).

Ex.: $0C, $7E, $22, $09, $78, $47, $30, $00, $00 ;OP1 0.0220978473 - 0.0012565562i $8C, $7D, $12, $56, $55, $62, $00, $00, $00 ;OP2

## List Objects (Complex & Real)

### Byte 1: List Token

This holds the list token, tVarLst = $5D.

### Byte 2-7: Name

Holds the list name. This is either Null-terminating, or limited to 5 characters.

Ex.: .db $01,$5D,"HELLO" ; Real list with name HELLO .db $0D,$5D,tL1,0 ; Complex list with name L1 (token)

### Byte 8: Unused

I believe this is unused, but to be safe you might want to set this to 0 if your list is 5 characters long.

## Program Objects (Protected/Unprotected)

Bytes 1-8 contain a null-terminating string with the name of the program, or if using all 8 characters, the null character can be omitted.

## Matrix Objects

Byte 1 always contains tVarMat = $5C. This is because the matrix token is 2 bytes. Byte 2 contains one of the tokens tMatA = $00 to tMatJ = $09. Byte 3 is always 0, and the rest can be undefined.

## String Objects

Like matrices, byte 1 contains the first string token tVarStrng = $AA. Byte 2 contains a token tStr1 = $00 to tStr0 = $09. Byte 3 must be 0, and the rest can be undefined.

## Picture Objects

Similar to matrices/strings. The first byte is tVarPict = $60, and the second bytes contains tPic1 = $00 through tPic0 = $09.

# ROM Calls

If you've tried doing anything with floating point math on your own, you'd probably figured out that it's not easy to do math on a 9-byte variable when your CPU can only work with 8/16 at a time. And TI has also written all the code necessary for floating point arithmetic. All we need to do is plug in the inputs and let the outputs pour forth.

For the full list of floating point ROM calls, see http://wikiti.brandonw.net/index.php?title=Category:83Plus:BCALLs:By_Name:FP_Math