summaryrefslogtreecommitdiffstats
path: root/software/pong3/pong3.c
diff options
context:
space:
mode:
Diffstat (limited to 'software/pong3/pong3.c')
-rw-r--r--software/pong3/pong3.c141
1 files changed, 79 insertions, 62 deletions
diff --git a/software/pong3/pong3.c b/software/pong3/pong3.c
index 63ae56c..0e88ac8 100644
--- a/software/pong3/pong3.c
+++ b/software/pong3/pong3.c
@@ -13,59 +13,12 @@ gpu_write (unsigned int reg, unsigned int data)
IOWR (GPU_0_BASE, reg << 2, data);
}
-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 (y < 0)
- y = 0;
- if (y > 479)
- y = 479;
- if ((y == 479) || (y == 0))
- yd = -yd;
-
- if ((x == 639) || (x == 0))
- xd = -xd;
- }
-
- return y;
-}
-
-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);
- if (*b < 20)
- *b = 20;
- if (*b > 459)
- *b = 459;
-
-}
-
static void
load_sprite (void)
{
// RRR GGG BBB
// set the sprite color 111 010 000 - orange
- gpu_write (4, 0x01D0);
+ gpu_write (5, 0x01D0);
// squirt the bromium logo into the sprite
gpu_write (0x10, 0x00C0);
@@ -86,6 +39,60 @@ load_sprite (void)
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)
{
@@ -117,35 +124,45 @@ main (void)
{
x += xd;
y += yd;
- if (y < 0)
- y = 0;
- if (y > 479)
- y = 479;
- if ((y == 479) || (y == 0))
+
+
+ if (squish (&y, 0, 480))
yd = -yd;
- if ((x == 639) || (x == 0))
+ if (squish (&x, 0, 640))
{
- xd = -xd;
+ xd = (rand () % 3) + 1;
+ if (x)
+ xd = -xd;
yd = rand () % 7;
yd -= 3;
- dbat0 = find_intersection (x + xd, y + yd, xd, yd, 0);
- dbat1 = find_intersection (x + xd, y + yd, xd, yd, 639);
+
+ 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 (0, x);
- gpu_write (1, y);
+ gpu_write (1, x + 0x80);
+ gpu_write (2, y + 0x80);
+ gpu_write (3, bat0 + 0x80);
+ gpu_write (4, bat1 + 0x80);
- gpu_write (2, bat0);
- gpu_write (3, bat1);
+ gpu_write (0, 0);
msleep (2);
}
}
}
-//-------------------------------------------------------------------------