1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/*
* GXemul demo: Random rectangles
*
* This file is in the Public Domain.
*/
#include "dev_fb.h"
#ifdef MIPS
/* Note: The ugly cast to a signed int (32-bit) causes the address to be
sign-extended correctly on MIPS when compiled in 64-bit mode */
#define PHYSADDR_OFFSET ((signed int)0xa0000000)
#else
#define PHYSADDR_OFFSET 0
#endif
/* Framebuffer linear memory and controller base addresss: */
#define FB_BASE (PHYSADDR_OFFSET + DEV_FB_ADDRESS)
#define FBCTRL_BASE (PHYSADDR_OFFSET + DEV_FBCTRL_ADDRESS)
#define XRES 800
#define YRES 600
void my_memset(unsigned char *a, int x, int len)
{
while (len-- > 0)
*a++ = x;
}
void draw_rectangle(int x1, int y1, int x2, int y2, int c)
{
int y, len;
for (y=y1; y<=y2; y++) {
len = 3 * (x2-x1+1);
if (len > 0) {
my_memset((unsigned char *)FB_BASE +
3 * (XRES * y + x1), c, len);
}
}
}
unsigned int my_random()
{
static int a = 0x124879b;
static int b = 0xb7856fa2;
int c = a ^ (b * 51);
a = 17 * c - (b * 171);
return c;
}
void fbctrl_write_port(int p)
{
*(volatile int *)(FBCTRL_BASE + DEV_FBCTRL_PORT) = p;
}
void fbctrl_write_data(int d)
{
*(volatile int *)(FBCTRL_BASE + DEV_FBCTRL_DATA) = d;
}
void fbctrl_set_x1(int v)
{
fbctrl_write_port(DEV_FBCTRL_PORT_X1);
fbctrl_write_data(v);
}
void fbctrl_set_y1(int v)
{
fbctrl_write_port(DEV_FBCTRL_PORT_Y1);
fbctrl_write_data(v);
}
void fbctrl_command(int c)
{
fbctrl_write_port(DEV_FBCTRL_PORT_COMMAND);
fbctrl_write_data(c);
}
void change_resolution(int xres, int yres)
{
fbctrl_set_x1(xres);
fbctrl_set_y1(yres);
fbctrl_command(DEV_FBCTRL_COMMAND_SET_RESOLUTION);
}
void f(void)
{
/* Change to the resolution we want: */
change_resolution(XRES, YRES);
/* Draw random rectangles forever: */
for (;;) {
draw_rectangle(my_random() % XRES, my_random() % YRES,
my_random() % XRES, my_random() % YRES, my_random());
}
}
|