PicoVGA  1.0-cmake
VGA/TV display on Raspberry Pico
Overlay Layers

Description

The display of the image by the PicoVGA library is performed by the PIO processor controller. PIO0 is used. The other controller, PIO1, is unused and can be used for other purposes. PIO0 contains a 4 state machines, SM0 to SM3. All PIO0 state machines use a common program of 32 instructions. Each state machine serves 1 overlay layer. SM0 services base layer 0, along with servicing the synchronization signal. The base layer service program consists of 15 instructions, starting at offset 17. This part of the program is immutable and is always used. However, the other 3 layers, 1 to 3, SM1 to SM3, use the other part of the program memory, 17 instructions starting at address 0. This part may change, depending on the mode of the overlay layers. All 3 overlay layers use a common program and must therefore operate in the same display mode. Some overlay modes use the same program and can be shared - see the table below for details.

Note
Only base layer 0 can contain segments in different formats. Overlay layers 1 to 3 are independent of the base layer format, sharing only the total display area with the base layer, but using their own image format, for which only the coordinates and dimensions are specified.

Overlay layers can use one of the following programs:

The desired mode of each overlay layer is specified in the video mode definition using the VgaCfg() function. The layer mode is used to derive the program and function used to operate the layer rendering. Multiple layer modes can share the same program type. Layer modes have different state machine timing requirements. The configuration function takes this into account and adjusts the processor frequency accordingly.

Modes of overlay layers:

*WHITE modes using white transparent color require image preparation using CopyWhiteImg() as specified for LAYERPROG_WHITE.

Shared overlay modes

Layer modes can only be combined together if they use the same program. CPP is the minimum required number of SMx clock cycles per pixel.

PROG_BASE PROG_KEY PROG_BLACK PROG_WHITE PROG_MONO PROG_RLE CPP
LAYERMODE_BASE X 2
LAYERMODE_KEY X 6
LAYERMODE_BLACK X 4
LAYERMODE_WHITE X 4
LAYERMODE_MONO X 4
LAYERMODE_COLOR X 2
LAYERMODE_RLE X 3
LAYERMODE_SPRITEKEY X 6
LAYERMODE_SPRITEBLACK X 4
LAYERMODE_SPRITEWHITE X 4
LAYERMODE_FASTSPRITEKEY X 6
LAYERMODE_FASTSPRITEBLACK X 4
LAYERMODE_FASTSPRITEWHITE X 4
LAYERMODE_PERSPKEY X 6
LAYERMODE_PERSPBLACK X 4
LAYERMODE_PERSPWHITE X 4
LAYERMODE_PERSP2KEY X 6
LAYERMODE_PERSP2BLACK X 4
LAYERMODE_PERSP2WHITE X 4

Selection of write planes

By default, the image is output from the layers to all output pins. This can be changed by redefining the LayerFirstPin and LayerNumPin fields (in vga_layer.cpp). It is possible to specify for each layer separately which output pins will be written to. This can create a kind of pseudo-transparency. For example, one layer will render curves in red, another layer in green, and the colors will blend independently. When redefining the pins, however, you must take into account that the offset of the pin mapping will shift. The output will always start from the lowest bits of the pixel.

Configure overlay layers

The first step for setting up the overlay layer is to specify the layer mode for the VgaCfg() initialization function. The function detects the required program and the required timing. It does not check if the correct layer modes are combined together.

The second step is to initialize the layer descriptor - the sLayer structure in the LayerScreen field. It is convenient to use the LayerSetup() initialization function for this.

Data Structures

struct  sLayer
 Layer screen descriptor (on change update SLAYER_* in define.h) More...
 
struct  sSprite
 Sprite (on change update SSPRITE_* in define.h) More...
 

Macros

#define BASE_OFFSET   17
 Offset of base layer PIO program.
 
#define LAYER_OFFSET   0
 Offset of overlapped layer PIO program.
 
#define LAYERPROG_BASE   0
 Program of base layer (overlapped layers are OFF)
 
#define LAYERPROG_KEY   1
 Layer with key color.
 
#define LAYERPROG_BLACK   2
 Layer with black key color.
 
#define LAYERPROG_WHITE   3
 Layer with white key color.
 
#define LAYERPROG_MONO   4
 Layer with mono pattern or simple color.
 
#define LAYERPROG_RLE   5
 Layer with RLE compression.
 
#define LAYERPROG_NUM   6
 Number of layer programs.
 
#define LAYERMODE_BASE   0
 Base layer.
 
#define LAYERMODE_KEY   1
 Layer with key color.
 
#define LAYERMODE_BLACK   2
 layer with black key color
 
#define LAYERMODE_WHITE   3
 Layer with white key color.
 
#define LAYERMODE_MONO   4
 Layer with mono pattern.
 
#define LAYERMODE_COLOR   5
 layer with simple color
 
#define LAYERMODE_RLE   6
 Layer with RLE compression.
 
#define LAYERMODE_SPRITEKEY   7
 Layer with sprites with key color.
 
#define LAYERMODE_SPRITEBLACK   8
 Layer with sprites with black key color.
 
#define LAYERMODE_SPRITEWHITE   9
 Layer with sprites with white key color.
 
#define LAYERMODE_FASTSPRITEKEY   10
 Layer with fast sprites with key color.
 
#define LAYERMODE_FASTSPRITEBLACK   11
 Layer with fast sprites with black key color.
 
#define LAYERMODE_FASTSPRITEWHITE   12
 Layer with fast sprites with white key color.
 
#define LAYERMODE_PERSPKEY   13
 Layer with key color and image with transformation matrix.
 
#define LAYERMODE_PERSPBLACK   14
 Layer with black key color and image with transformation matrix.
 
#define LAYERMODE_PERSPWHITE   15
 Layer with white key color and image with transformation matrix.
 
#define LAYERMODE_PERSP2KEY   16
 Layer with key color and double-pixel image with transformation matrix.
 
#define LAYERMODE_PERSP2BLACK   17
 Layer with black key color and double-pixel image with transformation matrix.
 
#define LAYERMODE_PERSP2WHITE   18
 Layer with white key color and double-pixel image with transformation matrix.
 
#define LAYERMODE_NUM   19
 Number of overlapped layer modes.
 

Functions

void LayerOn (u8 inx)
 Set overlapped layer 1..3 ON. More...
 
void LayerOff (u8 inx)
 Set overlapped layer 1..3 OFF. More...
 
void LayerSetX (u8 inx, s16 x)
 Set coordinate X of overlapped layer. More...
 
void LayerSetY (u8 inx, s16 y)
 Set coordinate Y of overlapped layer. More...
 
void LayerSetW (u8 inx, u16 w)
 Set width of image of overlapped layer. More...
 
void LayerSetH (u8 inx, u16 h)
 Set height of image of overlapped layer. More...
 
void LayerSetup (u8 inx, const u8 *img, const sVmode *vmode, u16 w, u16 h, u8 col=0, const void *par=NULL)
 Setup overlapped layer 1..3 (not for sprites or perspective mode) More...
 
void LayerPerspSetup (u8 inx, const u8 *img, const sVmode *vmode, u16 w, u16 h, u8 xbits, u8 ybits, s8 horiz, const int *mat, u8 col=0)
 Setup overlapped layer 1..3 for LAYERMODE_PERSP* modes. More...
 

Variables

sLayer LayerScreen [LAYERS]
 Current layer screens.
 
u8 LayerFirstPin [LAYERS_MAX]
 Index of first pin of layer (base layer should stay VGA_GPIO_FIRST)
 
u8 LayerNumPin [LAYERS_MAX]
 Number of pins of overlapped layer (base layer should stay VGA_GPIO_OUTNUM)
 

Function Documentation

◆ LayerOn()

void LayerOn ( u8  inx)

Set overlapped layer 1..3 ON.

Parameters
inxLayer index

◆ LayerOff()

void LayerOff ( u8  inx)

Set overlapped layer 1..3 OFF.

Parameters
inxLayer index

◆ LayerSetX()

void LayerSetX ( u8  inx,
s16  x 
)

Set coordinate X of overlapped layer.

Parameters
inxLayer index
xX coordinate

◆ LayerSetY()

void LayerSetY ( u8  inx,
s16  y 
)

Set coordinate Y of overlapped layer.

Parameters
inxLayer index
yY coordinate

◆ LayerSetW()

void LayerSetW ( u8  inx,
u16  w 
)

Set width of image of overlapped layer.

Note
Uses auto pitch wb (full line). Set custom wb after calling this function.
Parameters
inxLayer index
wWidth

◆ LayerSetH()

void LayerSetH ( u8  inx,
u16  h 
)

Set height of image of overlapped layer.

Parameters
inxLayer index
hHeight

◆ LayerSetup()

void LayerSetup ( u8  inx,
const u8 *  img,
const sVmode vmode,
u16  w,
u16  h,
u8  col = 0,
const void *  par = NULL 
)

Setup overlapped layer 1..3 (not for sprites or perspective mode)

The function sets the dimensions of the image and its address. The coordinates are cleared. The position of the image on the screen can be set by the LayetSetX() and LayerSetY() functions. The coordinates do not depend on the graphic modes of the base layer and refer to the upper left corner of the active screen area. After initialization, the layer remains disabled. Layer visibility must be turned on by calling the LayerOn() function.

Parameters
inxLayer index 1..3
imgPointer to image data
vmodePointer to initialized video configuration
wImage width in pixels (must be multiple of 4)
hImage height
colKey color (Needed for LAYERMODE_KEY and LAYERMODE_MONO. For both *BLACK and *WHITE modes, specify COL_BLACK or 0)
parAdditional data (RLE index table, integer transformation matrix)

◆ LayerPerspSetup()

void LayerPerspSetup ( u8  inx,
const u8 *  img,
const sVmode vmode,
u16  w,
u16  h,
u8  xbits,
u8  ybits,
s8  horiz,
const int *  mat,
u8  col = 0 
)

Setup overlapped layer 1..3 for LAYERMODE_PERSP* modes.

In contrast to the LayerSetup() function, the dimensions of the source image in number of bits (the image dimensions must be a power of 2), the height of the horizon/4 (for a negative value the floor turns into a ceiling, for zero the perspective transformation is not applied) and the pointer to the transformation matrix in integer form are also specified.

Parameters
inxLayer index 1..3
imgPointer to source image data (image width and height must be power of 2)
vmodePointer to initialized video configuration
wDestination image width in pixels (must be multiple of 4)
hDestination image height
xbitsNumber of bits of width of source image
ybitsNumber of bits of height of source image
horizHorizon of perspective projection/4 (0=no perspecitve, <0 ceilling)
matInteger transformation matrix
colKey color (needed for LAYERMODE_PERSPKEY layer mode)