Commit 17cdbeb8 authored by Bjorn Astrom's avatar Bjorn Astrom
Browse files

Full WIP DMARTG rendering implementation

parent 2f3374db
......@@ -625,7 +625,7 @@ void draw_line_solid(int16_t rect_x1, int16_t rect_y1, int16_t rect_x2, int16_t
break; \
}
void p2c_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint16_t sh, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src)
void p2c_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src)
{
uint32_t *dp = fb + (dy * fb_pitch);
......@@ -671,7 +671,7 @@ void p2c_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t
}
}
void p2d_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint16_t sh, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint32_t color_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src, uint32_t color_format)
void p2d_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint32_t color_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src, uint32_t color_format)
{
uint32_t *dp = fb + (dy * fb_pitch);
......
......@@ -53,8 +53,8 @@ void pattern_fill_rect(uint32_t color_format, uint16_t rect_x1, uint16_t rect_y1
void draw_line(int16_t rect_x1, int16_t rect_y1, int16_t rect_x2, int16_t rect_y2, uint16_t len, uint16_t pattern, uint16_t pattern_offset, uint32_t fg_color, uint32_t bg_color, uint32_t color_format, uint8_t mask, uint8_t draw_mode);
void draw_line_solid(int16_t rect_x1, int16_t rect_y1, int16_t rect_x2, int16_t rect_y2, uint16_t len, uint32_t fg_color, uint32_t color_format);
void p2c_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint16_t sh, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src);
void p2d_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint16_t sh, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint32_t color_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src, uint32_t color_format);
void p2c_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src);
void p2d_rect(int16_t sx, int16_t sy, int16_t dx, int16_t dy, int16_t w, int16_t h, uint8_t draw_mode, uint8_t planes, uint8_t mask, uint8_t layer_mask, uint32_t color_mask, uint16_t src_line_pitch, uint8_t *bmp_data_src, uint32_t color_format);
void invert_rect(uint16_t rect_x1, uint16_t rect_y1, uint16_t w, uint16_t h, uint8_t mask, uint32_t color_format);
#define MNTVA_COLOR_8BIT 0
......@@ -490,3 +490,40 @@ enum gfx_minterm_modes {
d[x] |= (s & color_mask); break; \
} break; \
}
#pragma pack(4)
struct GFXData {
uint32_t offset[2];
uint32_t rgb[2];
uint16_t x[4], y[4];
uint16_t user[4];
uint16_t pitch[4];
uint8_t u8_user[8];
uint8_t op, mask, minterm, u8offset;
};
enum gfx_dma_op {
OP_NONE,
OP_DRAWLINE,
OP_FILLRECT,
OP_COPYRECT,
OP_COPYRECT_NOMASK,
OP_RECT_TEMPLATE,
OP_RECT_PATTERN,
OP_P2C,
OP_P2D,
OP_INVERTRECT,
OP_NUM,
};
enum gfxdata_offsets {
GFXDATA_DST,
GFXDATA_SRC,
};
enum gfxdata_u8_types {
GFXDATA_U8_COLORMODE,
GFXDATA_U8_DRAWMODE,
GFXDATA_U8_LINE_PATTERN_OFFSET,
GFXDATA_U8_LINE_PADDING,
};
......@@ -29,6 +29,7 @@
#include "xil_cache.h"
#include "xclk_wiz.h"
#include "xil_exception.h"
#include "xtime_l.h"
#include "gfx.h"
#include "ethernet.h"
......@@ -605,7 +606,7 @@ void video_system_init_2(struct zz_video_mode *mode, int hdiv, int vdiv) {
#define MNT_FB_BASE 0x010000
#define REVISION_MAJOR 1
#define REVISION_MINOR 6
#define REVISION_MINOR 7
void video_mode_init(int mode, int scalemode, int colormode) {
int hdiv = 1, vdiv = 1;
......@@ -1016,6 +1017,8 @@ int main() {
int interrupt_enabled = 0;
int request_video_align=0;
int old_vblank = 0;
XTime time1 = 0, time2 = 0;
int vblank=0;
int custom_video_mode = ZZVMODE_CUSTOM;
......@@ -1269,6 +1272,201 @@ int main() {
rect_rgb2 |= (((zdata & 0xff) << 8) | zdata >> 8) << 16;
break;
#define SWAP16(a) a = __builtin_bswap16(a);
#define SWAP32(a) a = __builtin_bswap32(a);
// DMA RTG rendering
case REG_ZZ_BITTER_DMA_OP: {
struct GFXData *data = (struct GFXData*)((u32)Z3_SCRATCH_ADDR);
switch(zdata) {
// DrawLine
case OP_DRAWLINE:
SWAP16(data->x[0]);
SWAP16(data->x[1]);
SWAP16(data->y[0]);
SWAP16(data->y[1]);
SWAP16(data->user[0]);
SWAP16(data->user[1]);
SWAP16(data->pitch[0]);
SWAP32(data->offset[0]);
set_fb((uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0]);
if (data->user[1] == 0xFFFF && data->mask == 0xFF)
draw_line_solid(data->x[0], data->y[0], data->x[1], data->y[1],
data->user[0], data->rgb[0],
data->u8_user[GFXDATA_U8_COLORMODE]);
else
draw_line(data->x[0], data->y[0], data->x[1], data->y[1],
data->user[0], data->user[1], data->user[2], data->rgb[0], data->rgb[1],
data->u8_user[GFXDATA_U8_COLORMODE], data->mask, data->u8_user[GFXDATA_U8_DRAWMODE]);
break;
// FillRect
case OP_FILLRECT:
SWAP16(data->x[0]);
SWAP16(data->x[1]);
SWAP16(data->y[0]);
SWAP16(data->y[1]);
SWAP16(data->pitch[0]);
SWAP32(data->offset[0]);
set_fb((uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0]);
if (data->mask == 0xFF)
fill_rect_solid(data->x[0], data->y[0], data->x[1], data->y[1],
data->rgb[0], data->u8_user[GFXDATA_U8_COLORMODE]);
else
fill_rect(data->x[0], data->y[0], data->x[1], data->y[1], data->rgb[0],
data->u8_user[GFXDATA_U8_COLORMODE], data->mask);
break;
// CopyRect / CopyRectNoMaskComplete
case OP_COPYRECT:
case OP_COPYRECT_NOMASK:
SWAP16(data->x[0]);
SWAP16(data->x[1]);
SWAP16(data->x[2]);
SWAP16(data->y[0]);
SWAP16(data->y[1]);
SWAP16(data->y[2]);
SWAP16(data->pitch[0]);
SWAP16(data->pitch[1]);
SWAP32(data->offset[0]);
SWAP32(data->offset[1]);
set_fb((uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0]);
switch (zdata) {
case 3: // Regular BlitRect
if (data->mask == 0xFF || (data->mask != 0xFF && data->u8_user[GFXDATA_U8_COLORMODE] != MNTVA_COLOR_8BIT))
copy_rect_nomask(data->x[0], data->y[0], data->x[1], data->y[1], data->x[2],
data->y[2], data->u8_user[GFXDATA_U8_COLORMODE],
(uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0], MINTERM_SRC);
else
copy_rect(data->x[0], data->y[0], data->x[1], data->y[1], data->x[2],
data->y[2], data->u8_user[GFXDATA_U8_COLORMODE],
(uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0], data->mask);
break;
case 4: // BlitRectNoMaskComplete
copy_rect_nomask(data->x[0], data->y[0], data->x[1], data->y[1], data->x[2],
data->y[2], data->u8_user[GFXDATA_U8_COLORMODE],
(uint32_t*) ((u32) framebuffer + data->offset[1]),
data->pitch[1], data->minterm);
break;
}
break;
// FillTemplate / FillPattern
case OP_RECT_PATTERN:
case OP_RECT_TEMPLATE: {
SWAP16(data->x[0]);
SWAP16(data->x[1]);
SWAP16(data->x[2]);
SWAP16(data->y[0]);
SWAP16(data->y[1]);
SWAP16(data->y[2]);
SWAP16(data->pitch[0]);
SWAP16(data->pitch[1]);
SWAP32(data->offset[0]);
SWAP32(data->offset[1]);
uint8_t* tmpl_data = (uint8_t*) ((u32) framebuffer
+ data->offset[1]);
set_fb((uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0]);
uint8_t bpp = 2 * data->u8_user[GFXDATA_U8_COLORMODE];
if (bpp == 0)
bpp = 1;
uint16_t loop_rows = 0;
if (zdata == OP_RECT_PATTERN) {
SWAP16(data->user[0]);
loop_rows = data->user[0];
pattern_fill_rect(data->u8_user[GFXDATA_U8_COLORMODE], data->x[0],
data->y[0], data->x[1], data->y[1], data->u8_user[GFXDATA_U8_DRAWMODE], data->mask,
data->rgb[0], data->rgb[1], data->x[2], data->y[2], tmpl_data,
16, loop_rows);
}
else {
template_fill_rect(data->u8_user[GFXDATA_U8_COLORMODE], data->x[0],
data->y[0], data->x[1], data->y[1], data->u8_user[GFXDATA_U8_DRAWMODE], data->mask,
data->rgb[0], data->rgb[1], data->x[2], data->y[2], tmpl_data,
data->pitch[1]);
}
break;
}
// P2C / P2D
case OP_P2C:
case OP_P2D: {
SWAP16(data->x[0]);
SWAP16(data->x[1]);
SWAP16(data->x[2]);
SWAP16(data->y[0]);
SWAP16(data->y[1]);
SWAP16(data->y[2]);
SWAP16(data->pitch[0]);
SWAP16(data->pitch[1]);
SWAP32(data->offset[0]);
SWAP32(data->offset[1]);
SWAP16(data->user[0]);
SWAP16(data->user[1]);
uint8_t* bmp_data = (uint8_t*) ((u32) framebuffer
+ data->offset[1]);
set_fb((uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0]);
if (zdata == OP_P2C) {
p2c_rect(data->x[0], 0, data->x[1], data->y[1], data->x[2],
data->y[2], data->minterm, data->user[1], data->mask,
data->user[0], data->pitch[1], bmp_data);
}
else {
SWAP32(data->rgb[0]);
p2d_rect(data->x[0], 0, data->x[1], data->y[1], data->x[2],
data->y[2], data->minterm, data->user[1], data->mask, data->user[0],
data->rgb[0], data->pitch[1], bmp_data, data->u8_user[GFXDATA_U8_COLORMODE]);
}
break;
}
case OP_INVERTRECT:
SWAP16(data->x[0]);
SWAP16(data->x[1]);
SWAP16(data->y[0]);
SWAP16(data->y[1]);
SWAP16(data->pitch[0]);
SWAP32(data->offset[0]);
set_fb((uint32_t*) ((u32) framebuffer + data->offset[0]),
data->pitch[0]);
invert_rect(data->x[0], data->y[0], data->x[1], data->y[1],
data->mask, data->u8_user[GFXDATA_U8_COLORMODE]);
break;
default:
break;
}
break;
}
// RTG rendering
case REG_ZZ_FILLRECT:
set_fb((uint32_t*) ((u32) framebuffer + blitter_dst_offset),
......@@ -1401,7 +1599,6 @@ int main() {
uint8_t draw_mode = blitter_colormode >> 8;
uint8_t planes = (zdata & 0xFF00) >> 8;
uint8_t mask = (zdata & 0xFF);
uint16_t num_rows = blitter_user1;
uint8_t layer_mask = blitter_user2;
uint8_t* bmp_data = (uint8_t*) ((u32) framebuffer
+ blitter_src_offset);
......@@ -1410,7 +1607,7 @@ int main() {
blitter_dst_pitch);
p2c_rect(rect_x1, 0, rect_x2, rect_y2, rect_x3,
rect_y3, num_rows, draw_mode, planes, mask,
rect_y3, draw_mode, planes, mask,
layer_mask, blitter_src_pitch, bmp_data);
break;
}
......@@ -1419,7 +1616,6 @@ int main() {
uint8_t draw_mode = blitter_colormode >> 8;
uint8_t planes = (zdata & 0xFF00) >> 8;
uint8_t mask = (zdata & 0xFF);
uint16_t num_rows = blitter_user1;
uint8_t layer_mask = blitter_user2;
uint8_t* bmp_data = (uint8_t*) ((u32) framebuffer
+ blitter_src_offset);
......@@ -1427,7 +1623,7 @@ int main() {
set_fb((uint32_t*) ((u32) framebuffer + blitter_dst_offset),
blitter_dst_pitch);
p2d_rect(rect_x1, 0, rect_x2, rect_y2, rect_x3,
rect_y3, num_rows, draw_mode, planes, mask, layer_mask, rect_rgb,
rect_y3, draw_mode, planes, mask, layer_mask, rect_rgb,
blitter_src_pitch, bmp_data, (blitter_colormode & 0x0F));
break;
}
......
enum zz_video_modes {
ZZVMODE_1280x720,
ZZVMODE_800x600,
ZZVMODE_640x480,
ZZVMODE_1024x768,
ZZVMODE_1280x1024,
ZZVMODE_1920x1080_60,
ZZVMODE_720x576, // 50Hz
ZZVMODE_1920x1080_50, // 50Hz
ZZVMODE_720x480,
ZZVMODE_640x512,
ZZVMODE_CUSTOM,
ZZVMODE_NUM,
ZZVMODE_1280x720,
ZZVMODE_800x600,
ZZVMODE_640x480,
ZZVMODE_1024x768,
ZZVMODE_1280x1024,
ZZVMODE_1920x1080_60,
ZZVMODE_720x576, // 50Hz
ZZVMODE_1920x1080_50, // 50Hz
ZZVMODE_720x480,
ZZVMODE_640x512,
ZZVMODE_1600x1200,
ZZVMODE_2560x1440_30,
ZZVMODE_CUSTOM,
ZZVMODE_NUM,
};
struct zz_video_mode {
int hres, vres;
int hstart, hend, hmax;
int vstart, vend, vmax;
int polarity;
int mhz, phz, vhz;
int hdmi;
int mul, div, div2;
int hres, vres;
int hstart, hend, hmax;
int vstart, vend, vmax;
int polarity;
int mhz, phz, vhz;
int hdmi;
int mul, div, div2;
};
enum custom_vmode_params {
VMODE_PARAM_HRES,
VMODE_PARAM_VRES,
VMODE_PARAM_HSTART,
VMODE_PARAM_HEND,
VMODE_PARAM_HMAX,
VMODE_PARAM_VSTART,
VMODE_PARAM_VEND,
VMODE_PARAM_VMAX,
VMODE_PARAM_POLARITY,
VMODE_PARAM_MHZ,
VMODE_PARAM_PHZ,
VMODE_PARAM_VHZ,
VMODE_PARAM_HDMI,
VMODE_PARAM_MUL,
VMODE_PARAM_DIV,
VMODE_PARAM_DIV2,
VMODE_PARAM_NUM,
VMODE_PARAM_HRES,
VMODE_PARAM_VRES,
VMODE_PARAM_HSTART,
VMODE_PARAM_HEND,
VMODE_PARAM_HMAX,
VMODE_PARAM_VSTART,
VMODE_PARAM_VEND,
VMODE_PARAM_VMAX,
VMODE_PARAM_POLARITY,
VMODE_PARAM_MHZ,
VMODE_PARAM_PHZ,
VMODE_PARAM_VHZ,
VMODE_PARAM_HDMI,
VMODE_PARAM_MUL,
VMODE_PARAM_DIV,
VMODE_PARAM_DIV2,
VMODE_PARAM_NUM,
};
......@@ -56,6 +58,8 @@ struct zz_video_mode preset_video_modes[ZZVMODE_NUM] = {
{ 1920, 1080, 2448, 2492, 2640, 1084, 1089, 1125, 0, 150, 150000000, 50, 0, 15, 1, 10 },
{ 720, 480, 720, 752, 800, 490, 492, 525, 0, 25, 25175000, 60, 0, 15, 1, 60 },
{ 640, 512, 840, 968, 1056, 601, 605, 628, 0, 40, 40000000, 60, 0, 14, 1, 35 },
{ 1600, 1200, 1704, 1880, 2160, 1201, 1204, 1242, 0, 161, 16089999, 60, 0, 21, 1, 13 },
{ 2560, 1440, 2680, 2944, 3328, 1441, 1444, 1465, 0, 146, 15846000, 30, 0, 41, 2, 14 },
// The final exntry here is the custom video mode, accessible through registers for debug purposes.
{ 1280, 720, 1390, 1430, 1650, 725, 730, 750, 0, 75, 75000000, 60, 0, 15, 1, 20 },
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment