'				SCRNSUBS.BOX
'				Version 1.0
'
'		Copyright(c) Borland International, 1987
'==============================================================================


DEFINT A-Z

' Shared variables for the screen routines.
'   Scrn.Mode        -  the screen mode
'   Scrn.Retrace     -  0 = chk video retrace in screen accesses, else don't
'   Scrn.Segment     -  &HB800 for CGA, &HB000 for monochrome
'
' Routines for directly accessing the screen:
'   ScrnInit : Initialization.  Determines screen mode, whether checking
'     for horizontal & vertical retrace is necessary, and determines
'     screen segment address.
'   SaveScreenArea(UpperLeftRow, UpperLeftCol, NumberOfRows, NumberOfCols, _
'     SaveText$, SaveAttr$) : Saves the contents of the screen.
'   WriteScreenArea(UpperLeftRow, UpperLeftCol, NumberOfRows, _
'     NumberOfCols, Text$, Attr$) : Writes to screen.



SUB ScrnInit
  '
  ' Initialization.  Determines screen mode, whether checking
  ' for horizontal & vertical retrace is necessary, and determines
  ' screen segment address.
  '
  SHARED Scrn.Mode, Scrn.Segment, Scrn.Retrace

  CALL GetVid(Scrn.Mode)             'Get screen mode.

  IF (Scrn.Mode < 7)         _
  THEN Scrn.Segment = &HB800 _
  ELSE Scrn.Segment = &HB000

  Scrn.Retrace = (Scrn.Segment = &HB800)
END SUB 'ScrnInit


SUB SaveScreenArea(UpperLeftRow, UpperLeftCol, NumberOfRows, NumberOfCols, _
  SaveText$, SaveAttr$)
  '
  ' Saves the contents of the screen.
  ' No bounds checking is performed.
  ' Screen defined must be within the actual screen space.
  ' Number of rows or columns must be > 0.
  '
  SHARED Scrn.Retrace, Scrn.Segment

  NumberOfChars = NumberOfRows * NumberOfCols
  SaveText$ = STRING$(NumberOfChars, 0)
  SaveAttr$ = STRING$(NumberOfChars, 0)
  ScreenDisplacement = ((UpperLeftRow - 1) * 80) + (UpperLeftCol - 1)
  SavePtr = 0
  FOR i = 1 TO NumberOfRows
    CALL ReadVid(NumberOfCols, Scrn.Retrace, SaveText$, SaveAttr$, SavePtr, _
      Scrn.Segment, ScreenDisplacement + ((i - 1) * 80))
    SavePtr = SavePtr + NumberOfCols
  NEXT
END SUB 'SaveScreenArea



SUB WriteScreenArea _
  (UpperLeftRow, UpperLeftCol, NumberOfRows, NumberOfCols, Text$, Attr$)
  '
  ' Writes the contents of the screen variables.
  ' No bounds checking is performed.
  ' Screen defined must be within the actual screen space.
  ' Text$ and Attr$ must both be NumberOfRows * NumberOfCols long.
  ' Number of rows and number of columns must be > 0.
  '
  SHARED Scrn.Retrace, Scrn.Segment

  ScreenDisplacement = ((UpperLeftRow - 1) * 80) + (UpperLeftCol - 1)
  SavePtr = 0
  FOR i = 1 TO NumberOfRows
    CALL WriteVid(NumberOfCols, Scrn.Retrace, Text$, Attr$, SavePtr, _
      Scrn.Segment, ScreenDisplacement + ((i - 1) * 80))
    SavePtr = SavePtr + NumberOfCols
  NEXT
END SUB 'WriteScreenArea
