Printing VU-CALC On An 80 Column Printer

See all articles from CATS v3 n7
Author(s): Mark Fisher
Publication: CATS Newsletter
Pub Details: CATS v3 n7 (Volume 3, Issue 7)
Date: October 1985
Pages: 8

For both the 1000 & 2068

VU-CALC is an important part of the armory of software for the Timex owner. Unfortunately, the VU-CALC owner is restricted to printing one screenful at a time.

“80 column” printers offer the potential to print far more than the Timex’s 32 columns; in fact, they often offer a 132 column mode. Taking advantage of these printers requires understanding of the forms in which the spreadsheet is stored, and special programming to get the data out.

The programs below are designed to allow the user to print out any desired section of VU-CALC’s spreadsheet, while retaining the coordinate references. There is NO error trapping, and it is up to the user to ensure that his desired section of spreadsheet will fit on the printer. Good luck!

The 1000 VU-CALC

The 1000 does not easily handle unassigned data. Instead, the 1000 puts the spreadsheet into a one dimensional string, B$. The essence of a spreadsheet is in its arrangement as an array in two dimensions, and B$ is chopped up in a regular way to yield those dimensions. B$ is divided into two parts: B$(1 TO 8424) holds the contents of the 936 cells with nine bytes per cell, and B$(8425 TO 9824) holds the formulas, at 35 bytes per formula.

The array data is arranged in the following manner. B$(1 TO 9) holds the contents of cell A1. The first byte holds the reference number to any associated formula. This number can be set to a specific formula number “n” (for n=0 to 40) by LET B$(1)= CHR$ n. The next eight bytes, B$(2 TO 9), hold the datum you see on the screen in cell A1. The following nine bytes hold the next cell’s information–but this cell is B1, the cell below A1. The first column of cells are stored in order, then the next, and so forth, for 36 columns.

Formulas are held one after the next in the second part of B$. Each formula is allowed 32 bytes, followed by three bytes of CHR$ 255 as a divider. Absolute formulas are easy to read, but relative formulas yield only garbage on casual inspection.

To look at a particular cell, we will have to resort to some simple algebra. If we had an array of boxes, numbered like this:

1 4 7
2 5 8
3 6 9

and we wanted to reach a particular box, given its row and column number, we could use this formula:

cell# = (column - 1) * 3 + row

In the case of VU-CALC 1000, the array is 36 wide and 26 tall, and the corresponding formula is:

cell# = (column - 1) * 26 + row

To account for the fact that each cell occupies nine bytes, the formula becomes:

cell# = (column - 1) * 26 * 9 + (row - 1) * 9

This program returns cell# 0 for row 1, column 1; we need to add a constant of two to move our focus to cell# 2. We might as well combine the 26 and 9, as well:

cell# = (column - 1) * 234 + (row - 1) * 9 + 2

New program lines can be added to use the above formula and string slicing to rearrange the elements of B$ into the tabular form the reader expects.

9500~PRINT "PRINT TABLE UTILITY"
9510 PRINT "START COL ";
9520 INPUT SC
9530 PRINT SC,,"END COL ";
9540 INPUT EC
9550 PRINT EC,,"START ROW ";
9560 INPUT S$
9570 PRINT S$,,"END ROW ";
9580 INPUT E$
9590 PRINT E$
9600 LPRINT "PRINTER CODE HERE"
9610 REM COLUMN HDGS
9620 DIM T$(9)
9630 FOR C=SC TO EC
9640 LET T$=" "+STR$ C
9650 LPRINT T$;
9660 NEXT C
9670 LPRINT
9680 LPRINT
9690 FOR R=CODE S$-37 TO CODE E$-37
9700 LPRINT CHR$ (R+37);" ";
9710 FOR C=SC TO EC
9720 LET X=(C-1)*234+(R-1)*9+2
9730 LPRINT B$(X TO X+7)+" ";
9740 NEXT C
9750 LPRINT
9760 NEXT R

And One Little Catch….

Well, two. A) There is no extra room to add progamming lines to the 16K machine. B) If you have a larger memory, VU-CALC will crash if the BASIC code changes length by one byte.

Solutions:

A) Either get additional memory, or delete enough BASIC to make room for the new code. A quick way to make room is to SAVE VU-CALC, then delete the m/c lines, and type the printer driving code in.

B.1) If you delete the m/c as in A), you need not fear crashing the program, since it is crippled anyway. As you will have to type in the driver code each time you want to LPRINT an updated spreadsheet, you will probably leave out the “user friendly” lines. That would mean typing in only 9690, and 9710 through 60: and using immediate commands to set up the variables. It will still be faster than pasting all those little bits of thermal paper together.

B.2) If you have more than 16K RAM, you may either: add this code before you set up the spreadsheet; or use one of the transfer utilities (such as FASTLOAD or ZXLR-8) to move B$ to a safe cassette while you add the driver code. You can make it operate as a unified part of the program by changing the COPY in line 5030 to GOSUB 9500, and adding a RETURN line at the end. If you then use the “START VU-CALC” option, the m/c will know where the array is held, and you can reload your spreadsheet.

VU-CALC ON THE 2068

The 2068 has the ability to easily load information above RAMTOP, and VU-CALC puts both the m/c and the data there. The array is also ordered differently; in horizontal ranks, with cell# A2 following A1 in memory.

Putting the data above RAMTOP means that we can’t easily use string slicing to LPRINT the results. The net result is more detail programming to get the same output. On the other hand, VU-CALC on the 2068 has better than 1500 bytes of BASIC program space available, and the 80 column routine is easily integrated into the program by changing the first statement in line 2000 from COPY to GOSUB 9600. The 80 column routine will work, too–there’s plenty of room for a printer driver above the spreadsheet.

Doing the job

The spreadsheet is held as DATA at 34553, with a length of 20277 bytes. The first 20 bytes are some kind of system variables; thus the array starts at 34573. The array consists of 50 rows of 350 bytes each. The remaining 2758 bytes hold the formulas, in an unknown form (anyone want to do an article?).

To start on a given row, then, the row count is multiplied by 350, in the same way the column count was multiplied by 234 on the 1000. To start on a given column, that base value derived from the row count is added to the column count times the seven bytes per cell.

The complexities mainily came from trying to count using the alphabet as base 26. My answers to these problems, in lines 9650, 9670, and 9765 aren’t elegant, but they’re workable kludges. Other oddball lines include 9790, where I’m reducing the PEEKed address modulo 7 to provide spaces between the columns, and the various lines that use t$ to provide regular spacing; TAB sometimes doesn’t work with 80 column printers.

9600>POKE 23658,8:CLS :PRINT ''"80 Col. Printer Driver"
9610 INPUT "Start col: ";sc
9620 PRINT "Starting Col. = ";sc
9630 INPUT "End col: ";ec
9640 PRINT "Ending Col. = ";ec
9650 LET s=0: INPUT "Start row: ";s$: LET s=CODE s$(LEN s$)-64+(26*(LEN s$=2))
9660 PRINT "Starting Row = ";s$
9670 LET e=0: INPUT "End row: ";e$: LET e=CODE e$(LEN e$)-64+(26*(LEN e$=2))
9680 PRINT "Ending Row = ";e$: POKE 23658,0
9690 REM ** Set up printer **
9700 REM Col headings
9710 LPRINT " ": DIM t$(8): FOR x=sc TO ec
9720 LET t$=" "+STR$ x: LPRINT t$;
9730 NEXT x: DIM t$(3)
9740 LPRINT
9750 LET base=34573+(s-1)*350
9760 FOR r=base TO base+(e-s)*350 STEP 350
9765 LET t$=s$: LPRINT t$;: LET S$(LEN S$)=CHR$ (CODE S$(LEN S$)+1): IF CODE S$=91 THEN LET S$="AA"
9770 FOR x=(sc-1)*7+r TO (ec-sc+1)*7+r
9780 LPRINT CHR$ PEEK x;
9790 IF (x-34572)/7=INT ((x-34572)/7) THEN LPRINT " ";
9800 NEXT x
9810 LPRINT
9820 NEXT r
9830 RETURN

(An alternate method for doing the whole job would be to SAVE off the array, and LOAD the code into a dimensioned A$(20277), using:

LOAD "" CODE ( PEEK 23627+256* PEEK 23628+6)

Then use string slicing as before to print out the results.)

Using the program (1000 or 2068)

There is one line that I haven’t specified. That is the line that contains the specific commands to prepare your printer to print the spreadsheet. I use compressed mode, and emphasized.

The “minimum version” (1000 only)

If you are planning to type in the minimum program when you need it, you will have to set up the parameters (sc, ec, s$, e$) in immediate commands, then use goto 9500 to start the routine. As with the “full version”, calling for too many columns won’t destroy anything. If you are planning to continue calculations at the same session, don’t forget to remove the routine completely, or the program will crash when you attempt to “CONTINUE VU-CALC”

The “full version”

Once the patch has been added, and you are working on a spreadsheet, just use the “print” command from within the spreadsheet. When the full version is called, prompts will appear on the screen, asking for the limits of the spreadsheet that you want printed. It is up to to you to choose limits that will fit on the printer – though nothing serious will happen if you’re too wide. The RETURN at the end should return you to the section of the sheet you were working on.

May your exploration of the data be fruitful!

MF

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.