Graphic Library Main Page | Download Evaluation Package


AMD Élan SC400 Graphics Library

For 16-bit DOS and the C++ Language

Programming Reference

© 2000 Hemodynamics AG, Berne

This Material - Electronic Media included - is subject to Copyright.

All rights are reserved, whether the whole or part of the material is concerned, specifically those of translation, reprinting, data-copying, reproduction by photocopying machine, by electronical or similar means, and storage in data banks.


Hemodynamics AG
M
elchenbuhlweg 136A
PO Box 668
CH 3000 Berne 31

E-mail address: sales@hemodynamic.com
Phone: +41 31 941 3830
Fax: +41 31 941 3837

 


Contents

Introduction
Summary of Functions
Restrictions
Public Functions and Constants Declared in Header File
Detailed Description of Functions

getbitmap
getbkcolor
getcolor
getfont
graphexit
graphsetup
invertcolors
lineto
linex
liney
moveto
putbitmap
rect
rectblt
rectfill
rectround
rectxor
setbkcolor
setcolor
setfont
setpixel
textout


Introduction

This library of graphic routines was developed to take full advantage of the well-designed native graphics mode of the AMD Élan SC400 microcontroller. The library should cover the basic needs in most applications where it is desirable to display graphics on a quarter VGA (QVGA) LCD display. Although the main framework is written in C++, most of the actual code is written using in-line assembler. The routines are therefore very compact and fast. Furthermore, the structure of the library is made similar to the device context class in Visual C++. Contemporary programmers should immediately feel at home.

Because the native mode of the Élan SC400 microcontroller uses a flat memory mode, graphics operations are indeed fast and the 16-color/grayscale display offers a great improvement over the legacy CGA modes. The availabiltity of just the very basic operations also makes it compact and easy to use - the programmer does not have to introduce herself/himself to a vast array of overlapping function.


Summary of Functions

 


Restrictions

 


Public Functions and Constants (Declared in Source Header File)

//////////////////////////////////////////////////////////

// CGraph.h

// Header for Elan SC400 Graphics Library

//////////////////////////////////////////////////////////

#define byte unsigned char

#define bool unsigned char

#define word unsigned

#define dword unsigned long

#define true 1

#define false 0

#define GRAPHON 1

#define GRAPHOFF 0

#define MAXX 319 // Max X of screen

#define MAXY 239 // Max Y of screen

#define MEMDY 160 // distance between lines in bytes

 

byte gget(byte index); // Returns graphic register value

void graphsetup(bool graphon); // Switches between graph and text mode

/////////////////////////// Class declaration of CGraph:

class CGraph // The object or device context used

{

CGraph(); // Object constructor

void graphexit(); // Cleans up after use

bool getbitmap(char* name); // Load bitmaps used for text etc

void putbitmap(); // Entire bitmap to screen

// General graphics settings:

byte setcolor(byte color); // sets drawing color (0..15)

byte getcolor();

byte setfont(byte font); // sets font used (1..3)

byte setbkcolor(byte color); // sets background color (0..15)

byte getbkcolor();

void invertcolors();

// Single pixel routine:

void setpixel(int x,int y); // sets one pixel in drawing color

// Routines for writing text to screen:

int textout(int x,int y,char * st);

// Undocumented text routines:

void writeint(int x,int y,char * st,int value,int modulus);

void writedecimal(int x,int y,char * st,int value,char* stu);

// Line drawing routines:

void liney(int x,int y1,int y2); // draw a vertical line

void linex(int x1,int y,int x2); // draw horizontal line

void moveto(int x,int y); // Moves graph 'cursor pos'

void lineto(int x,int y); // Line from cursor pos to (x,y)

// Rectangle routines:

void rect(int x1,int y1,int x2,int y2); // draw rectangle

void rectround(int x1,int y1,int x2,int y2); // rounded rectangle

void rectfill(int x1,int y1, // upper lefthand corner

int x2,int y2, // lower righthand corner

unsigned color); // color to fill (0..15)

void rectxor(int x1,int y1, // ULH corner

int x2,int y2, // LRH corner

unsigned color); // XOR's a rectangle with color

void rectblt( int xs,int ys, // ULH Source of bitmap

int dxs,int dys, // Size of clip to be xferred

int xd,int yd); // ULH Destination on screen

// Undocumented:

void scrollrect(int xd,int yd,

int x,int y,unsigned color);

// X-Y axis routines (still undocumented):

void scalex(int x1,int y,int x2,int kscale,int div);

void scaley(int x,int y0, int y1, int y2,unsigned scale);

~CGraph(); // Graphic Object destructor

// Public variables:

char far* bitmap; // storage for graphics bitmap

/////// Definition of private class functions and variables:

private: // Not listed here

};

 


Detailed Description of Functions:

The following section lists the functions that are generally available, followed by a detailed description of each (alphabetically sorted). There are also some undocumented functions as seen from the cgraph.h header source file. These are primitives that the application does not have to call directly, additional information on these are contained in the cgraph.cpp source file. Some of these may be useful during program development. Look to the gdemo.cpp source file for detailed information on the use of the library.

 


getbitmap

The getbitmap function reads a bitmap used for character, symbols and other clips used in applications.

bool CGraph::getbitmap( char* name );

Parameters:
name Pointer to null-terminated string containing path to file to be used as bitmap.

Return Value:
zero if bitmap load failed, otherwise non-zero. If memory allocation for bitmap fails, the application will be terminated. 

Remarks
The getbitmap function should be called after calling graphsetup(), and before using the rectblt() and textout() functions of the library. If memory has not been previously allocated to the bitmap, this will be done automatically. Repeated calls to getbitmap() are possible, thereby providing an easy way to load various kinds of bitmaps for images and clips to the screen. See example in the gdemo.cpp source file for information on how to do this without loosing the character bitmaps. Flash- or ram-disks should be used to store such bitmaps to increase performance. 

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.


See Also: graphexit(), textout(), rectblt(), putbitmap()

 


getbkcolor

The getbkcolor function returns the current background color.

byte CGraph::getbkcolor( );

Parameters: none

Return Value:
Unsigned char (byte) representing the current background color
 

Remarks
The current background color is now used only in helping to draw the large font, it should be set to the background color used in the bitmap section where the large fonts are stored.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: setfont(), textout()

 


getcolor

The getcolor function returns the current drawing color.

byte CGraph::getcolor( );

Parameters: none

Return Value: Unsigned char (byte) representing the current drawing color

Remarks
The current color (0..15 on the Élan SC400) is used for drawing operations.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: setcolor()

 


getfont

The getfont function returns the font used in text output.

byte CGraph::getfont( );

Parameters: none

Return Value: byte (1..3) representing the current font

Restrictions
Currently, only font 2 has all the ascii symbols (32..126). In fonts 3 (large) and font 1 (small) only capital letters and numbers are available (this can be enlarged by expanding the bitmap storage of characters).

Remarks
After calling textout(), the current font is reset to 2 (default size)

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: setfont(), textout()

 


graphexit

The graphexit function cleans up after using the graph object.

byte CGraph::graphexit();

Parameters: none

Return Value none

Remarks
The graphexit function deallocates the memory used for the graphics library. No calls to CGraph functions involving the bitmap should be made after calling graphexit(). While it seems that some if not all operating systems/compiler combinations do automatic cleanup of such allocations, it is nevertheless good practice to perform memory deallocation before terminating the application.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: graphsetup(), getbitmap()  

 


graphsetup

The graphsetup function initializes and configures the graphics display of the Élan SC400.

void graphsetup( bool graphon );

Parameter: graphon This boolean is set to either GRAPHON or GRAPHOFF (true or false) depending on the mode desired.

Return Value none 

Remarks
The graphsetup function is used to switch between the Élan SC400 native graphics mode and the previous (text) mode of the display system. Before using the graphics object, the first call to this function should be with GRAPHON, as this saves the old settings of the internal graphics controller setup registers. These values are restored when the application calls graphsetup with GRAPHOFF. At the termination of the application such a call should be made to restore the graphics machine to the mode used before starting the application. (Probably a DOS text mode.)

See Also: graphexit(), getbitmap()  

 


invertcolors

The invertcolors function inverts the grayscale used. It switches between positive and negative displays – depending whether the LCD is of the transmissive or reflective type.

void CGraph::invertcolors( );

Parameters: none 

Return Value: none

Remarks
Only required in development for different displays.

See Also: graphsetup()

 


lineto

The lineto function draws a line from the current position up to, and including, the specified point.

void CGraph::lineto ( int x, int y );

Parameters:
x Specifies the x-coordinate of the line's ending point.  
y Specifies the y-coordinate of the line's ending point.  

Return Values: none

Remarks
The coordinates of the line's ending point are specified in screen pixel units. The line is drawn by using the current color. After drawing, the current position is set to the specified ending point.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: moveto(), setcolor()

 


linex

The linex function draws a horizontal line between and including the specified coordinates.

void CGraph::linex( int x1, int y, int x2 );

Parameters:
x1 Specifies the x-coordinate of the line's starting point. y
Specifies the y-coordinate of the line's starting and ending points
x2 Specifies the x-coordinate of the line's ending point.

Return Values none

Remarks
The coordinates of the line's start and ending points are specified in screen pixel units. To achieve maximum performance, use this routine instead of lineto and moveto when possible.

The line is drawn using the current color. The current graph cursor position is not affected by this function.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: lineto()setcolor()

 


liney

The liney function draws a vertical line between and including the specified coordinates.

void CGraph::linex( int x, int y1, int y2 );

Parameters:
x   Specifies the x-coordinate of line's starting and ending points.
y1 Specifies the y-coordinate of line's starting point.
y2 Specifies the y-coordinate of line's ending point. 

Return Values: none

Remarks
The coordinates of the line's start and ending points are specified in screen pixel units. To achieve maximum performance, use this routine instead of lineto and moveto when possible.

The line is drawn by using the current color. The current graph cursor position is not affected by this function.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: lineto()setcolor()

 


moveto

The moveto function places the current position of the graphics cursor at the specified point.

void CGraph::moveto( int x, int y ); 

Parameters:
x Specifies the x-coordinate of the current position.
y Specifies the y-coordinate of the current position.   

Return Values: none

Remarks
The coordinates of the current position are specified in screen pixel units. The only two functions that move the current position are lineto() and moveto()

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: lineto()

 


putbitmap

The putbitmap function display the entire bitmap read in by getbitmap.

void CGraph::putbitmap( ); 

Parameters: none

Return Values: none

Remarks
Displays entire screen as the bitmap previously read in. Useful for creating backgrounds etc.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: rectblt(), getbitmap()   

 


rect

The rect function draws a rectangle at the specified coordinates.

void CGraph::rect( int x1, int y1, int x2, int y2 ); 

Parameters:
x1 Specifies the x-coordinate of the rectangle's upper left corner.
y1 Specifies the y-coordinate of the rectangle's upper left corner.
x2 Specifies the x-coordinate of the rectangle's lower right corner.
y2 Specifies the y-coordinate of the rectangle's lower right corner.

Return Values: none

Remarks
The coordinates of the rectangle’s corners are specified in screen pixel position is not changed.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: rectround(), rectfill(), rectblt(), setcolor()   

 


rectblt

The rectblt function fills a destination rectangle at the specified coordinates with the specified source rectangle in the current bitmap used for symbols and clips.

void CGraph::rectfill( int xs, int ys, int dxs, int dys, int xd, int yd ); 

Parameters:
xs   the x-coordinate of the rectangle's upper left corner in the bitmap
ys   the y-coordinate of the rectangle's upper left corner in the bitmap
dxs  the width of the rectangle to be filled
dys the height of the rectangle to be filled
xd  the x-coordinate of the rectangle's upper left corner on the screen
yd  the y-coordinate of the rectangle's upper left corner on the screen

Return Values: none

Restrictions
To maximize speed, this routine assumes that xs, xd, and dxs are even numbers. If odd numbers are used, the parameters will be decremented with one.

Remarks
The coordinates of the rectangle’s corners are specified in screen pixel units. The current graph cursor position and the current colors are not changed.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: rect(), rectfill(), rectxor()


rectfill

The rectfill function fills the rectangle at the specified coordinates with the specified color.

void CGraph::rectfill( int x1, int y1, int x2, int y2, unsigned color ); 

Parameters:
x1 the x-coordinate of the rectangle’s upper left corner
y1 the y-coordinate of the rectangle’s upper left corner 
x2 the x-coordinate of the rectangle’s lower right corner
y2 the y-coordinate of the rectangle’s lower right corner 
color the color (grayscale value) used in filling the rectangle

Return Values: none

Remarks
The coordinates of the rectangle’s corners are specified in screen pixel units. The rectangle is filled by using the specified color. The current graph cursor position and the current background color are not changed. This routine does not have the restrictions of rectblt() and rectxor() that it operates on even x-values only.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: rect(), rectblt(), rextxor()

 


rectround

The rectround function draws a rounded rectangle at the specified coordinates.

void CGraph::rectround ( int x1, int y1, int x2, int y2 ); 

Parameters:
x1 Specifies the x-coordinate of the rectangle’s upper left corner.
y1 Specifies the y-coordinate of the rectangle’s upper left corner.
x2 Specifies the x-coordinate of the rectangle’s lower right corner.
y2 Specifies the y-coordinate of the rectangle’s lower right corner.

Return Values: none

Remarks
The coordinates of the rectangles corners are specified in screen pixel units.

The rectangle is drawn by using the current color. The current graph cursor position is not changed. This function is useful when drawing message-boxes and buttons.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: rect(), setcolor()   


rectxor

The rectxor function xor’s (exclusive or) the rectangle at the specified coordinates with the specified color value.

void CGraph::rectxor( int x1, int y1, int x2, int y2, unsigned color ); 

Parameters:
x1 the x-coordinate of the rectangle's upper left corner
y1 the y-coordinate of the rectangle's upper left corner
x2 the x-coordinate of the rectangle's lower right corner
y2 the y-coordinate of the rectangle's lower right corner
color the color (grayscale value) used in xor-ing the rectangle

Return Values: none

Restrictions To maximize speed, this routine assumes x1, and x2 are even numbers; if not their values will be anded (&-operator) with 0xfffe.

Remarks
The coordinates of the rectangle’s corners are specified in screen pixel units. The rectangle is xor’ed by using the specified color. The current graph cursor position and the current background color are not changed. This routine is useful to create menu cursor bars.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: rect(), rectfill(), rectblt()

 


setbkcolor

The setbkcolor function sets the current background color.

byte CGraph::setcolor( int color ); 

Parameters:
color Specifies the new background color

Return Value: unsigned char (byte) representing the current background color

Remarks
The current background color is (presently) used only in helping to draw the large font, it should be set to the background color used in the bitmap section where the large fonts are stored.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: getbkcolor(), setfont(), textout()

 


setcolor

The setcolor function sets the current drawing color.

byte CGraph::setcolor( int color ); 

Parameters: color Specifies the new drawing color.

Return Value: unsigned char (byte) representing the old drawing color

Remarks
The current color (0..15 on the Élan SC400) is used for drawing operations.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: getcolor(), lineto(), linex(), liney, setpixel(), rect(), rectround()

 


setfont

The setfont function sets the font to be used in text output.

byte CGraph::setfont( int font ); 

Parameters:
font Specifies the new font, presently restricted to (1..3).

Return Value: unsigned char (byte) representing the old font.

Restrictions Currently, only font 2 has all the ascii symbols (32..126). In fonts 3 (large) and font 1 (small) only capital letters and numbers are available (this can be enlarged by expanding the bitmap storage of characters).

Remarks
After calling textout(), the font is reset to 2 (default size). If font 1 or 3 is used, setfont() must be called prior to calling textout()

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: textout()   


setpixel

The setpixel function draws the pixel at the specified point with the current drawing color.

void CGraph::setpixel ( int x, int y ); 

Parameters:
x Specifies the x-coordinate of the pixel.
y Specifies the y-coordinate of the pixel. 

Return Values: none

Remarks
The pixel is drawn by using the current color. The current position is not affected by this function.

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: setcolor()

 

 

textout

The textout function outputs a character string to the screen using the current font.

int CGraph::textout ( int x, int y , char* st ); 

Parameters:
Specifies the x-coordinate of the upper left corner of the text.
Specifies the y-coordinate of the upper left corner of the text.
st Pointer to null terminated string containing text to be written.  

Return Value: x-coordinate of the position at the end of the text

Restrictions Currently, only font 2 has all the ascii symbols (32..126). In fonts 3 (large) and font 1 (small) only capital letters and numbers are available (this can be enlarged by expanding the bitmap storage of characters). If font 1 is used, the background color should be set to the background color used in the character bitmap

Remarks
If the parameter x is an odd number, it will be rounded down to the next even number before use.After calling textout(), the font is reset to 2 (default size).

Location
Header: Declared in cgraph.h.
Import File: cgraph.obj.

See Also: setbkcolor(), getfont(), setfont()