home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / utilsm / psionics / spr.fmt < prev    next >
Text File  |  1995-01-17  |  16KB  |  372 lines

  1. PSIONICS FILE - SPR.FMT
  2. =======================
  3. Format of Spreadsheet files
  4. Last modified 1994-03-01
  5. ===========================
  6.  
  7. This document describes the layout of SPR files for the SH3 spreadsheet.
  8.  
  9. A data file (also called a database file) begins with a 22 byte header of the
  10. following form:
  11.   Offset  0 (cstr): "SPREADSHEET"
  12.   Offset 16 (word): format version number
  13.   Offset 18 (word): offset value (meaning unknown)
  14.   Offset 20 (word): OPL runtime version number
  15.  
  16. The version numbers and offset value are all zero.
  17.  
  18. The rest of the file consists of records. All records have the form:
  19.   Offset  0 (word): type of record
  20.   Offset  2 (word): size of data portion in bytes (L)
  21.   Offset  4 to L+3: data portion
  22.  
  23. Unless stated otherwise, records may appear in any order. Record types 11 and
  24. 12 should not appear in Series 3 spreadsheets - they were used by the MC. Types
  25. 13 onwards are new in the Series 3.
  26.  
  27. Unless stated otherwise, a cell reference is two words - column then row - and
  28. a range reference is four words - left, top, right, bottom, in that order.
  29. Each word is intepreted as follows. If the word is N, then:
  30.       0 <= N <= $1FFF: Nth row or column (so 0 is row 1 or column A)
  31.            N =  $8000: this row or column
  32.   $8000 <  N <  $9FFF: row N-$8000 below or column N-$8000 to right
  33.   $E000 <  N <= $FFFF: row $10000-N above or column $10000-N to left
  34. Values with the top bit set are only permitted in formulae. In some other
  35. circumstances a reference containing all $FFFF values is used for "none".
  36.  
  37.  
  38. Record type 1 holds formulae. A formula must come before any cell (record type
  39. 2) that accesses it, and the relative order of type 1 records should be
  40. preserved. The record takes the form:
  41.   Offset  0 (word): number of records using this formula
  42.   Offset  2 (byte): length of formula (F)
  43.   Offset  3 to F+2: formula
  44.  
  45. A formula is stored using a Reverse Polish notation. In other words, to
  46. evaluate a formula, start with an empty stack, and then scan the formula in
  47. order; when finding an operand, push it on the stack, while when finding an
  48. operator, take its arguments off the stack, apply it, and push the answer on
  49. the stack.
  50.  
  51. Operators are represented by single bytes:
  52.   1 = <      5 = <>     9 = *     13 = -     17 = &
  53.   2 = <=     6 = =     10 = /     14 = NOT
  54.   3 = >      7 = +     11 = **    15 = AND
  55.   4 = >=     8 = -     12 = +     16 = OR
  56. (all take two operands except 12 to 14; 17 is string concatenate).
  57.  
  58. Delimiters are represented by single bytes:
  59.   18 = (     These are not strictly needed, but allow the original
  60.   19 = )     entered formula to be recreated for editing
  61.   20 = ,
  62.   @The above 3 need testing@
  63.   21 = end of formula
  64.  
  65. Operands are represented by a byte followed by the value of the operand:
  66.   22 = real (8 bytes)
  67.   23 = word (2 bytes)
  68.   24 = qstr
  69.   25 = cell reference
  70.   26 = range reference
  71.  
  72. Functions with no arguments or a fixed list of arguments are represented by
  73. single bytes; the operands are treated exactly as for operators. In the
  74. following list, the arguments are shown as "n" for numeric, "s" for string,
  75. and "r" for range.
  76.  
  77.   27 ERR              55 LOG(n)           83 STRING(n,n)
  78.   28 FALSE            56 LOWER(s)         84 CTERM(n,n)
  79.   29 NA               57 MINUTE(n)        85 DATE(n,n)
  80.   30 PI               58 MONTH(n)         86 DAVG(r,n,r)
  81.   31 RAND             59 N(r)             87 DCOUNT(r,n,r)
  82.   32 NOW              60 PROPER(s)        88 DMAX(r,n,r)
  83.   33 TRUE             61 ROWS(r)          89 DMIN(r,n,r)
  84.   34 ABS(n)           62 S(r)             90 DSTD(r,n,r)
  85.   35 ACOS(n)          63 SECOND(n)        91 DSUM(r,n,r)
  86.   36 ASIN(n)          64 SIN(n)           92 DVAR(r,n,r)
  87.   37 AT(s)            65 SQRT(n)          93 FIND(s,s,n)
  88.   38 ATAN(n)          66 TAN(n)           94 FV(n,n,n)
  89.   39 CELLPOINTER(n)   67 TIMEVALUE(s)     95 HLOOKUP(n,r,n)
  90.   40 CHAR(n)          68 TRIM(s)          96 IF(n,n,n)
  91.   41 CODE(s)          69 UPPER(s)         97 INDEX(r,n,n)
  92.   42 COLS(r)          70 VALUE(s)         98 MID(s,n,n)
  93.   43 COS(n)           71 YEAR(n)          99 PMT(n,n,n)
  94.   44 DATEVALUE(s)     72 ATAN2(n,n)      100 PV(n,n,n)
  95.   45 DAY(n)           73 CELL(n,r)       101 RATE(n,n,n)
  96.   46 EXP(n)           74 EXACT(s,s)      102 SIN(n)
  97.   47 HOUR(n)          75 IRR(n,n)        103 TERM(n,n,n)
  98.   48 INT(n)           76 LEFT(s,n)       104 TIME(n,n,n)
  99.   49 ISERR(r)         77 MOD(n,n)        105 VLOOKUP(r,n,n)
  100.   50 ISNA(r)          78 NPV(n,n)        106 DDB(n,n,n,n)
  101.   51 ISNUM(r)         79 --------        107 REPLACE(s,n,n,s)
  102.   52 ISSTR(r)         80 REPEAT(s,n)     108 SYD(n,n,n,n)
  103.   53 LEN(s)           81 RIGHT(s,n)
  104.   54 LN(n)            82 ROUND(n,n)
  105.  
  106. Functions with a variable list of arguments are more complex. The call is
  107. built up as follows:
  108.   - a START byte
  109.   - the arguments
  110.   - an END byte
  111.   - the number of arguments (a byte)
  112. The arguments are just placed in order. An argument is either:
  113.   - the value of the argument, followed by an ARG byte
  114.   - a RANGE byte followed by a range reference
  115. Note that all arguments other than ranges, including cell references, work
  116. by evaluating the argument in the normal way; ARG in effect says to pop the
  117. next argument off the stack.
  118.  
  119. The values of the four special bytes differ for each function:
  120.  
  121.                 START    END     ARG    RANGE
  122.     AVG()        120     112     136     128
  123.     CHOOSE()     121     113     137     129
  124.     COUNT()      122     114     138     130
  125.     MAX()        123     115     139     131
  126.     MIN()        124     116     140     132
  127.     STD()        125     117     141     133
  128.     SUM()        126     118     142     134
  129.     VAR()        127     119     143     135
  130.  
  131.  
  132. Record type 2 describes a cell. It has the following format:
  133.   Offset  0 to   3: cell reference
  134.   Offset  4 (byte): flags:
  135.     Bits 0 to 2: cell contents type:
  136.       0 = blank
  137.       1 = real constant
  138.       2 = text constant
  139.       3 = word constant
  140.       5 = real formula
  141.       6 = text formula
  142.     Bits 3 to 4: text alignment: 0 = repeat, 1 = left, 2 = right, 3 = centre
  143.     Bit 5:       set for left aligned numerics, clear for right aligned
  144.     Bit 6:       set if the cell has changed since the last recalculation
  145.     Bit 7:       should not be altered, used by natural order sort
  146.   Offset  5 (byte): format
  147.     Bits 0 to 3: number of digits in display format
  148.       For special formats, this selects the special format:
  149.          0 = bargraph,  1 = general, 5 = show formulae, 6 = hidden, 9 = date,
  150.         11 = time,     15 = default
  151.     Bits 4 to 6: display format: 0 = fixed,      1 = scientific,  2 = currency,
  152.                                  3 = percentage, 4 = triad/comma, 7 = special
  153.     Bit 7:       set if the cell is protected
  154.  
  155. This is then followed by a value block and then optionally a font byte.
  156. The value block depends on the contents type:
  157.   Type 0 (blank) has no value block
  158.   Type 1 (real constant):
  159.     Offset  6 (real): value
  160.   Type 2 (text constant):
  161.     Offset  6 (qstr): value
  162.   Type 3 (word constant):
  163.     Offset  6 (word): value
  164.   Type 5 (real formula):
  165.     Offset  6 (word): index of formula
  166.     Offset  8 (real): current value
  167.   Type 5 (text formula):
  168.     Offset  6 (word): index of formula
  169.     Offset  8 (qstr): current value
  170. The index of a formula is its position in the set of type 1 records. So 0
  171. means the first type 1 record, 1 the second type 1 record, and so on.
  172.  
  173. The font byte is simply a number from 0 to 3, giving the font of the cell.
  174.  
  175.  
  176. Record type 3 describes column widths, and appears for each column not of the
  177. default width. The record takes the form:
  178.   Offset  0 (byte): column number
  179.   Offset  1 (byte): width
  180.  
  181.  
  182. Record type 4 describes the default column width:
  183.   Offset  0 (word): default width
  184.  
  185.  
  186. Record type 5 holds general status information:
  187.   Offset  0 (byte): flags
  188.     Bit 0:       set if automatic recalculate is on
  189.     Bit 1:       set if protection override is on
  190.     Bit 2:       set if a cell has been deleted since the last recalculation
  191.     Bit 3:       set if table recalculation is on
  192.     Bits 4 to 7: unused, always zero
  193.   Offset  1 (byte): unused, always zero
  194.   Offset  2 (byte): default numeric display format
  195.   Offset  3 (byte): default alignment for new cells
  196. The default