From 31ca140f04a6c3188376ed8230f345824f86a313 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 10 Oct 2013 23:09:05 +0100 Subject: first working makefile --- software/Makefile | 60 +++++++++++++++++ software/pong3/.cproject | 60 ++++++++--------- software/pong3/pong3.c | 141 ++++++++++++++++++++++------------------ software/pong3_bsp/.cproject | 48 +++++++------- software/pong3_bsp/settings.bsp | 4 +- software/wrap.sh | 11 ++++ 6 files changed, 206 insertions(+), 118 deletions(-) create mode 100644 software/Makefile create mode 100755 software/wrap.sh (limited to 'software') diff --git a/software/Makefile b/software/Makefile new file mode 100644 index 0000000..13116c7 --- /dev/null +++ b/software/Makefile @@ -0,0 +1,60 @@ +# +# + +ELFDIR=../software/pong3 +BSPDIR=../software/pong3_bsp +ELF=pong3.elf + +SOPCINFO=../my_sys.sopcinfo +SOF=../pong3.sof + +run: load_elf.stamp + ./wrap.sh nios2-terminal + +flash: load_sof.stamp sof.flash elf.flash ${BSPDIR}/system.h + BASE=` grep EPCS_FLASH_CONTROLLER_0_BASE ${BSPDIR}/system.h | awk '{print $$3}' ` && \ + ./wrap.sh nios2-flash-programmer sof.flash --base=$${BASE} --epcs --accept-bad-sysid --device=1 --instance=0 --program --verbose && \ + ./wrap.sh nios2-flash-programmer elf.flash --base=$${BASE} --epcs --accept-bad-sysid --device=1 --instance=0 --program --verbose -g + +sof.flash: ${SOF} + ./wrap.sh sof2flash --input=$< --output=$@ --epcs --verbose + +elf.flash: ${ELFDIR}/${ELF} sof.flash + ./wrap.sh elf2flash --input=${ELFDIR}/${ELF} --output=$@ --epcs --after=sof.flash --verbose + + + + + + + +load_elf.stamp:load_sof.stamp ${ELFDIR}/${ELF} + ./wrap.sh nios2-download ${ELFDIR}/${ELF} -g + +load_sof.stamp: ${SOF} + ./wrap.sh quartus_pgm -m JTAG -o 'p;../pong3.sof' + +${ELFDIR}/${ELF}: ${BSPDIR}/libhal_bsp.a + ./wrap.sh ${MAKE} -C ${ELFDIR} + + +${BSPDIR}/libhal_bsp.a:${BSPDIR}/system.h + ./wrap.sh ${MAKE} -C ${BSPDIR} + +${BSPDIR}/system.h:${SOPCINFO} + rm -f $@ + (cd ${BSPDIR} && ${PWD}/wrap.sh ./create-this-bsp ) + + +clean: + ./wrap.sh ${MAKE} -C ${BSPDIR} clean + ./wrap.sh ${MAKE} -C ${ELFDIR} clean + /bin/rm -f sof.flash elf.flash + /bin/rm -rf ${BSPDIR}/drivers ${BSPDIR}/HAL ${BSPDIR}/linker.h ${BSPDIR}/linker.x ${BSPDIR}/system.h ${BSPDIR}/summary.html ${BSPDIR}/public.mk ${BSPDIR}/mem_init.mk ${BSPDIR}/memory.gdb ${BSPDIR}/alt_sys_init.c + + + + + + + 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 @@ - - + + - + - - - - - - - - - + @@ -313,32 +313,32 @@ - + - - - + + + - + - - - + + + - + 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); } } } -//------------------------------------------------------------------------- diff --git a/software/pong3_bsp/.cproject b/software/pong3_bsp/.cproject index bca629e..aaab98e 100644 --- a/software/pong3_bsp/.cproject +++ b/software/pong3_bsp/.cproject @@ -3,19 +3,19 @@ - - + + - + - - - - - - - - - + @@ -313,12 +313,12 @@ - + - + @@ -331,7 +331,7 @@ - + diff --git a/software/pong3_bsp/settings.bsp b/software/pong3_bsp/settings.bsp index e567b80..6bafac0 100644 --- a/software/pong3_bsp/settings.bsp +++ b/software/pong3_bsp/settings.bsp @@ -2,8 +2,8 @@ hal default - Oct 10, 2013 11:49:08 AM - 1381402148374 + Oct 10, 2013 11:06:28 PM + 1381442788161 /home/root/projects/altera/pong3/software/pong3_bsp ./settings.bsp ../../my_sys.sopcinfo diff --git a/software/wrap.sh b/software/wrap.sh new file mode 100755 index 0000000..4caed0f --- /dev/null +++ b/software/wrap.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +AD=/software/apps/altera/quartus_ii_13.0sp1 +LL=linux +QUARTUS_ROOTDIR="${AD}/quartus" +PATH="${AD}/quartus/bin:${AD}/nios2eds/sdk2/bin:${AD}/nios2eds/bin:${AD}/nios2eds/bin/gnu/H-i686-pc-linux-gnu/bin:${PATH}" +LD_LIBRARY_PATH="${AD}/quartus/${LL}:${LD_LIBRARY_PATH}" + +export LD_LIBRARY_PATH PATH QUARTUS_ROOTDIR + +"$@" -- cgit v1.2.3