freemyipod r760 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r759‎ | r760 | r761 >
Date:10:50, 11 August 2011
Author:user890104
Status:new
Tags:
Comment:
New app: ball
Tested on Nano2G and Nano4G, can someone test it on a Classic please?
Modified paths:
  • /apps/ball (added) (history)
  • /apps/ball/Makefile (added) (history)
  • /apps/ball/SOURCES (added) (history)
  • /apps/ball/ls.x (added) (history)
  • /apps/ball/main.c (added) (history)
  • /apps/ball/version.h (added) (history)

Diff [purge]

Index: apps/ball/SOURCES
@@ -0,0 +1 @@
 2+main.c
Index: apps/ball/ls.x
@@ -0,0 +1,42 @@
 2+ENTRY(__emcore_entrypoint)
 3+OUTPUT_FORMAT(elf32-littlearm)
 4+OUTPUT_ARCH(arm)
 5+
 6+MEMORY
 7+{
 8+ VIRTUAL : ORIGIN = 0x00000000, LENGTH = 0x10000000
 9+}
 10+
 11+SECTIONS
 12+{
 13+ .text :
 14+ {
 15+ __emcore_app_base = .;
 16+ KEEP(.emcoreentrypoint*)
 17+ *(.emcoreentrypoint*)
 18+ *(.text*)
 19+ *(.glue_7)
 20+ *(.glue_7t)
 21+ . = ALIGN(0x10);
 22+ } > VIRTUAL
 23+
 24+ .data :
 25+ {
 26+ *(.rodata*)
 27+ . = ALIGN(0x4);
 28+ *(.data*)
 29+ . = ALIGN(0x10);
 30+ } > VIRTUAL
 31+
 32+ .bss (NOLOAD) :
 33+ {
 34+ *(.bss*)
 35+ *(COMMON)
 36+ } > VIRTUAL
 37+
 38+ /DISCARD/ :
 39+ {
 40+ *(.eh_frame)
 41+ }
 42+
 43+}
Index: apps/ball/main.c
@@ -0,0 +1,121 @@
 2+//
 3+//
 4+// Copyright 2011 user890104
 5+//
 6+//
 7+// This file is part of emCORE.
 8+//
 9+// emCORE is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emCORE is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emCORE. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#include "emcoreapp.h"
 26+
 27+#define BALL_W 5
 28+#define BALL_H 5
 29+
 30+unsigned int dw, dh, dbpp;
 31+void* fb;
 32+
 33+static inline void drawat(unsigned int x, unsigned int y, unsigned char color)
 34+{
 35+ if (x >= dw || y >= dh) return;
 36+
 37+ // TODO: is there a better way?
 38+ *((char *)(fb + dbpp * x + dbpp * dw * y)) = color;
 39+ *((char *)(fb + dbpp * x + dbpp * dw * y + 1)) = color;
 40+ *((char *)(fb + dbpp * x + dbpp * dw * y + 2)) = color;
 41+}
 42+
 43+static void main()
 44+{
 45+ unsigned int run_cycles = 5000;
 46+
 47+ dw = lcd_get_width();
 48+ dh = lcd_get_height();
 49+ dbpp = 3; // 24-bit FB (rgb888)
 50+
 51+ unsigned int fb_size = dbpp * dw * dh;
 52+ fb = malloc(fb_size);
 53+
 54+ if (fb == NULL)
 55+ {
 56+ panic(PANIC_KILLTHREAD, "Unable to allocate framebuffer!");
 57+ }
 58+
 59+ unsigned int i, x = 0, y = 0,
 60+ old_x, old_y, bx, by,
 61+ size = BALL_W * BALL_H;
 62+ int vx = 1, vy = 1;
 63+
 64+ //filllcd(0, 0, dw, dh, 0xffffff); // broken on Nano 4G?
 65+ memset(fb, 0xff, fb_size);
 66+ displaylcd(0, 0, dw, dh, fb, 0, 0, dw);
 67+
 68+ while (run_cycles > 0)
 69+ {
 70+ memset(fb, 0xff, fb_size);
 71+
 72+ // check if we hit a wall
 73+ if ((x >= dw - BALL_W && vx > 0) || (x == 0 && vx < 0))
 74+ {
 75+ vx = -vx;
 76+ }
 77+
 78+ if ((y >= dh - BALL_H && vy > 0) || (y == 0 && vy < 1))
 79+ {
 80+ vy = -vy;
 81+ }
 82+
 83+ // store old x and y
 84+ // needed for redrawing later
 85+ old_x = x; old_y = y;
 86+
 87+ x += vx; y += vy;
 88+
 89+ // draw our ball-like object
 90+ // a circle-like actually, since we
 91+ // don't have a 3D engine yet :)
 92+ for (i = 1; i < BALL_W - 1; ++i)
 93+ {
 94+ drawat(x + i, y, 0);
 95+ }
 96+
 97+ for (i = BALL_W; i < size - BALL_W; ++i)
 98+ {
 99+ drawat(x + i % BALL_W, y + i / BALL_W, 0);
 100+ }
 101+
 102+ for (i = 1; i < BALL_W - 1; ++i)
 103+ {
 104+ drawat(x + i, y + BALL_H - 1, 0);
 105+ }
 106+
 107+ // offset to redraw from
 108+ bx = vx > 0 ? old_x : x;
 109+ by = vy > 0 ? old_y : y;
 110+
 111+ displaylcd(bx, by, BALL_W + ABS(vx), BALL_H + ABS(vy), fb, bx, by, dw);
 112+
 113+ sleep(1000);
 114+
 115+ --run_cycles;
 116+ }
 117+
 118+ cputs(3, "Application terminated\n");
 119+}
 120+
 121+
 122+EMCORE_APP_HEADER("Ball", main, 127)
Index: apps/ball/version.h
@@ -0,0 +1,36 @@
 2+//
 3+//
 4+// Copyright 2010 TheSeven
 5+//
 6+//
 7+// This file is part of emCORE.
 8+//
 9+// emCORE is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emCORE is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emCORE. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#ifndef __VERSION_H__
 26+#define __VERSION_H__
 27+
 28+
 29+#define VERSION "0.0.1pre"
 30+#define VERSION_MAJOR 0
 31+#define VERSION_MINOR 0
 32+#define VERSION_PATCH 1
 33+#define VERSION_SVN "$REVISION$"
 34+#define VERSION_SVN_INT $REVISIONINT$
 35+
 36+
 37+#endif
\ No newline at end of file
Index: apps/ball/Makefile
@@ -0,0 +1,120 @@
 2+NAME := ball
 3+STACKSIZE := 4096
 4+COMPRESS := true
 5+
 6+EMCOREDIR ?= ../../emcore/trunk/
 7+
 8+ifeq ($(shell uname),WindowsNT)
 9+CCACHE :=
 10+else
 11+CCACHE := $(shell which ccache)
 12+endif
 13+
 14+CROSS ?= arm-elf-eabi-
 15+CC := $(CCACHE) $(CROSS)gcc
 16+AS := $(CROSS)as
 17+LD := $(CROSS)ld
 18+OBJCOPY := $(CROSS)objcopy
 19+ELF2ECA := $(CROSS)elf2emcoreapp
 20+
 21+LIBINCLUDES :=
 22+
 23+CFLAGS += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -I$(EMCOREDIR)/export $(LIBINCLUDES) -ffunction-sections -fdata-sections -mcpu=arm940t -DARM_ARCH=4
 24+LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --emit-relocs --gc-sections
 25+
 26+preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
 27+preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:" | sed -e "s:^\\./::")
 28+
 29+REVISION := $(shell svnversion .)
 30+REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
 31+
 32+HELPERS := build/__emcore_armhelpers.o
 33+
 34+SRC := $(call preprocesspaths,SOURCES,-I. -I..)
 35+OBJ := $(SRC:%.c=build/%.o)
 36+OBJ := $(OBJ:%.S=build/%.o) $(HELPERS)
 37+
 38+all: $(NAME)
 39+
 40+-include $(OBJ:%=%.dep)
 41+
 42+$(NAME): build/$(NAME).emcoreapp
 43+
 44+build/$(NAME).emcoreapp: build/$(NAME).elf
 45+ @echo [EMCAPP] $<
 46+ifeq ($(COMPRESS),true)
 47+ @$(ELF2ECA) -z -s $(STACKSIZE) -o $@ $^
 48+else
 49+ @$(ELF2ECA) -s $(STACKSIZE) -o $@ $^
 50+endif
 51+
 52+build/$(NAME).elf: ls.x $(OBJ)
 53+ @echo [LD] $@
 54+ @$(LD) $(LDFLAGS) -o $@ -T ls.x $(OBJ)
 55+
 56+build/%.o: %.c build/version.h
 57+ @echo [CC] $<
 58+ifeq ($(shell uname),WindowsNT)
 59+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 60+else
 61+ @-mkdir -p $(dir $@)
 62+endif
 63+ @$(CC) -c $(CFLAGS) -o $@ $<
 64+ @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
 65+ @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
 66+ifeq ($(shell uname),WindowsNT)
 67+ @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
 68+else
 69+ @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
 70+endif
 71+ @rm -f $@.dep.tmp
 72+
 73+build/%.o: %.S build/version.h
 74+ @echo [CC] $<
 75+ifeq ($(shell uname),WindowsNT)
 76+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 77+else
 78+ @-mkdir -p $(dir $@)
 79+endif
 80+ @$(CC) -c $(CFLAGS) -o $@ $<
 81+ @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
 82+ @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
 83+ifeq ($(shell uname),WindowsNT)
 84+ @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
 85+else
 86+ @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
 87+endif
 88+ @rm -f $@.dep.tmp
 89+
 90+build/__emcore_%.o: $(EMCOREDIR)/export/%.c
 91+ @echo [CC] $<
 92+ifeq ($(shell uname),WindowsNT)
 93+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 94+else
 95+ @-mkdir -p $(dir $@)
 96+endif
 97+ @$(CC) -c $(CFLAGS) -o $@ $<
 98+
 99+build/__emcore_%.o: $(EMCOREDIR)/export/%.S
 100+ @echo [CC] $<
 101+ifeq ($(shell uname),WindowsNT)
 102+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 103+else
 104+ @-mkdir -p $(dir $@)
 105+endif
 106+ @$(CC) -c $(CFLAGS) -o $@ $<
 107+
 108+build/version.h: version.h .svn/entries
 109+ @echo [PP] $<
 110+ifeq ($(shell uname),WindowsNT)
 111+ @-if not exist build md build
 112+ @sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
 113+else
 114+ @-mkdir -p build
 115+ @sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
 116+endif
 117+
 118+clean:
 119+ @rm -rf build
 120+
 121+.PHONY: all clean $(NAME)
Index: apps/ball
Property changes on: apps/ball
___________________________________________________________________
Added: svn:ignore
## -0,0 +1 ##
 122+build