Commodore‎ > ‎BASIC‎ > ‎Keywords‎ > ‎

GRAPHIC

Keyword
Abbreviation Token (hex) Version(s) Classification
GRAPHIC G{Shift+R} DE 3.5, 7.0 Command and Statement
BSAVE B{Shift+S} DE 4.7 Command and Statement

Syntax  
GRAPHIC { CLR mode [ , clear [ , rows ] ] }
 
Parameters Type Legal Value(s) Default Value Note(s)
mode Integer
  1. 40-column text
  2. High-res bitamp
  3. High-res split-screen
  4. Multi-color bitmap
  5. Multi-color split-screen
  6. 80-column text
5 is only valid for v7.0 (C128) 
clear Integer  0 or 1  1 will clear the screen 
rows  Integer  0 to 25  20 Only allowed in v7.0
Must be "legal" but otherwise ignored if not split-screen
 
 
Purpose  
(De)allocate and/or clear a bitmap screen; this typically changes video display mode as well.

 
 
Remarks  
The GRAPHIC keyword may be followed by either the CLR keyword or 1 to 3 numeric parameters.  With the CLR keyword, the bitmap is de-allocated which frees room for BASIC.  The bitmap uses 10K on the C16 and Plus/4, and 9K on the C128 (40 columns).  Using the CLR keyword also returns the screen to text mode (assuming it was displaying a bitmap).  Once a bitmap is allocated (see below), it consumes memory until removed with GRAPHIC CLR; simply switching to text mode (GRAPHIC 0) will not free the memory used by the bitmap (but it will hide the bitmap).
 
In the case of the numeric parameters, they will be converted to integers if they are floating-point (see INT).  You will get TYPE MISMATCH ERROR if any are strings.  The first parameter, mode, sets the TED/VIC screen as follows:
mode Display Type
Bitmap Size
(X*Y pixels)
Bitmap Colors
(per cell)
Text Size
(X*Y characters)
Note(s) 
0 Text
320 * 200 (not visible)
2 40 * 25
No bitmap is allocated. On the C128, this activates the 40-column text editor.
 
1 High-resolution bitmap  320 * 200  2 40 * 25 (not visible)

 

2 High-resolution split-screen
320 * 160 (visible)
320 * 200 (total) 
2
40 * 25 (total)
40 * 5 (visible)

Text appears below the bitmap.  On the C128, this activates the 40-column text editor.

3 Multi-color bitmap  160 * 200  40 * 25 (not visible)   
4 Multi-color split-screen 
160 * 160 (visible)
160 * 200 (total) 
40 * 25 (total)
40 * 5 (visible)

Text appears below the bitmap.  On the C128, this activates the 40-column text editor.

5
Text (VDC)
VIC screen unchanged
none  none  80 * 25 

C128 Only.  Activates the 80-column text editor.

 
 
The second parameter, clear, acts like a boolean value.  If zero, nothing special happens.  If one, the bitmap is cleared, all color cells are initialized with the chipColors set by COLOR, and the pixel cursor is set to 0,0 (except GRAPHIC 0 and GRAPHIC 5 which select a text mode).  For GRAPHIC 0 or GRAPHIC 5 (or any split-screen mode) the text screen is cleared.  Due to the different ways the video chip interprets bitmap data, you should clear the screen when switching between high-resolution and multi-color modes; otherwise you will see strange things.  This parameter will not accept a boolean value returned by BASIC's own relational operators!  This is because they return -1 for true but the clear parameter only accepts 0 and 1.
 
The third parameter, rows, is intended to set the number of visible bitmap "rows" (where a row is 8 rasters) in the top (bitmap portion) of a split-screen mode.  However it is accepted in non-split-screen modes as well.  In those cases, it has not effect, but the value must still be "legal" as shown above.
 
This statement updates two secret variables (plus a "public" one, see RGR).  One secret variable is the "bitmap allocated" (set to non-zero when a bitmap is allocated, or zeroed when the CLR preposition is used).  The second secret variable (only on the C128) is the split screen row (the value is fixed on the Plus/4).
 
Whenever a bitmap is allocated or de-allocated, the BASIC program is moved in memory.  This requires the entire program to be re-linked, which can take a few seconds.  Threre is also a documented bug (so it is a feature!) with this memory shuffle: any user-functions are not updated to point to their new location in memory.  So execute your DEF statements after you (de)allocate your bitmap.  If you need your functions both before and after bitmap allocation, you can place them in a subroutine.  Then just remember to call your subroutine whenever you (de)allocate a bitmap.
 
BUG: In version 7.0, specifying mode 4 and clear 1 (i.e., clear the multi-color split-screen bitmap) will fail to initialize the memory used for colorSource 3.  This is normally not obvious because most bitmap commands will set the color memory when they plot on the bitmap.  However CHAR only writes one colorSource to the bitmap and all others take the old value, which could be wrong due to this bug. 
 
Examples:
GRAPHIC 0     : REM text mode
GRAPHIC 0,1 : REM text mode (clear text screen) GRAPHIC 1,1 : REM hi-res bitmap mode (clear bitmap)
GRAPHIC 2 : REM hi-res split screen (20 bitmap & 5 text rows) GRAPHIC 2,,0 : REM hi-res split screen (0 bitmap & 25 text rows) GRAPHIC 2,,25 : REM hi-res split screen (25 bitmap & 0 text rows) GRAPHIC 3 : REM multi-color bitmap mode (no clear) GRAPHIC 3,1 : REM multi-color bitmap mode (clear bitmap) GRAPHIC 4 : REM multi-color split-screen (20 bitmap & 5 text rows) GRAPHIC 4,1 : REM same as above, but clears bitmap and text GRAPHIC 5 : REM 80-column text mode (VIC mode unchanged) GRAPHIC CLR : REM free bitmap memory and set TED/VIC to text mode
 
Compare With  
 
See Also  

© H2Obsession, 2014
Comments