- initial import
git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
+228
@@ -0,0 +1,228 @@
|
||||
#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_even, box_odd, line_h_even, line_v_even, line_h_odd, line_v_odd, cross_v, cross_h;
|
||||
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;
|
||||
g_btn_r = 0;
|
||||
if (mouse_rsp[0] & 0x01)
|
||||
g_btn_l = 1;
|
||||
|
||||
if (mouse_rsp[0] & 0x02)
|
||||
g_btn_r = 1;
|
||||
|
||||
|
||||
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 *pFlashPicture = (UINT32*)(SYS_FLASH_MEM + 0x00600000);
|
||||
UINT32 framecount;
|
||||
UINT32 start, end;
|
||||
UINT32 *pPic;
|
||||
UINT32 rmb_posx, rmb_posy, rmb_clicked;
|
||||
|
||||
pPic = (UINT32*)malloc(800*600*sizeof(UINT32));
|
||||
memcpy(pPic, pFlashPicture, 800*600*sizeof(UINT32));
|
||||
|
||||
interrupt_register(5, (void*)handler5);
|
||||
interrupt_register(6, (void*)handler6);
|
||||
|
||||
srand(clock());
|
||||
UART1_setbaud(460800);
|
||||
|
||||
*pVGA_cgcol = 0x00FFFFFF;
|
||||
_g_posx = _g_posy = 0;
|
||||
rmb_posx = rmb_posy = 0;
|
||||
rmb_clicked = 0;
|
||||
g_color = 0xFFFFFFFF;
|
||||
GFX_init(&gfx);
|
||||
|
||||
GFX_set_background(&gfx, pPic, 800, 600, 1, 1);
|
||||
box_create(&box_even, 128, 128);
|
||||
box_create(&box_odd, 126, 126);
|
||||
GFX_box_draw(&gfx, &box_even, _g_posx, _g_posy, g_color);
|
||||
GFX_box_draw(&gfx, &box_odd, _g_posx+1, _g_posy+1, 0);
|
||||
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)
|
||||
{
|
||||
|
||||
_g_posx = (UINT32)mouse_x;
|
||||
_g_posy = (UINT32)mouse_y;
|
||||
|
||||
GFX_restore(&gfx, NULL, _g_posx, _g_posy);
|
||||
|
||||
GFX_box_draw(&gfx, &box_even, _g_posx, _g_posy, g_color);
|
||||
GFX_box_blit_bg(&gfx, &box_odd, rmb_posx+1, rmb_posy+1, _g_posx+1, _g_posy+1);
|
||||
// GFX_box_draw(&gfx, &box_odd, _g_posx+1, _g_posy+1, 0);
|
||||
break;
|
||||
}
|
||||
if (g_btn_l)
|
||||
{
|
||||
if (g_btn_r)
|
||||
{
|
||||
GFX_set_background(&gfx, pPic, 800, 600, 1, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
GFX_box_draw_bg(&gfx, &box_even, _g_posx, _g_posy, g_color);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_btn_r)
|
||||
{
|
||||
if (!rmb_clicked)
|
||||
g_color = (UINT32)rand();
|
||||
|
||||
rmb_clicked = 1;
|
||||
rmb_posx = _g_posx;
|
||||
rmb_posy = _g_posy;
|
||||
}
|
||||
else
|
||||
{
|
||||
rmb_clicked = 0;
|
||||
}
|
||||
}
|
||||
|
||||
GFX_show(&gfx);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user