Files
vhdl/lib/CPUs/MIPS/bsp/examples/test_vga.c
T
jens 191af92d47 Initial version
Committed on the Free edition of March Hare Software CVSNT Server.
Upgrade to CVS Suite for more features and support:
http://march-hare.com/cvsnt/


git-svn-id: http://moon:8086/svn/vhdl/trunk@790 cc03376c-175c-47c8-b038-4cd826a8556b
2010-03-13 14:13:53 +00:00

207 lines
3.9 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/times.h>
#include <sys/time.h>
#define CPU_FREQ_HZ 100000000
#include "libsys.h"
#include "irq.h"
#include "mips_gfx.h"
#include "mips_ps2.h"
static volatile INT32 mouse_x;
static volatile INT32 mouse_y;
static box_t box;
static gfx_t gfx;
static volatile int _g_posx, _g_posy;
static volatile g_btn_l, g_btn_r;
static volatile UINT32 g_color;
// -------------------------------------------------------------
void handler5(void)
{
UINT32 volatile *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
// Ack
*pVGA_ctrl |= SYS_VGA_BIT_BUFCHG_FLAG;
}
void handler6(void)
{
int p, i;
ps2_if_t *pIF;
UINT8 mouse_rsp[3];
UINT32 timeout_count, key;
INT32 dx, dy;
for (p=0; p < PS2_get_num_if(); p++)
{
pIF = PS2_get_if(p);
if (SYS_PS2_BIT_RX_ERR_FLAG & *pIF->pCTRL)
fprintf(stderr, "PS2[%d]: Status = 0x%08X\n", p, *pIF->pCTRL);
if (pIF->type == ps2_type_keyb)
{
while(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL)
{
key = *pIF->pDATA;
printf("Keyboard scan code = 0x%02X\n", key);
}
}
if (pIF->type == ps2_type_mouse)
{
if(!(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL))
continue;
for (i=0; i < 3; i++)
{
timeout_count = 100;
while(!(SYS_PS2_BIT_RX_IRQ & *pIF->pCTRL))
{
timeout_count--;
if (!timeout_count)
{
break;
}
sleep(1);
}
if (!timeout_count)
{
break;
}
mouse_rsp[i] = (UINT8)*pIF->pDATA;
}
if (!timeout_count)
{
continue;
}
dx = mouse_rsp[1];
if (mouse_rsp[0] & 0x10)
dx |= 0xFFFFFF00;
dy = mouse_rsp[2];
if (mouse_rsp[0] & 0x20)
dy |= 0xFFFFFF00;
// printf("dx = %5d, dy = %5d\n", dx, dy);
mouse_x += dx;
mouse_y -= dy;
g_btn_l = 0;
if (mouse_rsp[0] & 0x01)
g_btn_l = 1;
if (mouse_rsp[0] & 0x02)
{
if (g_btn_r == 0)
{
g_color = (UINT32)rand();
}
g_btn_r = 1;
}
else
g_btn_r = 0;
if (mouse_x < 0)
mouse_x = 0;
if (mouse_y < 0)
mouse_y = 0;
if (mouse_x > (gfx.w-1))
mouse_x = gfx.w-1;
if (mouse_y >= (gfx.h-1))
mouse_y = gfx.h-1;
// Screen_csr_set_x(mouse_x);
// Screen_csr_set_y(mouse_y);
// printf("x = %5d, y = %5d\n", mouse_x, mouse_y);
}
}
}
int main(void)
{
int i;
UINT32 volatile *pVGA_ctrl = (UINT32*)SYS_VGA_CTRL;
UINT32 volatile *pVGA_moffs_0 = (UINT32*)SYS_VGA_FB_FRONT;
UINT32 volatile *pVGA_moffs_1 = (UINT32*)SYS_VGA_FB_BACK;
UINT32 volatile *pVGA_cgcol = (UINT32*)SYS_VGA_CGCOL;
UINT32 volatile *pFlashPicture = (UINT32*)(SYS_FLASH_MEM + 0x00600000);
UINT32 framecount;
UINT32 start, end;
interrupt_register(5, (void*)handler5);
interrupt_register(6, (void*)handler6);
srand(clock());
UART1_setbaud(460800);
*pVGA_cgcol = 0x00FFFFFF;
_g_posx = _g_posy = 0;
g_color = 0xFFFFFFFF;
GFX_init(&gfx);
GFX_set_background(&gfx, pFlashPicture, 800, 600, 1, 1);
box_create(&box, 256, 256);
GFX_box_draw(&gfx, &box, _g_posx, _g_posy, g_color);
GFX_show(&gfx);
printf("VGA status = %08X\n", *pVGA_ctrl);
PS2_init(0);
PS2_init(1);
// Flush buffer
PS2_flush(0);
PS2_flush(1);
// interrupt_enable(5);
interrupt_enable(6);
framecount = Screen_get_fps();
start = clock();
while(1)
{
if (!framecount)
{
end = clock();
framecount = Screen_get_fps();
printf("%f FPS\n", (float)framecount/((float)(end-start)/CLOCKS_PER_SEC));
start = clock();
}
GFX_frame(&gfx, GFX_FRAME_SYNC);
framecount--;
while ((_g_posx != (UINT32)mouse_x) || (_g_posy != (UINT32)mouse_y) || g_btn_r || g_btn_l)
{
GFX_restore(&gfx, &box, _g_posx, _g_posy);
_g_posx = (UINT32)mouse_x;
_g_posy = (UINT32)mouse_y;
if (g_btn_l && !g_btn_r)
{
GFX_box_draw_bg(&gfx, &box, _g_posx, _g_posy, g_color);
}
if (g_btn_l && g_btn_r)
{
GFX_set_background(&gfx, pFlashPicture, 800, 600, 1, 1);
}
GFX_box_draw(&gfx, &box, _g_posx, _g_posy, g_color);
break;
}
GFX_show(&gfx);
}
return 0;
}