- bootloader added board file - refactored header files - constify constants git-svn-id: http://moon:8086/svn/mips@99 a8ebac50-d88d-4704-bea3-6648445a41b3
337 lines
7.6 KiB
C
337 lines
7.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <sys/times.h>
|
|
#include <sys/time.h>
|
|
|
|
#include <libsys.h>
|
|
#include <irq.h>
|
|
#include <mips_gfx.h>
|
|
#include <mips_ps2.h>
|
|
|
|
#define PS2_NUM_IF 2
|
|
char buffer[16384];
|
|
char * volatile pPtr_r;
|
|
char * volatile pPtr_w;
|
|
static volatile int32_t mouse_x;
|
|
static volatile int32_t 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_t g_color;
|
|
static char *ps2_name[PS2_NUM_IF] = {"PS2-0", "PS2-1"};
|
|
|
|
// -------------------------------------------------------------
|
|
void handler0(struct xcptcontext *xcp)
|
|
{
|
|
printf("Interrupt 0\n");
|
|
interrupt_clr(0);
|
|
}
|
|
|
|
void handler1(struct xcptcontext *xcp)
|
|
{
|
|
printf("Interrupt 1\n");
|
|
interrupt_clr(1);
|
|
}
|
|
|
|
void handler2(struct xcptcontext *xcp)
|
|
{
|
|
printf("Interrupt 2\n");
|
|
}
|
|
|
|
void handler3(struct xcptcontext *xcp)
|
|
{
|
|
volatile uint32_t *pUART0_stat = (uint32_t*)SYS_UART0_STAT;
|
|
volatile uint32_t *pUART0_data = (uint32_t*)SYS_UART0_DATA;
|
|
volatile uint32_t *pUART1_stat = (uint32_t*)SYS_UART1_STAT;
|
|
volatile uint32_t *pUART1_data = (uint32_t*)SYS_UART1_DATA;
|
|
|
|
while(0x200 & *pUART0_stat)
|
|
{
|
|
sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
|
if (pPtr_w == &buffer[16383])
|
|
pPtr_w = buffer;
|
|
*(pPtr_w++) = *pUART0_data;
|
|
}
|
|
|
|
while(0x200 & *pUART1_stat)
|
|
{
|
|
sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
|
if (pPtr_w == &buffer[16383])
|
|
pPtr_w = buffer;
|
|
*(pPtr_w++) = *pUART1_data;
|
|
}
|
|
|
|
}
|
|
|
|
void handler4(struct xcptcontext *xcp)
|
|
{
|
|
printf("Interrupt 4\n");
|
|
}
|
|
|
|
void handler5(struct xcptcontext *xcp)
|
|
{
|
|
uint32_t volatile *pVGA_ctrl = (uint32_t*)SYS_VGA_CTRL;
|
|
|
|
// Ack
|
|
*pVGA_ctrl |= SYS_VGA_BIT_BUFCHG_FLAG;
|
|
|
|
}
|
|
|
|
void handler6(struct xcptcontext *xcp)
|
|
{
|
|
int p, i;
|
|
ps2_if_t *pIF;
|
|
uint8_t mouse_rsp[3];
|
|
uint32_t timeout_count, key;
|
|
|
|
int32_t dx, dy;
|
|
|
|
for (p=0; p < PS2_NUM_IF; p++)
|
|
{
|
|
pIF = (ps2_if_t*)con_getInstanceByName(ps2_name[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_t)*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_t)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);
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
void handler7(void)
|
|
{
|
|
printf("Interrupt 7\n");
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
|
|
int i;
|
|
volatile uint32_t *pUART0_stat = (uint32_t*)SYS_UART0_STAT;
|
|
volatile uint32_t *pUART1_stat = (uint32_t*)SYS_UART1_STAT;
|
|
volatile uint32_t *pUART0_baud = (uint32_t*)SYS_UART0_BAUD;
|
|
volatile uint32_t *pUART1_baud = (uint32_t*)SYS_UART1_BAUD;
|
|
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_cgcol = (uint32_t*)SYS_VGA_CGCOL;
|
|
uint32_t volatile *pFlashPicture = (uint32_t*)(SYS_FLASH_MEM + 0x00600000);
|
|
uint32_t framecount;
|
|
uint32_t start, end;
|
|
char string[65];
|
|
|
|
interrupt_register(0, (void*)handler0);
|
|
interrupt_register(1, (void*)handler1);
|
|
// interrupt_register(2, (void*)handler2);
|
|
interrupt_register(3, (void*)handler3);
|
|
// interrupt_register(4, (void*)handler4);
|
|
// interrupt_register(5, (void*)handler5);
|
|
interrupt_register(6, (void*)handler6);
|
|
interrupt_register(7, (void*)handler7);
|
|
|
|
srand(clock());
|
|
UART_setbaud(con_getInstanceByName("UART-1"), 460800);
|
|
printf("Hello\n");
|
|
memset(buffer, 0, sizeof(buffer));
|
|
|
|
*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);
|
|
|
|
pPtr_r = buffer;
|
|
pPtr_w = buffer;
|
|
|
|
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
|
printf("UART0 Baud = 0x%8.8X\n", *pUART0_baud);
|
|
printf("UART1 Status = 0x%8.8X\n", *pUART1_stat);
|
|
printf("UART1 Baud = 0x%8.8X\n", *pUART1_baud);
|
|
|
|
// UART: enable RX interrupt
|
|
*pUART0_stat |= (1 << 6);
|
|
*pUART1_stat |= (1 << 6);
|
|
printf("UART0 Status = 0x%8.8X\n", *pUART0_stat);
|
|
printf("UART1 Status = 0x%8.8X\n", *pUART1_stat);
|
|
|
|
PS2_init((ps2_if_t*)con_getInstanceByName(ps2_name[0]));
|
|
PS2_init((ps2_if_t*)con_getInstanceByName(ps2_name[1]));
|
|
|
|
sputs("r: "); print_word((int)pPtr_r); sputs("\n");
|
|
sputs("w: "); print_word((int)pPtr_w); sputs("\n");
|
|
|
|
// Print Status register
|
|
sputs("Status : ");
|
|
print_word(CP0_SR_read());
|
|
sputs("\n");
|
|
sputs("\n");
|
|
|
|
interrupt_disable(6);
|
|
printf("Bitte gebe ein: ");
|
|
scanf("%s", string);
|
|
printf("Du schriebst: %s\n", string);
|
|
|
|
// Flush buffer
|
|
PS2_flush((ps2_if_t*)con_getInstanceByName(ps2_name[0]));
|
|
PS2_flush((ps2_if_t*)con_getInstanceByName(ps2_name[1]));
|
|
|
|
printf("Start:\n");
|
|
|
|
interrupt_enable(0);
|
|
interrupt_enable(1);
|
|
// interrupt_enable(2);
|
|
interrupt_enable(3);
|
|
// interrupt_enable(4);
|
|
// interrupt_enable(5);
|
|
interrupt_enable(6);
|
|
interrupt_enable(7);
|
|
|
|
interrupt_set(0);
|
|
interrupt_set(1);
|
|
interrupt_set(2);
|
|
interrupt_set(3);
|
|
interrupt_set(4);
|
|
interrupt_set(5);
|
|
interrupt_set(6);
|
|
interrupt_set(7);
|
|
|
|
// while(1)
|
|
// {
|
|
// printf("PS2-Status : 0x%08X\n", *(ps2_if[0].pCTRL));
|
|
// printf("PS2-Data : 0x%08X\n", *(ps2_if[0].pDATA));
|
|
// sleep(1000);
|
|
// }
|
|
|
|
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_t)mouse_x) || (_g_posy != (uint32_t)mouse_y) || g_btn_r || g_btn_l)
|
|
{
|
|
|
|
GFX_restore(&gfx, &box, _g_posx, _g_posy);
|
|
|
|
_g_posx = (uint32_t)mouse_x;
|
|
_g_posy = (uint32_t)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);
|
|
|
|
if(pPtr_w != pPtr_r)
|
|
{
|
|
// sputs("r: "); print_word((int)pPtr_r); sputs("\n");
|
|
if (pPtr_r == &buffer[16383])
|
|
pPtr_r = buffer;
|
|
writechar(0, *(pPtr_r++));
|
|
}
|
|
}
|
|
return 0;
|
|
}
|