Classic Monochrome Graphics - marinus-lab/z88dk GitHub Wiki
The graphics API provides a portable abstraction for drawing graphics primitives onto the displays of target platforms.
Classic graphics supports targets with screen sizes ranging from 64x64 to 1024x768 and beyond. As such when writing code that is meant to run on many targets, it is important that these difference are held in mind.
Traditionally, the graphics subsystem has been monochrome, and as such all functions do not take a colour parameter. However, on many targets the colour of a plotted pixel can be chosen by calling the textcolor()
function with the appropriate colour defined in <conio.h>
. This is a result of many targets supporting graphics based on hardware semi-graphics modes.
The following functions plot/reset pixels at the native resolution of the screen mode. (0,0) is the top left corner of the screen.
Plot a pixel to screen
Reset a pixel on the screen
Invert a pixel on the screen
Get the status of a pixel
The following functions plot/reset a pixel that is equivalent to a 4x4 pixel. These directives are perfect for emulating the lores graphics available on computers such as the ZX81 on machines that only have hires graphics.
Plot a 4x4 pixel to screen
Reset a 4x4 pixel on the screen
Invert a 4x4 pixel on the screen
Get the status of a 4x4 pixel
Get the maximum X coordinate value for the current target. On targets with multiple screen modes this returns the value for the currently selected mode.
Get the maximum Y coordinate value for the current target. On targets with multiple screen modes this returns the value for the currently selected mode.
Some targets support graphics resolutions such as 640x200 or 512x192 which result in vertically stretched pixels being drawn. Calling this function adjusts the graphics plotting functions so that lines and shapes are drawn using two horizontal pixels, effectively halving the horizontal resolution.
This function might not work correctly on all the platforms
Get horizontal or vertical pixel bar, up to 16 pixel long, for a quick pattern recognition in graphics applications or games.
Draw a line, given absolute coordinates
Draw a line in XOR mode, given absolute coordinates
Draw a white line (clear a line), given absolute coordinates
Draw a line, starting from the last plotted pixel to the given position
Draw a line in xor mode, starting from the last plotted pixel to the given position
Draw a white line starting from the last plotted pixel to the given position
Draw a line, starting from the last plotted pixel to the given relative position
Draw a line in XOR mode, starting from the last plotted pixel to the given relative position
Draw a white line starting from the last plotted pixel to the given relative position
Draw a box border
Draw a white box border
Invert the given box border. Useful for "select area" functions.
Draw a circle.
Draw a white circle.
Clear the screen and (if necessary for the platform) enter in graphics mode.
Clear the given screen area.
Invert the given screen area.
This function may not work correctly on all platforms since it uses a lot of stack space
This functions is not available for 8080 targets
Fill an area starting at the given point.
This feature is not available for 8080 targets
The "stencil" object is an evolution of a base concept introduced by Rafael de Oliveira Jannone in his gfx library: a convex area is defined by two byte vectors, pointing respectivelty to the leftmost and the rightmost X coordinates. They're stuffed in a single byte vector, long twice the Y axis.
First of all the programmer must initialize the 'stencil', object, then various shapes can be added to form the resulting convex object (note that no 'holes' are allowed on top and lower borders). As soon as the object is finished it can be drawn on the screen with the "stencil_render()" function. The resulting shape covers the previous picture.
Set/Reset the couple of vectors being part of a "stencil".
Add a single dot to a figure defined inside a stencil object, init the vector pointers.
Trace a relative line into a stencil object (extend shape).
Trace a line into a stencil object up to a given coordinate (extend shape).
Add a side to a figure defined inside a stencil object
Add a circular shape to a figure defined inside a stencil object
Render an area delimited by a stencil object, with the specified dither intensity (0..11)
The easiest way to import monochrome raster picture is to use the "sprite" object.
The putsprite()
function has been ported to almost all the supported target and permits to keep portable the data itself. The sprite editors let you import an external data file.
The sprite functions are based on a special data structure permitting dynamic sprite sizes: the first two bytes define the sprite size, while the next ones describe the picture.
The bits are right-padded to fill the last byte in a row.
Draw a sprite of variable size it can behave in three different ways, to be specified in the "ortype" parameter:
-
SPR_OR
the sprite will just be printed on the screen without deleting what's already there -
SPR_XOR
the sprite will be XORed with the pictures already present on the screen -
SPR_AND
the sprite will be "printed in white", eventually leaving a shape. This feature permits the use of "sprite masks".
Not available on 8080 targets.
Saves the screen area in a sprite-like structure. Position and size are saved in it (taking 4 bytes), but the area granularity works at byte-level, to run faster.:
char *background;
background=malloc( 4 + (width/8+1) * (height) );
sprintf(background, "%c%c",width,height);
bksave(x,y,background);
Restores the background area.
bkrestore(background);
Not available on 8080 targets
'Graphic Profiles' are byte streams containing vector and surface descriptions.
A data converter called z80svg
is provided. It converts data from the SVG format to a 'profile' stream.
A programmer might prepare his own pictures by just drawing them with InkScape, or directly describing the paths in data structures.
Render a picture defined in a 'profile' byte stream.
z88dk provides a monochrome sprite editor in source code format, in the {z88dk}/support/sprites folder. It requires the 'Allegro 5' library, its graphics interface is not elegant but very powerful and portable.
External alternatives are: