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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
#include <io.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#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 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);
// 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);
}
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 (y < 0)
y = 0;
if (y > 479)
y = 479;
if ((y == 479) || (y == 0))
yd = -yd;
if ((x == 639) || (x == 0))
{
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);
}
move_bat (&bat0, dbat0);
move_bat (&bat1, dbat1);
gpu_write (0, x);
gpu_write (1, y);
gpu_write (2, bat0);
gpu_write (3, bat1);
msleep (2);
}
}
}
//-------------------------------------------------------------------------
|