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.c52
1 files changed, 23 insertions, 29 deletions
diff --git a/software/pong3/pong3.c b/software/pong3/pong3.c
index 0e88ac8..39ee99c 100644
--- a/software/pong3/pong3.c
+++ b/software/pong3/pong3.c
@@ -3,10 +3,14 @@
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
+#include <stdint.h>
#include "system.h"
+#include "GPU.h"
+
#define msleep(msec) usleep(1000*msec);
+
static void
gpu_write (unsigned int reg, unsigned int data)
{
@@ -16,27 +20,17 @@ gpu_write (unsigned int reg, unsigned int data)
static void
load_sprite (void)
{
+ const uint16_t sprite[16]={ 0x00C0, 0x03E0, 0x0FF8, 0x1FFE, 0x3FC7, 0x3F83, 0x3933, 0x3987, 0x3D37, 0x3D37, 0x3D87, 0x3FFF, 0x1FFE, 0x07F8, 0x01E0, 0x00C0 };
+ const unsigned int n=sizeof(sprite)/sizeof(uint16_t);
+ unsigned int i;
+
// RRR GGG BBB
// set the sprite color 111 010 000 - orange
- gpu_write (5, 0x01D0);
+ gpu_write (GPU_REG_SPRITE_COLOUR, 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);
+ for (i=0;i<n;++i)
+ gpu_write (GPU_REG_SPRITE_BASE+i,sprite[i]);
}
@@ -83,10 +77,10 @@ find_intersection (int x, int y, int xd, int yd, int t)
x += xd;
y += yd;
- if (squish (&y, 0, 480))
+ if (squish (&y, 0, GPU_HEIGHT))
yd = -yd;
- if (squish (&x, 0, 640))
+ if (squish (&x, 0, GPU_WIDTH))
xd = -xd;
}
@@ -118,7 +112,7 @@ main (void)
yd = 1;
dbat0 = find_intersection (x + xd, y + yd, xd, yd, 0);
- dbat1 = find_intersection (x + xd, y + yd, xd, yd, 639);
+ dbat1 = find_intersection (x + xd, y + yd, xd, yd, GPU_WIDTH-1);
while (!missed)
{
@@ -126,10 +120,10 @@ main (void)
y += yd;
- if (squish (&y, 0, 480))
+ if (squish (&y, 0, GPU_HEIGHT))
yd = -yd;
- if (squish (&x, 0, 640))
+ if (squish (&x, 0, GPU_WIDTH))
{
xd = (rand () % 3) + 1;
if (x)
@@ -140,13 +134,13 @@ main (void)
if (x)
{
dbat0 = find_intersection (x + xd, y + yd, xd, yd, 0);
- dbat1 = 480 / 2;
+ dbat1 = GPU_HEIGHT / 2;
}
else
{
- dbat0 = 480 / 2;
+ dbat0 = GPU_HEIGHT / 2;
- dbat1 = find_intersection (x + xd, y + yd, xd, yd, 639);
+ dbat1 = find_intersection (x + xd, y + yd, xd, yd, GPU_WIDTH-1);
}
}
@@ -154,10 +148,10 @@ main (void)
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 (1, x + GPU_OFFSET);
+ gpu_write (2, y + GPU_OFFSET);
+ gpu_write (3, bat0 + GPU_OFFSET);
+ gpu_write (4, bat1 + GPU_OFFSET);
gpu_write (0, 0);