summaryrefslogtreecommitdiffstats
path: root/software/pong3
diff options
context:
space:
mode:
Diffstat (limited to 'software/pong3')
-rw-r--r--software/pong3/.cproject60
-rw-r--r--software/pong3/pong3.c141
2 files changed, 109 insertions, 92 deletions
diff --git a/software/pong3/.cproject b/software/pong3/.cproject
index ae6d1bc..f15f89f 100644
--- a/software/pong3/.cproject
+++ b/software/pong3/.cproject
@@ -3,19 +3,19 @@
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
- <buildSystem id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763">
- <storageModule id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763" moduleId="org.eclipse.cdt.core.settings"/>
+ <buildSystem id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440">
+ <storageModule id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440" moduleId="org.eclipse.cdt.core.settings"/>
</buildSystem>
- <cconfiguration id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763">
+ <cconfiguration id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440">
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <configuration buildProperties="" description="" id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763" name="Nios II" parent="org.eclipse.cdt.build.core.prefbase.cfg">
- <folderInfo id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763." name="/" resourcePath="">
- <toolChain id="altera.nios2.linux.gcc4.1592970977" name="Linux Nios II GCC4" superClass="altera.nios2.linux.gcc4">
- <targetPlatform id="altera.nios2.linux.gcc4.988746646" name="Nios II" superClass="altera.nios2.linux.gcc4"/>
- <builder buildPath="${workspace_loc://pong3}" id="cdt.managedbuild.target.gnu.builder.base.142418973" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
- <tool id="cdt.managedbuild.tool.gnu.archiver.base.1625897181" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
- <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1933293821" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
- <option id="gnu.cpp.compiler.option.preprocessor.undef.710001009" name="Undefined symbols (-U)" superClass="gnu.cpp.compiler.option.preprocessor.undef" valueType="undefDefinedSymbols">
+ <configuration buildProperties="" description="" id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440" name="Nios II" parent="org.eclipse.cdt.build.core.prefbase.cfg">
+ <folderInfo id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440." name="/" resourcePath="">
+ <toolChain id="altera.nios2.linux.gcc4.848844856" name="Linux Nios II GCC4" superClass="altera.nios2.linux.gcc4">
+ <targetPlatform id="altera.nios2.linux.gcc4.910507236" name="Nios II" superClass="altera.nios2.linux.gcc4"/>
+ <builder buildPath="${workspace_loc://pong3}" id="cdt.managedbuild.target.gnu.builder.base.152967692" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="cdt.managedbuild.target.gnu.builder.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.archiver.base.1040914647" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.1419793037" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base">
+ <option id="gnu.cpp.compiler.option.preprocessor.undef.1238194750" name="Undefined symbols (-U)" superClass="gnu.cpp.compiler.option.preprocessor.undef" valueType="undefDefinedSymbols">
<listOptionValue builtIn="false" value="__FLT_EVAL_METHOD__"/>
<listOptionValue builtIn="false" value="__FLT_EPSILON__"/>
<listOptionValue builtIn="false" value="__DEC64_MANT_DIG__"/>
@@ -151,10 +151,10 @@
<listOptionValue builtIn="false" value="__CHAR16_TYPE__"/>
<listOptionValue builtIn="false" value="__cplusplus"/>
</option>
- <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.579269023" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
+ <inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.473814365" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
- <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1403439131" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
- <option id="gnu.c.compiler.option.preprocessor.undef.symbol.1842834456" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" valueType="undefDefinedSymbols">
+ <tool id="cdt.managedbuild.tool.gnu.c.compiler.base.540100236" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base">
+ <option id="gnu.c.compiler.option.preprocessor.undef.symbol.1852800441" name="Undefined symbols (-U)" superClass="gnu.c.compiler.option.preprocessor.undef.symbol" valueType="undefDefinedSymbols">
<listOptionValue builtIn="false" value="__FLT_EVAL_METHOD__"/>
<listOptionValue builtIn="false" value="__FLT_EPSILON__"/>
<listOptionValue builtIn="false" value="__DEC64_MANT_DIG__"/>
@@ -282,23 +282,23 @@
<listOptionValue builtIn="false" value="unix"/>
<listOptionValue builtIn="false" value="__CHAR16_TYPE__"/>
</option>
- <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1504475877" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
+ <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.952505848" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
- <tool id="cdt.managedbuild.tool.gnu.c.linker.base.537533455" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
- <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.230683032" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
- <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1562487580" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
+ <tool id="cdt.managedbuild.tool.gnu.c.linker.base.780339284" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
+ <tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1093798203" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base">
+ <inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1769791579" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
- <tool id="cdt.managedbuild.tool.gnu.assembler.base.664604318" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
- <inputType id="cdt.managedbuild.tool.gnu.assembler.input.455490736" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
+ <tool id="cdt.managedbuild.tool.gnu.assembler.base.1967007695" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base">
+ <inputType id="cdt.managedbuild.tool.gnu.assembler.input.938120387" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
- <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763" moduleId="org.eclipse.cdt.core.settings" name="Nios II">
+ <storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440" moduleId="org.eclipse.cdt.core.settings" name="Nios II">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
@@ -313,32 +313,32 @@
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
- <project id="pong3.null.495750362" name="pong3"/>
+ <project id="pong3.null.1631886421" name="pong3"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
- <scannerConfigBuildInfo instanceId="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763;preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763.;cdt.managedbuild.tool.gnu.cpp.compiler.base.1933293821;cdt.managedbuild.tool.gnu.cpp.compiler.input.579269023">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
- <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
+ <scannerConfigBuildInfo instanceId="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440;preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440.;cdt.managedbuild.tool.gnu.c.compiler.base.540100236;cdt.managedbuild.tool.gnu.c.compiler.input.952505848">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
+ <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
- <runAction arguments="-E -P -v -dD &quot;${plugin_state_location}/specs.cpp&quot;" command="nios2-elf-g++" useDefault="true"/>
+ <runAction arguments="-E -P -v -dD &quot;${plugin_state_location}/specs.c&quot;" command="nios2-elf-gcc" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
</scannerConfigBuildInfo>
- <scannerConfigBuildInfo instanceId="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763;preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1609840763.;cdt.managedbuild.tool.gnu.c.compiler.base.1403439131;cdt.managedbuild.tool.gnu.c.compiler.input.1504475877">
- <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
- <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC">
+ <scannerConfigBuildInfo instanceId="preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440;preference.org.eclipse.cdt.managedbuilder.core.configurationDataProvider.1741772440.;cdt.managedbuild.tool.gnu.cpp.compiler.base.1419793037;cdt.managedbuild.tool.gnu.cpp.compiler.input.473814365">
+ <autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
+ <profile id="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP">
<buildOutputProvider>
<openAction enabled="true" filePath=""/>
<parser enabled="true"/>
</buildOutputProvider>
<scannerInfoProvider id="specsFile">
- <runAction arguments="-E -P -v -dD &quot;${plugin_state_location}/specs.c&quot;" command="nios2-elf-gcc" useDefault="true"/>
+ <runAction arguments="-E -P -v -dD &quot;${plugin_state_location}/specs.cpp&quot;" command="nios2-elf-g++" useDefault="true"/>
<parser enabled="true"/>
</scannerInfoProvider>
</profile>
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);
}
}
}
-//-------------------------------------------------------------------------