Files
mips/src/blittertest_tb.c
T
jens a655e1c5d9 - use build in data types
git-svn-id: http://moon:8086/svn/mips@35 a8ebac50-d88d-4704-bea3-6648445a41b3
2015-05-28 19:19:01 +00:00

179 lines
6.2 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <sys/times.h>
#include <sys/time.h>
#include "libsys.h"
#include "gpio.h"
#include "mips_gfx.h"
#define PIC_NX 800
#define PIC_NY 600
gpio_if_t gpio_if;
box_t box;
gfx_t gfx;
uint32_t color_cycle[12] = {0x000000FF, 0x00808080, 0x0000FFFF, 0x00808080, 0x0000FF00, 0x00808080, 0x00FFFF00, 0x00808080, 0x00FF0000, 0x00808080, 0x00FF00FF, 0x00808080};
void BlitConstColor(uint32_t fb_addr, uint32_t dim_x, uint32_t pos_x, uint32_t pos_y, uint32_t size_x, uint32_t size_y, uint32_t color);
void Blit(uint32_t fb_addr, uint32_t dim_x, uint32_t pos_x_src, uint32_t pos_y_src, uint32_t pos_x_dst, uint32_t pos_y_dst, uint32_t size_x, uint32_t size_y);
int main (void)
{
int result, i, j, cnt, size;
uint32_t volatile *pUART_baud = (uint32_t*)SYS_UART_BAUD;
uint32_t volatile *pUART_stat = (uint32_t*)SYS_UART_STAT;
uint32_t volatile *pGPIO = (uint32_t*)SYS_GPIO_0_DATA;
uint32_t volatile *pReg_usec = (uint32_t*)SYS_TIMER_USEC;
uint32_t volatile *pReg_sec = (uint32_t*)SYS_TIMER_SEC;
uint32_t volatile *pSSRAM = (uint32_t*)SYS_SSRAM_IO;
uint32_t volatile *pTim_ctrl = (uint32_t*)SYS_ITIM_CTRL;
uint32_t volatile *pTim_stat = (uint32_t*)SYS_ITIM_STAT;
uint32_t volatile *pTim0_cnt = (uint32_t*)SYS_ITIM0_CNT;
uint32_t volatile *pTim0_cmp = (uint32_t*)SYS_ITIM0_CMP;
uint32_t volatile *pTim1_cnt = (uint32_t*)SYS_ITIM1_CNT;
uint32_t volatile *pTim1_cmp = (uint32_t*)SYS_ITIM1_CMP;
uint32_t volatile *pVGA_cgcol = (uint32_t*)SYS_VGA_CGCOL;
uint32_t volatile *pFlashPicture = (uint32_t*)(SYS_FLASH_MEM + 0x00600000);
uint32_t volatile *pVGA_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0;
uint32_t volatile *pVGA_dst = (uint32_t*)SYS_VGA_BLIT_DST;
uint32_t volatile *pVGA_dimx_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0_DIMX;
uint32_t volatile *pVGA_dimx_dst = (uint32_t*)SYS_VGA_BLIT_DST_DIMX;
uint32_t volatile *pVGA_nx = (uint32_t*)SYS_VGA_BLIT_NX;
uint32_t volatile *pVGA_ny = (uint32_t*)SYS_VGA_BLIT_NY;
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
uint32_t volatile *pVGA_moffs_0 = (uint32_t*)SYS_VGA_FB_FRONT;
uint32_t volatile *pVGA_moffs_1 = (uint32_t*)SYS_VGA_FB_BACK;
uint32_t volatile *pVGA_const_color = (uint32_t*)SYS_VGA_BLIT_DST_LAST;
uint32_t screen_res_x, screen_res_y, screen_fps;
uint32_t pos, posx, posy, xoff, yoff, color;
uint64_t *pBuf64_0, *pBuf64_1;
time_t curr_date;
struct tm *pDate, date;
uint32_t start, end;
char sel[80];
struct timeval time_sec;
Screen_clr();
gpio_init(&gpio_if, SYS_GPIO_0_BASE);
*pVGA_ctrl &= ~SYS_VGA_BIT_BLIT_FIN_INTEN;
*pVGA_cgcol = 0x00FFFFFF;
pBuf64_0 = (uint64_t*)malloc(800*600*4);
*pVGA_moffs_0 = (uint32_t)pBuf64_0;
*pVGA_moffs_1 = (uint32_t)pBuf64_0;
*pVGA_ctrl |= SYS_VGA_BIT_MSTEN;
// GFX_init(&gfx);
while(1)
{
box_create(&box, 128, 128);
*pVGA_dimx_src0 = (uint32_t)4*800;
*pVGA_dimx_dst = (uint32_t)4*800;
*pVGA_nx = (uint32_t)box.w;
*pVGA_ny = (uint32_t)box.h;
*pVGA_ctrl |= SYS_VGA_BIT_BLIT_OP_CONSTCOL;
*pVGA_dst = (uint32_t)*pVGA_moffs_0 + 4*(5 + 800*5);// + 4*((uint32_t)rand()%800 + 800*((uint32_t)rand()%600));
*pGPIO = 1;
color = 0;
for (i=0; i < 100; i++)
{
// Blitter test
while (*pVGA_ctrl & SYS_VGA_BIT_BLIT_BSY);
color = ~color;
*pVGA_ctrl |= SYS_VGA_BIT_BLIT_REQ;
*pVGA_const_color = color;
}
while (*pVGA_ctrl & SYS_VGA_BIT_BLIT_ACTIVE);
// fprintf(stdout, "Hardware draw 1\n");
// sleep(1000);
*pGPIO = 0;
color = 0;
for (i=0; i < 100; i++)
{
// Blitter test
while (*pVGA_ctrl & SYS_VGA_BIT_BLIT_BSY);
*pVGA_const_color = color;
color = ~color;
*pVGA_ctrl |= SYS_VGA_BIT_BLIT_REQ;
}
while (*pVGA_ctrl & SYS_VGA_BIT_BLIT_ACTIVE);
// fprintf(stdout, "Hardware draw 2\n");
// sleep(1000);
}
}
void BlitConstColor(uint32_t fb_addr, uint32_t dim_x, uint32_t pos_x, uint32_t pos_y, uint32_t size_x, uint32_t size_y, uint32_t color)
{
uint32_t volatile *pVGA_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0;
uint32_t volatile *pVGA_dst = (uint32_t*)SYS_VGA_BLIT_DST;
uint32_t volatile *pVGA_dimx_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0_DIMX;
uint32_t volatile *pVGA_dimx_dst = (uint32_t*)SYS_VGA_BLIT_DST_DIMX;
uint32_t volatile *pVGA_nx = (uint32_t*)SYS_VGA_BLIT_NX;
uint32_t volatile *pVGA_ny = (uint32_t*)SYS_VGA_BLIT_NY;
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
uint32_t volatile *pVGA_moffs_0 = (uint32_t*)SYS_VGA_FB_FRONT;
uint32_t volatile *pVGA_const_color = (uint32_t*)SYS_VGA_BLIT_DST_LAST;
// fprintf(stdout, "BlitConstColor to (%d,%d), size (%d,%d) ...", pos_x, pos_y, size_x, size_y);
*pVGA_ctrl |= SYS_VGA_BIT_BLIT_OP_CONSTCOL;
*pVGA_const_color = color;
*pVGA_dst = fb_addr + 4*(pos_x + pos_y*dim_x);
*pVGA_dimx_dst = 4*dim_x;
*pVGA_nx = size_x - 0;
*pVGA_ny = size_y - 0;
while (*pVGA_ctrl & SYS_VGA_BIT_BLIT_BSY);
*pVGA_ctrl |= SYS_VGA_BIT_BLIT_REQ;
// fprintf(stdout, "done\n");
}
void Blit(uint32_t fb_addr, uint32_t dim_x, uint32_t pos_x_src, uint32_t pos_y_src, uint32_t pos_x_dst, uint32_t pos_y_dst, uint32_t size_x, uint32_t size_y)
{
uint32_t volatile *pVGA_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0;
uint32_t volatile *pVGA_dst = (uint32_t*)SYS_VGA_BLIT_DST;
uint32_t volatile *pVGA_dimx_src0 = (uint32_t*)SYS_VGA_BLIT_SRC0_DIMX;
uint32_t volatile *pVGA_dimx_dst = (uint32_t*)SYS_VGA_BLIT_DST_DIMX;
uint32_t volatile *pVGA_nx = (uint32_t*)SYS_VGA_BLIT_NX;
uint32_t volatile *pVGA_ny = (uint32_t*)SYS_VGA_BLIT_NY;
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
uint32_t volatile *pVGA_moffs_0 = (uint32_t*)SYS_VGA_FB_FRONT;
uint32_t volatile *pVGA_const_color = (uint32_t*)SYS_VGA_BLIT_DST_LAST;
// fprintf(stdout, "Blit from (%d,%d) to (%d,%d), size (%d,%d) ...", pos_x_src, pos_y_src, pos_x_dst, pos_y_dst, size_x, size_y);
*pVGA_ctrl &= ~SYS_VGA_BIT_BLIT_OP_CONSTCOL;
*pVGA_src0 = fb_addr + 4*(pos_x_src + pos_y_src*dim_x);
*pVGA_dimx_src0 = 4*dim_x;
*pVGA_dst = fb_addr + 4*(pos_x_dst + pos_y_dst*dim_x);
*pVGA_dimx_dst = 4*dim_x;
*pVGA_nx = size_x - 0;
*pVGA_ny = size_y - 0;
while (*pVGA_ctrl & SYS_VGA_BIT_BLIT_BSY);
*pVGA_ctrl |= SYS_VGA_BIT_BLIT_REQ;
// fprintf(stdout, "done\n");
}