PicoVGA  1.0-cmake
VGA/TV display on Raspberry Pico
vga_layer.h
Go to the documentation of this file.
1 
8 #ifndef _VGA_LAYER_H
9 #define _VGA_LAYER_H
10 
11 // base layer commands
12 #define VGADARK(num,col) (((u32)(vga_offset_dark+BASE_OFFSET)<<27) | ((u32)(num)<<8) | (u32)(col)) // assemble control word of "dark" command
13 #define VGACMD(jmp,num) (((u32)(jmp)<<27) | (u32)(num)) // assemble control word
14 
15 // --- overlapped layer init word (delay: use number of offset pixels * Vmode.cpp, num: number of pixels)
16 
17 // init word of key color layer LAYERPROG_KEY
18 #define VGAKEY(delay,num,col) (((u32)((delay)+1)<<19) | ((u32)(col)<<11) | (u32)((num)-1))
19 
20 // init word of mono layer LAYERPROG_MONO
21 #define VGAMONO(delay,num,col) (((u32)((delay)+0)<<20) | ((u32)(col)<<12) | ((u32)((num)-1)<<1) | B0)
22 
23 // init word of color layer LAYERPROG_MONO
24 #define VGACOLOR(delay,num) (((u32)((delay)+2)<<20) | ((u32)0xff<<12) | ((u32)((num)-1)<<1) | 0)
25 
26 // init word of black color layer LAYERPROG_BLACK
27 #define VGABLACK(delay,num) (((u32)((delay)+3)<<16) | (u32)((num)-1))
28 
29 // init word of white color layer LAYERPROG_WHITE
30 #define VGAWHITE(delay,num) (((u32)((delay)+3)<<16) | (u32)((num)-1))
31 
32 // init word of RLE layer LAYERPROG_RLE
33 #define VGARLE(delay) ((delay)+1)
34 
35 // swap bytes of command
36 #define BYTESWAP(n) ((((n)&0xff)<<24)|(((n)&0xff00)<<8)|(((n)&0xff0000)>>8)|(((n)&0xff000000)>>24))
37 
38 // align to multiple of 4
39 #define ALIGN4(x) ((x) & ~3)
40 
41 // Layer program descriptor
42 typedef struct {
43  const u16* ins; // pointer to program instructions (NULL=layers is OFF)
44  const struct pio_program* prg; // pointer to program descriptor
45  u8 length; // program length (number of instructions)
46  u8 wrap_target; // offset of wrap target
47  u8 wrap; // offset of wrap end
48  u8 idle; // offset of idle
49  u8 entry; // offset of entry
50  u8 maxidle; // max. offset of idle to detect end of job
51  u8 extranum; // number of extra offsets
52  u8 extra[2*16]; // extra offsets, pairs: offset, CPP-correction
53 } sLayerProg;
54 
55 // layer program descriptors
56 extern const sLayerProg LayerProg[LAYERPROG_NUM];
57 
58 // current layer program of overlapped layers
59 extern u8 LayerProgInx; // index of current layer program (LAYERPROG_*, LAYERPROG_BASE = overlapped layers are OFF)
60 extern sLayerProg CurLayerProg; // copy of current layer program
61 
62 // layer mode descriptor
63 typedef struct {
64  u8 prog; // layer program (LAYERPROG_*)
65  u8 mincpp; // minimal clock cycles per pixel
66  u8 maxcpp; // maximal clock cycles per pixel
67 } sLayerMode;
68 
69 // layer mode descriptors
70 extern const sLayerMode LayerMode[LAYERMODE_NUM];
71 
72 // current layer mode of layers
73 extern u8 LayerModeInx[LAYERS]; // index of current layer mode (LAYERMODE_*)
74 extern sLayerMode CurLayerMode[LAYERS]; // copy of current layer mode
75 extern u8 LayerMask; // mask of active layers
76 
194 typedef struct {
196  const u8* img;
197  const void* par;
198  u32 init;
199  u32 keycol;
200  u16 trans;
201  s16 x;
202  s16 y;
203  u16 w;
204  u16 h;
205  u16 wb;
206  u8 mode;
207  s8 horiz;
208  u8 xbits;
209  u8 ybits;
210  u16 spritenum;
211  Bool on;
212  u8 cpp;
213 } sLayer;
214 
216 typedef struct {
217  u8* img;
218  u8* x0;
219  u8* w0;
220  u32 keycol;
221  s16 x;
222  s16 y;
223  u16 w;
224  u16 h;
225  u16 wb;
226  u16 res;
227 } sSprite;
228 
230 extern sLayer LayerScreen[LAYERS];
231 
233 extern u8 LayerFirstPin[LAYERS_MAX];
234 
236 extern u8 LayerNumPin[LAYERS_MAX];
237 
242 void LayerOn(u8 inx);
243 
248 void LayerOff(u8 inx);
249 
255 void LayerSetX(u8 inx, s16 x);
256 
262 void LayerSetY(u8 inx, s16 y);
263 
270 void LayerSetW(u8 inx, u16 w);
271 
277 void LayerSetH(u8 inx, u16 h);
278 
293 void LayerSetup(u8 inx, const u8* img, const sVmode* vmode, u16 w, u16 h, u8 col = 0, const void* par = NULL);
294 
311 void LayerPerspSetup(u8 inx, const u8* img, const sVmode* vmode, u16 w, u16 h, u8 xbits, u8 ybits,
312  s8 horiz, const int* mat, u8 col = 0);
313 
315 
392 void LayerSpriteSetup(u8 inx, sSprite** sprite, u16 spritenum, const sVmode* vmode,
393  s16 x, s16 y, u16 w, u16 h, u8 col = 0);
394 
411 void SpritePrepLines(const u8* img, u8* x0, u8* w0, u16 w, u16 h, u16 wb, u8 col, Bool fast);
412 
423 void SortSprite(sSprite** list, int num);
424 
426 
427 #endif // _VGA_LAYER_H
sLayer::ybits
u8 ybits
Number of bits of height of source image (only with LAYERMODE_PERSP* modes)
Definition: vga_layer.h:209
sSprite
Sprite (on change update SSPRITE_* in define.h)
Definition: vga_layer.h:216
sLayer::on
Bool on
Layer is ON.
Definition: vga_layer.h:211
sLayer::img
const u8 * img
Pointer to image in current layer format, or sprite list.
Definition: vga_layer.h:196
LayerFirstPin
u8 LayerFirstPin[LAYERS_MAX]
Index of first pin of layer (base layer should stay VGA_GPIO_FIRST)
Definition: vga_layer.cpp:275
sLayer::keycol
u32 keycol
Key color.
Definition: vga_layer.h:199
LAYERMODE_NUM
#define LAYERMODE_NUM
Number of overlapped layer modes.
Definition: define.h:55
LayerSetW
void LayerSetW(u8 inx, u16 w)
Set width of image of overlapped layer.
Definition: vga_layer.cpp:357
sLayer::h
u16 h
Height.
Definition: vga_layer.h:204
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.
Definition: vga_layer.cpp:411
sSprite::x
s16 x
SSPRITE_X sprite X-coordinate on the screen.
Definition: vga_layer.h:221
LayerScreen
sLayer LayerScreen[LAYERS]
Current layer screens.
Definition: vga_layer.cpp:270
SortSprite
void SortSprite(sSprite **list, int num)
Sort fast sprite list by X coordinate.
Definition: vga_layer.cpp:493
sSprite::w
u16 w
SSPRITE_W sprite width (slow sprite: max. width 255)
Definition: vga_layer.h:223
sLayerMode
Definition: vga_layer.h:63
LayerSetY
void LayerSetY(u8 inx, s16 y)
Set coordinate Y of overlapped layer.
Definition: vga_layer.cpp:349
sLayer::wb
u16 wb
Image width in bytes (pitch of lines)
Definition: vga_layer.h:205
sSprite::x0
u8 * x0
SSPRITE_X0 pointer to array of start of lines, or fast sprite start of lines/4.
Definition: vga_layer.h:218
sSprite::w0
u8 * w0
SSPRITE_W0 pointer to array of length of lines, or fast sprite length of lines/4.
Definition: vga_layer.h:219
LAYERPROG_NUM
#define LAYERPROG_NUM
Number of layer programs.
Definition: define.h:28
sLayer::trans
u16 trans
Trans count.
Definition: vga_layer.h:200
sSprite::wb
u16 wb
SSPRITE_WB sprite pitch (number of bytes between lines)
Definition: vga_layer.h:225
LayerSetX
void LayerSetX(u8 inx, s16 x)
Set coordinate X of overlapped layer.
Definition: vga_layer.cpp:297
sLayerProg
Definition: vga_layer.h:42
sSprite::img
u8 * img
SSPRITE_IMG pointer to image data.
Definition: vga_layer.h:217
sSprite::keycol
u32 keycol
SSPRITE_KEYCOL key color.
Definition: vga_layer.h:220
sLayer::cpp
u8 cpp
Current clock pulses per pixel (used to calculate X coordinate)
Definition: vga_layer.h:212
sLayer::init
u32 init
Init word sent on start of scanline (start X coordinate)
Definition: vga_layer.h:198
LayerSpriteSetup
void LayerSpriteSetup(u8 inx, sSprite **sprite, u16 spritenum, const sVmode *vmode, s16 x, s16 y, u16 w, u16 h, u8 col=0)
Setup overlapped layer 1..3 for LAYERMODE_SPRITE* and LAYERMODE_FASTSPRITE* modes.
Definition: vga_layer.cpp:432
sLayer::mode
u8 mode
Layer mode.
Definition: vga_layer.h:206
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)
Definition: vga_layer.cpp:383
sLayer::horiz
s8 horiz
Horizon of perspective projection/4 (only with LAYERMODE_PERSP* modes, 0=no perspecitve,...
Definition: vga_layer.h:207
sLayer
Layer screen descriptor (on change update SLAYER_* in define.h)
Definition: vga_layer.h:195
sLayer::xbits
u8 xbits
Number of bits of width of source image (only with LAYERMODE_PERSP* modes)
Definition: vga_layer.h:208
LayerOff
void LayerOff(u8 inx)
Set overlapped layer 1..3 OFF.
Definition: vga_layer.cpp:289
sLayer::x
s16 x
Start X coordinate.
Definition: vga_layer.h:201
sLayer::y
s16 y
Start Y coordinate.
Definition: vga_layer.h:202
sSprite::res
u16 res
Reserved, structure align.
Definition: vga_layer.h:226
LayerSetH
void LayerSetH(u8 inx, u16 h)
Set height of image of overlapped layer.
Definition: vga_layer.cpp:368
sLayer::par
const void * par
Additional parameter (RLE index table, integer transformation matrix)
Definition: vga_layer.h:197
sSprite::y
s16 y
SSPRITE_Y sprite Y-coordinate on the screen.
Definition: vga_layer.h:222
sVmode
Videomode table - used to setup video driver.
Definition: vga_vmode.h:119
sLayer::w
u16 w
Width in pixels.
Definition: vga_layer.h:203
LayerNumPin
u8 LayerNumPin[LAYERS_MAX]
Number of pins of overlapped layer (base layer should stay VGA_GPIO_OUTNUM)
Definition: vga_layer.cpp:278
sLayer::spritenum
u16 spritenum
Number of sprites.
Definition: vga_layer.h:210
SpritePrepLines
void SpritePrepLines(const u8 *img, u8 *x0, u8 *w0, u16 w, u16 h, u16 wb, u8 col, Bool fast)
Prepare array of start and length of lines (detects transparent pixels)
Definition: vga_layer.cpp:451
sSprite::h
u16 h
SSPRITE_H sprite height.
Definition: vga_layer.h:224
LayerOn
void LayerOn(u8 inx)
Set overlapped layer 1..3 ON.
Definition: vga_layer.cpp:281