Some Fast Screen Tricks....................Bob Sander-Cederlof

Sometimes the standard Apple Monitor screen functions are too slow.  No reflection on Steve Wozniak, because he wrote them to be general and compact rather than quick.

I am thinking particular of the screen clear (HOME to Applesoft users) and the screen scroll subroutines.  They were both written to operate on a text window, not necessarily the whole screen.  But most of the time you do want to clear or scroll the whole screen.

The primary text screen memory is mapped into the addresses from $400 through $7FF, but not in an obvious or straightforward way.  This table shows the actual memory addresses for each screen line:

!lm+5
Line Addresses     Line Addresses     Line Addresses
  0  $400-$427       8  $428-$44F      16  $450-$477
  1  $480-$4A7       9  $4A8-$4CF      17  $4D0-$4F7
  2  $500-$527      10  $528-$54F      18  $550-$577
  3  $580-$5A7      11  $5A8-$5CF      19  $5D0-$5F7
  4  $600-$627      12  $628-$64F      20  $650-$677
  5  $680-$6A7      13  $6A8-$6CF      21  $6D0-$6F7
  6  $700-$727      14  $728-$74F      22  $750-$777
  7  $780-$6A7      15  $7A8-$7CF      23  $7D0-$7F7
!lm-5

Note that 120 consecutive bytes are used for three text lines spaced at an 8-line interval.  Then 8 bytes are not used.  Then the next 120, and so on.  Those 8 sets of 8 bytes that are not used by the screen mapping are used by peripheral cards and DOS for temporary storage.  In the standard Apple Monitor subroutines, a subroutine named BASCALC at $FBC1 calculates the starting address for a specified line.  Then the various screen functions use that address, which is kept up-to-date in BASL,BASH ($28,29).

In the listing that follows, I have included fast subroutines to clear the entire text screen (CLEAR); to set the entire text screen to whatever character is in the A-register (SET); to clear the entire Lo-Res Graphics screen (GCLEAR); and to scroll the entire text screen up one line.  For demonstration purposes, I also wrote routines to set the entire screen to each value from $00 through $FF; to alternate the screen between solid black and solid white until a key is pressed; to scroll end-around, placing the old top line on the bottom of the screen while moving the rest of the lines up; and to continuously scroll end-around until a key is pressed.

For comparison, I counted that the Wozniak's screen clear takes 15537 microseconds; mine takes only 5410 microseconds.  The fastest possible would be one LDA #$A0 followed by 960 "STA $xxx" and an RTS; that would take 3848 microseconds.  (All these times round off the Apple's cycle time to one microsecond; actually it is a little faster.)
