A.N.A.L.O.G. ISSUE 63 / AUGUST 1988 / PAGE 50

BCALC

48K Disk or Cassette
by Barry Kolbe and Bryan Schappel

A spreadsheet so easy to use that you don’t need this article! Well, almost. But seriously, BCALC has many features that make it easy to use, the kind of ease of use you enjoyed with Atariwriter.

Typing it in

Listing 1 contains the BASIC data statements used to create the BCALC file on your disk. Please refer to the M/L Editor found elsewhere in this issue for instructions in keying in BCALC.

Once the BCALC file has been created, simply binary load it from DOS. Refer to your DOS manual on how to do this if you are not sure. Please remove the cartridge from your 800 computer or turn BASIC off on your XL/XE computer by holding the option key down when booting up. When the program loads there will be a credit line at the top of the screen. Press any key to begin.

General information

BCALC (hereafter referred to as BC) is a spreadsheet using about 8K of memory. This leaves around 24K for data. BC has many of the features you would find in a commercial spreadsheet. The BC sheet is 64 columns wide (lettered AA-CL) and has 64 rows (numbered 01-64). The intersection of each column and row is called a cells. So if my arithmetic is still correct that means there are 64 × 64 or 4096 cell. Each cell has an overhead of at least four bytes plus whatever data is entered.

There are three kinds of information you can store in a cell. The type of data entered is displayed on the right side of the top screen line.

1. Text Data: This is anything that does not begin with a number 0-9 or the “=” or “-” sign. It’s possible to put numbers in as text (see below).

2. Numeric data: a number that begins with 0-9, “-” or “.” Numbers can be entered in scientific notation. For example, 345E-45. BC only accepts that part of input which is a valid number. For example, if you type: “-.234fgh” BC takes the “-.234” and ignores the rest. You may not type in commas. To display commas use the formatting commands which are discussed later.

3. Functions: An arithmetic or algebraic expression starting with the “=” sign (inversed also works). You mean I have to know algebra? Was my math teacher right in that there is a use for algebra? Perish the thought!

Entering functions is quite easy if one follows the rules. The five operations of ^ (exponentiation), * (multiplication), / (division), + (addition) and - (subtraction) are used. These are used as operators between numbers, cells or built-in functions. Be aware of the order of operations. My Dear Aunt Sally. Huh? This is a mnemonic to remember the order of operations: multiplications and divisions are done first in order from left to right. Next, additions and subtractions in order from left to right. Exponents and parentheses are done first however. You want an example? Sure thing.

= 3 + ((2 + 7) ^ 2-4*6)/6

The innermost parentheses are done first: (2 + 7) becomes 9. The 9 is then squared ( A 2) yielding 81. Next 4*6 = 24 is done. Then the difference 81 - 24 = 57 is calculated. Dividing by 6 yields 9.5. Add to 3 equals 12.5. Remember that each number above could be replaced by a cell or a built-in function. For example:

=@RND((1+AB24/12)^36)-BQ12

Always make sure that the cells used do not have text data or an error will result. Since you might enter text data in lower case, BC also allows you to enter functions in lower case; so you won’t have to toggle that CAPS key. Just type away!

Console keys

OPTION displays a status screen in the text window. The current filename, number of free bytes, recalculation status (on/off) and recalculation mode (row/column) are shown. Hit a key to exit.

SELECT puts you in the driver’s seat. Well, actually in command mode. The text window will change color in this mode. You may use upper- or lowercase letters and even inverse video in commands. Some commands require an argument such as a cell reference (e.g., BG24) or a number. Zeros are necessary in cell references (e.g., CD02).

The commands are:

[DIR]ECTORY n displays up to 16 files on the screen. If you do not type a drive number “n,” Drive 1 is the default. Make sure there is a space between “DIR” and “n.” That is also true for the other commands. Press a key to read more filenames. If there are exactly 16 files read in you will need to hit a key twice.

[WID]th ccrr sets the width of column cc to width rr. The width rr must be greater than one but less than 32.

[SAV]E Dn:filespec is used to save the sheet. You must type a complete filespec including the “Dn:”. Multiple drives are supported as well as a RAMDisk. If you attempt to save a sheet using the name of a file that already exists, you are asked if you wish to replace it. Merely hit the “Y” or “N” key to make your choice.

[LOA]D Dn:filespec is used to load a sheet that was saved. Seems reasonable.

[GOT]O ccrr is the fast way to go from here to there or at least to cell ccrr. cc must be in the range AA-CB and rr in the range 01-47.

[SET] ccrr sets the column and row references that are displayed at the bottom of the text window. An example is definitely called for. If we type SET AA02 and the cursor is on DE12 we see that data from cell AA12 and from DE02 displayed.

If I were doing my grades (after all, I am a teacher), I might have student names in column AA. But when I’m entering data in cell AG12, column AA is nowhere to be seen. However, if I use SET AA12 the student name from column AA row 12 appears on the last text window line. Also shown is heading for column AG row 02.

[LIS]T Dn:filespec lists the spreadsheet to the disk so the information can be used with a word processor like Atariwriter. Use the cursor keys to define the block of information you would like listed on disk. If you define a bad block an error results. The information listed will be in exactly the same format as you see it on the screen.

LISTed files cannot be reloaded into the sheet. Doing so will probably cause the computer to lockup, and you will likely see a very unusual screen staring at you! Use the SAVE command to store the sheet on disk. Just in case you try to do something clever, like LIST to the same filename that was used to SAVE the sheet, you’re told if the file already exists. You then may overwrite it if you wish. I’d recommend using a .LST extension on LISTED files.

START is used to abort input in either input mode, edit mode or command mode.

Special keys

These keys are used with the CONTROL key pressed simultaneously:

[-] (Arrow up) moves the cursor up one row.

[=] (Arrow down) moves cursor down one line.

[+] (Arrow left) moves one cell to the left.

[*] (Arrow right) moves one cell to the right.

The name of the current cell (e.g., AA01) occupied by the cursor is displayed in the center of the top screen line. To the right of it is a message showing the type of data in the cell. This is good to know since a number on the screen could be a stored number or it could be the result of a function.

These keys can be used in input mode to terminate input and send the cursor to the next cell. For example, if you are on cell AA01 and you type NAMES(CTRL-*), “NAMES” is entered in cell AA01 and the cursor will move to cell AB01. RETURN keeps the cursor on the current cell. In edit mode these keys move you around the text window to give you full-screen editing.

[H] takes the cursor to AA01.

[D] deletes a block of cells. Follow the prompts. Specifying an improper block results in an error.

[C] copies a block of cells. See below.

[M] moves a block of cells. See below.

[T] forces text mode. This allows you to enter numbers, etc, as text. For example, 342-48-2333 as a number would result in just 342 being entered. In forced text mode it is entered as text.

[G] changes the global format of the column the cursor is on.

[L,C,R] keys control Left, Center and Right justification.

[D] toggles the “$” symbol.

[,] toggles commas on and off.

[0-9] chooses the number of places displayed to the right of the decimal point.

[ESCAPE] makes the choice final and exits.

All new data entered in this column will take on the new format. Formatting information is stored with cell data when it is entered. So data already there has its own individual format. To change it use CTRL-F.

[F] formats an individual cell. Enter the data normally. Press CTRL-F. The global format information is displayed in the text window. Make the changes you desire as above in G. ESCAPE reformats the cell and makes the changes on the screen.

[E] displays the current cell data in the text window and allows you to edit the cell much as you are used to doing in Atari BASIC.

[P] prints the sheet. Follow the prompts in defining a block to be printed. The information will be printed exactly as you see it on the screen. So check your column widths, etc. The printing is clone by rows. If you have an 80-column printer and select columns whose widths add to more than 80 there will be some wraparound. Therefore you might want to print left and right halves of your sheet.

It’s possible to send printer codes out by typing them into a cell. Since some of these codes might conflict with the way BC handles input you might need to type a space first and then the codes.

[O] toggles the recalculation on/off flag. Turn it off to type in data. Otherwise the whole sheet is recalculated every time you enter data, which takes some time to do.

[R] changes recalculation order from by rows to by columns or vice-versa.

[K] erases a cell from the sheet.

[CAPS] toggles between upper and lowercase letters. This key can be used in any input mode.

[A] recalculates the whole sheet immediately. Use CTRL-E and RETURN to recalculate a particular cell.

[ESC] aborts the delete, copy, move and print options.

Let’s discuss copy and move. Copy makes an exact duplicate of the block of cells you chose. Move does the same thing but cell references are changed. For example:

cell    contents
----    --------
AA01    12.35
AA02    4
AA03    =AA01+3

Cell AA03 has 15.35 as a result. Copying cells AA02 and AA03 to AM23 results in:

cell    contents
----    --------
AM22    32 (this cell existed before.
AM23    4
AM24    =AA01+3

The result in AM24 is 15.35 ( the same as before). If you move the same cells to AM23 the result is:

cell    contents
----    --------
AM22    32
AM23    4
AM24    =AM22+3

Here AM24 will contain 35. Notice how the cell reference was changed in cell AM24.

After a copy or move some cells will be overwritten. None of the source cells are deleted in either except those that are overwritten. Clean up any cells not wanted using the delete option (CTRL-D).

We’d suggest that before doing a copy or move you save the sheet. It’s just prudent practice. We have tried to crash this program in every way we can think of, but there is always the unknown. Maybe a circuit gets a little overheated and causes a crash. I even got SynCalc to crash once. Fortunately, I was just fooling around with it. The old adage “Better SAVE than sorry” applies here.

Built-in functions

The built-in functions are typed in this format: @CNT(AA03, BX24) or @SQR(23.45) or @SQR(BD23). Parentheses must be used and cells must be separated by a comma.

The following functions require one argument which could be a cell or a number:

function    operation
--------    ---------
SQU         squaring
SQR         square root
ABS         absolute value
RND         round value
EXP         exponentiation base 10
LOG         logarithm base 10
INT         greatest integer

These functions require two arguments and they must be cells.

function    operation
--------    ---------
CHT         count the number of cells in a block.
SUM         add the entries in a block,
AVE         find the average of all the entries in a block

CNT counts all the cells that have entries in a block whether they be text, numbers or functions. SUM however, adds up only the values in cells containing a numeric result. Text cells are treated as a zero. Empty cells result in the word “Error” displayed on the screen. AVE operates like SUM. However, AVE uses the CNT and SUM routines to get its value. So if you try to average cells containing RENT,400,500,600, the result will be (O(RENT) + 400 + 500 + 600)/4 = 375, an incorrect result.

Functions can be mixed in with any arithmetic expression as in:

=AA01+(4*@AVE(CD24,CE32)^@RND(AG12))-(2+@SQR(AA02))

However, functions are not nestable, i.e., you can not type =@ABS(@EXP(AA01)).

Error messages

We used standard error numbers wherever we could to keep the program as small as possible. The most common errors are:

2—out of memory. You have used all available memory. Save the sheet as it is.

138 or 139—Device does not respond or malfunctions. This probably will refer to the printer not being on.

141—cursor out of range. Used in copy, move, delete, print and list if the defined block is incorrect.

144—disk error, probably write protected.

160—drive number not known.

162—disk full.

165—bad filename. You must specify the “Dn:” in the filespec.

167—file locked.

170—file not found.

Wrap-up

There’s an easy way to duplicate a formula in a column or row: Use the move command. For example, cell AC02 might have the formula =SQU(AB02). If I would like that formula in cells AC03 to AC23, I would first move cell AC02 to AC03. Then move the block AC02, AC03 lo AC04. Next move AC02, AC04 to AC05, etc., until done. Then column AC has the squares of the numbers in column AB. In this manner special formulas—statistical, financial or others—can be built up. For example, one formula for standard deviation is:

Square root of (mean of X^2 - (mean of X)^ 2)

Assume that the column AB02, AB23 has some data in it:

    AA       AB                 AC
01          data
02           .                square of AB02
03           .                square of AB03
.            .
.            .
23           .                square of AB23
24        mean of X          mean of x*2
25        square of AB24      AC24-AB25
26        square root of AC25

First find the mean of AB02, AB23 by using =@AVE(AB02,AB23) and enter this in cell AB24. In cell AB25 enter =@SQU(AB24). In column AC02.AC23 enter the formula =@SQU(ABrr) where rr goes from 02 to 23. Or use the move procedure described above. In cell AC24 enter =@AVE(AC02,AC23). In cell AC25 type =AC24-AB25. Finally in cell AB26 enter =@SQR(AC25). Cell AB26 will contain the standard deviation.

Let’s see what that new car will cost when financed at different rates and different principals.

Let r = rate as a decimal, p = principal, t = years of loan and A = cost of loan. The formula for the cost of a loan (principal plus interest) is:

A = (p*r*t*12)/(1-(1+r/12)^-12*t)

This formula can be entered into one cell; p, r and t can be numbers or cell references. If you would like to calculate a monthly payment just use p*r as the numerator. If cells AA01, AB01, AC01 contained p,r and t respectively, then the above formula would look like this:

=(AA01*AB01*12*AC01)/(1-(1+AB01/12)^-12*AC01)

We tried to put in features that would make it very easy for you to use this spreadsheet. The built-in functions provide you with the building blocks for almost any formula. This program took over five months to develop and test. We hope you will find it useful.


Barry Kolbe and his wife Linda live in the country with their two children Philip and Audra. Beware, Phil just got his driver’s license and Audra can be found at the local shopping mall. The household uses timesharing since the 800 and Nintendo are hooked up to the same TV.
Bryan Schappel discovered computers, bought one, went to college, drank beer, got engaged, left school and is taking a leave of absence from reality.

LISTING 1: M/L EDITOR DATA

1000 DATA 255,255,64,37,113,54,112,112,80,66,0,32,144,2,2,2,8400
1010 DATA 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1282
1020 DATA 144,66,32,35,2,2,2,65,64,37,72,138,72,174,122,37,1276
1030 DATA 189,123,37,141,10,212,141,24,208,238,122,37,104,170,104,64,6995
1040 DATA 0,130,0,169,0,141,122,37,162,4,189,196,2,157,22,208,5783
1050 DATA 202,16,247,76,95,228,32,234,40,32,210,44,32,255,41,32,4899
1060 DATA 142,40,32,146,42,169,37,141,49,2,169,64,141,48,2,169,2900
1070 DATA 0,133,128,169,32,133,129,169,70,162,9,160,0,32,155,40,3291
1080 DATA 32,163,42,169,69,162,224,160,0,32,155,40,32,104,42,32,1924
1090 DATA 146,42,32,123,47,32,145,46,173,31,208,201,5,208,3,76,4523
1100 DATA 176,63,201,3,208,6,32,233,46,76,201,37,173,252,2,201,8033
1110 DATA 255,240,226,32,172,42,162,16,133,167,41,127,221,125,70,240,9380
1120 DATA 13,202,16,248,165,167,32,142,62,176,196,76,34,38,189,142,7231
1130 DATA 70,141,26,38,189,159,70,141,27,38,169,255,141,252,2,32,6674
1140 DATA 255,255,32,85,48,76,201,37,173,192,36,201,155,208,6,32,6554
1150 DATA 231,50,76,207,37,165,193,240,156,173,187,72,208,123,173,192,3131
1160 DATA 36,201,61,240,7,201,189,240,3,76,144,38,165,193,133,206,190
1170 DATA 32,156,46,32,231,54,144,4,169,130,208,2,169,2,133,194,6756
1180 DATA 165,206,133,193,24,105,192,133,252,169,36,105,0,133,253,162,9949
1190 DATA 0,32,171,221,165,193,24,105,6,133,193,170,169,155,157,192,983
1200 DATA 36,32,9,44,32,145,46,174,65,36,32,238,60,32,141,221,5279
1210 DATA 32,92,46,76,189,38,201,45,144,31,208,15,173,193,36,201,7589
1220 DATA 58,176,22,201,47,240,18,201,46,144,14,201,47,240,10,201,7666
1230 DATA 58,176,6,32,5,46,76,189,38,169,0,133,194,141,187,72,6212
1240 DATA 32,9,44,165,147,133,145,165,158,32,39,45,32,104,42,165,3803
1250 DATA 194,32,134,48,173,68,71,240,3,32,46,68,173,179,72,240,7136
1260 DATA 3,32,225,38,76,201,37,201,31,240,3,76,96,39,164,155,5965
1270 DATA 192,63,176,42,173,188,72,24,121,203,75,201,41,176,32,72,5958
1280 DATA 173,188,72,133,146,104,141,188,72,230,155,165,157,133,145,165,1773
1290 DATA 158,32,39,45,32,104,42,164,155,185,10,76,133,144,96,230,7331
1300 DATA 155,169,2,164,155,24,121,202,75,201,40,176,4,136,76,31,4666
1310 DATA 39,200,132,143,32,255,41,32,1,45,169,2,164,143,196,155,6846
1320 DATA 240,9,24,121,202,75,200,196,155,208,247,133,146,24,121,202,1631
1330 DATA 75,141,188,72,165,155,201,63,208,9,165,146,24,109,9,76,4923
1340 DATA 141,188,72,76,14,39,201,30,208,68,165,146,201,2,208,5,6288
1350 DATA 165,143,208,30,96,198,155,165,157,133,145,165,158,32,39,45,6743
1360 DATA 165,146,72,56,164,155,249,202,75,133,146,104,141,188,72,76,8986
1370 DATA 14,39,198,155,165,155,133,143,32,255,41,32,1,45,169,2,3389
1380 DATA 133,146,164,143,24,121,202,75,141,188,72,76,14,39,201,28,4773
1390 DATA 208,90,165,157,208,5,165,156,208,13,96,32,104,42,198,157,7238
1400 DATA 198,147,198,158,76,104,42,32,104,42,198,156,198,158,169,208,727
1410 DATA 133,134,169,34,133,135,169,248,133,128,169,34,133,129,162,16,8061
1420 DATA 32,111,40,56,233,40,133,134,165,135,233,0,133,135,202,16,7729
1430 DATA 239,162,39,169,0,157,80,32,202,16,250,133,145,169,2,133,7277
1440 DATA 192,165,156,32,39,45,32,171,40,76,104,42,201,29,240,1,4018
1450 DATA 96,165,156,24,101,157,201,63,144,1,96,165,157,201,17,176,8066
1460 DATA 12,32,104,42,230,157,230,147,230,158,76,104,42,32,104,42,5854
1470 DATA 230,156,230,158,169,120,133,134,169,32,133,135,169,80,133,128,9186
1480 DATA 169,32,133,129,162,16,32,111,40,24,105,40,133,134,165,135,5121
1490 DATA 105,0,133,135,202,16,239,169,0,162,39,157,248,34,202,16,7584
1500 DATA 250,169,2,133,192,169,17,133,145,24,101,156,32,39,45,32,2460
1510 DATA 171,40,76,104,42,160,39,177,134,145,128,136,16,249,165,135,9289
1520 DATA 133,129,165,134,133,128,96,134,175,169,12,157,66,3,32,86,4156
1530 DATA 228,166,175,96,32,171,40,76,151,40,32,255,41,32,210,44,5079
1540 DATA 96,133,133,134,132,177,132,201,155,240,5,145,128,200,208,245,4185
1550 DATA 96,160,0,132,145,165,156,133,190,230,190,165,190,162,0,201,2399
1560 DATA 10,144,6,56,233,10,232,208,246,72,138,72,164,145,185,180,1746
1570 DATA 69,133,128,185,198,69,133,129,104,9,144,160,0,145,128,104,6540
1580 DATA 200,9,144,145,128,230,190,230,145,165,145,201,18,208,204,96,2704
1590 DATA 216,169,80,141,180,69,133,128,169,32,141,198,69,133,129,160,9239
1600 DATA 1,165,128,24,105,40,133,128,153,180,69,165,129,105,0,133,6322
1610 DATA 129,153,198,69,200,192,18,208,232,169,100,141,0,2,169,37,6582
1620 DATA 141,1,2,169,2,141,200,2,169,0,141,198,2,169,10,141,4963
1630 DATA 197,2,169,6,162,37,160,125,32,92,228,169,192,141,14,212,9330
1640 DATA 160,63,169,8,153,202,75,169,32,153,10,76,136,16,243,133,6924
1650 DATA 144,169,0,141,201,75,162,209,149,0,202,48,251,133,147,141,682
1660 DATA 69,71,141,68,71,169,2,133,146,24,109,202,75,141,188,72,7111
1670 DATA 165,121,5,122,240,10,165,121,141,189,42,165,122,141,190,42,8646
1680 DATA 169,127,168,170,138,153,201,74,73,128,153,73,75,202,136,48,8001
1690 DATA 16,192,95,208,4,162,63,208,235,192,31,208,231,162,95,208,3200
1700 DATA 227,169,202,133,128,169,76,133,129,160,0,165,128,153,74,76,7526
1710 DATA 165,129,200,153,74,76,165,128,24,105,1,133,128,165,129,105,6812
1720 DATA 0,133,129,200,192,128,208,227,160,63,169,255,153,202,76,136,3295
1730 DATA 16,250,169,10,141,189,72,169,77,141,190,72,169,87,133,128,9003
1740 DATA 141,193,72,169,73,133,129,141,251,72,160,1,165,128,24,105,7081
1750 DATA 6,133,128,153,193,72,165,129,105,0,133,129,153,251,72,200,341
1760 DATA 192,57,208,232,96,169,40,133,128,169,32,133,129,160,39,169,8452
1770 DATA 128,145,128,136,16,249,169,2,133,138,165,143,133,139,164,139,356
1780 DATA 192,64,240,22,185,202,75,72,74,24,101,138,133,141,198,141,8748
1790 DATA 104,24,101,138,133,140,201,41,144,1,96,169,33,133,142,165,7488
1800 DATA 139,201,26,144,14,230,142,56,233,26,201,26,144,5,230,142,8431
1810 DATA 56,233,26,72,164,141,165,142,73,128,145,128,104,24,105,33,5514
1820 DATA 73,128,200,145,128,230,139,165,140,133,138,76,24,42,32,133,6170
1830 DATA 42,172,188,72,136,177,128,73,128,145,128,136,196,146,16,245,684
1840 DATA 164,155,185,10,76,133,144,32,7,64,96,164,147,185,180,69,7383
1850 DATA 133,128,185,198,69,133,129,96,160,0,152,153,32,35,200,192,8326
1860 DATA 160,208,248,169,128,141,34,35,96,32,172,42,162,255,142,252,1278
1870 DATA 2,96,173,252,2,201,255,240,249,133,184,168,192,192,144,2,3499
1880 DATA 160,154,185,254,254,133,185,201,130,208,15,173,190,2,73,64,8998
1890 DATA 141,190,2,169,255,141,252,2,208,216,201,129,208,11,173,182,3150
1900 DATA 2,73,128,141,182,2,76,205,42,201,131,240,222,201,132,240,4319
1910 DATA 193,201,133,240,189,165,184,201,64,176,20,165,185,201,97,144,2209
1920 DATA 14,201,123,176,10,173,190,2,240,5,5,184,76,181,42,165,7108
1930 DATA 185,162,15,221,176,70,240,6,202,16,248,77,182,2,96,160,8420
1940 DATA 1,208,6,160,2,208,2,160,3,185,216,69,133,128,185,220,464
1950 DATA 69,133,129,160,1,96,160,2,32,140,52,76,184,46,173,189,6856
1960 DATA 72,141,151,43,24,101,154,141,154,43,173,190,72,141,152,43,7748
1970 DATA 105,0,141,155,43,197,106,176,221,173,189,72,56,229,130,133,1339
1980 DATA 152,173,190,72,229,131,133,153,173,189,72,24,101,154,141,189,557
1990 DATA 72,173,190,72,105,0,141,190,72,32,150,43,144,1,96,206,6054
2000 DATA 151,43,173,151,43,201,255,208,3,206,152,43,206,154,43,173,752
2010 DATA 154,43,201,255,208,3,206,155,43,76,115,43,173,255,255,141,2441
2020 DATA 255,255,198,152,165,152,201,255,208,10,198,153,165,153,201,255,6539
2030 DATA 208,2,56,96,24,96,165,130,141,154,43,24,101,154,141,151,7255
2040 DATA 43,165,131,141,155,43,105,0,141,152,43,173,189,72,56,237,8573
2050 DATA 151,43,133,152,173,190,72,237,152,43,133,153,173,189,72,56,9667
2060 DATA 229,154,141,189,72,173,190,72,233,0,141,190,72,32,150,43,7330
2070 DATA 144,1,96,238,151,43,208,3,238,152,43,238,154,43,208,3,8712
2080 DATA 238,155,43,76,231,43,134,175,170,189,201,74,166,175,96,165,2019
2090 DATA 155,133,150,165,156,24,101,157,133,151,10,168,185,74,76,133,8050
2100 DATA 130,200,185,74,76,133,131,160,0,177,130,16,93,165,193,24,7046
2110 DATA 105,4,133,154,32,56,43,160,0,165,150,145,130,165,144,160,9075
2120 DATA 1,145,130,200,165,193,145,130,200,169,0,5,194,145,130,32,8203
2130 DATA 249,59,160,0,185,192,36,145,130,200,196,193,208,246,165,193,5819
2140 DATA 24,105,4,133,154,165,151,32,101,44,96,10,168,200,200,76,7716
2150 DATA 127,44,185,74,76,24,101,154,153,74,76,200,185,74,76,105,7293
2160 DATA 0,153,74,76,200,192,128,208,233,96,197,150,208,6,165,151,2407
2170 DATA 32,165,44,56,176,151,160,2,177,130,24,101,130,133,130,165,8321
2180 DATA 131,105,0,133,131,32,249,59,76,33,44,72,160,2,177,130,5320
2190 DATA 24,105,4,133,154,32,176,43,104,10,168,200,200,76,205,44,8233
2200 DATA 185,74,76,56,229,154,153,74,76,200,185,74,76,233,0,153,9022
2210 DATA 74,76,200,192,128,208,233,96,162,17,32,219,44,202,16,250,339
2220 DATA 96,189,180,69,133,128,189,198,69,133,129,169,0,160,2,145,7838
2230 DATA 128,200,192,40,208,249,96,164,143,24,121,202,75,201,40,176,499
2240 DATA 3,200,208,245,132,140,96,169,0,133,145,165,156,133,139,165,1291
2250 DATA 139,32,39,45,230,139,230,145,165,145,201,18,208,241,96,10,544
2260 DATA 168,185,74,76,133,130,200,185,74,76,133,131,96,72,165,143,9129
2270 DATA 133,138,169,2,133,192,32,241,44,166,145,32,219,44,104,32,6733
2280 DATA 25,45,160,0,177,130,201,255,240,24,197,138,240,27,144,19,172
2290 DATA 164,138,185,202,75,24,101,192,133,192,230,138,165,138,197,140,3430
2300 DATA 144,224,96,32,242,59,76,60,45,165,130,24,105,4,133,132,5185
2310 DATA 165,131,105,0,133,133,164,145,185,180,69,133,134,185,198,69,1049
2320 DATA 133,135,165,192,133,141,160,1,177,130,133,144,160,3,177,130,9566
2330 DATA 16,3,76,33,46,41,3,240,23,201,1,240,91,160,2,177,6522
2340 DATA 130,56,233,6,24,101,132,170,165,133,105,0,168,76,246,45,7943
2350 DATA 32,145,46,160,2,177,130,168,169,155,153,192,36,136,177,132,973
2360 DATA 153,192,36,136,16,248,169,192,133,132,169,36,133,133,32,25,7115
2370 DATA 54,164,138,185,202,75,133,149,160,0,132,142,164,142,185,128,1028
2380 DATA 5,32,0,44,164,141,145,134,230,142,230,141,165,142,197,149,3562
2390 DATA 208,234,32,145,46,76,74,45,166,132,164,133,32,137,221,32,7681
2400 DATA 79,46,32,230,216,32,201,52,76,203,45,169,1,133,194,32,7216
2410 DATA 66,46,32,68,218,32,0,216,162,192,160,36,32,167,221,169,289
2420 DATA 6,133,193,32,9,44,96,162,0,169,5,133,149,164,138,185,8280
2430 DATA 202,75,201,4,208,2,198,149,164,141,189,215,70,145,134,200,2726
2440 DATA 232,228,149,208,245,76,74,45,169,36,133,244,169,192,133,243,4006
2450 DATA 169,0,133,242,96,169,5,133,244,169,128,133,243,169,0,133,1122
2460 DATA 242,96,32,79,46,32,230,216,160,0,177,243,48,6,153,192,9444
2470 DATA 36,200,208,246,41,127,153,192,36,200,132,193,192,1,240,22,642
2480 DATA 173,192,36,201,48,208,15,160,0,185,193,36,153,192,36,200,9644
2490 DATA 196,193,208,245,198,193,96,162,127,169,32,157,192,36,202,16,147
2500 DATA 250,96,160,0,185,192,36,201,155,240,18,41,127,201,123,176,970
2510 DATA 6,201,97,144,2,73,32,153,192,36,200,208,231,96,32,210,652
2520 DATA 44,32,205,46,32,255,41,32,171,40,32,1,45,32,85,48,1039
2530 DATA 76,104,42,169,0,133,143,133,156,133,158,133,155,133,157,133,907
2540 DATA 147,169,2,133,146,164,143,24,121,202,75,141,188,72,96,32,7500
2550 DATA 146,42,160,26,185,246,70,153,34,35,136,16,247,160,32,185,8714
2560 DATA 17,71,153,74,35,136,16,247,169,0,56,237,189,72,133,212,386
2570 DATA 165,106,237,190,72,133,213,32,170,217,32,230,216,160,0,177,2015
2580 DATA 243,72,41,127,32,0,44,153,61,35,200,104,16,241,160,0,5619
2590 DATA 185,199,70,201,155,240,11,32,0,44,153,39,35,200,192,16,5717
2600 DATA 208,238,32,129,62,76,146,42,32,50,50,32,115,50,176,48,3345
2610 DATA 32,54,61,176,43,32,115,50,162,0,185,192,35,157,192,35,7139
2620 DATA 201,155,240,4,200,232,208,242,162,3,189,192,35,32,0,44,7129
2630 DATA 157,197,74,202,16,244,165,150,141,178,72,165,151,141,177,72,1675
2640 DATA 96,32,121,48,162,1,189,199,74,157,173,35,189,197,74,157,482
2650 DATA 153,35,202,16,241,165,156,24,101,157,32,25,45,160,0,177,5810
2660 DATA 130,201,255,240,7,205,178,72,240,11,144,3,76,242,47,32,7487
2670 DATA 242,59,76,151,47,160,3,177,130,41,3,240,31,201,1,208,7547
2680 DATA 235,32,111,48,32,230,216,160,0,177,243,72,41,127,32,0,5934
2690 DATA 44,153,156,35,104,48,33,200,192,14,208,237,160,2,177,130,130
2700 DATA 133,176,32,249,59,160,0,177,130,32,0,44,153,156,35,200,6864
2710 DATA 196,176,240,4,192,14,208,239,173,177,72,32,25,45,165,155,8819
2720 DATA 133,138,160,0,177,130,201,255,240,6,197,138,240,9,144,1,186
2730 DATA 96,32,242,59,76,252,47,160,3,177,130,41,3,240,31,201,8152
2740 DATA 1,208,237,32,111,48,32,230,216,160,0,177,243,72,41,127,9385
2750 DATA 32,0,44,153,176,35,104,48,33,200,192,14,208,237,160,2,8759
2760 DATA 177,130,133,176,32,249,59,160,0,177,130,32,0,44,153,176,6958
2770 DATA 35,200,196,176,240,4,192,14,208,239,96,166,155,165,158,32,1694
2780 DATA 151,69,144,6,169,3,133,194,208,34,160,3,177,130,41,3,5663
2790 DATA 133,194,76,134,48,32,249,59,166,130,164,131,76,137,221,160,1673
2800 DATA 119,169,0,153,32,35,200,192,160,208,248,96,165,194,10,10,9746
2810 DATA 10,170,160,31,189,74,71,153,0,32,232,200,192,39,208,244,2212
2820 DATA 96,32,210,44,169,49,141,193,70,32,50,50,32,115,50,176,5148
2830 DATA 3,141,193,70,162,32,32,129,40,169,1,133,145,169,3,162,6777
2840 DATA 32,157,66,3,169,192,157,68,3,169,70,157,69,3,169,6,4977
2850 DATA 157,74,3,169,0,157,75,3,32,86,228,16,6,32,140,52,2637
2860 DATA 76,196,46,162,32,169,5,157,66,3,169,128,157,68,3,169,6340
2870 DATA 5,157,69,3,169,0,157,73,3,169,20,157,72,3,32,86,2591
2880 DATA 228,16,11,32,129,62,162,32,32,129,40,76,196,46,32,52,3142
2890 DATA 49,162,0,160,11,189,128,5,201,155,240,10,32,0,44,145,5543
2900 DATA 128,200,232,76,15,49,230,145,165,145,201,17,208,181,32,129,699
2910 DATA 62,32,210,44,169,0,133,145,240,169,164,145,185,180,69,133,2260
2920 DATA 128,185,198,69,133,129,96,32,50,50,32,115,50,32,156,50,3575
2930 DATA 32,119,54,144,5,160,165,76,215,48,32,160,54,144,3,76,5352
2940 DATA 184,46,169,8,160,11,208,18,32,50,50,32,115,50,32,156,3114
2950 DATA 50,32,119,54,176,223,169,4,160,7,133,173,132,174,162,32,9213
2960 DATA 32,129,40,162,32,165,173,157,74,3,169,3,157,66,3,169,5940
2970 DATA 199,157,68,3,169,70,157,69,3,169,0,157,75,3,32,86,3089
2980 DATA 228,16,3,76,215,48,162,32,165,174,168,157,66,3,169,202,9930
2990 DATA 157,68,3,169,75,157,69,3,192,7,208,10,169,255,157,72,9272
3000 DATA 3,157,73,3,208,17,173,189,72,56,233,202,157,72,3,173,9470
3010 DATA 190,72,233,75,157,73,3,32,86,228,16,7,192,136,240,3,7205
3020 DATA 76,215,48,162,32,32,129,40,165,173,201,8,240,19,162,32,7743
3030 DATA 169,202,24,125,72,3,141,189,72,169,75,125,73,3,141,190,7861
3040 DATA 72,76,184,46,32,50,50,32,115,50,176,43,32,54,61,176,3956
3050 DATA 38,165,151,201,47,176,32,165,150,201,55,176,26,32,104,42,6605
3060 DATA 32,210,44,165,150,133,143,133,155,165,151,133,156,133,158,169,3183
3070 DATA 0,32,215,46,76,190,46,96,160,114,185,192,36,153,192,35,9542
3080 DATA 136,16,247,96,32,46,68,76,184,46,169,1,141,187,72,96,6947
3090 DATA 165,155,170,165,156,24,101,157,133,138,32,151,69,144,1,96,6827
3100 DATA 165,138,32,165,44,32,104,42,169,2,133,192,165,157,133,145,9739
3110 DATA 165,158,32,39,45,32,104,42,96,160,0,185,192,35,201,155,8489
3120 DATA 240,9,201,32,240,7,200,192,32,208,240,56,96,200,185,192,3862
3130 DATA 35,201,155,240,246,201,32,208,7,200,192,32,208,240,240,235,7299
3140 DATA 24,96,162,0,185,192,35,157,199,70,201,155,240,4,200,232,3870
3150 DATA 208,242,96,32,50,50,32,115,50,176,49,32,54,61,176,44,3985
3160 DATA 230,151,165,151,201,2,144,36,201,33,176,32,164,150,153,202,1322
3170 DATA 75,32,210,44,32,255,41,32,1,45,164,143,132,155,169,2,6780
3180 DATA 133,146,24,121,202,75,141,188,72,32,104,42,96,166,155,165,9265
3190 DATA 158,32,151,69,144,1,96,160,1,177,130,133,0,200,177,130,9159
3200 DATA 133,154,200,177,130,41,3,208,22,32,249,59,164,154,136,177,655
3210 DATA 130,153,192,36,136,16,248,169,255,133,148,32,48,62,96,201,15
3220 DATA 2,240,29,32,249,59,166,130,164,131,32,137,221,32,230,216,2727
3230 DATA 160,0,177,243,72,41,127,153,192,36,104,48,218,200,208,242,4046
3240 DATA 165,154,56,233,6,133,154,76,3,51,169,1,133,191,32,231,8314
3250 DATA 50,32,145,62,8,169,0,133,191,40,144,1,96,104,104,165,6784
3260 DATA 0,133,144,76,34,38,32,146,42,164,155,185,10,76,133,144,7488
3270 DATA 162,18,202,48,31,189,64,72,157,34,35,224,5,144,243,189,155
3280 DATA 77,72,157,74,35,189,90,72,157,114,35,189,103,72,157,154,9155
3290 DATA 35,76,108,51,76,243,51,173,252,2,201,255,240,249,162,255,8259
3300 DATA 142,252,2,201,28,208,1,96,162,2,221,136,72,240,5,202,63
3310 DATA 16,248,48,14,165,144,41,252,133,176,138,5,176,133,144,76,75
3320 DATA 243,51,201,58,208,9,165,144,73,8,133,144,76,243,51,201,200
3330 DATA 32,208,9,165,144,73,4,133,144,76,243,51,162,9,221,165,243
3340 DATA 72,240,5,202,16,248,48,175,138,72,165,144,41,15,133,144,8566
3350 DATA 104,10,10,10,10,5,144,133,144,165,144,41,3,170,189,123,7940
3360 DATA 72,141,51,35,165,144,41,8,74,74,74,170,189,121,72,141,7794
3370 DATA 91,35,165,144,41,4,74,74,170,189,121,72,141,131,35,165,8388
3380 DATA 144,41,240,74,74,74,74,170,189,126,72,141,171,35,76,145,8932
3390 DATA 51,32,96,51,164,155,165,144,153,10,76,96,165,158,166,155,846
3400 DATA 32,151,69,144,1,96,32,96,51,160,1,165,144,145,130,166,8648
3410 DATA 157,134,145,165,158,32,39,45,164,155,185,10,76,133,144,76,7952
3420 DATA 104,42,173,68,71,73,3,141,68,71,170,160,0,189,50,71,5985
3430 DATA 153,24,71,232,200,192,3,208,244,96,173,69,71,73,6,141,8787
3440 DATA 69,71,170,160,0,189,56,71,153,44,71,232,200,192,6,208,983
3450 DATA 244,96,132,177,162,32,32,129,40,164,177,132,212,169,0,133,29
3460 DATA 213,32,170,217,32,230,216,160,255,200,177,243,72,41,127,32,2532
3470 DATA 0,44,153,231,70,104,16,241,32,121,48,160,20,185,225,70,9246
3480 DATA 153,156,35,136,16,247,169,255,141,252,2,32,106,62,96,160,9820
3490 DATA 255,200,177,243,153,0,5,16,248,160,127,169,48,153,192,36,55
3500 DATA 136,16,250,169,36,141,192,36,169,193,133,132,169,36,133,133,1074
3510 DATA 165,144,72,41,240,74,74,74,74,141,176,72,104,41,4,208,7287
3520 DATA 12,160,255,200,177,243,145,132,16,249,76,99,53,160,255,200,4443
3530 DATA 185,0,5,48,5,201,46,208,246,136,132,179,162,29,169,2,9392
3540 DATA 141,175,72,185,0,5,41,127,157,128,5,202,136,48,13,206,7423
3550 DATA 175,72,16,239,169,44,157,128,5,202,16,226,232,160,1,189,1353
3560 DATA 128,5,153,192,36,200,232,224,30,208,244,166,179,189,0,5,1800
3570 DATA 16,11,136,185,192,36,9,128,153,192,36,208,12,232,189,0,9447
3580 DATA 5,153,192,36,48,3,200,208,244,165,144,41,8,240,8,169,143
3590 DATA 192,133,132,169,36,133,133,169,0,141,113,54,160,255,200,185,3292
3600 DATA 192,36,48,46,201,69,208,246,238,113,54,136,185,192,36,9,310
3610 DATA 128,153,192,36,162,255,232,200,185,192,36,72,41,127,157,114,1663
3620 DATA 54,169,48,153,192,36,104,16,237,232,142,113,54,169,155,157,2076
3630 DATA 114,54,160,255,200,185,192,36,16,16,41,127,153,192,36,200,9790
3640 DATA 169,46,153,192,36,132,179,76,213,53,201,46,208,230,132,179,3939
3650 DATA 200,185,192,36,16,250,41,127,153,192,36,165,179,24,109,176,610
3660 DATA 72,168,173,176,72,208,1,136,169,155,153,193,36,173,113,54,513
3670 DATA 240,16,162,0,189,114,54,153,193,36,201,155,240,4,232,200,3683
3680 DATA 208,242,173,193,36,201,45,208,22,173,194,36,201,44,208,15,111
3690 DATA 160,0,185,195,36,153,194,36,201,155,240,3,200,208,243,160,5681
3700 DATA 255,200,177,132,201,155,208,249,132,179,162,127,169,32,157,128,4129
3710 DATA 5,202,16,250,165,144,41,3,170,240,36,202,208,14,164,138,1485
3720 DATA 185,202,75,56,229,179,16,22,162,0,240,21,164,138,185,202,1686
3730 DATA 75,56,229,179,16,7,73,255,74,168,76,66,54,74,170,160,8815
3740 DATA 255,200,177,132,201,155,240,6,157,128,5,232,208,243,169,128,5338
3750 DATA 133,132,169,5,133,133,96,0,118,54,249,61,155,173,199,70,424
3760 DATA 201,68,208,23,173,200,70,201,58,240,14,201,56,240,14,201,1978
3770 DATA 49,144,8,201,52,176,4,144,4,24,96,56,96,173,201,70,7240
3780 DATA 201,58,240,245,208,245,169,0,141,34,35,162,32,32,129,40,6867
3790 DATA 169,36,157,66,3,169,70,157,69,3,169,199,157,68,3,32,5989
3800 DATA 86,228,189,67,3,72,162,32,32,129,40,104,201,1,240,2,6539
3810 DATA 24,96,169,72,162,139,160,1,32,48,69,173,252,2,162,255,1010
3820 DATA 201,43,240,236,201,35,208,243,142,252,2,56,96,169,0,133,620
3830 DATA 180,32,68,218,162,0,134,193,189,192,36,157,192,35,201,155,2824
3840 DATA 240,3,232,208,243,134,193,162,1,189,192,35,201,64,240,8,1948
3850 DATA 232,228,193,208,244,76,101,58,134,138,169,56,133,131,169,86,1387
3860 DATA 133,130,232,134,139,160,0,177,130,240,234,48,18,221,192,35,2044
3870 DATA 208,4,232,200,208,241,169,4,32,251,59,166,139,208,230,41,3547
3880 DATA 127,221,192,35,208,240,160,3,177,130,133,176,232,134,139,10,2394
3890 DATA 170,189,127,56,141,246,55,189,128,56,141,247,55,169,0,133,557
3900 DATA 178,164,139,185,192,35,201,40,240,2,56,96,200,185,192,35,1038
3910 DATA 201,68,176,246,201,65,176,35,132,242,132,139,32,241,61,32,611
3920 DATA 0,216,176,230,32,254,55,176,225,164,242,185,192,35,201,41,4481
3930 DATA 208,3,76,206,55,201,44,240,211,208,207,132,139,32,54,61,786
3940 DATA 176,200,164,178,165,150,153,159,0,165,151,153,163,0,165,176,2345
3950 DATA 201,7,240,9,166,150,165,151,32,22,56,176,227,164,178,169,2871
3960 DATA 128,153,198,0,32,254,55,176,215,165,139,24,105,4,133,139,9507
3970 DATA 168,76,133,55,200,132,140,164,138,166,140,32,206,61,162,0,9781
3980 DATA 189,192,35,201,155,240,3,232,208,246,134,193,32,221,61,164,4725
3990 DATA 138,169,35,153,192,35,165,195,153,193,35,32,255,255,144,1,2205
4000 DATA 96,76,1,55,165,180,164,178,153,195,0,230,178,200,192,3,3077
4010 DATA 176,8,170,32,199,61,230,180,24,96,56,96,134,150,32,25,6917
4020 DATA 45,160,0,177,130,201,255,240,6,197,150,240,11,144,2,56,293
4030 DATA 96,32,242,59,76,27,56,96,160,3,177,130,41,3,240,26,6422
4040 DATA 201,1,240,10,160,2,177,130,56,233,6,32,251,59,169,4,8066
4050 DATA 32,251,59,166,130,164,131,32,137,221,24,96,83,81,213,0,8499
4060 DATA 65,66,211,1,83,81,210,2,82,78,196,3,69,88,208,4,6304
4070 DATA 76,79,199,5,73,78,212,6,67,78,212,7,83,85,205,8,6557
4080 DATA 65,86,197,9,0,245,56,147,56,207,56,14,57,166,57,175,8060
4090 DATA 57,163,56,45,57,61,57,132,57,32,248,57,165,212,41,127,8932
4100 DATA 133,212,166,195,32,199,61,24,96,169,0,141,250,61,32,248,706
4110 DATA 57,32,79,46,32,230,216,32,45,58,165,212,72,32,0,216,8144
4120 DATA 104,16,15,173,250,61,240,10,162,179,160,74,32,152,221,32,636
4130 DATA 96,218,76,156,56,32,248,57,162,36,160,62,32,167,221,32,9081
4140 DATA 209,222,162,185,160,74,32,152,221,32,40,219,144,1,96,32,7918
4150 DATA 204,221,176,6,32,251,61,76,204,56,96,32,248,57,32,209,9731
4160 DATA 222,162,185,160,74,32,152,221,32,219,218,144,1,96,32,204,1000
4170 DATA 221,144,228,96,32,248,57,162,191,160,74,32,152,221,32,102,789
4180 DATA 218,144,1,96,32,230,216,32,45,58,32,79,46,32,0,216,5168
4190 DATA 76,156,56,32,4,58,32,11,58,32,22,58,32,184,57,76,2397
4200 DATA 156,56,96,32,4,58,32,11,58,32,22,58,32,79,57,176,2537
4210 DATA 3,76,156,56,96,32,35,58,32,68,218,165,167,133,169,32,8864
4220 DATA 182,221,166,169,165,171,32,22,56,176,7,240,7,32,102,218,9047
4230 DATA 144,2,56,96,230,169,165,169,197,168,240,227,144,225,230,171,9626
4240 DATA 165,171,197,172,240,213,144,211,24,96,32,4,58,32,11,58,5071
4250 DATA 32,22,58,32,184,57,176,19,32,73,58,32,79,57,176,11,3955
4260 DATA 32,87,58,32,40,219,176,3,76,156,56,96,32,248,57,32,6805
4270 DATA 204,221,144,244,96,32,248,57,32,209,222,144,245,96,32,35,1305
4280 DATA 58,169,0,133,173,133,174,165,167,133,169,166,169,165,171,32,3677
4290 DATA 22,56,176,6,230,173,208,2,230,174,230,169,165,169,197,168,7158
4300 DATA 240,233,144,231,230,171,165,171,197,172,240,219,144,217,32,68,6300
4310 DATA 218,165,173,133,212,165,174,133,213,32,170,217,24,96,165,178,3931
4320 DATA 240,4,201,1,240,3,104,104,56,96,165,178,201,2,208,246,3065
4330 DATA 96,160,1,185,198,0,16,238,136,16,248,96,165,164,197,163,3763
4340 DATA 144,228,165,160,197,159,144,222,96,162,7,181,159,149,167,202,5421
4350 DATA 16,249,96,160,0,177,243,48,15,201,46,240,3,200,208,245,4349
4360 DATA 141,250,61,169,155,145,243,96,41,127,145,243,200,208,244,166,7952
4370 DATA 180,189,251,72,168,189,193,72,170,32,167,221,96,166,180,189,5505
4380 DATA 251,72,168,189,193,72,170,32,152,221,96,160,1,185,192,35,1475
4390 DATA 201,68,176,4,201,65,176,8,200,196,193,208,240,76,254,58,5263
4400 DATA 132,138,152,24,105,4,133,140,32,54,61,176,19,165,151,32,6905
4410 DATA 25,45,160,0,177,130,201,255,240,6,197,150,240,9,144,1,1726
4420 DATA 96,32,242,59,76,140,58,160,3,177,130,41,3,240,241,201,2397
4430 DATA 1,240,10,160,2,177,130,56,233,6,32,251,59,169,4,32,7237
4440 DATA 251,59,166,130,164,131,32,137,221,169,4,133,139,32,207,58,360
4450 DATA 164,138,76,114,58,164,138,166,140,32,206,61,165,193,56,229,3071
4460 DATA 139,133,193,32,221,61,164,138,169,35,153,192,35,165,180,200,3818
4470 DATA 153,192,35,132,138,170,189,251,72,168,189,193,72,170,32,167,3872
4480 DATA 221,230,180,96,160,1,185,192,35,201,155,240,53,201,40,240,4575
4490 DATA 13,201,41,240,9,201,35,208,9,200,200,76,60,59,200,76,163
4500 DATA 0,59,132,242,132,138,32,241,61,32,0,216,176,41,166,242,2307
4510 DATA 138,133,140,56,229,138,133,139,32,207,58,164,138,200,196,193,5160
4520 DATA 240,27,185,192,35,201,155,240,20,162,4,221,82,73,240,9,851
4530 DATA 202,16,248,201,41,240,230,56,96,200,76,0,59,160,0,185,9682
4540 DATA 192,35,201,155,240,7,201,40,240,44,200,208,242,160,0,185,4636
4550 DATA 192,35,201,155,240,9,201,41,240,42,200,208,242,240,37,162,5953
4560 DATA 0,189,193,35,157,64,36,201,155,240,5,232,200,76,123,59,1773
4570 DATA 32,7,60,176,15,96,200,185,192,35,201,41,240,8,201,155,2539
4580 DATA 240,2,208,242,56,96,132,208,136,185,192,35,201,40,208,248,5727
4590 DATA 132,207,162,255,164,207,232,200,196,208,240,9,185,192,35,157,6650
4600 DATA 64,36,76,176,59,169,155,157,64,36,32,7,60,176,213,165,9769
4610 DATA 208,56,229,207,201,1,240,204,166,207,173,64,36,157,192,35,3109
4620 DATA 173,65,36,232,157,192,35,164,208,232,200,185,192,35,157,192,6478
4630 DATA 35,201,155,208,244,76,87,59,160,2,177,130,32,251,59,169,1607
4640 DATA 4,24,101,130,133,130,165,131,105,0,133,131,96,160,0,132,8743
4650 DATA 142,32,164,60,201,155,240,35,144,1,96,32,221,60,165,183,1345
4660 DATA 201,94,208,14,32,19,61,176,241,32,249,60,32,197,61,76,9091
4670 DATA 7,60,165,142,24,105,3,168,76,9,60,160,0,132,142,32,5819
4680 DATA 164,60,201,155,240,48,144,1,96,32,221,60,165,183,201,42,1420
4690 DATA 208,7,32,219,218,176,241,144,9,201,47,208,16,32,40,219,733
4700 DATA 176,230,32,249,60,32,197,61,164,142,76,55,60,165,142,24,8783
4710 DATA 105,3,168,76,55,60,160,0,132,142,32,164,60,201,155,240,2071
4720 DATA 39,144,1,96,32,221,60,165,183,201,43,208,7,32,102,218,843
4730 DATA 176,241,144,9,201,45,208,235,32,96,218,176,230,32,249,60,4358
4740 DATA 32,197,61,164,142,76,114,60,24,96,185,64,36,201,35,240,75
4750 DATA 6,201,155,240,44,56,96,200,185,64,36,201,155,240,246,133,5717
4760 DATA 181,200,185,64,36,133,183,201,155,240,22,200,185,64,36,201,3513
4770 DATA 155,240,14,201,35,208,222,200,185,64,36,201,155,240,214,133,6654
4780 DATA 182,24,96,166,181,32,238,60,32,141,221,166,182,32,238,60,2670
4790 DATA 32,156,221,96,189,193,72,133,252,189,251,72,133,253,96,165,6986
4800 DATA 142,24,105,2,168,24,105,3,170,189,64,36,153,64,36,201,8253
4810 DATA 155,240,5,200,232,76,3,61,96,166,181,32,238,60,32,141,9954
4820 DATA 221,32,209,222,144,2,56,96,166,182,32,238,60,32,156,221,2138
4830 DATA 32,219,218,176,241,32,204,221,176,236,24,96,32,123,61,176,2480
4840 DATA 5,32,79,61,144,1,96,164,205,200,32,123,61,176,247,32,1247
4850 DATA 148,61,164,205,96,165,203,162,2,221,56,73,240,5,202,16,815
4860 DATA 248,48,15,189,59,73,133,141,165,204,201,91,176,4,201,65,2024
4870 DATA 176,2,56,96,56,233,65,24,101,141,133,150,201,64,176,242,3530
4880 DATA 96,185,192,35,201,155,240,16,133,203,200,185,192,35,201,155,5933
4890 DATA 240,6,133,204,132,205,24,96,56,96,165,203,32,180,61,176,1565
4900 DATA 23,133,151,165,204,32,180,61,176,14,138,24,101,151,170,202,2001
4910 DATA 224,64,176,4,134,151,24,96,56,96,162,9,221,62,73,240,348
4920 DATA 5,202,16,248,56,96,189,72,73,24,96,166,181,32,238,60,400
4930 DATA 32,171,221,96,189,192,35,153,192,35,201,155,240,4,200,232,5954
4940 DATA 208,242,96,166,193,189,192,35,157,194,35,202,228,138,240,245,8885
4950 DATA 176,243,230,193,230,193,96,169,35,133,244,169,192,133,243,96,7302
4960 DATA 251,61,35,62,32,182,221,162,42,160,62,32,167,221,162,36,1096
4970 DATA 160,62,32,137,221,32,40,219,162,42,160,62,32,152,221,32,9980
4980 DATA 102,218,162,191,160,74,32,152,221,32,219,218,96,48,62,179,2500
4990 DATA 69,169,0,133,139,168,170,134,140,166,139,189,216,69,24,105,2425
5000 DATA 2,133,128,189,220,69,105,0,133,129,166,140,189,192,36,32,847
5010 DATA 0,44,228,148,208,2,73,128,145,128,232,200,192,38,208,236,6422
5020 DATA 160,0,230,139,165,139,201,3,208,205,96,173,31,208,201,6,2996
5030 DATA 208,16,104,104,169,155,141,192,36,169,0,133,191,141,201,75,2578
5040 DATA 56,96,173,252,2,201,255,240,226,32,163,42,166,148,96,32,2569
5050 DATA 145,46,169,0,133,148,32,48,62,32,106,62,166,148,164,191,489
5060 DATA 208,30,172,201,75,208,25,160,4,217,180,72,240,5,136,16,262
5070 DATA 248,48,20,141,179,72,201,155,208,70,140,179,72,76,255,62,3089
5080 DATA 201,155,208,3,76,255,62,201,27,208,10,32,106,62,201,155,737
5090 DATA 240,46,76,222,62,160,12,217,76,70,240,18,136,16,248,157,2092
5100 DATA 192,36,232,134,148,224,114,144,173,202,134,148,208,168,185,50,6088
5110 DATA 70,141,250,62,185,63,70,141,251,62,32,255,255,76,149,62,3278
5120 DATA 160,114,136,185,192,36,201,32,240,248,169,155,200,153,192,36,6052
5130 DATA 132,193,169,0,133,191,24,96,32,145,46,169,0,133,148,96,8792
5140 DATA 166,148,240,8,202,169,32,157,192,36,134,148,96,166,148,240,4828
5150 DATA 251,202,134,148,96,166,148,224,113,176,241,232,134,148,96,166,7225
5160 DATA 148,189,193,36,157,192,36,232,224,122,208,245,96,162,122,189,7288
5170 DATA 192,36,157,193,36,202,228,148,16,245,232,169,32,157,192,36,4093
5180 DATA 141,50,37,96,165,148,56,233,38,16,3,24,105,114,133,148,8032
5190 DATA 96,165,148,24,105,38,201,114,144,244,56,233,114,76,109,63,1565
5200 DATA 162,0,165,148,201,38,144,8,162,38,201,76,144,2,162,76,9261
5210 DATA 134,148,96,32,127,63,169,37,133,141,32,76,63,198,141,16,8381
5220 DATA 249,96,32,127,63,169,37,133,141,32,62,63,198,141,16,249,716
5230 DATA 96,169,4,141,124,37,169,1,141,201,75,32,142,62,176,47,8867
5240 DATA 32,156,46,162,0,169,89,133,128,169,70,133,129,160,0,177,1028
5250 DATA 128,240,222,217,192,36,208,34,200,192,3,208,242,189,111,70,5122
5260 DATA 141,236,63,189,118,70,141,237,63,32,146,42,32,255,255,169,4223
5270 DATA 0,141,124,37,141,201,75,76,201,37,232,165,128,24,105,3,9450
5280 DATA 133,128,144,201,230,129,208,197,165,155,162,0,56,233,26,48,1826
5290 DATA 3,232,208,248,72,138,24,105,161,141,19,32,104,24,105,187,9276
5300 DATA 141,20,32,166,158,232,138,162,0,56,233,10,48,3,232,208,1402
5310 DATA 248,72,138,24,105,144,141,21,32,104,24,105,154,141,22,32,6426
5320 DATA 96,32,146,42,169,80,141,199,70,169,58,141,200,70,169,155,3235
5330 DATA 141,201,70,169,72,162,3,160,0,140,72,71,32,48,69,32,5071
5340 DATA 119,69,32,104,69,32,142,69,32,104,69,165,159,133,138,165,898
5350 DATA 160,56,229,159,48,7,165,164,56,229,163,16,8,160,141,32,9444
5360 DATA 140,52,76,196,46,162,32,32,129,40,162,32,169,3,157,66,7675
5370 DATA 3,169,70,157,69,3,169,199,157,68,3,169,0,157,75,3,7212
5380 DATA 169,8,157,74,3,32,86,228,48,213,166,138,189,202,75,133,3547
5390 DATA 149,165,163,32,151,69,176,93,160,1,177,130,133,144,160,3,781
5400 DATA 177,130,16,3,76,98,65,41,3,240,3,76,115,65,160,2,5857
5410 DATA 177,130,168,32,249,59,169,155,153,192,36,136,48,8,177,130,1297
5420 DATA 153,192,36,76,218,64,169,192,133,132,169,36,133,133,32,25,9841
5430 DATA 54,32,49,65,230,138,165,138,197,160,240,174,144,172,165,159,7592
5440 DATA 133,138,32,26,65,230,163,165,163,197,164,240,157,144,155,162,7310
5450 DATA 32,32,129,40,96,32,87,65,76,240,64,169,11,162,32,157,9113
5460 DATA 66,3,169,0,157,72,3,157,73,3,169,155,32,86,228,48,8747
5470 DATA 34,96,169,11,162,32,157,66,3,165,149,157,72,3,169,0,7589
5480 DATA 157,73,3,169,5,157,69,3,169,128,157,68,3,32,86,228,8711
5490 DATA 48,1,96,104,104,76,215,48,162,127,169,32,157,128,5,202,1220
5500 DATA 16,250,96,32,87,65,160,4,185,220,70,153,128,5,136,16,8910
5510 DATA 247,76,240,64,201,1,208,19,32,249,59,166,130,164,131,32,1386
5520 DATA 137,221,32,230,216,32,201,52,76,240,64,160,2,177,130,168,3060
5530 DATA 32,249,59,152,56,233,6,24,101,130,170,165,131,105,0,168,677
5540 DATA 76,126,65,32,50,50,32,115,50,32,156,50,32,119,54,144,6167
5550 DATA 3,76,79,49,32,160,54,144,3,76,184,46,32,146,42,169,7945
5560 DATA 72,162,34,76,86,64,32,146,42,169,71,162,138,160,0,140,9635
5570 DATA 70,71,140,72,71,32,48,69,32,119,69,32,104,69,32,142,5616
5580 DATA 69,32,104,69,32,137,67,32,104,69,165,160,197,159,176,3,844
5590 DATA 76,124,64,165,164,197,163,144,247,165,161,197,159,208,6,165,6778
5600 DATA 165,197,163,240,235,165,161,197,160,208,6,165,165,197,164,240,9245
5610 DATA 223,165,160,56,229,159,133,171,133,169,165,164,56,229,163,133,6442
5620 DATA 172,56,165,161,229,159,133,202,56,165,165,229,163,133,201,32,5914
5630 DATA 50,67,10,170,189,131,67,141,215,66,189,132,67,141,216,66,3251
5640 DATA 32,104,42,165,159,133,173,165,161,133,174,165,165,32,25,45,1151
5650 DATA 160,0,177,130,201,255,240,19,197,174,240,8,176,13,32,242,4299
5660 DATA 59,76,79,66,166,174,165,165,32,165,44,165,130,133,132,165,3295
5670 DATA 131,133,133,165,163,32,25,45,160,0,177,130,201,255,240,87,4790
5680 DATA 197,173,240,8,176,81,32,242,59,76,119,66,169,35,133,135,735
5690 DATA 169,192,133,134,160,2,177,130,24,105,4,168,136,133,154,132,1647
5700 DATA 149,177,130,145,134,136,192,255,208,247,165,174,141,192,35,165,7974
5710 DATA 132,133,130,165,133,133,131,173,70,71,240,3,32,169,67,164,1349
5720 DATA 149,200,132,154,32,56,43,165,165,32,101,44,164,149,177,134,1859
5730 DATA 145,132,136,192,255,208,247,32,255,255,176,3,76,74,66,32,2166
5740 DATA 46,68,32,1,45,32,104,42,24,96,230,174,230,173,198,171,4415
5750 DATA 165,171,201,255,208,26,230,165,230,163,198,172,165,172,201,255,1596
5760 DATA 208,2,56,96,165,159,133,173,165,161,133,174,165,169,133,171,6506
5770 DATA 24,96,230,174,230,173,198,171,165,171,201,255,208,242,198,165,2482
5780 DATA 198,163,76,249,66,198,174,198,173,198,171,165,171,201,255,208,1436
5790 DATA 223,240,195,165,165,197,163,208,45,165,161,197,159,208,5,104,5458
5800 DATA 104,76,124,64,144,28,165,160,56,229,159,24,101,161,133,161,2976
5810 DATA 201,64,176,235,165,160,72,165,159,133,160,104,133,159,169,1,3491
5820 DATA 24,96,169,0,24,96,144,250,165,164,56,229,163,24,101,165,3346
5830 DATA 133,165,201,64,176,201,165,164,72,165,163,133,164,104,133,163,5583
5840 DATA 169,2,24,96,233,66,36,67,17,67,169,2,133,176,169,71,9388
5850 DATA 162,239,160,3,76,125,69,32,146,42,169,1,133,176,141,70,9884
5860 DATA 71,169,71,162,168,160,0,76,209,65,160,4,185,192,35,201,2711
5870 DATA 61,240,1,96,200,196,149,176,250,185,192,35,201,68,176,244,8166
5880 DATA 201,65,144,240,140,73,71,32,54,61,144,5,172,73,71,208,9885
5890 DATA 227,165,150,24,101,202,133,150,201,64,176,215,165,151,24,101,4041
5900 DATA 201,133,151,201,64,176,229,172,73,71,162,2,165,150,221,59,3656
5910 DATA 73,176,3,202,16,248,72,189,56,73,153,192,35,104,56,253,2756
5920 DATA 59,73,24,105,65,200,153,192,35,230,151,165,151,162,9,221,4907
5930 DATA 72,73,176,3,202,16,248,72,189,62,73,200,153,192,35,104,2496
5940 DATA 56,253,72,73,170,189,62,73,200,153,192,35,76,179,67,169,3077
5950 DATA 0,133,151,133,150,173,69,71,208,29,32,111,68,230,150,165,2880
5960 DATA 150,201,64,144,245,169,0,133,150,230,151,165,151,201,64,144,5915
5970 DATA 233,32,1,45,76,104,42,32,111,68,230,151,165,151,201,64,2323
5980 DATA 144,245,169,0,133,151,230,150,165,150,201,64,144,233,176,225,8840
5990 DATA 165,151,166,150,133,186,134,187,32,151,69,144,3,76,203,68,1291
6000 DATA 165,130,133,188,165,131,133,189,160,3,177,130,48,239,201,2,3624
6010 DATA 208,235,136,177,130,56,233,6,168,169,155,153,192,36,32,249,4676
6020 DATA 59,136,48,8,177,130,153,192,36,76,160,68,32,231,54,165,1559
6030 DATA 188,133,130,165,189,133,131,160,2,177,130,56,233,2,24,101,397
6040 DATA 130,133,252,165,131,105,0,133,253,32,171,221,165,186,133,151,6491
6050 DATA 165,187,133,150,96,32,146,42,169,71,162,106,160,0,140,72,235
6060 DATA 71,32,48,69,32,119,69,32,104,69,32,142,69,32,104,69,5919
6070 DATA 165,160,197,159,144,6,165,164,197,163,176,3,76,124,64,165,2704
6080 DATA 159,133,161,166,161,165,163,32,151,69,176,5,165,163,32,165,2436
6090 DATA 44,230,161,165,161,197,160,240,234,144,232,230,163,165,163,197,1648
6100 DATA 164,240,220,144,218,32,146,42,32,210,44,32,1,45,76,104,7323
6110 DATA 42,133,133,134,132,132,177,185,216,69,24,105,2,133,128,185,2450
6120 DATA 220,69,105,0,133,129,160,0,177,132,201,155,240,5,145,128,3749
6130 DATA 200,208,245,96,32,163,42,201,155,208,2,24,96,201,27,208,2485
6140 DATA 2,56,96,32,225,38,76,83,69,174,72,71,165,155,149,159,2318
6150 DATA 165,158,149,163,238,72,71,96,169,71,162,198,160,1,132,177,3912
6160 DATA 32,48,69,32,83,69,176,1,96,104,104,32,146,42,96,169,8754
6170 DATA 71,162,218,160,2,76,125,69,134,150,32,25,45,160,0,177,8767
6180 DATA 130,201,255,240,6,197,150,240,10,144,2,56,96,32,242,59,1113
6190 DATA 76,156,69,24,96,216,69,70,71,32,72,112,152,35,35,35,6346
6200 DATA 35,128,162,141,163,225,236,227,128,136,227,137,128,145,153,152,8248
6210 DATA 151,128,128,128,161,161,144,145,128,128,128,180,185,176,165,154,7260
6220 DATA 128,128,128,128,128,128,128,128,128,155,128,162,141,163,225,236,8148
6230 DATA 227,128,226,249,128,162,225,242,242,249,128,171,239,236,226,229,5103
6240 DATA 128,134,128,162,242,249,225,238,128,179,227,232,225,240,240,229,5623
6250 DATA 236,128,155,23,31,62,76,99,112,44,52,146,161,43,43,43,6950
6260 DATA 63,63,63,63,63,63,63,63,63,63,63,63,63,125,126,254,9697
6270 DATA 255,28,29,30,31,157,156,127,158,159,68,73,82,71,79,84,9218
6280 DATA 83,65,86,76,79,65,83,69,84,87,73,68,76,73,83,0,5473
6290 DATA 155,254,65,98,66,173,162,48,49,49,49,47,50,65,28,29,4904
6300 DATA 30,31,8,20,11,4,3,13,5,6,7,15,18,16,1,172,287
6310 DATA 11,100,232,184,68,74,212,197,150,68,54,43,92,116,64,62,9709
6320 DATA 39,40,39,38,46,50,50,68,65,67,51,52,52,52,52,64,3780
6330 DATA 50,255,254,253,159,158,157,156,155,127,126,125,31,30,29,28,11
6340 DATA 27,68,49,58,42,46,42,155,68,49,58,32,32,32,32,32,2882
6350 DATA 32,32,32,32,32,32,32,155,37,114,114,111,114,69,114,114,8527
6360 DATA 111,114,37,114,114,111,114,26,0,0,0,0,48,114,101,115,5083
6370 DATA 115,0,97,0,107,101,121,38,105,108,101,26,0,0,0,0,2516
6380 DATA 0,0,0,0,0,0,0,0,0,0,0,0,0,38,114,101,238
6390 DATA 101,26,50,101,99,97,108,99,26,47,38,38,0,0,0,0,1300
6400 DATA 0,0,0,0,0,0,0,0,0,0,98,121,26,50,47,55,1553
6410 DATA 0,0,0,47,38,38,47,46,0,50,47,55,0,0,0,35,9950
6420 DATA 47,44,53,45,46,0,0,0,74,71,184,72,180,229,248,244,4558
6430 DATA 128,128,128,128,174,245,237,226,229,242,128,128,166,245,238,227,3732
6440 DATA 244,233,239,238,128,128,128,128,128,128,128,128,36,37,44,37,9761
6450 DATA 52,37,26,0,48,111,115,105,116,105,111,110,0,35,117,114,7909
6460 DATA 115,111,114,12,0,50,37,52,53,50,46,155,35,47,48,57,4250
6470 DATA 26,0,48,111,115,105,116,105,111,110,0,35,117,114,115,111,9078
6480 DATA 114,12,0,50,37,52,53,50,46,155,45,47,54,37,26,0,2719
6490 DATA 48,111,115,105,116,105,111,110,0,35,117,114,115,111,114,12,8348
6500 DATA 0,50,37,52,53,50,46,155,53,112,112,101,114,0,108,101,7805
6510 DATA 102,116,0,111,102,0,34,108,111,99,107,155,44,111,119,101,9453
6520 DATA 114,0,114,105,103,104,116,0,111,102,0,34,108,111,99,107,7929
6530 DATA 155,53,112,112,101,114,0,108,101,102,116,0,111,102,0,36,6280
6540 DATA 101,115,116,14,155,48,50,41,46,52,26,0,48,111,115,105,5819
6550 DATA 116,105,111,110,0,35,117,114,115,111,114,12,0,50,37,52,5220
6560 DATA 53,50,46,155,44,41,51,52,26,0,48,111,115,105,116,105,7189
6570 DATA 111,110,0,35,117,114,115,111,114,12,0,50,37,52,53,50,4553
6580 DATA 46,155,38,47,50,45,33,52,0,0,0,42,117,115,116,105,5460
6590 DATA 102,121,0,44,36,111,108,108,97,114,0,4,8,36,9,0,2380
6600 DATA 46,35,111,109,109,97,115,0,0,8,12,9,0,46,36,101,2537
6610 DATA 99,14,0,112,108,97,99,101,115,0,16,46,57,44,50,35,4238
6620 DATA 16,17,18,19,20,21,22,23,24,25,0,40,18,38,105,108,2379
6630 DATA 101,0,101,120,105,115,116,115,12,0,50,101,112,108,97,99,8338
6640 DATA 101,31,0,57,15,46,155,50,31,30,26,24,29,27,51,53,2388
6650 DATA 48,0,0,0,0,0,155,28,29,30,31,187,72,187,72,0,5787
6660 DATA 53,73,86,73,11,2,20,65,66,67,0,26,52,48,49,50,2595
6670 DATA 51,52,53,54,55,56,57,0,10,20,30,40,50,60,70,80,3130
6680 DATA 90,94,42,47,43,45,179,74,200,74,64,1,0,0,0,0,2858
6690 DATA 64,2,0,0,0,0,63,80,0,0,0,0,33,33,16,17,9242
6700 DATA 226,2,227,2,144,37,0,0,0,0,0,0,0,0,0,0,8561

LISTING 2: ASSEMBLY

;SAVE#D:BCALC.PT1
	.OPT	NOLIST
	*=	0
PASS	.=	PASS+1
	.IF	PASS=1
	.INCLUDE	#D:BCALC.PT2
	.ENDIF
;close
;save X & res X in XSAV
	.MACRO	CLOSE 
	LDX	#<%1*16
	JSR	CLOSE
	.ENDM
;
	.OPT	NOLIST
	*=	$2000
SCMEM	.DS	40*20
TXTWIN	.DS	160
BF1	.DS	$80
BF2	.DS	$80
STRING	.DS	$80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Y
	CMP	#40
	BCS	OA
	INY
	BNE	OB
OA	STY	TM2	;lst col
	RTS
;refresh screen
REFSCR	LDA	#0	;vert lines
	STA	VCNT
	LDA	FROW
	STA	TM1	;rows
;
OH	LDA	TM1
	JSR	REFROW
	INC	TM1
	INC	VCNT
	LDA	VCNT
	CMP	#18
	BNE	OH
	RTS		;done
;get RAD
STRAD	ASL	A
	TAY
	LDA	RAD,Y
	STA	LL
	INY
	LDA	RAD,Y
	STA	LL+1
	RTS
;ref a row enter w/A=row
REFROW	PHA		;save row
	LDA	FCOL
	STA	TM	;col
	LDA	#2
	STA	SPX
	JSR	LSTCOL
	LDX	VCNT
	JSR	CLRLIN
	PLA
	JSR	STRAD
VE	LDY	#0
	LDA	(LL),Y
	CMP	#$FF
	BEQ	VA	;done w/row
	CMP	TM
	BEQ	VB	;got col
	BCC	VC
VD	LDY	TM	;next col
	LDA	COLW,Y	;scrn pos
	CLC
	ADC	SPX
	STA	SPX
	INC	TM
	LDA	TM
	CMP	TM2	;last col?
	BCC	VE
VA	RTS
VC	JSR	UP1COL	;inc ll
	JMP	VE
VB	LDA	LL
	CLC
	ADC	#DTLEN
	STA	IL
	LDA	LL+1
	ADC	#0
	STA	IL+1	;keep LL
	LDY	VCNT
	LDA	Y40L,Y
	STA	JL
	LDA	Y40H,Y
	STA	JL+1
	LDA	SPX
	STA	TM3
	LDY	#1
	LDA	(LL),Y
	STA	FORMAT
	LDY	#3
	LDA	(LL),Y
	BPL	NNER
	JMP	NUER
NNER	AND	#3
	BEQ	NNM
	CMP	#1
	BEQ	ISN	;a #
	LDY	#2	;a F
	LDA	(LL),Y
	SEC
	SBC	#6
	CLC
	ADC	IL
	TAX		;low
	LDA	IL+1
	ADC	#0
	TAY
	JMP	ISN2
;put on scrn
NNM	JSR	CLRSTR
	LDY	#2
	LDA	(LL),Y
	TAY
	LDA	#EOL
	STA	STRING,Y
	DEY
YTA	LDA	(IL),Y
	STA	STRING,Y
	DEY
	BPL	YTA
	LDA	#<STRING
	STA	IL
	LDA	#>STRING
	STA	IL+1
	JSR	FRMTXT	;result in IL
;put on screen
NNM1	LDY	TM
	LDA	COLW,Y
	STA	GMX
	LDY	#0
	STY	TM4
YLP	LDY	TM4
	LDA	LBUF,Y
	JSR	AS2IC
	LDY	TM3
	STA	(JL),Y
	INC	TM4
	INC	TM3
	LDA	TM4
	CMP	GMX
	BNE	YLP
	JSR	CLRSTR
	JMP	VD
;refr #s il has #
ISN	LDX	IL	;strt of #
	LDY	IL+1
ISN2	JSR	FLD0R
	JSR	SETINB
	JSR	FASC
	JSR	FRMNUM
	JMP	NNM1
;numbers
SBNUM	LDA	#1
	STA	DTYP
	JSR	SETFP
	JSR	ZFR0
	JSR	AFP
	LDX	#<STRING
	LDY	#>STRING
	JSR	FST0R
	LDA	#6
	STA	STR
	JSR	INSERT
	RTS
;error in cell
NUER	LDX	#0
	LDA	#5
	STA	GMX
	LDY	TM
	LDA	COLW,Y
	CMP	#4
	BNE	ADQ
	DEC	GMX
ADQ	LDY	TM3
ADP	LDA	ERMES,X
	STA	(JL),Y
	INY
	INX
	CPX	GMX
	BNE	ADP
	JMP	VD	;nx col
;set fp ptrs
SETFP	LDA	#>STRING
	STA	INBUF+1
	LDA	#<STRING
	STA	INBUF
	LDA	#0
	STA	CIX
	RTS
;set inbuf
SETINB	LDA	#>LBUF
	STA	INBUF+1
	LDA	#<LBUF
	STA	INBUF
	LDA	#0
	STA	CIX
	RTS
;# to STRING
NM2STR	JSR	SETINB
	JSR	FASC
	LDY	#0
NLP	LDA	(INBUF),Y
	BMI	NL2
	STA	STRING,Y
	INY
	BNE	NLP
NL2	AND	#$7F
	STA	STRING,Y
	INY
	STY	STR
	CPY	#1
	BEQ	NRT
	LDA	STRING
	CMP	#'0
	BNE	NRT
	LDY	#0
NL3	LDA	STRING+1,Y
	STA	STRING,Y
	INY
	CPY	STR
	BNE	NL3
	DEC	STR
NRT	RTS
;do spec ctrl cmds
;clear STRING for FP
CLRSTR	LDX	#$7F
	LDA	#$20
CSTL	STA	STRING,X
	DEX
	BPL	CSTL
	RTS
;convert low to upp case
LO2UP	LDY	#0
LOLP	LDA	STRING,Y
	CMP	#EOL
	BEQ	LODON
	AND	#$7F
	CMP	#'z+1
	BCS	NLO
	CMP	#'a
	BCC	NLO
	EOR	#$20
NLO	STA	STRING,Y
	INY
	BNE	LOLP
LODON	RTS
	.INCLUDE	#D:BCALC.PT3
	.INCLUDE	#D:BCALC.PT4
	.INCLUDE	#D:BCALC.PT5
	.INCLUDE	#D:BCALC.PT6
ENPROG	=	*
	*=	RUNAD
	.WORD	BEGIN
	.END

LISTING 3: ASSEMBLY

;SAVE#D:BCEQU
;
CIOV	=	$E456
ICCOM	=	$0342
ICBAL	=	$0344
ICBAH	=	$0345
ICBLL	=	$0348
ICBLH	=	$0349
AUX1	=	$034A
AUX2	=	$034B
RUNAD	=	$02E0
INITAD	=	$02E2
;
SDLSTL	=	$0230
SDMCTL	=	$022F
VDSLST	=	$0200
NMIEN	=	$D40E
WSYNC	=	$D40A
SETVBV	=	$E45C
SYSVBV	=	$E45F
COLOR0	=	$02C4
COLOR1	=	$02C5
COLOR2	=	$02C6
COLOR4	=	$02C8
COLPF0	=	$D016
COLPF2	=	$D018
KEYDEF	=	$79
INVFLG	=	$02B6
;fp equates
CIX	=	$F2
INBUF	=	$F3
FR0	=	$D4
FR1	=	$E0
FLPTR	=	$FC
LBUF	=	$0580
AFP	=	$D800
FASC	=	$D8E6
IFP	=	$D9AA
ZFR0	=	$DA44
ZF1	=	$DA46
FSUB	=	$DA60
FADD	=	$DA66
FMUL	=	$DADB
FDIV	=	$DB28
FST0R	=	$DDA7
FST0P	=	$DDAB
FLD0R	=	$DD89
FLD1R	=	$DD98
FLD0P	=	$DD8D
FLD1P	=	$DD9C
FMOVE	=	$DDB6
EXP10	=	$DDCC
LOG10	=	$DED1
;
CONSOL	=	$D01F
CH	=	$02FC
EOL	=	$9B
DOSVEC	=	$0A
RAMTOP	=	$6A
SEOL	=	$BB
CAPS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1
	JSR	FINARG
	JSR	GTFILE
	JSR	CHKDEV
	BCS	DEVERR
	LDA	#4	;read
	LDY	#7	;input
DOIT	STA	DM6	;keep em
	STY	DM7
		CLOSE 2
	LDX	#$20
	LDA	DM6
	STA	AUX1,X
	LDA	#3
	STA	ICCOM,X
	LDA	#<FNAME
	STA	ICBAL,X
	LDA	#>FNAME
	STA	ICBAH,X
	LDA	#0
	STA	AUX2,X
	JSR	CIOV
	BPL	RWOK
	JMP	GENER	;error
RWOK	LDX	#$20
	LDA	DM7
	TAY
	STA	ICCOM,X
	LDA	#<COLW
	STA	ICBAL,X
	LDA	#>COLW
	STA	ICBAH,X
	CPY	#7	;inp?
	BNE	RITE
	LDA	#$FF
	STA	ICBLL,X
	STA	ICBLH,X
	BNE	SINP
RITE	LDA	ENDAT
	SEC
	SBC	#<COLW
	STA	ICBLL,X
	LDA	ENDAT+1
	SBC	#>COLW
	STA	ICBLH,X
SINP	JSR	CIOV
	BPL	IOOK
	CPY	#136	;EOF?
	BEQ	IOOK
	JMP	GENER	; error
IOOK		CLOSE 2
	LDA	DM6
	CMP	#8
	BEQ	WRF
	LDX	#$20
	LDA	#<COLW
	CLC
	ADC	ICBLL,X
	STA	ENDAT
	LDA	#>COLW
	ADC	ICBLH,X
	STA	ENDAT+1
WRF	JMP	HOME
;goto
GOTO	JSR	ST2BF1
	JSR	FINARG
	BCS	QAB
	JSR	GTCLRW
	BCS	QAB
	LDA	ROWNU
	CMP	#47
	BCS	QAB
	LDA	COLNU
	CMP	#55
	BCS	QAB
	JSR	IVCRS
	JSR	CLRSCN
	LDA	COLNU
	STA	FCOL
	STA	SCOL
	LDA	ROWNU
	STA	FROW
	STA	SROW
	LDA	#0	;4 crs2
	JSR	CRS2
	JMP	HM2
QAB	RTS
;str2bf1
ST2BF1	LDY	#114
SO1	LDA	STRING,Y
	STA	BF1,Y
	DEY
	BPL	SO1
	RTS
;recalc now
ARECL	JSR	RECALC
	JMP	HOME
;force text
FORCE	LDA	#1
	STA	FRCTXT
	RTS
;kill cell
KILLCL	LDA	SCOL
	TAX
	LDA	FROW
	CLC
	ADC	CURRW
	STA	TM
	JSR	LOCCEL
	BCC	LCELL
	RTS		;none
LCELL	LDA	TM
	JSR	DELTCL
	JSR	IVCRS
	LDA	#2
	STA	SPX
	LDA	CURRW
	STA	VCNT
	LDA	SROW
	JSR	REFROW
	JSR	IVCRS
	RTS
;find arg
FINARG	LDY	#0
F8LP	LDA	BF1,Y
	CMP	#EOL
	BEQ	NOARG
	CMP	#$20
	BEQ	FSPCE
	INY
	CPY	#$20
	BNE	F8LP
NOARG	SEC
	RTS
FSPCE	INY
FARG	LDA	BF1,Y
	CMP	#EOL
	BEQ	NOARG
	CMP	#$20	;spac
	BNE	GTARG
	INY
	CPY	#$20
	BNE	FARG
	BEQ	NOARG
GTARG	CLC
	RTS
;get file name
GTFILE	LDX	#0
F9LP	LDA	BF1,Y
	STA	FNAME,X
	CMP	#EOL
	BEQ	FGD
	INY
	INX
	BNE	F9LP
FGD	RTS
;chng col width
WIDTH	JSR	ST2BF1
	JSR	FINARG
	BCS	NOW
	JSR	GTCLRW
	BCS	NOW
	INC	ROWNU
	LDA	ROWNU
	CMP	#2
	BCC	NOW
	CMP	#33
	BCS	NOW
	LDY	COLNU
	STA	COLW,Y
	JSR	CLRSCN
	JSR	DRAWH
	JSR	REFSCR
	LDY	FCOL
	STY	SCOL
	LDA	#2
	STA	CRSX
	CLC
	ADC	COLW,Y
	STA	CRSEN
	JSR	IVCRS
NOW	RTS
;show a cell's content
SHOCEL	LDX	SCOL
	LDA	SROW
	JSR	LOCCEL
	BCC	UAA
	RTS		;none
UAA	LDY	#1	;format
	LDA	(LL),Y
	STA	$00
	INY		;length
	LDA	(LL),Y
	STA	LENG
	INY
	LDA	(LL),Y
	AND	#3
	BNE	UAB
UAG	JSR	ADDDT
	LDY	LENG	;text
	DEY
UAH	LDA	(LL),Y
	STA	STRING,Y
	DEY
	BPL	UAH
UAE	LDA	#$FF
	STA	XPOS
	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LA
	ASL	A
	ASL	A
	ASL	A
	ASL	A
	ORA	FORMAT
	STA	FORMAT
;
SHOFRM	LDA	FORMAT
	AND	#3
	TAX
	LDA	LCR,X
	STA	TXTWIN+19
	LDA	FORMAT
	AND	#8
	LSR	A
	LSR	A
	LSR	A
	TAX
	LDA	YN,X
	STA	TXTWIN+59
	LDA	FORMAT
	AND	#4
	LSR	A
	LSR	A
	TAX
	LDA	YN,X
	STA	TXTWIN+99
	LDA	FORMAT
	AND	#$F0
	LSR	A
	LSR	A
	LSR	A
	LSR	A
	TAX
	LDA	SDEC,X
	STA	TXTWIN+139
	JMP	FPC
;global format
GLOBAL	JSR	FORM
	LDY	SCOL
	LDA	FORMAT
	STA	FMCOL,Y
	RTS
;format a cell
FORMC	LDA	SROW
	LDX	SCOL
	JSR	LOCCEL
	BCC	ECL
	RTS
ECL	JSR	FORM
	LDY	#1
	LDA	FORMAT
	STA	(LL),Y
	LDX	CURRW
	STX	VCNT
	LDA	SROW
	JSR	REFROW
	LDY	SCOL	;restore
	LDA	FMCOL,Y	;glob. formt
	STA	FORMAT
	JMP	IVCRS
;recalc flag
RONOF	LDA	ONF
	EOR	#3
	STA	ONF
	TAX
	LDY	#0
RPP	LDA	ONOFM,X
	STA	SEG+7,Y
	INX
	INY
	CPY	#3
	BNE	RPP
	RTS
;flip row/col flg
RCFLP	LDA	RCFLG
	EOR	#6
	STA	RCFLG
	TAX
	LDY	#0
RHK	LDA	RCMES,X
	STA	SEG+27,Y
	INX
	INY
	CPY	#6
	BNE	RHK
	RTS
;disk error
DSKERR	STY	YSAV
		CLOSE 2
	LDY	YSAV
	STY	FR0
	LDA	#0
	STA	FR0+1
	JSR	IFP
	JSR	FASC
	LDY	#$FF
ERLPA	INY
	LDA	(INBUF),Y
	PHA
	AND	#$7F
	JSR	AS2IC
	STA	DERM+6,Y
	PLA
	BPL	ERLPA
	JSR	CLLIN3
	LDY	#20
ERLPB	LDA	DERM,Y
	STA	TXTWIN+124,Y
	DEY
	BPL	ERLPB
	LDA	#$FF
	STA	CH
	JSR	GAKEY
	RTS
;Number Format Subroutine
;for B-CALC
;FORMAT BYTE 1
;bit 4-7: Places after Decimal
;bit 3:   Dollar Sign Flag
;bit 2:   Comma Flag
;bit 0-1: L/C/R Justify
;
FRMNUM	LDY	#$FF
:FM0	INY
	LDA	(INBUF),Y
	STA	NUMB,Y
	BPL	:FM0
	LDY	#$7F
	LDA	#'0
FN.1	STA	STRING,Y
	DEY
	BPL	FN.1
	LDA	#'$
	STA	STRING
	LDA	#<[STRING+1]
	STA	IL
	LDA	#>[STRING+1]
	STA	IL+1
;
	LDA	FORMAT	;get FM byte
	PHA
	AND	#$F0
	LSR	A
	LSR	A
	LSR	A
	LSR	A
	STA	TORITE
	PLA
;
	AND	#4	;commas?
	BNE	FNCOM	;yes
	LDY	#$FF
:CPL	INY
	LDA	(INBUF),Y
	STA	(IL),Y
	BPL	:CPL
:FM1	JMP	:DSGN
;insert ','s
FNCOM	LDY	#$FF
FM:1	INY
	LDA	NUMB,Y
	BMI	FM:D
	CMP	#'.
	BNE	FM:1
	DEY
FM:D	STY	SVY
	LDX	#29
:LP1	LDA	#2
	STA	FCNT
:LP2	LDA	NUMB,Y
	AND	#$7F
	STA	LBUF,X
	DEX
	DEY
	BMI	:LV
	DEC	FCNT
	BPL	:LP2
	LDA	#',
	STA	LBUF,X
	DEX
	BPL	:LP1
:LV	INX
	LDY	#1
:LP3	LDA	LBUF,X
	STA	STRING,Y
	INY
	INX
	CPX	#30
	BNE	:LP3
	LDX	SVY
	LDA	NUMB,X
	BPL	:NNV
	DEY
	LDA	STRING,Y
	ORA	#$80
	STA	STRING,Y
	BNE	:DSGN
;
:NNV	INX
	LDA	NUMB,X
	STA	STRING,Y
	BMI	:DSGN
	INY
	BNE	:NNV
;
:DSGN	LDA	FORMAT
	AND	#8
	BEQ	:AFTER
	LDA	#<STRING
	STA	IL
	LDA	#>STRING
	STA	IL+1
;handle places after decimal
;search for E
:AFTER	LDA	#0
	STA	SCI	;flag
	LDY	#$FF
HXA	INY
	LDA	STRING,Y
	BMI	:AF2	;none
	CMP	#'E
	BNE	HXA	;kot yet
;got exp
	INC	SCI	;set flg
	DEY		;invs prev byt
	LDA	STRING,Y
	ORA	#$80
	STA	STRING,Y
	LDX	#$FF	;bck to E
HXB	INX
	INY
	LDA	STRING,Y
	PHA
	AND	#$7F
	STA	SVEX,X
	LDA	#'0
	STA	STRING,Y
	PLA
	BPL	HXB
;show end
	INX
	STX	SCI
	LDA	#EOL
	STA	SVEX,X
:AF2	LDY	#$FF
:AF	INY
	LDA	STRING,Y
	BPL	:TP
	AND	#$7F
	STA	STRING,Y
	INY
	LDA	#'.
	STA	STRING,Y
	STY	SVY
	JMP	:JM
:TP	CMP	#'.
	BNE	:AF
	STY	SVY
:A2	INY
	LDA	STRING,Y
	BPL	:A2
	AND	#$7F
	STA	STRING,Y
:JM	LDA	SVY
	CLC
	ADC	TORITE
	TAY
	LDA	TORITE
	BNE	:EL
	DEY
:EL	LDA	#EOL
	STA	STRING+1,Y
;chk for E
	LDA	SCI
	BEQ	CKMIN
	LDX	#0
HXC	LDA	SVEX,X
	STA	STRING+1,Y
	CMP	#EOL
	BEQ	CKMIN
	INX
	INY
	BNE	HXC
;chk for $-,
CKMIN	LDA	STRING+1
	CMP	#'-
	BNE	FRMTXT
	LDA	STRING+2
	CMP	#',
	BNE	FRMTXT
	LDY	#0
MILP	LDA	STRING+3,Y
	STA	STRING+2,Y
	CMP	#EOL
	BEQ	FRMTXT
	INY
	BNE	MILP
;get length of number
FRMTXT	LDY	#$FF
:L1	INY
	LDA	(IL),Y
	CMP	#EOL
	BNE	:L1
	STY	SVY
;left/center/right justify
:LCR	LDX	#$7F
	LDA	#$20
:L2	STA	LBUF,X
	DEX
	BPL	:L2
;
	LDA	FORMAT
	AND	#3
	TAX
	BEQ	:HAV
;right justify
	DEX
	BNE	:CEN
	LDY	TM
	LDA	COLW,Y
	SEC
	SBC	SVY
	BPL	:HV
YUA	LDX	#0
	BEQ	:LC
;center
:CEN	LDY	TM
	LDA	COLW,Y
	SEC
	SBC	SVY
	BPL	:C1
	EOR	#$FF
	LSR	A
	TAY
	JMP	YUA
:C1	LSR	A
:HV	TAX
;copy the number
:HAV	LDY	#$FF
:LC	INY
	LDA	(IL),Y
	CMP	#EOL
	BEQ	:LB
	STA	LBUF,X
	INX
	BNE	:LC
:LB	LDA	#<LBUF
	STA	IL
	LDA	#>LBUF
	STA	IL+1
	RTS
SCI	.BYTE	0
SVEX	.DS	4
	.BYTE	EOL
;check for D:
CHKDEV	LDA	FNAME
	CMP	#'D
	BNE	WRDEV
	LDA	FNAME+1
DVNUM	CMP	#':
	BEQ	AYOK
	CMP	#'8
	BEQ	MYOK
	CMP	#'1
	BCC	WRDEV
	CMP	#'4
	BCS	WRDEV
	BCC	MYOK
AYOK	CLC
	RTS
WRDEV	SEC
	RTS
MYOK	LDA	FNAME+2
	CMP	#':
	BEQ	AYOK
	BNE	WRDEV
;check if file exist
FILEXST	LDA	#0
	STA	TXTWIN+2
		CLOSE 2
	LDA	#36	;unloc
	STA	ICCOM,X
	LDA	#>FNAME
	STA	ICBAH,X
	LDA	#<FNAME
	STA	ICBAL,X
	JSR	CIOV
	LDA	ICCOM+1,X	;stat?
	PHA
		CLOSE 2
	PLA
	CMP	#1
	BEQ	FYES
OVWR	CLC
	RTS
FYES	LDA	#>REPMES
	LDX	#<REPMES
	LDY	#1
	JSR	PRNTTW
YNK	LDA	CH
	LDX	#$FF
	CMP	#$2B	;yes
	BEQ	OVWR
	CMP	#$23
	BNE	YNK
	STX	CH
	SEC		;no
	RTS

LISTING 5: ASSEMBLY

;SAVE#D:bcalc.pt4
;
;start of parsing
TRYFNC	LDA	#0
	STA	FPPTR
	JSR	ZFR0
PARS	LDX	#0
	STX	STR
PLP	LDA	STRING,X
	STA	BF1,X
	CMP	#EOL
	BEQ	PDON
	INX
	BNE	PLP
PDON	STX	STR
;pass 1 remove @
;replace with #
; @ABS(---,---,---)
; TM  .TM1.       T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JMP	FFH
;collapse & do fp
FFI	INY
	STY	TM2
	LDY	TM
	LDX	TM2
	JSR	COLAPS
	LDX	#0
FFO	LDA	BF1,X
	CMP	#EOL
	BEQ	FFL
	INX
	BNE	FFO
FFL	STX	STR
	JSR	ADD2SP
	LDY	TM
	LDA	#'#
	STA	BF1,Y
	LDA	FPN1
	STA	BF1+1,Y
JPOFF	JSR	$FFFF
;back to begin
	BCC	JJJ
	RTS
JJJ	JMP	FNDFUN
SPFR2ST	LDA	FPPTR
	LDY	NARG
	STA	FPN1,Y
	INC	NARG
	INY
	CPY	#3
	BCS	FFG
	TAX
	JSR	FR0X
	INC	FPPTR
	CLC
	RTS
FFG	SEC
	RTS
;get a cell's #
;X=col A=row FR0=#
CL2FR0	STX	COLNU
	JSR	STRAD
EE	LDY	#0
	LDA	(LL),Y
	CMP	#$FF
	BEQ	ED
	CMP	COLNU
	BEQ	EB
	BCC	EC
ED	SEC		;err
	RTS
EC	JSR	UP1COL
	JMP	EE
	RTS		;c is set
EB	LDY	#3	;data typ
	LDA	(LL),Y
	AND	#3
	BEQ	EN	;txt!
	CMP	#1
	BEQ	EF
	LDY	#2	;fn
	LDA	(LL),Y
	SEC
	SBC	#6
	JSR	INCLL
EF	LDA	#4
	JSR	INCLL
	LDX	LL
	LDY	LL+1
	JSR	FLD0R	;2 fr0
EN	CLC
	RTS
;func tabl pad 3 spaces! + tok
FTAB	.BYTE	"SQU",0
	.BYTE	"ABS",1
	.BYTE	"SQR",2
	.BYTE	"RND",3
	.BYTE	"EXP",4
	.BYTE	"LOG",5
	.BYTE	"INT",6
	.BYTE	"CNT",7
	.BYTE	"SUM",8
	.BYTE	"AVE",9
	.BYTE	0
;jmp tabl
JTAB	.WORD	SQU
	.WORD	ABS
	.WORD	SQR
	.WORD	RND
	.WORD	EXP
	.WORD	LOG
	.WORD	INT
	.WORD	CNT
	.WORD	SUM
	.WORD	AVE
;absolute val
ABS	JSR	CHKONE
AXB	LDA	FR0
	AND	#$7F
	STA	FR0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	DM5
	BEQ	DAG
	BCC	DAG
	CLC
	RTS
;average
AVE	JSR	CHKTWO
	JSR	CHKCEL
	JSR	CHKSIZ
	JSR	CNTSUB
	BCS	AV2
	JSR	SAVFPN	;2 stck
	JSR	SUMSUB
	BCS	AV2
	JSR	RETFPN	;2 fr1-fpptr
	JSR	FDIV	;does not chng
	BCS	AV2
EX5	JMP	EXX
AV2	RTS
;exp
EXP	JSR	CHKONE
	JSR	EXP10
EX1	BCC	EX5	;xit
	RTS
;log
LOG	JSR	CHKONE
	JSR	LOG10
	BCC	EX1
	RTS
;count subrt
CNTSUB	JSR	DUPDAT
	LDA	#0
	STA	DM6
	STA	DM7	;cntrs
CNC	LDA	DM0
	STA	DM2
;is cell empty
CNB	LDX	DM2
	LDA	DM4
	JSR	CL2FR0
	BCS	CNA	;skip empties
	INC	DM6	;add rows
	BNE	CNA
	INC	DM7
CNA	INC	DM2	;nxt col
	LDA	DM2
	CMP	DM1
	BEQ	CNB
	BCC	CNB
	INC	DM4	;nxt row
	LDA	DM4
	CMP	DM5
	BEQ	CNC
	BCC	CNC
	JSR	ZFR0
	LDA	DM6	;gt cnt
	STA	FR0
	LDA	DM7
	STA	FR0+1
	JSR	IFP
	CLC
	RTS
;chekc 4 1 arg
CHKONE	LDA	NARG
	BEQ	CZ
	CMP	#1
	BEQ	CY
CZ	PLA		;pull ret
	PLA
	SEC
CY	RTS
;chk 4 2 arg
CHKTWO	LDA	NARG
	CMP	#2
	BNE	CZ	;err
	RTS
;entries cells?
CHKCEL	LDY	#1
CWP	LDA	ARGT,Y
	BPL	CZ	;err
	DEY
	BPL	CWP
	RTS
;right size?
CHKSIZ	LDA	ROWS
	CMP	ROWF
	BCC	CZ	;err
	LDA	COLS
	CMP	COLF
	BCC	CZ	;err
	RTS
;dup colf-rowz
DUPDAT	LDX	#7
DDT	LDA	COLF,X
	STA	DM0,X
	DEX
	BPL	DDT
	RTS
;truncate
TRUNC	LDY	#0
TI	LDA	(INBUF),Y
	BMI	TEX
	CMP	#'.
	BEQ	TJAA
	INY
	BNE	TI
TJAA	STA	TRCF	;flag
TJ	LDA	#EOL
	STA	(INBUF),Y
	RTS		;NEW
TEX	AND	#$7F
	STA	(INBUF),Y
	INY
	BNE	TJ
;save fp #
SAVFPN	LDX	FPPTR
	LDA	STHI,X
	TAY
	LDA	STLO,X
	TAX
	JSR	FST0R
	RTS
;retrv fpn to fr1
RETFPN	LDX	FPPTR
	LDA	STHI,X
	TAY
	LDA	STLO,X
	TAX
	JSR	FLD1R
	RTS
;pass 2 find cells
;replace with #
PASS2	LDY	#1
LCEL	LDA	BF1,Y
	CMP	#'D
	BCS	NXY
	CMP	#'A
	BCS	AHA
NXY	INY
	CPY	STR
	BNE	LCEL
	JMP	PASS3	;do #'s next
AHA	STY	TM	;for collps
	TYA		;strt
	CLC
	ADC	#4
	STA	TM2	;end
	JSR	GTCLRW
	BCS	ACD
	LDA	ROWNU
	JSR	STRAD
ACC	LDY	#0
	LDA	(LL),Y
	CMP	#$FF	;end?
	BEQ	ACD	;error
	CMP	COLNU
	BEQ	ACA	;yup
	BCC	ACB
ACD	RTS
ACB	JSR	UP1COL
	JMP	ACC
ACA	LDY	#3	;gt cell
	LDA	(LL),Y
	AND	#3	;dt type
	BEQ	ACD	;text!
	CMP	#1	;#?
	BEQ	ACE
	LDY	#2
	LDA	(LL),Y
	SEC
	SBC	#6
	JSR	INCLL
;default
ACE	LDA	#4
	JSR	INCLL
	LDX	LL
	LDY	LL+1
	JSR	FLD0R
	LDA	#4
	STA	TM1
	JSR	PUTTOK
	LDY	TM
	JMP	NXY
;put tok in2 bf1
PUTTOK	LDY	TM
	LDX	TM2
	JSR	COLAPS
	LDA	STR
	SEC
	SBC	TM1
	STA	STR
	JSR	ADD2SP
	LDY	TM
	LDA	#'#
	STA	BF1,Y
	LDA	FPPTR
	INY
	STA	BF1,Y
	STY	TM
;move fp to stck
	TAX
	LDA	STHI,X
	TAY
	LDA	STLO,X
	TAX
	JSR	FST0R
	INC	FPPTR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X
	JSR	CALCIT
	BCS	P4ER
	LDA	RIGHTP
	SEC
	SBC	LEFTP
	CMP	#1
	BEQ	P4ER
	LDX	LEFTP
	LDA	BF2
	STA	BF1,X
	LDA	BF2+1
	INX
	STA	BF1,X
	LDY	RIGHTP
PSU	INX
	INY
	LDA	BF1,Y
	STA	BF1,X
	CMP	#EOL
	BNE	PSU
	JMP	PASS4
;go up 1 col
UP1COL	LDY	#2
	LDA	(LL),Y
	JSR	INCLL
ADDDT	LDA	#DTLEN
INCLL	CLC
	ADC	LL
	STA	LL
	LDA	LL+1
	ADC	#0
	STA	LL+1
	RTS
;calculate bf2
;exponents first
CALCIT
CALCEX	LDY	#0
CCW	STY	TM4	;save for clpse
	JSR	GT2TOK
	CMP	#EOL
	BEQ	CALMD	;try *,/
	BCC	CCA
CCB	RTS		;SEC=error
CCA	JSR	MV2FPN
	LDA	OPERAT
	CMP	#'^
	BNE	CCE
	JSR	FIGEXP
	BCS	CCB	;error
	JSR	CLPSBF2	;collpase
	JSR	FR02ST
	JMP	CALCEX
CCE	LDA	TM4
	CLC
	ADC	#3
	TAY
	JMP	CCW	;look 4 more
;calculate * & /
CALMD	LDY	#0
CDC	STY	TM4
	JSR	GT2TOK
	CMP	#EOL
	BEQ	CALAS
	BCC	CDA
CDB	RTS		;error
CDA	JSR	MV2FPN
	LDA	OPERAT
	CMP	#'*
	BNE	CDD
	JSR	FMUL
	BCS	CDB	;error
	BCC	CDE
CDD	CMP	#'/
	BNE	CDF
	JSR	FDIV
	BCS	CDB	;error
CDE	JSR	CLPSBF2
	JSR	FR02ST
	LDY	TM4
	JMP	CDC
CDF	LDA	TM4
	CLC
	ADC	#3
	TAY
	JMP	CDC
;calculate +,-
CALAS	LDY	#0
CEG	STY	TM4
	JSR	GT2TOK
	CMP	#EOL
	BEQ	CDONE
	BCC	CEA
CEB	RTS		;SEC =error
CEA	JSR	MV2FPN
	LDA	OPERAT
	CMP	#'+
	BNE	CEC
	JSR	FADD
	BCS	CEB
	BCC	CED
CEC	CMP	#'-
	BNE	CEB	;error
	JSR	FSUB
	BCS	CEB	;error
CED	JSR	CLPSBF2
	JSR	FR02ST
	LDY	TM4
	JMP	CEG
CDONE	CLC		;ok
	RTS
;get 2 tokens & operation
GT2TOK	LDA	BF2,Y
	CMP	#'#
	BEQ	GBA
	CMP	#EOL	;done?
	BEQ	GBB
GBC	SEC		;error
	RTS
GBA	INY
	LDA	BF2,Y
	CMP	#EOL
	BEQ	GBC	;error
	STA	FTOK
	INY
	LDA	BF2,Y
	STA	OPERAT
	CMP	#EOL
	BEQ	GBB	;done
	INY
	LDA	BF2,Y
	CMP	#EOL
	BEQ	GBB	;done
	CMP	#'#
	BNE	GBC	;error
	INY
	LDA	BF2,Y
	CMP	#EOL
	BEQ	GBC	;error
	STA	STOK
GBB	CLC		;A=eol if done
	RTS
;move tok # to fp reg
MV2FPN	LDX	FTOK
	JSR	STFLPTR
	JSR	FLD0P
	LDX	STOK
	JSR	STFLPTR
	JSR	FLD1P
	RTS
;set pointers
STFLPTR	LDA	STLO,X
	STA	FLPTR
	LDA	STHI,X
	STA	FLPTR+1
	RTS
;collapse bf2
CLPSBF2	LDA	TM4
	CLC
	ADC	#2
	TAY
	CLC
	ADC	#3
	TAX
CF1	LDA	BF2,X
	STA	BF2,Y
	CMP	#EOL
	BEQ	CF2
	INY
	INX
	JMP	CF1
CF2	RTS
;figure exp
FIGEXP	LDX	FTOK
	JSR	STFLPTR
	JSR	FLD0P
	JSR	LOG10
	BCC	FIA
FIB	SEC
	RTS
FIA	LDX	STOK
	JSR	STFLPTR
	JSR	FLD1P
	JSR	FMUL
	BCS	FIB
	JSR	EXP10
	BCS	FIB
	CLC
	RTS
;get a cell
;colnu,rownu have col,row
GTCLRW	JSR	GET2CH
	BCS	GRX
	JSR	FINCNU
	BCC	GRW
GRX	RTS		;error
GRW	LDY	HLDY
	INY
	JSR	GET2CH
	BCS	GRX
	JSR	FINRNU
	LDY	HLDY
	RTS
;find the column #
FINCNU	LDA	HLDF
	LDX	#2
FCA	CMP	AS26,X
	BEQ	FCC
	DEX
	BPL	FCA
	BMI	FCER
FCC	LDA	N26,X
	STA	TM3
	LDA	HLDS
	CMP	#'[
	BCS	FCER
	CMP	#'A
	BCS	FCB
FCER	SEC		;error
	RTS
FCB	SEC
	SBC	#'A
	CLC
	ADC	TM3
	STA	COLNU	;col #
	CMP	#64	;0-63
	BCS	FCER
	RTS
;get 2 chr's from bf1
GET2CH	LDA	BF1,Y
	CMP	#EOL
	BEQ	GERR
	STA	HLDF
	INY
	LDA	BF1,Y
	CMP	#EOL
	BEQ	GERR
	STA	HLDS
	STY	HLDY
	CLC
	RTS
GERR	SEC
	RTS
;get the row #
FINRNU	LDA	HLDF
	JSR	GETDEC
	BCS	FRER
	STA	ROWNU
	LDA	HLDS
	JSR	GETDEC
	BCS	FRER
	TXA
	CLC
	ADC	ROWNU
	TAX
	DEX
	CPX	#64
	BCS	FRER
	STX	ROWNU
	CLC
	RTS
FRER	SEC
	RTS
;get a decimal # (row)
GETDEC	LDX	#9
DECB	CMP	DECN,X
	BEQ	DECA
	DEX
	BPL	DECB
	SEC
	RTS
DECA	LDA	DECM,X
	CLC
	RTS
;move fr0 to fpstack
FR02ST	LDX	FTOK
FR0X	JSR	STFLPTR
	JSR	FST0P
	RTS
;collapse ;x=beg y=des
;uses tm3
COLAPS	LDA	BF1,X
	STA	BF1,Y
	CMP	#EOL
	BEQ	CPF
	INY
	INX
	BNE	COLAPS
CPF	RTS
;room for fp token
ADD2SP	LDX	STR
ASLP	LDA	BF1,X
	STA	BF1+2,X
	DEX
	CPX	TM
	BEQ	ASLP
	BCS	ASLP
	INC	STR
	INC	STR
	RTS
;point 2 bf1
FP2BF1	LDA	#>BF1
	STA	INBUF+1
	LDA	#<BF1
	STA	INBUF
	RTS
TRCF	.DS	1
;round off sqrts
RNDSQR	JSR	FMOVE	;rt to fr1
	LDX	#<SROOT	;save root
	LDY	#>SROOT
	JSR	FST0R
	LDX	#<SFPN
	LDY	#>SFPN
	JSR	FLD0R	;N to fr0
	JSR	FDIV	;N/rt
	LDX	#<SROOT
	LDY	#>SROOT
	JSR	FLD1R	;res. root
	JSR	FADD	;add rts
	LDX	#<HALF
	LDY	#>HALF
	JSR	FLD1R
	JSR	FMUL	;x .5
	RTS
SFPN	.DS	6
SROOT	.DS	6

LISTING 6: ASSEMBLY

;save#D:BCALC.PT5
;draw text wndw
DRWIN	LDA	#0
	STA	TM1
	TAY
	TAX
DIT	STX	TM2
	LDX	TM1
	LDA	TWINL,X
	CLC
	ADC	#2
	STA	L
	LDA	TWINH,X
	ADC	#0
	STA	L+1
	LDX	TM2
DRLP	LDA	STRING,X
	JSR	AS2IC
	CPX	XPOS
	BNE	DRSC
	EOR	#$80
DRSC	STA	(L),Y
	INX
	INY
	CPY	#38
	BNE	DRLP
	LDY	#0
	INC	TM1
	LDA	TM1
	CMP	#3
	BNE	DIT
	RTS
;get a key w/OPTION
GAKEY	LDA	CONSOL
	CMP	#6
	BNE	GCH
	PLA
	PLA
	LDA	#EOL
	STA	STRING
	LDA	#0
	STA	EDIT
	STA	SPFLG
	SEC
	RTS
GCH	LDA	CH
	CMP	#$FF
	BEQ	GAKEY
	JSR	GNKEY
	LDX	XPOS
	RTS
;input routine
INPUT	JSR	CLRSTR
INPUT2	LDA	#0
	STA	XPOS
INMAIN	JSR	DRWIN
	JSR	GAKEY
	LDX	XPOS
	LDY	EDIT	;edit mode?
	BNE	ENTS	;yes
	LDY	SPFLG	;comd mode?
	BNE	ENTS	;yes
	LDY	#4	;ck 4 eol &
IELP	CMP	ENKEY,Y	;cursor keys
	BEQ	INEN
	DEY
	BPL	IELP
	BMI	SESC
INEN	STA	CDIR
	CMP	#EOL
	BNE	INDON
	STY	CDIR
	JMP	INDON
ENTS	CMP	#EOL
	BNE	SESC
	JMP	INDON
SESC	CMP	#27	;ESC?
	BNE	INEXT
	JSR	GAKEY
	CMP	#EOL
	BEQ	INDON
	JMP	INOVR
INEXT	LDY	#12	;test special
IN1LP	CMP	INSPC,Y
	BEQ	INPRC
	DEY
	BPL	IN1LP
INOVR	STA	STRING,X
	INX
	STX	XPOS
	CPX	#114
	BCC	INMAIN
	DEX
	STX	XPOS
	BNE	INMAIN
;
INPRC	LDA	INTABL,Y
	STA	INJSR+1
	LDA	INTABH,Y
	STA	INJSR+2
INJSR	JSR	$FFFF
	JMP	INMAIN
;
INDON	LDY	#114
INOUT	DEY
	LDA	STRING,Y
	CMP	#$20
	BEQ	INOUT
	LDA	#EOL
	INY
	STA	STRING,Y
	STY	STR
	LDA	#0
	STA	EDIT
	CLC
	RTS
;kill input
ZAPST	JSR	CLRSTR
	LDA	#0
	STA	XPOS
	RTS
;del char
INDEL	LDX	XPOS
	BEQ	INDO
	DEX
	LDA	#$20
	STA	STRING,X
	STX	XPOS
INDO	RTS
;input left
INLEFT	LDX	XPOS
	BEQ	INDO
	DEX
	STX	XPOS
	RTS
;input rt
INRT	LDX	XPOS
	CPX	#113
	BCS	INDO
	INX
	STX	XPOS
	RTS
;cntrol-del
INCTDL	LDX	XPOS
INCTD	LDA	STRING+1,X
	STA	STRING,X
	INX
	CPX	#$7A
	BNE	INCTD
	RTS
;cntrol-ins
ININS	LDX	#$7A
ININD	LDA	STRING,X
	STA	STRING+1,X
	DEX
	CPX	XPOS
	BPL	ININD
	INX
	LDA	#$20
	STA	STRING,X
	STA	STRING+114
	RTS
;inout up
INUP	LDA	XPOS
	SEC
	SBC	#38
	BPL	INST
	CLC
	ADC	#114
INST	STA	XPOS
	RTS
;inp dwn
INDWN	LDA	XPOS
	CLC
	ADC	#38
	CMP	#114
	BCC	INST
	SEC
	SBC	#114
	JMP	INST
;xpos to strt of line
INMOD	LDX	#0
	LDA	XPOS
	CMP	#38
	BCC	INMD
	LDX	#38
	CMP	#76
	BCC	INMD
	LDX	#76
INMD	STX	XPOS
	RTS
;insert line
ININLN	JSR	INMOD
	LDA	#37
	STA	TM3
INLNL	JSR	ININS
	DEC	TM3
	BPL	INLNL
	RTS
;del a line
INDLLN	JSR	INMOD
	LDA	#37
	STA	TM3
INLND	JSR	INCTDL
	DEC	TM3
	BPL	INLND
	RTS
;command mode
COMMODE	LDA	#4
	STA	DLIC+1
	LDA	#1
	STA	SPFLG
	JSR	INPUT
	BCS	CMOUT
	JSR	LO2UP
CMAOK	LDX	#0	;Command #
	LDA	#<CMTAB
	STA	L
	LDA	#>CMTAB
	STA	L+1
CMBG	LDY	#0
CMST	LDA	(L),Y
	BEQ	COMMODE
	CMP	STRING,Y
	BNE	CU3
	INY
	CPY	#3
	BNE	CMST
;
	LDA	COML,X
	STA	CMJP+1
	LDA	COMH,X
	STA	CMJP+2
	JSR	CLRTXT
CMJP	JSR	$FFFF
CMOUT	LDA	#0
	STA	DLIC+1
	STA	SPFLG
	JMP	BFLP
;
CU3	INX
	LDA	L
	CLC
	ADC	#3
	STA	L
	BCC	CMBG
	INC	L+1
	BNE	CMBG
;show col/row
SHWCRI	LDA	SCOL
	LDX	#0
XGZ	SEC
	SBC	#26
	BMI	XGY
	INX
	BNE	XGZ
XGY	PHA
	TXA
	CLC
	ADC	#$A1
	STA	SCMEM+19
	PLA
	CLC
	ADC	#$BB
	STA	SCMEM+20
	LDX	SROW
	INX
	TXA
	LDX	#0
XGU	SEC
	SBC	#10
	BMI	XGV
	INX
	BNE	XGU
XGV	PHA
	TXA
	CLC
	ADC	#$90
	STA	SCMEM+21
	PLA
	CLC
	ADC	#$9A
	STA	SCMEM+22
	RTS
;print sheet
PRNT	JSR	CLRTXT
	LDA	#'P
	STA	FNAME
	LDA	#':
	STA	FNAME+1
	LDA	#EOL
	STA	FNAME+2
	LDA	#>PRITMS
	LDX	#<PRITMS
PRNTIT	LDY	#0
	STY	CPOS	;curs. index
	JSR	PRNTTW
	JSR	PRMS1
	JSR	STCRS
	JSR	PRMS2
	JSR	STCRS
	LDA	COLF
	STA	TM	;1st col
	LDA	COLS
	SEC		;chk cell range
	SBC	COLF
	BMI	PERRR
	LDA	ROWS
	SEC
	SBC	ROWF
	BPL	PROK
PERRR	LDY	#141	;range err
PERRA	JSR	DSKERR
	JMP	HM3
;open #2 P:
PROK		CLOSE 2
	LDX	#$20
	LDA	#3
	STA	ICCOM,X
	LDA	#>FNAME
	STA	ICBAH,X
	LDA	#<FNAME
	STA	ICBAL,X
	LDA	#0
	STA	AUX2,X
	LDA	#8
	STA	AUX1,X
	JSR	CIOV
	BMI	PERRA
PXD	LDX	TM	;curr col
	LDA	COLW,X	;get width
	STA	GMX
	LDA	ROWF
	JSR	LOCCEL
	BCS	CMTE	;empty
	LDY	#1
	LDA	(LL),Y
	STA	FORMAT
	LDY	#3
	LDA	(LL),Y
	BPL	PXF
	JMP	ISERR	;error
PXF	AND	#3
	BEQ	PXA	;text
	JMP	ITSAN	;#/F
PXA	LDY	#2
	LDA	(LL),Y
	TAY
	JSR	ADDDT	;up 4
	LDA	#EOL
	STA	STRING,Y
PXC	DEY
	BMI	PXB
	LDA	(LL),Y
	STA	STRING,Y
	JMP	PXC
PXB	LDA	#<STRING
	STA	IL
	LDA	#>STRING
	STA	IL+1
	JSR	FRMTXT
PXE	JSR	SNDOUT
	INC	TM	;do nxt col
	LDA	TM
	CMP	COLS
	BEQ	PXD
	BCC	PXD
	LDA	COLF
	STA	TM
	JSR	SNDEOL	;snd eol
	INC	ROWF	;next row
	LDA	ROWF
	CMP	ROWS
	BEQ	PXD
	BCC	PXD
		CLOSE 2
	RTS		;done
;send out blanks
CMTE	JSR	SPLBF
	JMP	PXE
;line feed
SNDEOL	LDA	#11
	LDX	#$20
	STA	ICCOM,X
	LDA	#0
	STA	ICBLL,X
	STA	ICBLH,X
	LDA	#$9B
	JSR	CIOV
	BMI	LSERR
	RTS
;send out cell
SNDOUT	LDA	#11
	LDX	#$20
	STA	ICCOM,X
	LDA	GMX
	STA	ICBLL,X
	LDA	#0
	STA	ICBLH,X
	LDA	#>LBUF
	STA	ICBAH,X
	LDA	#<LBUF
	STA	ICBAL,X
	JSR	CIOV
	BMI	LSERR
	RTS
;list/prnt err
LSERR	PLA
	PLA
	JMP	GENER
;space out lbuf
SPLBF	LDX	#$7F
	LDA	#$20
SL9	STA	LBUF,X
	DEX
	BPL	SL9
	RTS
;err in cell
ISERR	JSR	SPLBF
	LDY	#4
ISA	LDA	CERR,Y
	STA	LBUF,Y
	DEY
	BPL	ISA
	JMP	PXE
;its a # or F
ITSAN	CMP	#1
	BNE	ITSAF
	JSR	ADDDT
	LDX	LL
	LDY	LL+1	;???
ITSG	JSR	FLD0R
	JSR	FASC
	JSR	FRMNUM
	JMP	PXE
;must be a F
ITSAF	LDY	#2
	LDA	(LL),Y
	TAY
	JSR	ADDDT
	TYA
	SEC
	SBC	#6
	CLC
	ADC	LL
	TAX
	LDA	LL+1
	ADC	#0
	TAY
	JMP	ITSG
;list to disk
LIST	JSR	ST2BF1
	JSR	FINARG
	JSR	GTFILE
	JSR	CHKDEV
	BCC	LDOK
	JMP	DEVERR
LDOK	JSR	FILEXST
	BCC	FILOK
	JMP	HOME
FILOK	JSR	CLRTXT
	LDA	#>LSMES
	LDX	#<LSMES
	JMP	PRNTIT
;copy & move
;cmflg 0=cpy 1=mov
;copy a block verbatim
COPY	JSR	CLRTXT
	LDA	#>CPYMES
	LDX	#<CPYMES
	LDY	#0
	STY	CMFLG
JMCPY	STY	CPOS
	JSR	PRNTTW
	JSR	PRMS1
	JSR	STCRS
	JSR	PRMS2
	JSR	STCRS
	JSR	PRMS3
	JSR	STCRS
;chk for block errs
	LDA	COLS
	CMP	COLF
	BCS	CLOK
CSER	JMP	PERRR
CLOK	LDA	ROWS
	CMP	ROWF
	BCC	CSER
;chk if dest = corners
	LDA	COLT
	CMP	COLF
	BNE	LOWR
	LDA	ROWT
	CMP	ROWF
	BEQ	CSER
LOWR	LDA	COLT
	CMP	COLS
	BNE	CKOK
	LDA	ROWT
	CMP	ROWS
	BEQ	CSER
;set cntrs
CKOK	LDA	COLS
	SEC
	SBC	COLF
	STA	DM4
	STA	DM2
	LDA	ROWS
	SEC
	SBC	ROWF
	STA	DM5
;offsets
	SEC
	LDA	COLT
	SBC	COLF
	STA	COFST
	SEC
	LDA	ROWT
	SBC	ROWF
	STA	ROFST
	JSR	CHKFSD	;A =typ inc
	ASL	A
	TAX
	LDA	INCTAB,X
	STA	INCRES+1
	LDA	INCTAB+1,X
	STA	INCRES+2
	JSR	IVCRS
CPY1	LDA	COLF
	STA	DM6
	LDA	COLT
	STA	DM7
CPY5	LDA	ROWT	;dest
	JSR	STRAD	;get add
CPY2	LDY	#0	;see if MT
	LDA	(LL),Y
	CMP	#$FF	;MT
	BEQ	NOEN
	CMP	DM7	;col?
	BEQ	FUL
	BCS	NOEN
	JSR	UP1COL
	JMP	CPY2
FUL	LDX	DM7
	LDA	ROWT
	JSR	DELTCL
NOEN	LDA	LL
	STA	IL
	LDA	LL+1
	STA	IL+1
	LDA	ROWF
	JSR	STRAD
CPY3	LDY	#0	;chk source
	LDA	(LL),Y
	CMP	#$FF
	BEQ	INCRES	;no cell
	CMP	DM6	;col?
	BEQ	GT1
	BCS	INCRES	;no cell
	JSR	UP1COL
	JMP	CPY3
;move cell to bf1
GT1	LDA	#>BF1
	STA	JL+1
	LDA	#<BF1
	STA	JL
	LDY	#2
	LDA	(LL),Y
	CLC
	ADC	#DTLEN
	TAY
	DEY
	STA	LENG	;4 move
	STY	GMX
CPY4	LDA	(LL),Y
	STA	(JL),Y
	DEY
	CPY	#$FF
	BNE	CPY4
	LDA	DM7	;new col #
	STA	BF1
	LDA	IL
	STA	LL
	LDA	IL+1
	STA	LL+1
	LDA	CMFLG
	BEQ	NOCHG
	JSR	MVPARS
NOCHG	LDY	GMX
	INY
	STY	LENG
	JSR	MOVUP
	LDA	ROWT
	JSR	UPRAD
	LDY	GMX
CPY6	LDA	(JL),Y
	STA	(IL),Y
	DEY
	CPY	#$FF
	BNE	CPY6
INCRES	JSR	$FFFF
	BCS	CFIN
	JMP	CPY5
CFIN	JSR	RECALC
	JSR	REFSCR
	JSR	IVCRS
	CLC
	RTS
;increase ptr routs
RTDN	INC	DM7
	INC	DM6	;next col
	DEC	DM4
	LDA	DM4
	CMP	#$FF
	BNE	RBX
RBZ	INC	ROWT	;next row
	INC	ROWF
RRR	DEC	DM5
	LDA	DM5
	CMP	#$FF
	BNE	RBY
	SEC		;done
	RTS
RBY	LDA	COLF
	STA	DM6
	LDA	COLT
	STA	DM7
	LDA	DM2
	STA	DM4
RBX	CLC
	RTS		;keep going
;
RTUP	INC	DM7
	INC	DM6
	DEC	DM4
	LDA	DM4
	CMP	#$FF
	BNE	RBX
	DEC	ROWT
	DEC	ROWF
	JMP	RRR
;
LFDN	DEC	DM7
	DEC	DM6
	DEC	DM4
	LDA	DM4
	CMP	#$FF
	BNE	RBX
	BEQ	RBZ
;check source,end &dest. cell
;if in sheet
CHKFSD	LDA	ROWT
	CMP	ROWF
	BNE	TBFH
	LDA	COLT	;A,E
	CMP	COLF
	BNE	VAE
VER	PLA		;error
	PLA
	JMP	PERRR
VAE	BCC	VEE	;E
	LDA	COLS	;A
	SEC
	SBC	COLF
	CLC
	ADC	COLT
	STA	COLT
	CMP	#64	;0-63
	BCS	VER
	LDA	COLS	;switch
	PHA
	LDA	COLF
	STA	COLS
	PLA
	STA	COLF
	LDA	#1	;lfdn
	CLC
	RTS
VEE	LDA	#0	;rtdn
	CLC
	RTS
TBFH	BCC	VEE
	LDA	ROWS
	SEC
	SBC	ROWF
	CLC
	ADC	ROWT
	STA	ROWT
	CMP	#64
	BCS	VER
	LDA	ROWS	;switch
	PHA
	LDA	ROWF
	STA	ROWS
	PLA
	STA	ROWF
	LDA	#2	;rtup
	CLC
	RTS
;
INCTAB	.WORD	RTDN
	.WORD	LFDN
	.WORD	RTUP
;prn ms3
PRMS3	LDA	#2
	STA	ASAV
	LDA	#>CMES3
	LDX	#<CMES3
	LDY	#3
	JMP	PRMA
;move block
MOVEB	JSR	CLRTXT
	LDA	#1
	STA	ASAV
	STA	CMFLG
	LDA	#>MOVMES
	LDX	#<MOVMES
	LDY	#0
	JMP	JMCPY	;jmp in2 cpy
;reassign cell values
;if error = changed to eol
;dm0,dm1 used
MVPARS	LDY	#4
	LDA	BF1,Y
	CMP	#'=
	BEQ	JAA
JAB	RTS		;quit
JAA	INY
	CPY	GMX	;max len
	BCS	JAB	;end!
	LDA	BF1,Y
	CMP	#'D
	BCS	JAA	;nxt
	CMP	#'A
	BCC	JAA
	STY	Y9	;get cell
	JSR	GTCLRW
	BCC	JAC
JAD	LDY	Y9
	BNE	JAA
JAC	LDA	COLNU
	CLC
	ADC	COFST	;col offset
	STA	COLNU
	CMP	#64
	BCS	JAB	;err
	LDA	ROWNU
	CLC
	ADC	ROFST	;row offset
	STA	ROWNU
	CMP	#64
	BCS	JAD	;err
	LDY	Y9
;now change'm
	LDX	#2
	LDA	COLNU
JAE	CMP	N26,X
	BCS	JAF
	DEX
	BPL	JAE
JAF	PHA
	LDA	AS26,X
	STA	BF1,Y
	PLA
	SEC
	SBC	N26,X
	CLC
	ADC	#65
	INY
	STA	BF1,Y
	INC	ROWNU
	LDA	ROWNU
	LDX	#9
JAH	CMP	DECM,X
	BCS	JAG
	DEX
	BPL	JAH
JAG	PHA
	LDA	DECN,X
	INY
	STA	BF1,Y
	PLA
	SEC
	SBC	DECM,X
	TAX
	LDA	DECN,X
	INY
	STA	BF1,Y
	JMP	JAA
;recalc 
RECALC	LDA	#0
	STA	ROWNU
	STA	COLNU
	LDA	RCFLG
	BNE	BYC
;by rows
IG	JSR	RARITH
	INC	COLNU
	LDA	COLNU
	CMP	#64
	BCC	IG
	LDA	#0
	STA	COLNU
	INC	ROWNU
	LDA	ROWNU
	CMP	#64
	BCC	IG
BYR	JSR	REFSCR
	JMP	IVCRS
;by cols
BYC	JSR	RARITH
	INC	ROWNU
	LDA	ROWNU
	CMP	#64
	BCC	BYC
	LDA	#0
	STA	ROWNU
	INC	COLNU
	LDA	COLNU
	CMP	#64
	BCC	BYC
	BCS	BYR	;done
;arith done here
RARITH	LDA	ROWNU
	LDX	COLNU
	STA	TA1
	STX	TA2
	JSR	LOCCE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BEQ	PR2
	STA	(L),Y
	INY
	BNE	PR1
PR2	RTS
;get RET/ESC
RETESC	JSR	GNKEY
	CMP	#$9B
	BNE	III
	CLC
	RTS
III	CMP	#$1B
	BNE	IIT
	SEC
	RTS
IIT	JSR	MVCRS	;move?
	JMP	RETESC
;stor crs pos
STCRS	LDX	CPOS
	LDA	SCOL
	STA	COLF,X
	LDA	SROW
	STA	ROWF,X
	INC	CPOS
	RTS
;print ms1
PRMS1	LDA	#>CMES1
	LDX	#<CMES1
	LDY	#1
PRMA	STY	YSAV	;line#
	JSR	PRNTTW
	JSR	RETESC
	BCS	EOUT
	RTS
EOUT	PLA		;exit
	PLA
	JSR	CLRTXT
	RTS
;prn ms2
PRMS2	LDA	#>CMES2
	LDX	#<CMES2
	LDY	#2
	JMP	PRMA	;cheat
;chk parmeters
;locat cell
;X=col A=row ll=loc
LOCCEL	STX	COLNU
	JSR	STRAD
FU	LDY	#0
	LDA	(LL),Y
	CMP	#$FF
	BEQ	FQE
	CMP	COLNU
	BEQ	FQF
	BCC	FQG
FQE	SEC
	RTS
FQG	JSR	UP1COL
	JMP	FU
FQF	CLC
	RTS

LISTING 7: ASSEMBLY

;SAVE#D:bcalc.pt6
;
Y40L	.DS	18
Y40H	.DS	18
TWINL	.BYTE	<TXTWIN
	.BYTE	<[TXTWIN+$28]
	.BYTE	<[TXTWIN+$50]
	.BYTE	<[TXTWIN+$78]
TWINH	.BYTE	>TXTWIN
	.BYTE	>[TXTWIN+$28]
	.BYTE	>[TXTWIN+$50]
	.BYTE	>[TXTWIN+$78]
CREDIT	.SBYTE	+$80," B-Calc (c)"
	.SBYTE	+$80," 1987   AA01  "
	.SBYTE	+$80," TYPE:        "
	.SBYTE	+$80," "
	.BYTE	EOL
CREDTF	.SBYTE	+$80," B-Calc by "
	.SBYTE	+$80,"Barry Kolbe & "
	.SBYTE	+$80,"Bryan Schappel"
	.SBYTE	+$80," "
	.BYTE	EOL
;input tables
INTABL	.BYTE	<ZAPST
	.BYTE	<INDEL
	.BYTE	<INCTDL
	.BYTE	<ININS
	.BYTE	<INUP
	.BYTE	<INDWN
	.BYTE	<INLEFT
	.BYTE	<INRT
	.BYTE	<ININLN
	.BYTE	<INDLLN
	.BYTE	<INDO
	.BYTE	<INDO
	.BYTE	<INDO
INTABH	.BYTE	>ZAPST
	.BYTE	>INDEL
	.BYTE	>INCTDL
	.BYTE	>ININS
	.BYTE	>INUP
	.BYTE	>INDWN
	.BYTE	>INLEFT
	.BYTE	>INRT
	.BYTE	>ININLN
	.BYTE	>INDLLN
	.BYTE	>INDO
	.BYTE	>INDO
	.BYTE	>INDO
;
INSPC	.BYTE	$7D,$7E,$FE,$FF
	.BYTE	$1C,$1D,$1E,$1F
	.BYTE	$9D,$9C,$7F,$9E
	.BYTE	$9F
;
;commnd mode tables
CMTAB	.BYTE	"DIR"
	.BYTE	"GOT"	;GOTO cell
	.BYTE	"SAV"	;SAVE Sheet
	.BYTE	"LOA"	;LOAD Sheet
	.BYTE	"SET"	;CROSS reference
	.BYTE	"WID"	;set col WIDTH
	.BYTE	"LIS"	;LIST to disk
	.BYTE	0
;
COML	.BYTE	<DIR,<GOTO
	.BYTE	<SAVE,<LOAD
	.BYTE	<SETREF,<WIDTH
	.BYTE	<LIST
;
COMH	.BYTE	>DIR,>GOTO
	.BYTE	>SAVE,>LOAD
	.BYTE	>SETREF,>WIDTH
	.BYTE	>LIST
;
SPCKEY	.BYTE	$1C,$1D,$1E,$1F
	.BYTE	$08,$14,$0B
	.BYTE	$04,$03,$0D
	.BYTE	$05,$06,$07
	.BYTE	$0F,$12,$10
	.BYTE	$01
;
SPECL	.BYTE	<CU,<CD,<CL,<CR
	.BYTE	<HOME,<FORCE
	.BYTE	<KILLCL,<DELETE
	.BYTE	<COPY,<MOVEB
	.BYTE	<EDITM,<FORMC
	.BYTE	<GLOBAL,<RONOF
	.BYTE	<RCFLP,<PRNT
	.BYTE	<ARECL
;
SPECH	.BYTE	>CU,>CD,>CL,>CR
	.BYTE	>HOME,>FORCE
	.BYTE	>KILLCL,>DELETE
	.BYTE	>COPY,>MOVEB
	.BYTE	>EDITM,>FORMC
	.BYTE	>GLOBAL,>RONOF
	.BYTE	>RCFLP,>PRNT
	.BYTE	>ARECL
SLKEY	.BYTE	$FF,$FE,$FD,$9F
	.BYTE	$9E,$9D,$9C,$9B
	.BYTE	$7F,$7E,$7D,$1F
	.BYTE	$1E,$1D,$1C,$1B
;
;Special Text
;
DIRTXT	.BYTE	"D1:*.*",EOL
FNAME	.BYTE	"D1:            ",EOL
ERMES	.SBYTE	"Error"
CERR	.BYTE	"Error"
DERM	.SBYTE	"Error:    Press a key"
;
STT	.SBYTE	"File:             "
	.SBYTE	"    Free:"
SEG	.SBYTE	"Recalc:OFF        "
	.SBYTE	"      by:ROW   "
;
ONOFM	.SBYTE	"OFFON "
RCMES	.SBYTE	"ROW   COLUMN"
ONF	.BYTE	0
RCFLG	.BYTE	0
CMFLG	.BYTE	0
KPY	.DS	1	;y sav
CPOS	.DS	1
Y9	.DS	1
;
TEXTYP	.SBYTE	"Text    "
NUMTYP	.SBYTE	"Number  "
FUNTYP	.SBYTE	"Function"
	.SBYTE	"        "
;
DELMS	.SBYTE	"DELETE: Position Cursor, RETURN",SEOL
CPYMES	.SBYTE	"COPY: Position Cursor, RETURN",SEOL
MOVMES	.SBYTE	"MOVE: Position Cursor, RETURN",SEOL
CMES1	.SBYTE	"Upper left of Block",SEOL
CMES2	.SBYTE	"Lower right of Block",SEOL
CMES3	.SBYTE	"Upper left of Dest.",SEOL
PRITMS	.SBYTE	"PRINT: Position Cursor, RETURN",SEOL
LSMES	.SBYTE	"LIST: Position Cursor, RETURN",SEOL
;
FMES	.SBYTE	"FORMAT   Justify L"
FMA	.SBYTE	"Dollar $(D) N"
FMB	.SBYTE	"Commas  (,) N"
FMC	.SBYTE	"Dec. places 0"
YN	.SBYTE	"NY"
LCR	.SBYTE	"LRC"
SDEC	.SBYTE	"0123456789"
;raw L,C,R
JSKEY	.BYTE	$00,$28,$12
REPMES	.SBYTE	"File exists, Replace? Y/N",SEOL
;raw 0-9
NKEY	.BYTE	$32,$1F,$1E,$1A
	.BYTE	$18,$1D,$1B,$33
	.BYTE	$35,$30
FCNT	.BYTE	0
TORITE	.BYTE	0
SETROW	.BYTE	0
SETCOL	.BYTE	0
CDIR	.BYTE	0	;cursor directn
ENKEY	.BYTE	EOL,$1C,$1D,$1E,$1F
EOM	.DS	2	;end of memry
FRCTXT	.BYTE	0
CRSEN	.DS	1
ENDAT	.DS	2
FXS	.DS	1
FXA	.DS	1
STLO	.DS	58
STHI	.DS	58
CTLCMD	.BYTE	$0B,$02,$14
AS26	.BYTE	"ABC"
N26	.BYTE	0,26,52
DECN	.BYTE	"0123456789"
DECM	.BYTE	0,10,20,30,40,50
	.BYTE	60,70,80,90
OPTAB	.BYTE	"^*/+-"
FPSTACK	.DS	6*58
ONE	.FLOAT	1
TWO	.FLOAT	2
HALF	.FLOAT	.5
REFTAB	.SBYTE	"AA"
	.SBYTE	"01"
AIT	.DS	256
SPFLG	.DS	1
COLW	.DS	64
FMCOL	.DS	64
RAD	.DS	$80	;row add tabl
RO1	.DS	$40	;row data