PicoVGA  1.0-cmake
VGA/TV display on Raspberry Pico
define.h
Go to the documentation of this file.
1 
7 #include "vga_config.h" // VGA configuration
8 
9 #define LAYERS_MAX 4 // max. number of layers (should be 4)
10 
11 #define BLACK_MAX MAXX // size of buffer with black color (used to clear rest of unused line)
12 
15 
16 // VGA PIO program
17 #define BASE_OFFSET 17
18 #define LAYER_OFFSET 0
19 
20 // layer program
21 #define LAYERPROG_BASE 0
22 #define LAYERPROG_KEY 1
23 #define LAYERPROG_BLACK 2
24 #define LAYERPROG_WHITE 3
25 #define LAYERPROG_MONO 4
26 #define LAYERPROG_RLE 5
27 
28 #define LAYERPROG_NUM 6
29 
30 // layer mode (CPP = clock cycles per pixel)
31 // Control buffer: 16 bytes
32 // Data buffer: 4 bytes
33 // fast sprites can be up Control buffer: width*2 bytes
34 // sprites Data buffer: width bytes
35 #define LAYERMODE_BASE 0
36 #define LAYERMODE_KEY 1
37 #define LAYERMODE_BLACK 2
38 #define LAYERMODE_WHITE 3
39 #define LAYERMODE_MONO 4
40 #define LAYERMODE_COLOR 5
41 #define LAYERMODE_RLE 6
42 #define LAYERMODE_SPRITEKEY 7
43 #define LAYERMODE_SPRITEBLACK 8
44 #define LAYERMODE_SPRITEWHITE 9
45 #define LAYERMODE_FASTSPRITEKEY 10
46 #define LAYERMODE_FASTSPRITEBLACK 11
47 #define LAYERMODE_FASTSPRITEWHITE 12
48 #define LAYERMODE_PERSPKEY 13
49 #define LAYERMODE_PERSPBLACK 14
50 #define LAYERMODE_PERSPWHITE 15
51 #define LAYERMODE_PERSP2KEY 16
52 #define LAYERMODE_PERSP2BLACK 17
53 #define LAYERMODE_PERSP2WHITE 18
54 
55 #define LAYERMODE_NUM 19
56 
57 
59 // Structure of sprite sSprite (on change update structure sSprite in vga_layer.h)
60 #define SSPRITE_IMG 0 // u8* img; // pointer to image data
61 #define SSPRITE_X0 4 // u8* x0; // pointer to pixel offset of start of lines/4 (used with fast sprites)
62 #define SSPRITE_W0 8 // u8* w0; // pointer to pixel length of length of lines/4 (used with fast sprites)
63 #define SSPRITE_KEYCOL 12 // u32 keycol; // key color
64 #define SSPRITE_X 16 // s16 x; // sprite X-coordinate on the screen
65 #define SSPRITE_Y 18 // s16 y; // sprite Y-coordinate on the screen
66 #define SSPRITE_W 20 // u16 w; // sprite width
67 #define SSPRITE_H 22 // u16 h; // sprite height
68 #define SSPRITE_WB 24 // u16 wb; // sprite pitch (number of bytes between lines)
69  // u16 res; // ...reserved, structure align
70 #define SSPRITE_SIZE 28 // size of sSprite structure
71 
72 // Structure of layer screen sLayer (on change update structure sLayer in vga_layer.h)
73 #define SLAYER_IMG 0 // const u8* img; // pointer to image in current layer format, or sprite list
74 #define SLAYER_PAR 4 // const void* par; // additional parameter (RLE index table, transformation matrix)
75 #define SLAYER_INIT 8 // u32 init; // init word sent on start of scanline
76 #define SLAYER_KEYCOL 12 // u32 keycol; // key color
77 #define SLAYER_TRANS 16 // u16 trans; // trans count
78 #define SLAYER_X 18 // s16 x; // start X coordinate
79 #define SLAYER_Y 20 // s16 y; // start Y coordinate
80 #define SLAYER_W 22 // u16 w; // width in pixels
81 #define SLAYER_H 24 // u16 h; // height
82 #define SLAYER_WB 26 // u16 wb; // image width in bytes (pitch of lines)
83 #define SLAYER_MODE 28 // u8 mode; // layer mode
84 #define SLAYER_HORIZ 29 // s8 horiz; // horizon of perspective projection/4 (only with LAYERMODE_PERSP* modes, 0=no perspecitve, <0 ceilling)
85 #define SLAYER_XBITS 30 // u8 xbits; // number of bits of width of source image (only with LAYERMODE_PERSP* modes)
86 #define SLAYER_YBITS 31 // u8 ybits; // number of bits of height of source image (only with LAYERMODE_PERSP* modes)
87 #define SLAYER_SPRITENUM 32 // u16 spritenum; // number of sprites
88 #define SLAYER_ON 34 // Bool on; // layer is ON
89 #define SLAYER_CPP 35 // u8 cpp; // current clock pulses per pixel (used to calculate X coordinate)
90 #define SLAYER_SIZE 36 // size of sLayer structure
91 
92 // Structure of video segment sSegm (on change update structure sSegm in vga_screen.h)
93 #define SSEGM_WIDTH 0 // u16 width; // width of this video segment in pixels (must be multiple of 4, 0=inactive segment)
94 #define SSEGM_WB 2 // u16 wb; // pitch - number of bytes between lines
95 #define SSEGM_OFFX 4 // s16 offx; // display offset at X direction (must be multiple of 4)
96 #define SSEGM_OFFY 6 // s16 offy; // display offset at Y direction
97 #define SSEGM_WRAPX 8 // u16 wrapx; // wrap width in X direction (number of pixels, must be multiply of 4 and > 0)
98  // text modes: wrapx must be multiply of 8
99 #define SSEGM_WRAPY 10 // u16 wrapy; // wrap width in Y direction (number of lines, cannot be 0)
100 #define SSEGM_DATA 12 // const void* data; // pointer to video buffer with image data
101 #define SSEGM_FORM 16 // u8 form; // graphics format GF_*
102 #define SSEGM_DBLY 17 // bool dbly; // double Y (2 scanlines per 1 image line)
103 #define SSEGM_PAR3 18 // u16 par3; // SSEGM_PAR3 parameter 3
104 #define SSEGM_PAR 20 // u32 par; // parameter 1: color, pointer to palettes, tile source, font
105 #define SSEGM_PAR2 24 // u32 par2; // parameter 2
106 #define SSEGM_SIZE 28 // size of sSegm structure
107 
108 // Structure of video strip sStrip (on change update structure sStrip in vga_screen.h)
109 #define SSTRIP_HEIGHT 0 // u16 height; // height of this strip in number of scanlines
110 #define SSTRIP_NUM 2 // u16 num; // number of video segments
111 #define SSTRIP_SEG 4 // sSegm seg[SEGMAX];
112 #define SSTRIP_SIZE (4+SSEGM_SIZE*SEGMAX) // size of sStrip structure (= 4 + 28*8 = 228 bytes)
113 
114 // Structure of video screen sScreen (on change update structure sScreen in vga_screen.h)
115 #define SSCREEN_NUM 0 // u16 num; // number of video strips
116 #define SSCREEN_BACKUP 2 // u16 num_backup; // backup number of video strips during display OFF
117 #define SSCREEN_STRIP 4 // sStrip strip[STRIPMAX]; // list of video strips
118 #define SSCREEN_SIZE (4+SSTRIP_SIZE*STRIPMAX) // size of sScreen structure (= 4 + 228*8 = 1828 bytes)
119 
120 // --- graphics formats
121 // There are 3 groups of formats - separated due internal reasons, do not mix them.
122 
123 // 1st group of formats - rendered specially
124 #define GF_COLOR 0 // simple color (par=color pattern 4-pixels even line, par2=color pattern 4-pixels odd line)
125 // Data buffer: width bytes (320 pixels: 320 bytes)
126 // Control buffer: 8 bytes
127 
128 // 2nd group of formats - rendering into control buffer cbuf
129 #define GF_GRAPH8 1 // native 8-bit graphics (X1Y1R2G2B2) - fast, transfers "as is" to PIO
130  // (num = number of pixels/4 = number of bytes/4)
131 // Control buffer: 8 bytes (320 pixels: 8 bytes)
132 #define GF_TILE 2 // tiles (par = tile table with one column of tiles,
133  // par2 = tile height, par3 = tile width as multiple of 4)
134 // Control buffer: width/tile width*8 bytes (320 pixels of 32x32: 80 bytes)
135 #define GF_TILE2 3 // alternate tiles (par = tile table with one row of tiles,
136  // par2 = LOW tile height, HIGH tile width bytes,
137  // par3 = tile width as multiple of 4)
138 // Control buffer: width/tile width*8 bytes (320 pixels of 32x32: 80 bytes)
139 #define GF_PROGRESS 4 // horizontal progress indicator (data = values 0..255 of 4-pixels in rows,
140  // par = scanline gradient < data, par2 = scanline gradient >= data)
141 // Control buffer: 16 bytes
142 #define GF_GRAD1 5 // gradient with 1 line
143 // Control buffer: 8 bytes (320 pixels: 8 bytes)
144 #define GF_GRAD2 6 // gradient with 2 lines
145 // Control buffer: 8 bytes (320 pixels: 8 bytes)
146 
147 #define GF_GRP2MIN GF_GRAPH8 // 2nd group minimal format
148 #define GF_GRP2MAX GF_GRAD2 // 2nd group maximal format
149 
150 // 3rd group of formats - rendering into data buffer dbuf
151 // Control buffer: 8 bytes
152 // Data buffer: width bytes
153 #define GF_GRAPH4 7 // 4-bit graphics (num = number of pixels/4 = number of bytes/2;
154  // par = pointer to 16-color palette translation table)
155 #define GF_GRAPH2 8 // 2-bit graphics (num = number of pixels/4 = number of bytes,
156  // par = pointer to 4-color palette translation table)
157 #define GF_GRAPH1 9 // 1-bit graphics (num = number of pixels/8 = number of bytes,
158  // par = 2 colors of palettes)
159 #define GF_MTEXT 10 // 8-pixel mono text (num = number of characters, font is 8-bit width,
160  // par = pointer to 1-bit font, par2 = 2 colors of palettes)
161 #define GF_ATEXT 11 // 8-pixel attribute text, character + 2x4 bit attributes
162  // (num = number of characters, font is 8-bit width,
163  // par = pointer to 1-bit font, par2 = pointer to 16 colors of palettes)
164 #define GF_FTEXT 12 // 8-pixel foreground color text, character + foreground color
165  // (num = number of characters, font is 8-bit width,
166  // par = pointer to 1-bit font, par2 = background color)
167 #define GF_CTEXT 13 // 8-pixel color text, character + background color + foreground color
168  // (num = number of characters, font is 8-bit width,
169  // par = pointer to 1-bit font)
170 #define GF_GTEXT 14 // 8-pixel gradient text (par = pointer to 1-bit font, par2 = pointer to color array)
171 #define GF_DTEXT 15 // 8-pixel double gradient text (par = pointer to 1-bit font, par2 = pointer to color array)
172 #define GF_LEVEL 16 // level graph (data=samples 0..255, par = 2 colors of palettes, par2 = Y zero level 0..255)
173 #define GF_LEVELGRAD 17 // level gradient graph (data = samples 0..255, par = scanline gradient < data, par2 = scanline gradient >= data)
174 #define GF_OSCIL 18 // oscilloscope pixel graph (data=samples 0..255, par = 2 colors of palettes, par2 = height of pixels - 1)
175 #define GF_OSCLINE 19 // oscilloscope line graph (data=samples 0..255, par = 2 colors of palettes)
176 #define GF_PLANE2 20 // 4 colors on 2 graphic planes (data=graphic, par=offset of 2nd graphic plane,
177  // par2 = pointer to 4-color palette translation table)
178 #define GF_ATTRIB8 21 // 2x4 bit color attribute per 8x8 pixel sample (data=mono graphic, par=offset of color attributes,
179  // par2 = pointer to 16-color palette table)
180 #define GF_GRAPH8MAT 22 // 8-bit graphics with 2D matrix transformation, using hardware interpolator inter1 (inter1 state is not saved during interrup)
181  // (data=image, par=pointer to 6 matrix integer parameters m11,m12..m23 ((int)(m*FRACTMUL)),
182  // par2 LOW=number of bits of image width, par2 HIGH=number of bits of image height)
183 #define GF_GRAPH8PERSP 23 // 8-bit graphics with perspective, using hardware interpolator inter1 (inter1 state is not saved during interrup)
184  // (data=image, par=pointer to 6 matrix integer parameters m11,m12..m23 ((int)(m*FRACTMUL)),
185  // par2 LOW=number of bits of image width, par2 HIGH=number of bits of image height,
186  // par3=horizon offset)
187 #define GF_TILEPERSP 24 // tiles with perspective, using hardware interpolators inter0 and inter1 (their state is not saved during interrup)
188  // (data=tile map, par=one column of tiles, par2=pointer to integer matrix,
189  // wb LOW=number of bits of map width, wb HIGH=number of bits of map height,
190  // par3 LOW=number of bits of tile size, par3 HIGH=horizon offset/4 or 0=no perspective or <0=ceilling,
191  // wrapy=segment height)
192 #define GF_TILEPERSP15 25 // tiles with perspective, 1.5 pixels (parameters as GF_TILEPERSP)
193 #define GF_TILEPERSP2 26 // tiles with perspective, double pixels (parameters as GF_TILEPERSP)
194 #define GF_TILEPERSP3 27 // tiles with perspective, triple pixels (parameters as GF_TILEPERSP)
195 #define GF_TILEPERSP4 28 // tiles with perspective, quadruple pixels (parameters as GF_TILEPERSP)
196 
197 #define GF_GRP3MIN GF_GRAPH4 // 3rd group minimal format
198 #define GF_GRP3MAX GF_TILEPERSP4 // 3rd group maximal format
199 
200 
201 #define FRACT 12 // number of bits of fractional part of fractint number (use max. 13, min. 8)
202 #define FRACTMUL (1<<FRACT)