Preface: I have used spreadsheet for quite a while, and I felt it is a fantastic tool. My most familiar spreadsheet is Lotus 123 (or VIP professional). One thing that I feel terrible is its MACRO language. It is not as user-friendly as its display. I feel BASIC is more suitable than MACRO for a spreadsheet language. So, I think that may be profitable to write a BASIC interpreter in a spreadsheet environment. The first thing I have to do is creating the spreadsheet program. I had written a calculator program using Personal Pascal. Hence, I can borrow a lot of functions from that program. After I finished the book "ATARI ST APPLICATION PROGRAMMING" by POLLACK and WEBER from BANTAM, I felt if I wanted to take full use of GEM, I have to switch to C language. To speed up the process of writing the spreadsheet, I was thinking to download some public domain spreadsheet programs and learned from them first. The first one I tried is a MODULA-2 program written for BYTE magazine. To my surprise, I could not understand the source file. I knew there is another public domain spreadsheet program -- MICROCAL (from Borland for Turbo Pascal). This program is much easier to understand. I learned what is essential for building a spreadsheet program from it. With MICROCAL, BANTAM book, and my calculator program, I think I can make a robust spreadsheet very fast. After 3 and half months struggle, I have a usable spreadsheet running now. The spreadsheet is not done yet and the BASIC interpreter is still a long way to go. Anyway, I feel the spreadsheet is quite usable even in its infant stage. Disclaimer: I have made every effort to insure the accuracy of the program. However, there is no warranty either express or implied for its uses. Program specification: SHEET (the name of this program) is written in Mark Williams C. The accuracy for real number (double) in Mark Williams C is up to 17 digits (Lotus 123 is up to 15 digits). The range of calculation is -1E-37 to 1E+37. Each spreadsheet contains 255 by 1280 cells and the spreadsheet is implemented by using Sparse Matrix. (What does Sparce Matrix mean? Simply speaking, the empty cells will not occupy any computer memory. So, you can insert something in cell "IU1280" without running into "NOT ENOUGH MEMORY" error). But there are some peculiar effects that is due to Sparse Matrix. I will refer to this later. Any input to a cell will be tokenized before it is being inserted. Currently, only one window can be used. The future version will support up to 4 windows. Requirements: * Atari 520 ST or 1040 ST with disk drive(s). * Monochrome or color monitor. * Both SHEET.PRG and CALC.RSC on the same directory. How to locate a cell: I assume you know how to operate with GEM. To locate a cell, - use vertical and horizontal slider bars to move to the desired display range. - put the mouse over the desired cell and press left button. Cell input: The operation of cell input is similar to Lotus 123. Anything you type will be inserted into the editing buffer. Special key: erases the last character. terminates input and the cell cursor remains on the same cell. terminates input and the cell cursor moves one row up if possible. terminates input and the cell cursor moves one row down if possible. terminates input and the cell cursor moves one column left if possible. terminates input and the cell cursor moves one column right if possible. terminates input and moves the cell cursor in the direction you specified by page. Special operations: if the mouse cursor is inside the display range and if you press the left button, the cell coordinate that the mouse is over will be inserted into the editing buffer. (Sometimes, GEM detects the mouse event very fast. But sometimes it does not. So, if you see nothing on the editing line when you press the mouse left button, press it a little bit longer. The problem may be caused by too many hide_mouse, show_mouse calls. If you reboot the system, it will always detect the mouse event very fast.) You can change the display range by moving the vertical or horizontal slider bars. But except , any special key will resume the display back to the display range before editing. Cell editing: Press and the current cell's content will be inserted into the editing buffer. The editing session must be terminated by . Special key: move one character left if possible move one character right if possible move the editing cursor to the leftmost character move the editing cursor to the rightmost character toggle the INSERT mode. Delete the character on the left side of editing cursor. Delete the character on the right side of editing cursor. type of input: (Input are case-insensitive ) FORMULA: Input string starts with "+","-",digits,"(" STATEMENT: String starts with "!" COMMAND: String starts with "@" TEXT: String starts with "\"" or character other than above leading character. Differences between types: Internally, FORMULA will be separated to FORMULA or CONSTANT depending whether the formula refers to other cells or other variables (Yes, you can use variables. Remember, we will have a BASIC interpreter). A cell contains CONSTANT will never be recalculated. It should speed up the spreadsheet recalculation time. STATEMENT is tokenized BASIC statements.You can have multiple statements with ":" as separator. (Right now, every input STATEMENT will be executed before inserting into the current cell. It should not be so. There are two reasons for that. First, I want to test each statement. Second,I do not have the RUN statement yet .) Currently, there are just a few statements being implemented: SAVE: The same as choosing menu item "Save" LOAD: The same as choosing menu item "Load" = (Assigment): compare the followings: +c1=12 It is a logical operation. A one means TRUE and zero means FALSE. !c1=12 It is a statement that changes the content of cell "C1" to a constant value 12. IF: IF condition THEN statements (ELSE statements) The ELSE statement is optional. DEFINE: For use with user define functions. (In the future, all the user defined functions will be on a file call FORMULA.DEF. You have to define your functions before calling SHEET. ) e.g. !define f(x,y)=3*x+4*y In any cell, type +f(3,4), you will have 25 as a result. NOTE:- Do not use DEFINE as COMMAND. - In the cell the function f(x,y) being defined, you will see: DEFINE F(X,Y)=3*PARAM1+4*PARAM2 You have to manually change PARAMx when you want to change its definition by using . - Each function can have at most 9 and at least one parameters. - You have to define the functions again each time you load the spreadsheet in. COMMAND is similar to STATEMENT. The only exception is its content will not be stored in the current cell. For saving some memory, each time you define a function, the pointer of its tokens is being pushed into the symbol table instead of storing the same tokens twice. So, if you say "@DEFINE F(X,Y)=3*x+4*y". After its execution, the symbol table has a pointer that will be freed back to the operating system. What will happen? I do not know! Change display format: Default format: TEXT: left justified STATEMENT: left justified FORMULA, CONSTANT: the number of digits after the decimal point is six; right justified of calculated result, if possible, a blank space is added at the rightmost place. WIDTH: 9 characters per column Only calculated result and column width can be changed. Change column width: - Select menu item "Width" from menu title "Sheet" - Change the column coordinate and column width as desired. Change cell format: - Select menu item "Reformat" from menu title "Sheet" - Choose the format, decimal place and range of cells you want to change. - NOTE: YOU CAN ONLY REFORMAT THOSE CELLS WHICH EXIST. That is because of Sparse Matrix. After a cell has been created, the cell possesses attributes. If you format some empty cells and insert something into those cells after that, those cells appear as default. It is not a bug. Calculation: Accuracy: up to 17 digits Range: -1E-37 to 1E+37 Arithmetic operators: "+", "-", "*", "/", "^", MOD Logical operators: AND, OR, NOT, "=", "<>", ">", "<", ">=", "<=", "=>", "=<" Built-In functions: Math: SIN, COS, TAN, ASIN, ACOS, ATAN, LOG (logarithm base 10), EXP, LN (logarithm base e), ABS, INT (integer part of a real number), FRAC (fraction part of a real number), SQR, SQRT, DATE( calculate the Julian days, 3 parameters, dd,mm,yy), FACT(factorial), RAD_DEG(radian to degree), DEG_RAD(degree to radian). Statistics: AVERAGE, MEDIAN, STD (standard deviation) Miscellaneous: MAX, MIN, SUM Finance: NONE. String: NONE. Priority: Lowest: - "+", "-", OR - "*", "/", "^", AND, MOD - number, cell reference, variable, function call, NOT, "+", "-" (unary operator) Highest:- Parenthesis Constants: PI(0.31415926535897932e+01), TODAY(Julian days when you press TODAY, similar to the function @TODAY on VIP professional. In Lotus 123, @TODAY will be recalculate when you load the file, but VIP won't) Recalculation: Recalculation orders: Natural: Recalculate each cell in the order they are inserted. It works like first-come-first- serve. Row: Recalculate each row in the ascending order. Column: Recalculate each column in the ascending order. Manual recalculation: The spreadsheet stops automatic recalculation. User has to press , or for natural, row or column recalculation, where means press key with character key simultaneously. Notes: Row and column recalculation methods are faster than natural recalculation method. That is due to Sparse Matrix. Each cell is linked with with its left, right, top, down cells tightly. For natural recalculation, each cell has to locate individually. For row and column recalculation, each cell can move to its next cell by using the linked pointer. File format: Header: - 2 bytes for version number, current version is 1.0 - 268 bytes for print-dialog information (actually, only 262 bytes are used. When the graphic part is done, this area will be used for graph information) - 40 bytes for window title. (39 characters with a null character) - 2 bytes for check sum of the window title to make sure I am handling the right work sheet. - 256 bytes for width of each columns (you cannot display column 0, but it is planned to be used by the BASIC interpreter for internal operation). - 2 bytes for window type (It is useless) - 8 bytes for current window size - 4 bytes for display range top row, top column - 4 bytes for current cell cursor address - 2 bytes for current recalculation mode Cell contents: - 4 bytes for cell row, column - 2 bytes for display attribute - 2 bytes for decimal place - 2 bytes for tokens length - 8 bytes for calculated result - tokens length bytes of actual tokens Print: You can print your work sheet to a file or to printer. The print routine will print those columns that fits on the margins. If some columns on the print range are not print on the first pass, they will be printed on later passes. Conclusion: What is next? I plan to implement the COPY, MOVE and ERASE commands on next release. Some new functions like COLUMN and MATRIX should be done also. What are they? Here are 2 examples: (e.g. If you have "Quantity" in column B starting from row 1 to row 20, and you have "Price" on column C on the same row range, and if you want to calculate subtotal for each item (each row), in Lotus, you will do this: +b1*c1 on cell D1 copy d1 starting from d2 down to d20 But if I finish the COLUMN function, you can do this in one line on cell D1: COLUMN(d1..d20, b1..b20 * c1..c20) What do we gain by using COLUMN function instead of COPY? Speed! By using COPY command, you have to recalculate as many cells as you copy to. But using COLUMN function, only one formula will be recalculated in a loop. It should increase the recalculation performance. e.g. MATRIX(a1..b3, a1..b3 + d1..e3 - 3*(f1..g3)) Well, it works similar to COLUMN function and not only matrix addition, subtraction, but also matrix multiplication and inverse will be functioning. If I finish those functions, then linear regression and simultaneous equations can be solved easily. ) Well, this program is not finished yet and it needs your help (comments and suggestions) and support (donation $10). My addresses are: Mr. Chor-ming Lung 33 Garden St #3 Boston, MA 02114 U.S.A. GEnie: LUNG CompuServe: 72740,40 I will log on GEnie more often than CompuServe. P.S. I am planning to write a simplified version for desk accesory. Any one who donates will receive it when it is done. A blank disk with name and address on label is necessary for the desk accessory program. o 15 digits). The range of calculation is -1E-3