From 6e30f473f7af569b3907d3f2f2dda07108440f5a Mon Sep 17 00:00:00 2001 From: schneider Date: Sun, 11 Dec 2011 18:39:50 +0100 Subject: [PATCH] removed old lodable dir --- firmware/loadable/.gitignore | 4 - firmware/loadable/Makefile | 12 - firmware/loadable/Makefile.sub | 57 ---- firmware/loadable/bin2h.pl | 41 --- firmware/loadable/blinktest.c | 10 - firmware/loadable/mandelbrot.c | 190 ------------ firmware/loadable/ram.ld | 47 --- firmware/loadable/recvcard.c | 338 ---------------------- firmware/loadable/sendcard.c | 285 ------------------ firmware/loadable/spaceinvaders.c | 462 ------------------------------ 10 files changed, 1446 deletions(-) delete mode 100644 firmware/loadable/.gitignore delete mode 100644 firmware/loadable/Makefile delete mode 100644 firmware/loadable/Makefile.sub delete mode 100755 firmware/loadable/bin2h.pl delete mode 100644 firmware/loadable/blinktest.c delete mode 100644 firmware/loadable/mandelbrot.c delete mode 100644 firmware/loadable/ram.ld delete mode 100644 firmware/loadable/recvcard.c delete mode 100644 firmware/loadable/sendcard.c delete mode 100644 firmware/loadable/spaceinvaders.c diff --git a/firmware/loadable/.gitignore b/firmware/loadable/.gitignore deleted file mode 100644 index 7652361..0000000 --- a/firmware/loadable/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -*.elf -*.bin -*.h -loadable.ld diff --git a/firmware/loadable/Makefile b/firmware/loadable/Makefile deleted file mode 100644 index fa86f1e..0000000 --- a/firmware/loadable/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# Make doesn't allow dependencies on parent directory, so we need to -# run make from one level up: - -MAKEFILE=loadable/Makefile.sub -MAKE+=--no-print-directory - -all: - @cd .. && $(MAKE) -f $(MAKEFILE) - -clean: - @cd .. && $(MAKE) -f $(MAKEFILE) clean - diff --git a/firmware/loadable/Makefile.sub b/firmware/loadable/Makefile.sub deleted file mode 100644 index aa2f3ee..0000000 --- a/firmware/loadable/Makefile.sub +++ /dev/null @@ -1,57 +0,0 @@ -DIR?= loadable - -########################################################################## -# User configuration and firmware specific object files -########################################################################## -SRCS = $(wildcard $(DIR)/*.c) -OBJS = $(foreach mod,$(SRCS),$(subst .c,.o,$(mod))) -ELFS = $(foreach mod,$(SRCS),$(subst .c,.elf,$(mod))) -BINS = $(foreach mod,$(SRCS),$(subst .c,.bin,$(mod))) -HDRS = $(foreach mod,$(SRCS),$(subst .c,.h,$(mod))) - -########################################################################## -# GNU GCC compiler flags -########################################################################## -ROOT_PATH?= . - -INCLUDE_PATHS = -I$(ROOT_PATH) -I$(ROOT_PATH)/core - -include $(ROOT_PATH)/Makefile.inc - -########################################################################## -# Compiler settings, parameters and flags -########################################################################## -FIRMWARE=$(ROOT_PATH)/$(OUTFILE).elf -LDSRCFILE=$(DIR)/ram.ld -LDFILE=$(DIR)/loadable.ld -CFLAGS+=-mlong-calls -fno-toplevel-reorder -LDFLAGS+= -R $(FIRMWARE) - -all: $(OBJS) $(ELFS) $(BINS) $(HDRS) - -$(LDFILE): - -@echo "MEMORY" > $(LDFILE) - -@echo "{" >> $(LDFILE) - -@echo " sram(rwx): ORIGIN = 0x10002000 - $(RAMCODE), LENGTH = $(RAMCODE)" >> $(LDFILE) - -@echo "}" >> $(LDFILE) - -@echo "INCLUDE $(LDSRCFILE)" >> $(LDFILE) - -%.o : %.c - $(CC) $(CFLAGS) -o $@ $< - -%.elf: %.o $(FIRMWARE) $(LDFILE) - $(LD) $(LDFLAGS) -T $(LDFILE) -o $@ $< - $(SIZE) $@ - -%.bin: %.elf - $(OBJCOPY) $(OCFLAGS) -O binary $< $@ - -%.h: %.bin $(DIR)/bin2h.pl - $(DIR)/bin2h.pl $< - -clean: - cd $(DIR) && rm -f *.o *.elf *.bin - -.SUFFIXES: - -.PHONY: $(LDFILE) diff --git a/firmware/loadable/bin2h.pl b/firmware/loadable/bin2h.pl deleted file mode 100755 index 185bc54..0000000 --- a/firmware/loadable/bin2h.pl +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/perl -# -# vim:set ts=4 sw=4: - -use strict; - -sub dwim{ - local $/=undef; - my $file=shift; - - open(IN,"<:bytes",$file) || die "Can't open $file: $!"; - my @bytes=unpack("C*",); - close(IN); - - $file=~s/\.[^.]+$//; - - open(OUT,">","${file}.h") || die "Can't write ${file}.h: $!"; - - $file=~s!.*/!!; - - print OUT "const uint16_t loadable_${file}_size = ", scalar @bytes, ";\n"; - print OUT "const uint8_t loadable_${file}[] = {\n"; - - my $ctr=0; - for(@bytes){ - print OUT "\t" if($ctr==0); - printf OUT "0x%02x, ",$_; - if(++$ctr==8){ - print OUT "\n"; - $ctr=0; - }; - }; - print OUT "\n" if($ctr!=0); - - print OUT "};\n"; - close(OUT); -}; - -for(@ARGV){ - dwim($_); -}; diff --git a/firmware/loadable/blinktest.c b/firmware/loadable/blinktest.c deleted file mode 100644 index 7530f14..0000000 --- a/firmware/loadable/blinktest.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#include "basic/basic.h" - -void ram(void){ - for (int x=0;x<20;x++){ - gpioSetValue (RB_LED1, x%2); - delayms(50); - }; -}; diff --git a/firmware/loadable/mandelbrot.c b/firmware/loadable/mandelbrot.c deleted file mode 100644 index f66b691..0000000 --- a/firmware/loadable/mandelbrot.c +++ /dev/null @@ -1,190 +0,0 @@ -#include - -#include "basic/basic.h" - -#include "lcd/render.h" -#include "lcd/display.h" -#include "lcd/allfonts.h" - -#define FIXSIZE 25 -#define mul(a,b) ((((long long)a)*(b))>>FIXSIZE) -#define fixpt(a) ((long)(((a)*(1<>FIXSIZE) - -#define ZOOM_RATIO 0.90 -#define ITERATION_MAX 150 - -void mandelInit(); -void mandelMove(); -void mandelUpdate(); - -void ram(void) { - int key; - mandelInit(); - while (1) { - lcdDisplay(); - mandelMove(); - mandelUpdate(); - - // Exit on enter+direction - key=getInputRaw(); - if(key&BTN_ENTER && key>BTN_ENTER) - return; - } - return; -} - -struct mb { - long rmin, rmax, imin, imax; - bool dirty, dup, ddown, dleft, dright, clickmark; - int count, limitZIn, limitZOut; -} mandel; - -void mandelInit() { - //mandel.rmin = -2.2*0.9; - //mandel.rmax = 1.0*0.9; - //mandel.imin = -2.0*0.9; - //mandel.imax = 2.0*0.9; - mandel.rmin = fixpt(-2); - mandel.rmax = fixpt(1); - mandel.imin = fixpt(-2); - mandel.imax = fixpt(2); - mandel.count = 0; - mandel.limitZIn = 40; - mandel.limitZOut = 30; - - mandel.dirty = true; - mandel.dup = false; - mandel.ddown = false; - mandel.dleft = false; - mandel.dright = false; - mandel.clickmark = false; -} - -void mandelMove() { - //long delta_r = (mandel.rmax - mandel.rmin)/10; - //long delta_i = (mandel.imax - mandel.imin)/10; - - long rs =(mandel.rmax-mandel.rmin)/RESY; - long is =(mandel.imax-mandel.imin)/RESX; - - char key = getInputRaw(); - - if (key == BTN_LEFT) { - mandel.imax -=is; - mandel.imin -=is; - mandel.dleft = true; - } else if (key == BTN_RIGHT) { - mandel.imax += is; - mandel.imin += is; - mandel.dright = true; - } else if (key == BTN_DOWN) { - mandel.rmax += rs; - mandel.rmin += rs; - mandel.ddown = true; - } else if (key == BTN_UP) { - mandel.rmax -= rs; - mandel.rmin -= rs; - mandel.dup = true; - } else if (key == BTN_ENTER) { - if (mandel.count < mandel.limitZIn) { - mandel.count = mandel.count + 1; - } - } else if (key == BTN_NONE) { - if(mandel.count > 0 ) { - mandel.count = mandel.count - 1; - mandel.clickmark = true; - } - if (mandel.count == 0 ) { - mandel.clickmark = false; - } - } - if (mandel.count > mandel.limitZOut && mandel.clickmark && key == BTN_ENTER) { - mandel.imin = mandel.imin - (mandel.imax-mandel.imin)/10; - mandel.imax = mandel.imax + (mandel.imax-mandel.imin)/10; - mandel.rmin = mandel.rmin -(mandel.rmax-mandel.rmin)/10; - mandel.rmax = mandel.rmax +(mandel.rmax-mandel.rmin)/10; - mandel.dirty = true; - } - if (mandel.count == mandel.limitZIn && key == BTN_ENTER) { - mandel.imin = mandel.imin + (mandel.imax-mandel.imin)/10; - mandel.imax = mandel.imax - (mandel.imax-mandel.imin)/10; - mandel.rmin = mandel.rmin +(mandel.rmax-mandel.rmin)/10; - mandel.rmax = mandel.rmax -(mandel.rmax-mandel.rmin)/10; - mandel.dirty = true; - } -} - -void mandelPixel(int x, int y) { - long r0,i0,rn, p,q; - long rs,is; - int iteration; - - rs=(mandel.rmax-mandel.rmin)/RESY; - is=(mandel.imax-mandel.imin)/RESX; - //p=fixpt(mandel.rmin+y*rs); - //q=fixpt(mandel.imin+x*is); - p=mandel.rmin+y*rs; - q=mandel.imin+x*is; - - rn=0; - r0=0; - i0=0; - iteration=0; - while ((mul(rn,rn)+mul(i0,i0))1); - lcdSetPixel(x, y, pixel); -} - -void mandelUpdate() { - int xmin,xmax,ymin,ymax; - if (mandel.dirty) { - xmin = 0; - xmax = RESX; - ymin = 0; - ymax = RESY; - mandel.dirty = false; - } else if (mandel.dleft) { - lcdShift(1,0,false); - xmin = 0; - xmax = 1; - ymin = 0; - ymax = RESY; - mandel.dleft = false; - } else if (mandel.dright) { - lcdShift(-1,0,false); - xmin = RESX-1; - xmax = RESX; - ymin = 0; - ymax = RESY; - mandel.dright = false; - } else if (mandel.dup) { - lcdShift(0,-1,true); - xmin=0; - xmax=RESX; - ymin=0; - ymax=1; - mandel.dup = false; - } else if (mandel.ddown) { - lcdShift(0,1,true); - xmin=0; - xmax=RESX; - ymin=RESY-1; - ymax=RESY; - mandel.ddown = false; - } else { - return; - } - - for (int x = xmin; x sram - - /* - * More information about Special Section Indexes is available in the - * free "ELF for the ARM Architecture" document from ARM Limited - * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf - * - */ - .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } > sram - __exidx_start = .; - .ARM.exidx : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) } > sram - __exidx_end = .; - - _etext = .; - - .data : AT (__exidx_end) - { - _data = .; - *(vtable) - *(.data*) - _edata = .; - } > sram - - /* zero initialized data */ - .bss : - { - _bss = .; - *(.bss*) - *(COMMON) - _ebss = .; - } > sram - - end = .; - - /* For GDB compatibility we decrease the top with 16 bytes */ - stack_entry = sram_top - 16; -} diff --git a/firmware/loadable/recvcard.c b/firmware/loadable/recvcard.c deleted file mode 100644 index 8571f7c..0000000 --- a/firmware/loadable/recvcard.c +++ /dev/null @@ -1,338 +0,0 @@ -#include -#include -#include -#include -#include -#include "basic/basic.h" -#include "lcd/render.h" -#include "lcd/allfonts.h" -#include "basic/ecc.h" -#include "funk/nrf24l01p.h" -#include "filesystem/ff.h" -#include "filesystem/diskio.h" -#include "funk/filetransfer.h" -#include "lcd/print.h" - -uint8_t mac[5] = {1,2,3,2,1}; - -void ram(void) -{ - if( sendKeys() ) - return; - - char priv[42]; - UINT readbytes; - FIL file; - - if( f_open(&file, "priv.key", FA_OPEN_EXISTING|FA_READ) ){ - return; - } - if( f_read(&file, priv, 41, &readbytes) || readbytes != 41 ){ - return; - } - f_close(&file); - priv[41] = 0; - - uint8_t done = 0; - uint8_t key; - uint8_t k1[16], k2[16], rx[4*NUMWORDS], ry[4*NUMWORDS]; - - while( !done ){ - lcdClear(); - lcdPrintln("Receiving file"); - lcdPrintln("Down=Abort"); - lcdRefresh(); - key = getInput(); - delayms(20); - if( key == BTN_DOWN ){ - return -1; - } - if( receiveR(rx,ry) ) - continue; - lcdPrintln("Creating key"); - lcdRefresh(); - ECIES_decryptkeygen(rx, ry, k1, k2, priv); - if( filetransfer_receive(mac,(uint32_t*)k1) < 0 ) - continue; - lcdPrintln("Right=OK"); - lcdPrintln("Left=Retry"); - lcdPrintln("Down=Abort"); - lcdRefresh(); - - while(1){ - key = getInput(); - delayms(20); - if( key == BTN_LEFT ){ - break; - }else if( key == BTN_RIGHT ){ - done = 1; - break; - }else if( key == BTN_DOWN ){ - return -1; - } - } - } -} - -void sendPublicKey(void) -{ - uint8_t exp[2 + 4*NUMWORDS + 2]; - char buf[42]; - UINT readbytes; - FIL file; - - if( f_open(&file, "pubx.key", FA_OPEN_EXISTING|FA_READ) ){ - return; - } - if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){ - return; - } - f_close(&file); - buf[41] = 0; - - exp[0] = 'P'; - bitstr_parse_export((char*)exp+2, buf); - exp[1] = 'X'; - nrf_snd_pkt_crc(32, exp); - delayms(10); - - if( f_open(&file, "puby.key", FA_OPEN_EXISTING|FA_READ) ){ - return; - } - if( f_read(&file, buf, 41, &readbytes) || readbytes != 41 ){ - return; - } - f_close(&file); - buf[41] = 0; - - exp[1] = 'Y'; - bitstr_parse_export((char*)exp+2, buf); - nrf_snd_pkt_crc(32, exp); - delayms(10); -} - - -int receiveKey(uint8_t type, uint8_t *x, uint8_t *y) -{ - uint8_t buf[32]; - uint8_t n; - - n = nrf_rcv_pkt_time(1000, 32, buf); - if( n == 32 && buf[0] == type && buf[1] == 'X' ){ - for(int i=0; i -#include "funk/nrf24l01p.h" -#include "funk/filetransfer.h" -#include "funk/rftransfer.h" -#include "basic/basic.h" -#include "basic/xxtea.h" -#include "filesystem/ff.h" -#include "lcd/print.h" - - -int filetransfer_receive(uint8_t *mac, uint32_t const k[4]) -{ - uint8_t buf[MAXSIZE+1]; - uint16_t size; - uint8_t n; - - UINT written = 0; - FIL file; - FRESULT res; - //uint8_t macbuf[5]; - //nrf_get_rx_max(0,5,macbuf); - - uint8_t metadata[32]; - - //nrf_set_rx_mac(0, 32, 5, mac); - n = nrf_rcv_pkt_time_encr(3000, 32, metadata, k); - if( n != 32 ) - return 1; //timeout - //nrf_set_rx_mac(0, 32, 5, macbuf); - //lcdPrintln("got meta"); lcdRefresh(); - metadata[19] = 0; //enforce termination - size = (metadata[20] << 8) | metadata[21]; - - if( size > MAXSIZE ) {lcdPrintln("too big"); lcdRefresh(); while(1);} - if( size > MAXSIZE ) return 1; //file to big - //if(fileexists(metadata)) return 1; //file already exists - - //lcdPrint("open"); lcdPrintln((const char*)metadata); lcdRefresh(); - res = f_open(&file, (const char*)metadata, FA_OPEN_ALWAYS|FA_WRITE); - - //lcdPrintln("file opened"); lcdRefresh(); - if( res ) {lcdPrintln("res"); lcdPrint(f_get_rc_string(res)); lcdRefresh(); while(1);} - if( res ) - return res; - - uint16_t wordcount = (size+3)/4; - - //nrf_set_rx_mac(0, 32, 5, mac); - //lcdPrintln("get file"); lcdRefresh(); - int fres = rftransfer_receive(buf, wordcount*4, 1000); - if( fres == -1 ){ - lcdPrintln("checksum wrong"); - }else if( fres == -2 ){ - lcdPrintln("timeout"); - }else{ - //lcdPrintln("got file"); - } - lcdRefresh(); - if( fres < 0 ) - return 1; - //nrf_set_rx_mac(0, 32, 5, macbuf); - - xxtea_decode_words((uint32_t *)buf, wordcount, k); - - res = f_write(&file, buf, size, &written); - f_close(&file); - if( res ) - return res; - if( written != size ) - return 1; //error while writing - lcdClear(); - lcdPrintln("Received"); lcdPrintln((const char*)metadata); lcdRefresh(); - - return 0; -} - -#define MAXPACKET 32 -int16_t rftransfer_receive(uint8_t *buffer, uint16_t maxlen, uint16_t timeout) -{ - uint8_t buf[MAXPACKET]; - uint8_t state = 0; - uint16_t pos = 0, seq = 0, size = 0, rand = 0, crc = 0; - int n,i; - unsigned int currentTick = systickGetTicks(); - unsigned int startTick = currentTick; - - while(systickGetTicks() < (startTick+timeout) ){//this fails if either overflows - n = nrf_rcv_pkt_time(1000, MAXPACKET, buf); - switch(state){ - case 0: - if( n == 32 && buf[0] == 'L' ){ - size = (buf[1] << 8) | buf[2]; - rand = (buf[3] << 8) | buf[4]; - seq = 0; - pos = 0; - if( size <= maxlen ){ - //lcdClear(); - //lcdPrint("got l="); lcdPrintInt(size); - //lcdPrintln(""); lcdRefresh(); - state = 1; - } - } - break; - case 1: - if( n == 32 && buf[0] == 'D' && ((buf[3]<<8)|buf[4])==rand ){ - //lcdPrint("got d"); lcdRefresh(); - if( seq == ((buf[1]<<8)|buf[2]) ){ - //lcdPrintln(" in seq"); lcdRefresh(); - for(i=5; i -#include -#include -#include -#include -#include "basic/basic.h" -#include "lcd/render.h" -#include "lcd/allfonts.h" -#include "basic/ecc.h" -#include "funk/nrf24l01p.h" -#include "filesystem/ff.h" -#include "filesystem/diskio.h" -#include "funk/filetransfer.h" -#include "lcd/print.h" - - - -uint8_t mac[5] = {1,2,3,2,1}; - -void ram(void) -{ - char file[13]; - selectFile(file,"TXT"); - sendFile(file); -} - -void sendR(uint8_t *rx, uint8_t *ry) -{ - uint8_t exp[2 + 4*NUMWORDS + 2]; - exp[0] = 'R'; - for(int i=0; i<4*NUMWORDS; i++) - exp[2+i] = rx[i]; - exp[1] = 'X'; - nrf_snd_pkt_crc(32, exp); - delayms(10); - exp[1] = 'Y'; - for(int i=0; i<4*NUMWORDS; i++) - exp[2+i] = ry[i]; - nrf_snd_pkt_crc(32, exp); - delayms(10); -} - -int receiveKey(uint8_t type, uint8_t *x, uint8_t *y) -{ - uint8_t buf[32]; - uint8_t n; - - n = nrf_rcv_pkt_time(1000, 32, buf); - if( n == 32 && buf[0] == type && buf[1] == 'X' ){ - for(int i=0; i -#include "funk/nrf24l01p.h" -#include "funk/filetransfer.h" -#include "funk/rftransfer.h" -#include "basic/basic.h" -#include "basic/xxtea.h" -#include "filesystem/ff.h" -#include "lcd/print.h" - - -//TODO: use a proper MAC to sign the message -int filetransfer_send(uint8_t *filename, uint16_t size, - uint8_t *mac, uint32_t const k[4]) -{ - uint8_t buf[MAXSIZE]; - FIL file; - FRESULT res; - UINT readbytes; - - - if( size > MAXSIZE ) - return 1; //File to big - - res=f_open(&file, (const char*)filename, FA_OPEN_EXISTING|FA_READ); - if( res ) - return res; - - //res = f_read(&file, (char *)buf, size, &readbytes); - for(uint16_t i=0; i> 8; - metadata[21] = size & 0xFF; - - //nrf_get_tx_max(5,macbuf); - - //nrf_set_tx_mac(5, mac); - nrf_snd_pkt_crc_encr(32, metadata, k); - delayms(20); - xxtea_encode_words((uint32_t *)buf, wordcount, k); - rftransfer_send(wordcount*4, buf); - //nrf_set_tx_mac(5, macbuf); - return 0; -} - -#include "funk/rftransfer.h" -#include "funk/nrf24l01p.h" -#include -#include -#include -#include - -#define MAXPACKET 32 -void rftransfer_send(uint16_t size, uint8_t *data) -{ - uint8_t buf[MAXPACKET]; - buf[0] = 'L'; - buf[1] = size >> 8; - buf[2] = size & 0xFF; - - uint16_t rand = getRandom() & 0xFFFF; - buf[3] = rand >> 8; - buf[4] = rand & 0xFF; - - nrf_snd_pkt_crc(32,buf); //setup packet - delayms(20); - uint16_t index = 0; - uint8_t i; - uint16_t crc = crc16(data,size); - - while(size){ - buf[0] = 'D'; - buf[1] = index >> 8; - buf[2] = index & 0xFF; - buf[3] = rand >> 8; - buf[4] = rand & 0xFF; - for(i=5; i0; i++,size--){ - buf[i] = *data++; - } - index++; - nrf_snd_pkt_crc(32,buf); //data packet - delayms(20); - } - - buf[0] = 'C'; - buf[1] = crc >> 8; - buf[2] = crc & 0xFF; - buf[3] = rand >> 8; - buf[4] = rand & 0xFF; - nrf_snd_pkt_crc(32,buf); //setup packet - delayms(20); -} - diff --git a/firmware/loadable/spaceinvaders.c b/firmware/loadable/spaceinvaders.c deleted file mode 100644 index fbcf38a..0000000 --- a/firmware/loadable/spaceinvaders.c +++ /dev/null @@ -1,462 +0,0 @@ -#include -#include - -#include "basic/basic.h" -#include "basic/random.h" - -#include "lcd/render.h" -#include "lcd/display.h" -#include "lcd/allfonts.h" - -/**************************************************************************/ -#define POS_PLAYER_Y 60 -#define POS_PLAYER_X RESX/2-3 -#define POS_UFO_Y 0 -#define ENEMY_ROWS 3 -#define ENEMY_COLUMNS 6 -#define DISABLED 255 - -#define UFO_PROB 1024 - -#define TYPE_PLAYER 1 -#define TYPE_ENEMY_A 3 -#define TYPE_ENEMY_B 2 -#define TYPE_ENEMY_C 4 -#define TYPE_UFO 5 - -#define BUNKERS 3 -#define BUNKER_WIDTH 10 -static const uint8_t BUNKER_X[] = {15, RESX/2-BUNKER_WIDTH/2,RESX-BUNKER_WIDTH-15}; -static const uint8_t ENEMY_WIDTHS[] = {8,10,12}; - -struct gamestate { - char player; - char ufo; - char shot_x, shot_y; - char shots_x[ENEMY_COLUMNS]; - char shots_y[ENEMY_COLUMNS]; - char alive; - int16_t move; - char direction, lastcol; - bool killed; - bool step; - uint32_t score; - uint16_t level; - int8_t rokets; - char enemy_x[ENEMY_ROWS][ENEMY_COLUMNS]; - char enemy_row_y[ENEMY_ROWS]; - uint8_t bunker[BUNKERS][BUNKER_WIDTH]; -} game; -char key; - -void init_game(); -void init_enemy(); -void check_end(); -void move_ufo(); -void move_shot(); -void move_shots(); -void move_player(); -void move_enemy(); -void draw_score(); -void draw_bunker(); -void draw_player(); -void draw_enemy(); -void draw_shots(); -void draw_sprite(char type, char x, char y); -void draw_ufo(); -void screen_intro(); -void screen_gameover(); -void screen_level(); -bool check_bunker(char xpos, char ypos, int8_t shift); - -void ram(void) { - //gpioSetValue (RB_LED1, CFG_LED_OFF); - //backlightInit(); - while(1) { - screen_intro(); - game.rokets = 3; - game.level = 1; - init_game(); - screen_level(); - while (game.rokets>=0) { - ////checkISP(); - lcdFill(0); - check_end(); - move_ufo(); - move_shot(); - move_shots(); - move_player(); - move_enemy(); - draw_score(); - draw_ufo(); - draw_bunker(); - draw_player(); - draw_enemy(); - draw_shots(); - // draw_status(); - lcdDisplay(); - delayms(12); - } - screen_gameover(); - } - return; -} - -void screen_intro() { - char key=0; - while(key==0) { - lcdFill(0); - font = &Font_Invaders; - DoString(28,25,"ABC"); - font = &Font_7x8; - DoString (28,40,"SPACE"); - DoString (18,50,"INVADERS"); - //DoString (20,RESY-24, "Highscore"); - DoString (0, 0, "12345"); - DoString (0, 9, "iggy"); - lcdDisplay(); - - delayms_queue(50); - key=getInput(); - } -} - -void screen_gameover() { - char key =0; - while(key==0) { - lcdFill(0); - font = &Font_7x8; - DoString (12,32, "GAME OVER"); - DoInt (0,0, game.score); - DoString (0,9,"HIGHSCORE!"); - lcdDisplay(); - delayms_queue(50); - key=getInput(); - } -} - -void screen_level() { - lcdFill(0); - draw_score(); - font = &Font_7x8; - int dx = DoString(20,32, "Level "); - DoInt(dx,32,game.level); - lcdDisplay(); - delayms(500); -} - -void init_game(void) { - game.player = POS_PLAYER_X; - game.shot_x = DISABLED; - game.shot_y = 0; - game.alive = ENEMY_ROWS*ENEMY_COLUMNS; - game.move = 0; - if (getRandom()%2 == 0) { - game.direction = -1; - game.lastcol = ENEMY_COLUMNS-1; - } else { - game.direction = 1; - game.lastcol = 0; - } - game.killed = 0; - game.step = false; - game.ufo = DISABLED; - game.score = 0; - init_enemy(); - - for (int col=0; colBUNKER_X[BUNKERS-1-b] && - xposRESY-16) { - int offset = BUNKER_WIDTH - (xpos-BUNKER_X[BUNKERS-1-b]); - if (game.bunker[b][offset]!=0) { - if (shift>0) - game.bunker[b][offset]&=game.bunker[b][offset]<>-shift; - return true; - } - } - } - return false; -} - -void move_shot() { - //No shot, do nothing - if(game.shot_x == DISABLED) { - return; - } - - //moving out of top, end shot - if (game.shot_y <= 0) { - game.shot_x = DISABLED; - return; - } - - if (check_bunker(game.shot_x,game.shot_y-5,1 )) - game.shot_x=DISABLED; - - //check for collision with enemy, kill enemy if - for (int row=0; row= game.shot_y && game.enemy_row_y[row]+6 < game.shot_y+7) { - for(int col = 0; col= game.enemy_x[row][col] && game.shot_x < game.enemy_x[row][col]+ENEMY_WIDTHS[row]) { - game.enemy_x[row][col]=DISABLED; - game.shot_x = DISABLED; - game.alive--; - game.score+=(3-row)*10; - return; - } - } - } - } - - //check for collision with ufo - if (game.ufo != DISABLED && - game.shot_x>game.ufo && - game.shot_x= RESY) { - game.shots_x[col] = DISABLED; - return; - } - //check for collision with bunker - if (check_bunker(game.shots_x[col],game.shots_y[col],-1)) - game.shots_x[col]=DISABLED; - - //check for collision with player - if (game.shots_y[col] >= RESY-13 && - game.shots_x[col] > game.player+1 && - game.shots_x[col] < game.player+6) { - - game.killed = true; - } - - //move shots down - game.shots_y[col] += 1; - } -} - -void move_ufo() { - if (game.ufo == DISABLED) { - if ((getRandom()%UFO_PROB)==0) { - game.ufo = 0; - } - return; - } - if (game.ufo >= RESX){ - game.ufo = DISABLED; - return; - } - game.ufo++; -} - -void move_player() { - if(gpioGetValue(RB_BTN0)==0 && game.player > 0 ){ - game.player-=1; - } - - if(gpioGetValue(RB_BTN1)==0 && game.player < RESX-8){ - game.player+=1; - } - - if(gpioGetValue(RB_BTN4)==0 && game.shot_x == 255){ - game.shot_x = game.player+4; - game.shot_y = POS_PLAYER_Y; - } -} - -void move_enemy() { - if(game.move > 0){ - game.move-=game.level/5+1; - return; - } - - game.step = !game.step; - for (int col = 0; col < ENEMY_COLUMNS; col++) { - for (int row = 0; row < ENEMY_ROWS; row++) { - char pos = game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col]; - if (pos != DISABLED) { - //Check collision with player - if((game.enemy_row_y[row]+8 >= POS_PLAYER_Y && pos+8 >= game.player && pos < game.player+8) || - game.enemy_row_y[row]+8 >= POS_PLAYER_Y+8) { - for(int row=0; row=RESX-10 && game.direction == 1)){ - game.direction = (game.direction==1)?-1:1; - for (int r = 0; r=23?4:2; - } - return; - } - game.enemy_x[row][(game.direction==1)?(ENEMY_COLUMNS-(col+1)):col] += game.direction; - } - } - } - - game.move = game.alive*2-1; -} - -void draw_player() { - draw_sprite(TYPE_PLAYER, game.player, POS_PLAYER_Y); -} - -void draw_ufo() { - if (game.ufo!=DISABLED) - draw_sprite(TYPE_UFO, game.ufo, POS_UFO_Y); -} - -void draw_enemy() { - for (int row = 0; row