!lm10
!rm76
Screen Printer

Last month I alluded to my trouble in getting a screen printing subroutine to work with the Apple Parallel Interface.  I finally got it going, and now it doesn7t look hard at all.

The program is set up to be loaded and started with a BRUN command.  This doesn't start any printing, however.  The initial code just puts a hook address into location $38 and $39, and passes them to DOS.  Henceforth, all character-input calls will have to go through my routine at lines 1260-1320.

The SCRN.PRNT subroutine looks at each input character to see if it is a control-P (ascii code = $90).  If not, the character is passed on to whatever program tried to read a character.  If it is a control-P, the current contents of the screen are printed.

(My printer is in slot 1; if you are using a different slot, change lines 1110 and 1120.)

The actual printing subroutine is really straightforward.  It consists of four parts:  1) save current registers and cursor position; 2) initialize Apple Parallel Interface temporaries; 3) print each line of the screen on the printer; and 4) restore the cursor position and registers.

Lines 1350-1410 save the A-, X-, and Y-registers on the stack, followed by the cursor horizontal position.  I pushed them on the stack rather than allocate temporaries, but either way will work.  Using the stack saves a few bytes of code and 4 bytes of temporary memory, but it takes a few more cycles if you are worried about speed.

Lines 1420-1490 initialize the temporaries used by the code in Apple's Parallel Interface ROM.  These temporaries are actually inside the screen buffer memory (between $0400 and $07FF), but they are in bytes that do not get displayed.  (There are 64 bytes in the screen buffer that do not get displayed, and which are used by interface cards for temporary memory.  These are $478-47F, $4F8-4FF, $578-57F, $5F8-5FF, $678-67F, $6F8-6FF, $778-77F, and $7F8-7FF.)  For more information on how the Parallel Interface uses these temporaries, see your manual.

Lines 1500-1670 actually print the screen contents.  The X-register is used as a line counter, and runs from 0 to 23.  See lines 1500, 1510, and 1650-1670.  This is quite analogous to a BASIC statement like FOR I=0 TO 23.

Inside the X-loop, line 1520 computes a new base address for the current line.  Then the Y-register is used as a column counter.  Lines 1530 and 1600-1620 control the Y-loop.  Inside the Y-loop, each character of the line is picked up in turn.  Lines 1550-1580 convert inverse or flashing characters to normal ASCII codes for printing.  Line 1590 calls on the Parallel Interface program to print one character.  (The entry at $Cx02 assumes all temporaries are already set up.)  At the end of each line, lines 1630 and 1640 send a carriage return to the printer.

Lines 1680-1700 restore the cursor position and base address pointer, and lines 1710-1750 restore the 6502 registers.

I wrote this program, lines 1340-1760, as a subroutine even though it could have been in-line.  I did it so that you can call it directly from your Applesoft or Integer BASIC program, with a "CALL 793".  This feature makes the very-valuable screen printer even more useful.
