From 44e84677e77f5ad4f4be1c4f29eea1b44632e157 Mon Sep 17 00:00:00 2001 From: tixiv Date: Fri, 2 Jan 2009 02:18:20 +0000 Subject: [PATCH] Game and menu support added. Dependencies fixed. Compiles fine for AVR and Windows. Linux simulator is still missing a linker script. --- Makefile | 3 +- animations/snake.c | 1 - avr5.x | 4 +- config.in | 29 +++++-- defaults.mk | 6 +- display_loop.c | 2 +- games/Makefile | 12 --- games/config.in | 9 ++ games/games.mk | 12 +++ games/snake/Makefile | 8 ++ games/{ => snake}/snake_game.c | 14 +-- games/space_invaders/Makefile | 8 ++ games/{ => space_invaders}/invader_draw.c | 0 games/{ => space_invaders}/invader_init.c | 0 games/{ => space_invaders}/invader_proc.c | 4 +- games/{ => space_invaders}/invaders2.c | 28 ++++-- games/{ => space_invaders}/invaders2.h | 17 ++-- games/tetris/Makefile | 27 ++---- games/tetris/input.c | 23 ++--- games/tetris/logic.c | 21 +++-- games/tetris/view.c | 18 ++-- joystick.c | 13 --- joystick.h | 33 ------- joystick/Makefile | 9 ++ joystick/config.in | 101 ++++++++++++++++++++++ joystick/joystick.c | 16 ++++ joystick/joystick.h | 29 +++++++ main.c | 5 ++ makros.h | 4 + menu/menu.c | 17 ++-- profiles/borg-16 | 77 +++++++++++++++++ simulator/eeprom.c | 10 ++- simulator/i386pe.x | 6 +- util.c | 2 +- 34 files changed, 397 insertions(+), 171 deletions(-) delete mode 100644 games/Makefile create mode 100644 games/config.in create mode 100644 games/games.mk create mode 100644 games/snake/Makefile rename games/{ => snake}/snake_game.c (88%) create mode 100644 games/space_invaders/Makefile rename games/{ => space_invaders}/invader_draw.c (100%) rename games/{ => space_invaders}/invader_init.c (100%) rename games/{ => space_invaders}/invader_proc.c (97%) rename games/{ => space_invaders}/invaders2.c (82%) rename games/{ => space_invaders}/invaders2.h (96%) delete mode 100644 joystick.c delete mode 100644 joystick.h create mode 100644 joystick/Makefile create mode 100644 joystick/config.in create mode 100644 joystick/joystick.c create mode 100644 joystick/joystick.h create mode 100644 profiles/borg-16 diff --git a/Makefile b/Makefile index 1b51379..07e5898 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,6 @@ include defaults.mk @ echo "checking in which subdirs to build" @ $(RM) -f $@ @ echo "SUBDIRS += animations" >> $@ -# @ echo "SUBDIRS += animations games menu" >> $@ @ (for subdir in `grep -e "^#define .*_SUPPORT" autoconf.h \ | sed -e "s/^#define //" -e "s/_SUPPORT.*//" \ | tr "[A-Z]\\n" "[a-z] " `; do \ @@ -54,12 +53,14 @@ ifneq ($(MAKECMDGOALS),menuconfig) include $(TOPDIR)/.subdirs include $(TOPDIR)/.config +include $(TOPDIR)/games/games.mk endif # MAKECMDGOALS!=menuconfig endif # MAKECMDGOALS!=mrproper endif # MAKECMDGOALS!=clean endif # no_deps!=t + ############################################################################## SUBDIRS_AVR = borg_hw diff --git a/animations/snake.c b/animations/snake.c index a43a21b..9d6c7de 100644 --- a/animations/snake.c +++ b/animations/snake.c @@ -4,7 +4,6 @@ #include "../util.h" #include "../random/prng.h" #include "snake.h" -#include "../joystick.h" #define RANDOM8() (random8()) diff --git a/avr5.x b/avr5.x index 3e08033..30312af 100644 --- a/avr5.x +++ b/avr5.x @@ -154,9 +154,9 @@ SECTIONS *(.rodata) /* We need to include .rodata here if gcc is used */ *(.rodata*) /* with -fdata-sections. */ *(.gnu.linkonce.d*) - __game_descriptors_start__ = . ; + PROVIDE (_game_descriptors_start__ = .) ; *(.game_descriptors) - __game_descriptors_end__ = . ; + PROVIDE (_game_descriptors_end__ = .) ; . = ALIGN(2); _edata = . ; PROVIDE (__data_end = .) ; diff --git a/config.in b/config.in index 97c4e5f..6474678 100644 --- a/config.in +++ b/config.in @@ -20,35 +20,52 @@ comment "General Setup" endmenu ############################################################################### + ###################### Borg Hardware Menu ##################################### source borg_hw/config.in ############################################################################### + + +########################### Features Menu ##################################### mainmenu_option next_comment comment "Features" bool "prng random number generator" RANDOM_SUPPORT y endmenu +############################################################################### + + ########################## Scrolltext Menu #################################### source scrolltext/config.in ############################################################################### +############################ Joystick Menu #################################### +source joystick/config.in +############################################################################### + +dep_bool "menu support" MENU_SUPPORT $JOYSTICK_SUPPORT + +############################ Game Menu ######################################## +source games/config.in +############################################################################### + ######################### Animations Menu ##################################### mainmenu_option next_comment comment "Animations" comment "selects which animations are displayed in main loop" - dep_bool "Scrolltext" ANIMATION_SCROLLTEXT $SCROLLTEXT_SUPPORT + dep_bool "Scrolltext" ANIMATION_SCROLLTEXT $SCROLLTEXT_SUPPORT bool "Spirale" ANIMATION_SPIRALE bool "Joern1" ANIMATION_JOERN1 - bool "Snake" ANIMATION_SNAKE + dep_bool "Snake" ANIMATION_SNAKE $RANDOM_SUPPORT bool "Schachbrett" ANIMATION_SCHACHBRETT - bool "Feuer" ANIMATION_FEUER - bool "Matrix" ANIMATION_MATRIX - bool "Random bright" ANIMATION_RANDOM_BRIGHT - bool "Game of Life" ANIMATION_GAMEOFLIFE + dep_bool "Feuer" ANIMATION_FEUER $RANDOM_SUPPORT + dep_bool "Matrix" ANIMATION_MATRIX $RANDOM_SUPPORT + dep_bool "Random bright" ANIMATION_RANDOM_BRIGHT $RANDOM_SUPPORT + dep_bool "Game of Life" ANIMATION_GAMEOFLIFE $RANDOM_SUPPORT comment "Special Animations" bool "Test Animations" ANIMATION_TESTS diff --git a/defaults.mk b/defaults.mk index dbdf98b..7f82f58 100644 --- a/defaults.mk +++ b/defaults.mk @@ -22,7 +22,7 @@ CFLAGS ?= -Wall -W -Wno-unused-parameter -Wno-sign-compare CFLAGS += -g -Os -std=gnu99 -fgnu89-inline # flags for the linker -LDFLAGS += -mmcu=$(MCU) -T avr5.x +LDFLAGS += -T ./avr5.x -mmcu=$(MCU) ############################################################################# @@ -34,11 +34,11 @@ OSTYPE = $(shell echo $$OSTYPE) ifeq ($(OSTYPE),cygwin) CFLAGS_SIM = -g -Wall -pedantic -std=c99 -O2 -D_WIN32 -mno-cygwin LDFLAGS_SIM = -Wl -mno-cygwin -T simulator/i386pe.x - LIBS_SIM = -lglut32 -lglu32 -lopengl32 + LIBS_SIM = -lglut32 -lglu32 -lopengl32 else CFLAGS_SIM = -g -Wall -pedantic -std=c99 -O2 LDFLAGS_SIM = -Wl - LIBS_SIM = -lglut -lpthread -lGL -lGLU + LIBS_SIM = -lglut -lpthread -lGL -lGLU endif ############################################################################## diff --git a/display_loop.c b/display_loop.c index c952b74..264810d 100644 --- a/display_loop.c +++ b/display_loop.c @@ -14,7 +14,7 @@ #include "mcuf/mcuf.h" #include "menu/menu.h" #include "pixel.h" -#include "joystick.h" +#include "joystick/joystick.h" volatile unsigned char oldMode, oldOldmode, mode; diff --git a/games/Makefile b/games/Makefile deleted file mode 100644 index fccd335..0000000 --- a/games/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -TARGET = libanimations.a -TOPDIR = .. - -include $(TOPDIR)/defaults.mk - - -#ifeq ($(GAME_SNAKE),y) - SRC += snake_game.c -#endif - - -include $(TOPDIR)/rules.mk diff --git a/games/config.in b/games/config.in new file mode 100644 index 0000000..b4cbad7 --- /dev/null +++ b/games/config.in @@ -0,0 +1,9 @@ +mainmenu_option next_comment +comment "Games" + +dep_bool "tetris" GAME_TETRIS $JOYSTICK_SUPPORT $RANDOM_SUPPORT +dep_bool "space invaders" GAME_SPACE_INVADERS $JOYSTICK_SUPPORT $RANDOM_SUPPORT +dep_bool "snake" GAME_SNAKE $JOYSTICK_SUPPORT $RANDOM_SUPPORT + + +endmenu \ No newline at end of file diff --git a/games/games.mk b/games/games.mk new file mode 100644 index 0000000..cc67749 --- /dev/null +++ b/games/games.mk @@ -0,0 +1,12 @@ + +ifeq ($(GAME_TETRIS),y) + SUBDIRS += games/tetris +endif + +ifeq ($(GAME_SPACE_INVADERS),y) + SUBDIRS += games/space_invaders +endif + +ifeq ($(GAME_SNAKE),y) + SUBDIRS += games/snake +endif diff --git a/games/snake/Makefile b/games/snake/Makefile new file mode 100644 index 0000000..6419b6d --- /dev/null +++ b/games/snake/Makefile @@ -0,0 +1,8 @@ +TARGET = +TOPDIR = ../.. + +include $(TOPDIR)/defaults.mk + +SRC = snake_game.c + +include $(TOPDIR)/rules.mk diff --git a/games/snake_game.c b/games/snake/snake_game.c similarity index 88% rename from games/snake_game.c rename to games/snake/snake_game.c index 16a446a..30fd9e0 100644 --- a/games/snake_game.c +++ b/games/snake/snake_game.c @@ -1,11 +1,11 @@ -#include "../config.h" -#include "../compat/pgmspace.h" -#include "../menu/menu.h" -#include "../pixel.h" -#include "../random/prng.h" -#include "../util.h" -#include "../joystick.h" +#include "../../config.h" +#include "../../compat/pgmspace.h" +#include "../../menu/menu.h" +#include "../../pixel.h" +#include "../../random/prng.h" +#include "../../util.h" +#include "../../joystick/joystick.h" // MSB is leftmost pixel static uint8_t icon[8] PROGMEM = diff --git a/games/space_invaders/Makefile b/games/space_invaders/Makefile new file mode 100644 index 0000000..cf00935 --- /dev/null +++ b/games/space_invaders/Makefile @@ -0,0 +1,8 @@ +TARGET = +TOPDIR = ../.. + +include $(TOPDIR)/defaults.mk + +SRC = invader_init.c invader_draw.c invader_proc.c invaders2.c + +include $(TOPDIR)/rules.mk diff --git a/games/invader_draw.c b/games/space_invaders/invader_draw.c similarity index 100% rename from games/invader_draw.c rename to games/space_invaders/invader_draw.c diff --git a/games/invader_init.c b/games/space_invaders/invader_init.c similarity index 100% rename from games/invader_init.c rename to games/space_invaders/invader_init.c diff --git a/games/invader_proc.c b/games/space_invaders/invader_proc.c similarity index 97% rename from games/invader_proc.c rename to games/space_invaders/invader_proc.c index bfd521f..d4698f0 100644 --- a/games/invader_proc.c +++ b/games/space_invaders/invader_proc.c @@ -1,5 +1,7 @@ #include -#include "prng.h" +#include "../../config.h" +#include "../../joystick/joystick.h" +#include "../../random/prng.h" #include "invaders2.h" void procCannon(Cannon * cn, uPixel * shot) diff --git a/games/invaders2.c b/games/space_invaders/invaders2.c similarity index 82% rename from games/invaders2.c rename to games/space_invaders/invaders2.c index a4e7da5..d0953a9 100644 --- a/games/invaders2.c +++ b/games/space_invaders/invaders2.c @@ -1,12 +1,24 @@ #include -#include "util.h" +#include "../../util.h" +#include "../../compat/eeprom.h" +#include "../../compat/pgmspace.h" +#include "../../menu/menu.h" +#include "../../scrolltext/scrolltext.h" #include "invaders2.h" //#include -#ifndef __AVR__ -#define wait(_X) myWait(_X) -#endif +// MSB is leftmost pixel +static uint8_t icon[8] PROGMEM = + {0x66, 0x18, 0x3c, 0x5a, 0xff, 0xbd, 0xa5, 0x18}; // Invaders icon + +void borg_invaders(); + +game_descriptor_t invaders_game_descriptor __attribute__((section(".game_descriptors"))) ={ + &borg_invaders, + icon, +}; + void borg_invaders() { @@ -118,9 +130,11 @@ void borg_invaders() clearScreen (); //wait(5000); - char text[64]; - snprintf(text, 64, " #include #include -#include "../joystick.h" -#include "../util.h" +#include "../../config.h" +#include "../../joystick/joystick.h" +#include "../../util.h" #include "input.h" -/* - the API simulator and the real API have different named wait functions - * - the macro PM helps in reading values from PROGMEM on the AVR arch - */ -#ifdef __AVR__ - #include - #define WAIT(ms) wait(ms) - #define PM(value) pgm_read_word(&value) -#else - #define PROGMEM - #define WAIT(ms) myWait(ms) - #define PM(value) (value) -#endif - +#include "../../compat/pgmspace.h" +#define WAIT(ms) wait(ms) +#define PM(value) pgm_read_word(&value) /*********** * defines * @@ -70,7 +61,7 @@ void tetris_input_chatterProtect (tetris_input_t *pIn, // amount of loop cycles a command is ignored after its button has been // released (every command has its own counter) - const static uint8_t nInitialIgnoreValue[TETRIS_INCMD_NONE] PROGMEM = + static const uint8_t nInitialIgnoreValue[TETRIS_INCMD_NONE] PROGMEM = { TETRIS_INPUT_CHATTER_TICKS_ROT_CW, TETRIS_INPUT_CHATTER_TICKS_ROT_CCW, diff --git a/games/tetris/logic.c b/games/tetris/logic.c index e9dc154..3709c43 100644 --- a/games/tetris/logic.c +++ b/games/tetris/logic.c @@ -8,17 +8,16 @@ #include #include -#ifdef __AVR__ - #include - #include -#endif +#include "../../compat/eeprom.h" +#include "../../compat/pgmspace.h" +#include "../../menu/menu.h" #include "logic.h" #include "piece.h" #include "playfield.h" #include "view.h" #include "input.h" -#include "../prng.h" +#include "../../random/prng.h" #ifdef EEMEM @@ -29,6 +28,18 @@ uint16_t tetris_logic_nHighscore EEMEM; #endif + // MSB is leftmost pixel +static uint8_t icon[8] PROGMEM = + {0x0f, 0x0f, 0xc3, 0xdb, 0xdb, 0xc3, 0xf0, 0xf0}; // Tetris icon + +void tetris(); + +game_descriptor_t tetris_game_descriptor __attribute__((section(".game_descriptors"))) ={ + &tetris, + icon, +}; + + /*************************** * non-interface functions * ***************************/ diff --git a/games/tetris/view.c b/games/tetris/view.c index 8b63667..35571a9 100644 --- a/games/tetris/view.c +++ b/games/tetris/view.c @@ -3,22 +3,16 @@ #include #include #include -#include "../config.h" -#include "../pixel.h" -#include "../util.h" -#include "../scrolltext.h" +#include "../../config.h" +#include "../../pixel.h" +#include "../../util.h" +#include "../../scrolltext/scrolltext.h" #include "logic.h" #include "piece.h" #include "playfield.h" #include "view.h" -/* the API simulator and the real API have different named wait functions */ -#ifdef __AVR__ - #define WAIT(ms) wait(ms) -#else - #define WAIT(ms) myWait(ms) -#endif - +#define WAIT(ms) wait(ms) /*********** * defines * @@ -416,6 +410,8 @@ void tetris_view_showResults(tetris_view_t *pV) " - -unsigned char waitForFire; - - -inline void joy_init(){ - DDRB &= ~((1< + +unsigned char waitForFire; + + +inline void joy_init(){ + PORT_FROM_PIN(JOYSTICK_PIN_UP ) |= (1< + +#define JOYISUP (!(JOYSTICK_PIN_UP & (1<= EEPROM_SIZE){ printf ("warning: eeprom write to %X\n",addr); } @@ -52,8 +54,8 @@ void eeprom_write_byte (uint8_t *p, uint8_t value){ void eeprom_write_word (uint16_t *p, uint16_t value){ init(); - eemem[conv_addr(p) ] = value & 0xff; - eemem[conv_addr(p)+1] = value >> 8; + eemem[conv_addr((uint8_t*)p) ] = value & 0xff; + eemem[conv_addr((uint8_t*)p)+1] = value >> 8; fseek(fp, 0, SEEK_SET); fwrite(eemem, 1, EEPROM_SIZE, fp); @@ -67,5 +69,5 @@ uint8_t eeprom_read_byte (uint8_t *p){ uint16_t eeprom_read_word (uint16_t *p){ init(); - return eemem[conv_addr(p)] | (eemem[conv_addr(p)+1]<<8); + return eemem[conv_addr((uint8_t*)p)] | (eemem[conv_addr((uint8_t*)p)+1]<<8); } diff --git a/simulator/i386pe.x b/simulator/i386pe.x index 6f250eb..bd4ed97 100644 --- a/simulator/i386pe.x +++ b/simulator/i386pe.x @@ -3,8 +3,6 @@ OUTPUT_FORMAT(pei-i386) SEARCH_DIR("/usr/i686-pc-cygwin/lib"); SEARCH_DIR("/usr/local/lib"); SEARCH_DIR("/usr/lib"); SEARCH_DIR("/usr/lib/w32api"); SECTIONS { - . = 0; - /*.eeprom (NOLOAD) : { *.(eeprom) }*/ /* Make the virtual address and file offset synced if the alignment is lower than the target page size. */ . = SIZEOF_HEADERS; @@ -38,7 +36,9 @@ SECTIONS *(.data2) *(SORT(.data$*)) *(.jcr) - __game_descriptors_start__ = . ; + __eeprom_start__ = . ; + *(.eeprom) + __game_descriptors_start__ = . ; *(.game_descriptors) __game_descriptors_end__ = . ; __data_end__ = . ; diff --git a/util.c b/util.c index 27a2319..ce56fe8 100644 --- a/util.c +++ b/util.c @@ -1,7 +1,7 @@ #include #include -#include "joystick.h" +#include "joystick/joystick.h" //this buffer is declared in main extern jmp_buf newmode_jmpbuf;