#include #include #include #include #include #include "system.h" #define msleep(msec) usleep(1000*msec); static void gpu_write (unsigned int reg, unsigned int data) { IOWR (GPU_0_BASE, reg << 2, data); } static void load_sprite (void) { // RRR GGG BBB // set the sprite color 111 010 000 - orange gpu_write (5, 0x01D0); // squirt the bromium logo into the sprite gpu_write (0x10, 0x00C0); gpu_write (0x11, 0x03E0); gpu_write (0x12, 0x0FF8); gpu_write (0x13, 0x1FFE); gpu_write (0x14, 0x3FC7); gpu_write (0x15, 0x3F83); gpu_write (0x16, 0x3933); gpu_write (0x17, 0x3987); gpu_write (0x18, 0x3D37); gpu_write (0x19, 0x3D37); gpu_write (0x1a, 0x3D87); gpu_write (0x1b, 0x3FFF); gpu_write (0x1c, 0x1FFE); gpu_write (0x1d, 0x07F8); gpu_write (0x1e, 0x01E0); gpu_write (0x1f, 0x00C0); } static int dir (int a, int b) { if (a > b) return 1; if (a < b) return -1; return 0; } static void move_bat (int *b, int db) { *b += dir (db, *b); } static int squish (int *v, int min, int max) { if (*v < min) { *v = min; return 1; } if (*v >= max) { *v = max - 1; return 1; } return 0; } static int find_intersection (int x, int y, int xd, int yd, int t) { // super lazy - we should use the power of MATHS while (x != t) { x += xd; y += yd; if (squish (&y, 0, 480)) yd = -yd; if (squish (&x, 0, 640)) xd = -xd; } return y; } int main (void) { int x, y, xd, yd; int bat0, dbat0; int bat1, dbat1; int missed = 0; printf ("Working...\n"); msleep (500); srand (12392184); bat0 = 100; bat1 = 200; load_sprite (); while (1) { x = 1; y = 1; xd = 1; yd = 1; dbat0 = find_intersection (x + xd, y + yd, xd, yd, 0); dbat1 = find_intersection (x + xd, y + yd, xd, yd, 639); while (!missed) { x += xd; y += yd; if (squish (&y, 0, 480)) yd = -yd; if (squish (&x, 0, 640)) { xd = (rand () % 3) + 1; if (x) xd = -xd; yd = rand () % 7; yd -= 3; if (x) { dbat0 = find_intersection (x + xd, y + yd, xd, yd, 0); dbat1 = 480 / 2; } else { dbat0 = 480 / 2; dbat1 = find_intersection (x + xd, y + yd, xd, yd, 639); } } move_bat (&bat0, dbat0); move_bat (&bat1, dbat1); gpu_write (1, x + 0x80); gpu_write (2, y + 0x80); gpu_write (3, bat0 + 0x80); gpu_write (4, bat1 + 0x80); gpu_write (0, 0); msleep (2); } } }