'===========================================================================
' Subject: COPY TEXT SCREEN                   Date: 04-16-00 (19:29)       
'  Author: Jerry Fielden                      Code: PB                     
'  Origin: fielden@pldi.net                 Packet: PB.ABC
'===========================================================================
'------------------------------------------------------------------|
' Author: Jerry Fielden                            Date: 1992      |
'                                                                  |
'------------------------------------------------------------------|
'  Textgetz copy portions of the text screen and Textputz will     |
'  paste it back in the same or different locations.               |
'------------------------------------------------------------------|

DECLARE SUB textputz (r1%, c1%, r2%, c2%, Area$())
DECLARE SUB textgetz (r1%, c1%, r2%, c2%, sa$())
DECLARE SUB SaveToFile (Area$(), TotalChar%, FileNames$)
DECLARE SUB LoadFmFile (Wide%, Tall%, Area$(),  FileNames$)
DECLARE SUB MakeBox ()
DIM Area$(4000)
OPTION BINARY BASE 1

 MakeBox             '.....................Call the box maker

 DELAY 1

 R1% = 1             '......................Starting row
 C1% = 1             '......................Starting column
 r2% = 6             '......................Ending row
 c2% = 16             '.....................Ending column

 TextGetz R1%, C1%, R2%, C2%, Area$()      'put it in arrays

 TextPutz 1, 34, 6, 49, Area$()       'put it at top middle of screen
 delay .5

'--------------- Put it into a file and load it back --------------

 Wide% = 32                                        ' Columns + Color attributes.
 Tall% = 6                                         ' Number of rows
 TotalChar% = Wide% * Tall%

 FileNames$ = "box6-32.BNY"                        ' Give it a name
 SaveToFile Area$(), TotalChar%, FileNames$        ' Save it
 ERASE Area$                                       ' Clear ARRAY

 LoadFmFile Wide%, Tall%, Area$(), FileNames$      ' Load it back

'---------------------- Paste it at the bottom of screen -------------

 TextPutz 20, 34, 25, 49, Area$()
 DELAY .5

'---------------------------- Move it around -------------------------
 C1% = 1 : c2% = 16
 FOR R1% = 1 TO 24 STEP 6
     r2% = r1% + 5
     TextPutz R1%, C1%, R2%, C2%, Area$()
     C1% = C1% + 17
     c2% = c2% + 17
      DELAY .2
 NEXT R1%

 DELAY 2


 '--- Copying Full Screen, saving it to a file and loading it back ----------

 TextGetz 1, 1, 25, 80, Area$()                ' Copy full screen
 FileNames$ = "Ful25-80.BNY"                   ' Give it a name
 Tall% = 25 : Wide% = 160                      ' Give its some size
 TotalChar% = 4000                             ' Number of chars + Attributes
 SaveToFile Area$(), TotalChar%, FileNames$    ' Save it to file
 COLOR 7, 0

 ERASE Area$ : CLS                     '...............Clear Arrays & screen
 LOCATE 12, 1
 PRINT "            Loading Full Screen from File and here it is "
 delay 3
 LoadFmFile Wide%, Tall%, Area$(),  FileNames$          ' Load it back
 TextPutz 1, 1, 25, 80, Area$()                         ' Put it on Screen
 delay 5
 COLOR 7, 0
 CLS
 KILL "Ful25-80.BNY"
 KILL "box6-32.bny" '.........Get rid of files



  '---------------------------------------------------------------------
  ' TextGetz will copy any portion of the screen, even full |
  ' screen, into Arrays which can be Saved to a Binary      |
  ' File in sequential order for later use.                 |
  '----------------------------------------------------------

 SUB textgetz (r1%, c1%, r2%, c2%, Area$())
     DEF SEG = &HB800
     ERASE Area$
     DECR r1%
     colx% = (c2% - c1% + 1) * 2
     col1% = (c1% * 2) + (r1% * 160) - 2
     ro% = r2% - r1%
     FOR x = 1 TO ro%
    	Area$(x) = peek$(col1%, colx%)
    	INCR col1%, 160
     NEXT x

END SUB


  '---------------------------------------------------------------------
  ' TextPutz will put screen portions back  to different     |
  ' locations. Portions can be obtained by using TextGetz or |
  ' LoadFmFile SUBs.
  '-----------------------------------------------------------

 SUB textputz (r1%, c1%, r2%, c2%, Area$())
     DEF SEG = &HB800
     DECR r1%: DECR c1%
     col1% = (c1% * 2) + (r1% * 160)
     ro% = r2% - r1%
     FOR x = 1 TO ro% + 1
       POKE$  col1%, Area$(x)
       INCR col1%, 160
     NEXT x

 END SUB



'----------------------------------------------------------------------
' SaveToFile saves Full Screen or portions that    |
' was acquired by TextGetz to a binary file which  |
' is also compatible with DOS POKE$ statements     |
'---------------------------------------------------

SUB SaveToFile (Area$(), TotalChar%, FileNames$)
 OPEN FileNames$ FOR BINARY AS #1               '....Put it in a file
   FOR x = 1 TO TotalChar%
     PUT$ #1, Area$(x)                  '...........Save 1 char of area
   NEXT x                                '..........Do it again
 CLOSE #1
END SUB


'---------------------------------------------------------------------
' LoadFmFile will Load a binary file into ARRAYs       |
' that can be used BY TextPutz to put on the screen.   |
'-------------------------------------------------------

 SUB LoadFmFile (Wide%, Tall%, Area$(),  FileNames$)
  OPEN FileNames$ FOR BINARY AS #1
    FOR x = 1 TO Tall%
      GET$ #1, Wide%, Area$(x)              '...........get some chars
    NEXT x                             '................Go Do it again
  CLOSE #1
 END SUB

'----------------------------------------------------------
SUB MakeBox()
  COLOR 1, 11
  FOR r% = 1 TO 25                    'fill screen with chars .
    FOR c% = 1 TO 80
        PRINT CHR$(176);
    NEXT c%
  NEXT r%

   COLOR 14, 1 : LOCATE 1, 1                               'make a box
   PRINT CHR$(201);
   FOR x = 1 TO 14 : PRINT CHR$(205); : NEXT x
   PRINT CHR$(187)

   PRINT CHR$(186) + "  This is an  " + CHR$(186)
   PRINT CHR$(186) + "  Example of  " + CHR$(186)
   COLOR 11, 4
   PRINT CHR$(186) + " Screen parts " + CHR$(186)
   PRINT CHR$(186) + " Copy & Save  " + CHR$(186)
   PRINT CHR$(200);
   FOR x = 1 TO 14 : PRINT CHR$(205); : NEXT x
   PRINT CHR$(188)

 END SUB
