'=========================== GETSIZE.BAS ==================================
'                          Quick Basic 4.5
'                 Copyright 1989 - Frederick Volking
' All Rights released to public domain by original author on 12/01/89
'
' =====================================================================
'
' This SUB calculates the Array size needed for a graphics GET
' image function. Works with SCREEN modes 1,2,7,8,9,10,11,12,13
'
'        WARNING: Only tested on SCREEN modes 1,2,7,8,9...
'
' Provides two seperate functions as based on incomming value of
' "DoingText" variable:
'
'  1) If "DoingText" is TRUE (non-zero): then routine assumes
'     values passed in LRow,LCol,RRow,RCol as text oriented
'     row and column coordinates. Thus it converts the text
'     coordinates to appropriate pixel coordinates and
'     calculates pixel area necessary to GET an image to fill
'     the described rows and columns area. IMPORTANT! before
'     return, LRow,LCol,RRow,RCol are CONVERTED from text
'     oriented coordinates to pixel oriented coordinates
'     describing the exact boundries needed to be used by the
'     GET statement.
'
'  2) If DoingText is FALSE (0): then the routine assumes the
'     values passed in LRow,LCol,RRow,RCol as describing a
'     pixel oriented area.
'
' ----------- Notes on Improvements Suggested -----------------
'
' Note #0: Commercial routines exist to perform all below
'   suggested improvements. But for copyright reasons, I'm
'   not at liberty to include them herein ....
'
' Note #1: ScreenMode - Rather than being passed to the routine,
'   it would be more functional if routine made own determination.
'
' Note #2: Planes in EGA#9 could be set to Planes = 2 if a
'   method could be devised to determine if the currently
'   installed EGA card HAS MORE OR LESS THAN 64K of onboard memory
'       ie;  IF > 64k THEN Planes = 4 ELSE Planes = 2
'
' Note #3 - LINES - Only needed in EGA and VGA modes(25,30,43,60)
'   Rather than being passed, would be more functional if routine
'   made determination itself and took appropriate action
'
' ==================================================================
'  Author:       Frederick Volking
'  Contact:      (415)952-3450 [home]          (415)378-4640 [work]
'  USPO Mail:    425 Larch Avenue  -  South San Francisco, CA 94080
'  EchoMail:     ANY Basic conference (I try to read them all)
'  Library At:   QBCentral BBS - Vancouver Washington (206)892-7500
' ==================================================================
DEFINT A-Z
SUB GetSize(IntNeed,LRow,LCol,RRow,RCol,DoingText,ScreenMode,Lines)STATIC

   SELECT CASE ScreenMode                    ' See Note #1
      CASE  1: Bits = 2: Planes = 1 'CGA
      CASE  2: Bits = 1: Planes = 1 'CGA
      CASE  7: Bits = 1: Planes = 4 'EGA
      CASE  8: Bits = 1: Planes = 4 'EGA
      CASE  9: Bits = 1: Planes = 4 'EGA     ' See Note #2
      CASE 10: Bits = 1: Planes = 2 'VGA
      CASE 11: Bits = 1: Planes = 1 'VGA
      CASE 12: Bits = 1: Planes = 4 'VGA
      CASE 13: Bits = 8: Planes = 1 'VGA
   END SELECT

   IF DoingText THEN
      SELECT CASE ScreenMode                 ' See Note #3
         CASE  9,10
            IF Lines=43 THEN CharPixTall= 8 ELSE CharPixTall=14
         CASE 11,12
            IF Lines=30 THEN CharPixTall=16 ELSE CharPixTall= 8
         CASE ELSE: CharPixTall=8
      END SELECT
      LRow = (LRow - 1) * CharPixTall
      LCol = (LCol - 1) * 8
      RRow = (RRow * CharPixTall) - 1
      RCol = (RCol * 8) - 1
   END IF

   IntNeed = 4+INT(((RCol-LCol+1)*(Bits)+7)/8)*Planes*((RRow-LRow)+1)
   IntNeed = INT(CSNG(IntNeed+1)/2)

END SUB