You will find this program to be a great improvement over the ‘JUST ANOTHER SPREADSHEET!’. It has more file space, it is faster and it is much easier to work with. Spreadsheet II is a machine-code spreadsheet of up to 150 columns, driven by a menu arrow moved with Q, A, O, P and SPACE or a joystick. Cells hold numbers, names (up to 10 characters) or formulas (up to 32 characters), and the FILES menu saves, loads, calculates, prints, sets the sheet size, chooses the printer and arrow speed, clears the sheet and quits.
Formulas can use the BASIC functions SIN, COS, TAN, ASN, ACS, ATN, INT, RND, SGN, ABS, SQR, LN, EXP, PI, AND, OR, NOT, comparisons and arithmetic, plus range functions (MN, MX, AV, SM and CT over a range such as [A1..Z99]) and business functions: present value, future value, monthly payment, remaining balance, range of homes, simple and compound interest, and fraction. Numbers run from -999999.99 to 9999999.99. Printing goes to the TS2040 or to a full-size printer through a driver, with settable carriage return, line feed and form feed.
Written by Kristian Boisvert, ©1988 Byte Power. Loading name SHEET II. Published on the Fall 1988 (Issue 11) tape of Byte Power, followed by an AERCO printer DRIVER and a SHEET DEMO file to load from the FILES menu; those two are on the issue tape (#51120) but not in this program’s download.
Program Analysis
The BASIC loader (line 9000) does CLEAR 28874, loads the 19,026-byte main code at 46510 and the 123-byte ONERR block at 28875, dimensions A$(150) and enters the code. The rest of the BASIC is a set of services the machine code calls back into.
Formula evaluation through BASIC
Lines 100–200 are marked “DON’T MESS WITH THIS!”. The machine code places a formula, translated into BASIC form, in A$, and line 120 evaluates it with LET E=VAL A$, so the spreadsheet uses the ROM’s own expression evaluator. Line 130 then finds E in the variables area (PEEK 23627+256*PEEK 23628+157, just past the 150-byte A$) and copies its five-byte floating-point value to 61856 for the code to pick up. Line 110 calls the ONERR routine after RANDOMIZE 200; this appears to install an error trap that resumes at line 200, which sets E=1E10 as an error value, so a bad formula is reported as “ERROR IN CELL” instead of stopping the program.
Files
Lines 1000–2050 load and save sheets as a code file at 29000; the save length is computed by the code (16000-USR 62770) and the file is verified after saving.
Notable Techniques
- Using
VALon a built string as a full expression evaluator for spreadsheet formulas. - Reading a numeric variable’s five bytes straight out of the variables area with
PEEK. - A small machine-code error trap in place of
ON ERR, which the Spectrum 48K does not have.
Potential Issues
- The magazine notes that formulas are calculated in the order they were entered, so a formula that depends on one entered later can need a second calculation.
- Editing a cell erases any formula in it (
SHIFT+1recalls it), and a name containing a digit is taken as a formula.
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
