summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomer Shalev <shalev.tomer@gmail.com>2010-01-15 05:53:15 +0000
committerTomer Shalev <shalev.tomer@gmail.com>2010-01-15 05:53:15 +0000
commit7719d297f2a1da0e45fd39cad21e99e23fd695c8 (patch)
treeae2b97d1b372340627ca3537554cd45310bace92
parent51630cbac1dcb04345fb1384812f1576f0ea29db (diff)
downloadrockbox-7719d297f2a1da0e45fd39cad21e99e23fd695c8.tar.gz
rockbox-7719d297f2a1da0e45fd39cad21e99e23fd695c8.zip
FS#10911 - Plugins: Fractals (formerly Mandelbrot)
- Rename the mandelbrot plugin to fractals - Update manual accordingly - Separate plugin's functionality into separate files - Lay the ground for having fractals sets other than the Mandelbrot set. For that the following will need to be implemented: - Create a new file for the new fracral set - Provide key mapping to switch between sets git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24230 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/CATEGORIES2
-rw-r--r--apps/plugins/SOURCES1
-rw-r--r--apps/plugins/SUBDIRS1
-rw-r--r--apps/plugins/fractals/SOURCES10
-rw-r--r--apps/plugins/fractals/cpu_arm.c40
-rw-r--r--apps/plugins/fractals/cpu_arm.h27
-rw-r--r--apps/plugins/fractals/cpu_coldfire.c58
-rw-r--r--apps/plugins/fractals/cpu_coldfire.h29
-rw-r--r--apps/plugins/fractals/cpu_sh7043.c94
-rw-r--r--apps/plugins/fractals/cpu_sh7043.h29
-rw-r--r--apps/plugins/fractals/fractal.c260
-rw-r--r--apps/plugins/fractals/fractal.h352
-rw-r--r--apps/plugins/fractals/fractal_rect.c209
-rw-r--r--apps/plugins/fractals/fractal_rect.h38
-rw-r--r--apps/plugins/fractals/fractal_sets.h52
-rw-r--r--apps/plugins/fractals/fractals.make21
-rw-r--r--apps/plugins/fractals/mandelbrot_set.c392
-rw-r--r--apps/plugins/fractals/mandelbrot_set.h60
-rw-r--r--manual/plugins/fractals.tex (renamed from manual/plugins/mandelbrot.tex)2
-rw-r--r--manual/plugins/main.tex4
20 files changed, 1676 insertions, 5 deletions
diff --git a/apps/plugins/CATEGORIES b/apps/plugins/CATEGORIES
index fc9589282e..a41514f93d 100644
--- a/apps/plugins/CATEGORIES
+++ b/apps/plugins/CATEGORIES
@@ -41,7 +41,7 @@ keybox,apps
41lamp,apps 41lamp,apps
42logo,demos 42logo,demos
43lua,viewers 43lua,viewers
44mandelbrot,demos 44fractals,demos
45matrix,demos 45matrix,demos
46maze,games 46maze,games
47mazezam,games 47mazezam,games
diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES
index a3ce60fbf8..16f7ff6f9a 100644
--- a/apps/plugins/SOURCES
+++ b/apps/plugins/SOURCES
@@ -77,7 +77,6 @@ codebuster.c
77 77
78/* Plugins needing the grayscale lib on low-depth LCDs */ 78/* Plugins needing the grayscale lib on low-depth LCDs */
79fire.c 79fire.c
80mandelbrot.c
81plasma.c 80plasma.c
82 81
83blackjack.c 82blackjack.c
diff --git a/apps/plugins/SUBDIRS b/apps/plugins/SUBDIRS
index 587050fb94..0993e8221c 100644
--- a/apps/plugins/SUBDIRS
+++ b/apps/plugins/SUBDIRS
@@ -20,6 +20,7 @@ rockboy
20pictureflow 20pictureflow
21#endif 21#endif
22chessbox 22chessbox
23fractals
23jpeg 24jpeg
24sudoku 25sudoku
25reversi 26reversi
diff --git a/apps/plugins/fractals/SOURCES b/apps/plugins/fractals/SOURCES
new file mode 100644
index 0000000000..72a22467c2
--- /dev/null
+++ b/apps/plugins/fractals/SOURCES
@@ -0,0 +1,10 @@
1fractal.c
2fractal_rect.c
3mandelbrot_set.c
4#if CONFIG_CPU == SH7034
5cpu_sh7043.c
6#elif defined CPU_COLDFIRE
7cpu_coldfire.c
8#elif defined CPU_ARM
9cpu_arm.c
10#endif
diff --git a/apps/plugins/fractals/cpu_arm.c b/apps/plugins/fractals/cpu_arm.c
new file mode 100644
index 0000000000..1d8b1a76f6
--- /dev/null
+++ b/apps/plugins/fractals/cpu_arm.c
@@ -0,0 +1,40 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "cpu_arm.h"
23
24inline long muls32_asr26(long a, long b)
25{
26 long r, t1;
27 asm (
28 "smull %[r], %[t1], %[a], %[b] \n"
29 "mov %[r], %[r], lsr #26 \n"
30 "orr %[r], %[r], %[t1], lsl #6 \n"
31 : /* outputs */
32 [r] "=&r,&r,&r"(r),
33 [t1]"=&r,&r,&r"(t1)
34 : /* inputs */
35 [a] "%r,%r,%r" (a),
36 [b] "r,0,1" (b)
37 );
38 return r;
39}
40
diff --git a/apps/plugins/fractals/cpu_arm.h b/apps/plugins/fractals/cpu_arm.h
new file mode 100644
index 0000000000..51a3718f66
--- /dev/null
+++ b/apps/plugins/fractals/cpu_arm.h
@@ -0,0 +1,27 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _CPU_ARM_H
23#define _CPU_ARM_H
24
25inline long muls32_asr26(long a, long b);
26
27#endif
diff --git a/apps/plugins/fractals/cpu_coldfire.c b/apps/plugins/fractals/cpu_coldfire.c
new file mode 100644
index 0000000000..a005a3141e
--- /dev/null
+++ b/apps/plugins/fractals/cpu_coldfire.c
@@ -0,0 +1,58 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "cpu_coldfire.h"
23
24inline short muls16_asr10(short a, short b)
25{
26 asm (
27 "muls.w %[a],%[b] \n"
28 "asr.l #8,%[b] \n"
29 "asr.l #2,%[b] \n"
30 : /* outputs */
31 [b]"+d"(b)
32 : /* inputs */
33 [a]"d" (a)
34 );
35 return b;
36}
37
38inline long muls32_asr26(long a, long b)
39{
40 long r, t1;
41 asm (
42 "mac.l %[a], %[b], %%acc0 \n" /* multiply */
43 "move.l %%accext01, %[t1] \n" /* get low part */
44 "movclr.l %%acc0, %[r] \n" /* get high part */
45 "asl.l #5, %[r] \n" /* hi <<= 5, plus one free */
46 "lsr.l #3, %[t1] \n" /* lo >>= 3 */
47 "and.l #0x1f, %[t1] \n" /* mask out unrelated bits */
48 "or.l %[t1], %[r] \n" /* combine result */
49 : /* outputs */
50 [r] "=d"(r),
51 [t1]"=d"(t1)
52 : /* inputs */
53 [a] "d" (a),
54 [b] "d" (b)
55 );
56 return r;
57}
58
diff --git a/apps/plugins/fractals/cpu_coldfire.h b/apps/plugins/fractals/cpu_coldfire.h
new file mode 100644
index 0000000000..452f18e2c5
--- /dev/null
+++ b/apps/plugins/fractals/cpu_coldfire.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _CPU_COLDFIRE_H
23#define _CPU_COLDFIRE_H
24
25inline short muls16_asr10(short a, short b);
26
27inline long muls32_asr26(long a, long b);
28
29#endif
diff --git a/apps/plugins/fractals/cpu_sh7043.c b/apps/plugins/fractals/cpu_sh7043.c
new file mode 100644
index 0000000000..1bce37d654
--- /dev/null
+++ b/apps/plugins/fractals/cpu_sh7043.c
@@ -0,0 +1,94 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "cpu_sh7043.h"
23
24inline short muls16_asr10(short a, short b)
25{
26 short r;
27 asm (
28 "muls %[a],%[b] \n"
29 "sts macl,%[r] \n"
30 "shlr8 %[r] \n"
31 "shlr2 %[r] \n"
32 : /* outputs */
33 [r]"=r"(r)
34 : /* inputs */
35 [a]"r"(a),
36 [b]"r"(b)
37 );
38 return r;
39}
40
41inline long muls32_asr26(long a, long b)
42{
43 long r, t1, t2, t3;
44 asm (
45 /* Signed 32bit * 32bit -> 64bit multiplication.
46 Notation: xxab * xxcd, where each letter represents 16 bits.
47 xx is the 64 bit sign extension. */
48 "swap.w %[a],%[t1] \n" /* t1 = ba */
49 "mulu %[t1],%[b] \n" /* a * d */
50 "swap.w %[b],%[t3] \n" /* t3 = dc */
51 "sts macl,%[t2] \n" /* t2 = a * d */
52 "mulu %[t1],%[t3] \n" /* a * c */
53 "sts macl,%[r] \n" /* hi = a * c */
54 "mulu %[a],%[t3] \n" /* b * c */
55 "clrt \n"
56 "sts macl,%[t3] \n" /* t3 = b * c */
57 "addc %[t2],%[t3] \n" /* t3 += t2, carry -> t2 */
58 "movt %[t2] \n"
59 "mulu %[a],%[b] \n" /* b * d */
60 "mov %[t3],%[t1] \n" /* t1t3 = t2t3 << 16 */
61 "xtrct %[t2],%[t1] \n"
62 "shll16 %[t3] \n"
63 "sts macl,%[t2] \n" /* lo = b * d */
64 "clrt \n" /* hi.lo += t1t3 */
65 "addc %[t3],%[t2] \n"
66 "addc %[t1],%[r] \n"
67 "cmp/pz %[a] \n" /* ab >= 0 ? */
68 "bt 1f \n"
69 "sub %[b],%[r] \n" /* no: hi -= cd (sign extension of ab is -1) */
70 "1: \n"
71 "cmp/pz %[b] \n" /* cd >= 0 ? */
72 "bt 2f \n"
73 "sub %[a],%[r] \n" /* no: hi -= ab (sign extension of cd is -1) */
74 "2: \n"
75 /* Shift right by 26 and return low 32 bits */
76 "shll2 %[r] \n" /* hi <<= 6 */
77 "shll2 %[r] \n"
78 "shll2 %[r] \n"
79 "shlr16 %[t2] \n" /* (unsigned)lo >>= 26 */
80 "shlr8 %[t2] \n"
81 "shlr2 %[t2] \n"
82 "or %[t2],%[r] \n" /* combine result */
83 : /* outputs */
84 [r] "=&r"(r),
85 [t1]"=&r"(t1),
86 [t2]"=&r"(t2),
87 [t3]"=&r"(t3)
88 : /* inputs */
89 [a] "r" (a),
90 [b] "r" (b)
91 );
92 return r;
93}
94
diff --git a/apps/plugins/fractals/cpu_sh7043.h b/apps/plugins/fractals/cpu_sh7043.h
new file mode 100644
index 0000000000..4805092377
--- /dev/null
+++ b/apps/plugins/fractals/cpu_sh7043.h
@@ -0,0 +1,29 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#ifndef _CPU_SH7043_H
23#define _CPU_SH7043_H
24
25inline short muls16_asr10(short a, short b);
26
27inline long muls32_asr26(long a, long b);
28
29#endif
diff --git a/apps/plugins/fractals/fractal.c b/apps/plugins/fractals/fractal.c
new file mode 100644
index 0000000000..3a0c785bdd
--- /dev/null
+++ b/apps/plugins/fractals/fractal.c
@@ -0,0 +1,260 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004 Matthias Wientapper
11 * Heavily extended 2005 Jens Arnold
12 * Extended 2009 Tomer Shalev
13 *
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24#include "plugin.h"
25
26#ifdef HAVE_LCD_BITMAP
27
28#include "fractal.h"
29#include "fractal_rect.h"
30#include "fractal_sets.h"
31#include "mandelbrot_set.h"
32
33#if (LCD_DEPTH < 8)
34#define USEGSLIB
35#define MYLCD(fn) grey_ub_ ## fn
36#define MYLCD_UPDATE()
37#define MYXLCD(fn) grey_ub_ ## fn
38#else
39#define MYLCD(fn) rb->lcd_ ## fn
40#define MYLCD_UPDATE() rb->lcd_update();
41#define MYXLCD(fn) xlcd_ ## fn
42#endif
43
44#ifdef USEGSLIB
45GREY_INFO_STRUCT
46static unsigned char *gbuf;
47static size_t gbuf_size = 0;
48unsigned char imgbuffer[LCD_HEIGHT];
49#else
50fb_data imgbuffer[LCD_HEIGHT];
51#endif
52
53#define REDRAW_NONE 0
54#define REDRAW_PARTIAL 1
55#define REDRAW_FULL 2
56
57PLUGIN_HEADER
58
59/* returns 1 if a button has been pressed, 0 otherwise */
60static int button_yield(void *ctx)
61{
62 long *button = (long *)ctx;
63
64 *button = rb->button_get(false);
65 switch (*button)
66 {
67 case FRACTAL_QUIT:
68 case FRACTAL_UP:
69 case FRACTAL_DOWN:
70 case FRACTAL_LEFT:
71 case FRACTAL_RIGHT:
72 case FRACTAL_ZOOM_IN:
73 case FRACTAL_ZOOM_OUT:
74 case FRACTAL_PRECISION_INC:
75 case FRACTAL_PRECISION_DEC:
76 case FRACTAL_RESET:
77#ifdef FRACTAL_ZOOM_IN2
78 case FRACTAL_ZOOM_IN2:
79#endif
80#ifdef FRACTAL_ZOOM_IN_PRE
81 case FRACTAL_ZOOM_IN_PRE:
82#endif
83 return 1;
84 default:
85 *button = BUTTON_NONE;
86 return 0;
87 }
88}
89
90static void cleanup(void *parameter)
91{
92 (void)parameter;
93#ifdef USEGSLIB
94 grey_release();
95#endif
96}
97
98enum plugin_status plugin_start(const void* parameter)
99{
100 long lastbutton = BUTTON_NONE;
101 int redraw = REDRAW_FULL;
102 struct fractal_ops *ops = &mandelbrot_ops;
103
104 (void)parameter;
105
106#ifdef USEGSLIB
107 /* get the remainder of the plugin buffer */
108 gbuf = (unsigned char *)rb->plugin_get_buffer(&gbuf_size);
109
110 /* initialize the greyscale buffer.*/
111 if (!grey_init(gbuf, gbuf_size, GREY_ON_COP, LCD_WIDTH, LCD_HEIGHT, NULL))
112 {
113 rb->splash(HZ, "Couldn't init greyscale display");
114 return 0;
115 }
116 grey_show(true); /* switch on greyscale overlay */
117#endif
118
119#if LCD_DEPTH > 1
120 rb->lcd_set_backdrop(NULL);
121#endif
122
123 ops->init();
124
125 /* main loop */
126 while (true)
127 {
128 long button = BUTTON_NONE;
129
130 if (redraw != REDRAW_NONE)
131 {
132#ifdef HAVE_ADJUSTABLE_CPU_FREQ
133 rb->cpu_boost(true);
134#endif
135 if (redraw == REDRAW_FULL)
136 {
137 MYLCD(clear_display)();
138 MYLCD_UPDATE();
139 rects_queue_init();
140 }
141
142 /* paint all rects */
143 rects_calc_all(ops->calc, button_yield, (void *)&button);
144#ifdef HAVE_ADJUSTABLE_CPU_FREQ
145 rb->cpu_boost(false);
146#endif
147 /* not interrupted by button press - screen is fully drawn */
148 redraw = (button == BUTTON_NONE) ? REDRAW_NONE : REDRAW_PARTIAL;
149 }
150
151 if (button == BUTTON_NONE)
152 button = rb->button_get(true);
153
154 switch (button)
155 {
156#ifdef FRACTAL_RC_QUIT
157 case FRACTAL_RC_QUIT:
158#endif
159 case FRACTAL_QUIT:
160#ifdef USEGSLIB
161 grey_release();
162#endif
163 return PLUGIN_OK;
164
165 case FRACTAL_ZOOM_OUT:
166#ifdef FRACTAL_ZOOM_OUT_PRE
167 if (lastbutton != FRACTAL_ZOOM_OUT_PRE)
168 break;
169#endif
170 ops->zoom(-1);
171 redraw = REDRAW_FULL;
172 break;
173
174
175 case FRACTAL_ZOOM_IN:
176#ifdef FRACTAL_ZOOM_IN_PRE
177 if (lastbutton != FRACTAL_ZOOM_IN_PRE)
178 break;
179#endif
180#ifdef FRACTAL_ZOOM_IN2
181 case FRACTAL_ZOOM_IN2:
182#endif
183 ops->zoom(1);
184 redraw = REDRAW_FULL;
185 break;
186
187 case FRACTAL_UP:
188 ops->move(0, +1);
189 MYXLCD(scroll_down)(LCD_SHIFT_Y);
190 MYLCD_UPDATE();
191 if (redraw != REDRAW_FULL)
192 redraw = rects_move_down() ? REDRAW_FULL : REDRAW_PARTIAL;
193 break;
194
195 case FRACTAL_DOWN:
196 ops->move(0, -1);
197 MYXLCD(scroll_up)(LCD_SHIFT_Y);
198 MYLCD_UPDATE();
199 if (redraw != REDRAW_FULL)
200 redraw = rects_move_up() ? REDRAW_FULL : REDRAW_PARTIAL;
201 break;
202
203 case FRACTAL_LEFT:
204 ops->move(-1, 0);
205 MYXLCD(scroll_right)(LCD_SHIFT_X);
206 MYLCD_UPDATE();
207 if (redraw != REDRAW_FULL)
208 redraw = rects_move_right() ? REDRAW_FULL : REDRAW_PARTIAL;
209 break;
210
211 case FRACTAL_RIGHT:
212 ops->move(+1, 0);
213 MYXLCD(scroll_left)(LCD_SHIFT_X);
214 MYLCD_UPDATE();
215 if (redraw != REDRAW_FULL)
216 redraw = rects_move_left() ? REDRAW_FULL : REDRAW_PARTIAL;
217 break;
218
219 case FRACTAL_PRECISION_DEC:
220#ifdef FRACTAL_PRECISION_DEC_PRE
221 if (lastbutton != FRACTAL_PRECISION_DEC_PRE)
222 break;
223#endif
224 if (ops->precision(-1))
225 redraw = REDRAW_FULL;
226
227 break;
228
229 case FRACTAL_PRECISION_INC:
230#ifdef FRACTAL_PRECISION_INC_PRE
231 if (lastbutton != FRACTAL_PRECISION_INC_PRE)
232 break;
233#endif
234 if (ops->precision(+1))
235 redraw = REDRAW_FULL;
236
237 break;
238
239 case FRACTAL_RESET:
240 ops->init();
241 redraw = REDRAW_FULL;
242 break;
243
244 default:
245 if (rb->default_event_handler_ex(button, cleanup, NULL)
246 == SYS_USB_CONNECTED)
247 return PLUGIN_USB_CONNECTED;
248 break;
249 }
250
251 if (button != BUTTON_NONE)
252 lastbutton = button;
253 }
254#ifdef USEGSLIB
255 grey_release();
256#endif
257 return PLUGIN_OK;
258}
259
260#endif
diff --git a/apps/plugins/fractals/fractal.h b/apps/plugins/fractals/fractal.h
new file mode 100644
index 0000000000..e1dfd5b6c9
--- /dev/null
+++ b/apps/plugins/fractals/fractal.h
@@ -0,0 +1,352 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _FRACTAL_H
22#define _FRACTAL_H
23
24/* variable button definitions */
25#if CONFIG_KEYPAD == RECORDER_PAD
26#define FRACTAL_QUIT BUTTON_OFF
27#define FRACTAL_UP BUTTON_UP
28#define FRACTAL_DOWN BUTTON_DOWN
29#define FRACTAL_LEFT BUTTON_LEFT
30#define FRACTAL_RIGHT BUTTON_RIGHT
31#define FRACTAL_ZOOM_IN BUTTON_PLAY
32#define FRACTAL_ZOOM_OUT BUTTON_ON
33#define FRACTAL_PRECISION_INC BUTTON_F2
34#define FRACTAL_PRECISION_DEC BUTTON_F1
35#define FRACTAL_RESET BUTTON_F3
36
37#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
38#define FRACTAL_QUIT BUTTON_OFF
39#define FRACTAL_UP BUTTON_UP
40#define FRACTAL_DOWN BUTTON_DOWN
41#define FRACTAL_LEFT BUTTON_LEFT
42#define FRACTAL_RIGHT BUTTON_RIGHT
43#define FRACTAL_ZOOM_IN BUTTON_SELECT
44#define FRACTAL_ZOOM_OUT BUTTON_ON
45#define FRACTAL_PRECISION_INC BUTTON_F2
46#define FRACTAL_PRECISION_DEC BUTTON_F1
47#define FRACTAL_RESET BUTTON_F3
48
49#elif CONFIG_KEYPAD == ONDIO_PAD
50#define FRACTAL_QUIT BUTTON_OFF
51#define FRACTAL_UP BUTTON_UP
52#define FRACTAL_DOWN BUTTON_DOWN
53#define FRACTAL_LEFT BUTTON_LEFT
54#define FRACTAL_RIGHT BUTTON_RIGHT
55#define FRACTAL_ZOOM_IN_PRE BUTTON_MENU
56#define FRACTAL_ZOOM_IN (BUTTON_MENU | BUTTON_REL)
57#define FRACTAL_ZOOM_IN2 (BUTTON_MENU | BUTTON_UP)
58#define FRACTAL_ZOOM_OUT (BUTTON_MENU | BUTTON_DOWN)
59#define FRACTAL_PRECISION_INC (BUTTON_MENU | BUTTON_RIGHT)
60#define FRACTAL_PRECISION_DEC (BUTTON_MENU | BUTTON_LEFT)
61#define FRACTAL_RESET (BUTTON_MENU | BUTTON_OFF)
62
63#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
64 (CONFIG_KEYPAD == IRIVER_H300_PAD)
65#define FRACTAL_QUIT BUTTON_OFF
66#define FRACTAL_UP BUTTON_UP
67#define FRACTAL_DOWN BUTTON_DOWN
68#define FRACTAL_LEFT BUTTON_LEFT
69#define FRACTAL_RIGHT BUTTON_RIGHT
70#define FRACTAL_ZOOM_IN BUTTON_SELECT
71#define FRACTAL_ZOOM_OUT BUTTON_MODE
72#define FRACTAL_PRECISION_INC (BUTTON_ON | BUTTON_RIGHT)
73#define FRACTAL_PRECISION_DEC (BUTTON_ON | BUTTON_LEFT)
74#define FRACTAL_RESET BUTTON_REC
75
76#define FRACTAL_RC_QUIT BUTTON_RC_STOP
77
78#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
79 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
80 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
81#define FRACTAL_QUIT (BUTTON_SELECT | BUTTON_MENU)
82#define FRACTAL_UP BUTTON_MENU
83#define FRACTAL_DOWN BUTTON_PLAY
84#define FRACTAL_LEFT BUTTON_LEFT
85#define FRACTAL_RIGHT BUTTON_RIGHT
86#define FRACTAL_ZOOM_IN BUTTON_SCROLL_FWD
87#define FRACTAL_ZOOM_OUT BUTTON_SCROLL_BACK
88#define FRACTAL_PRECISION_INC (BUTTON_SELECT | BUTTON_RIGHT)
89#define FRACTAL_PRECISION_DEC (BUTTON_SELECT | BUTTON_LEFT)
90#define FRACTAL_RESET (BUTTON_SELECT | BUTTON_PLAY)
91
92#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
93#define FRACTAL_QUIT BUTTON_POWER
94#define FRACTAL_UP BUTTON_UP
95#define FRACTAL_DOWN BUTTON_DOWN
96#define FRACTAL_LEFT BUTTON_LEFT
97#define FRACTAL_RIGHT BUTTON_RIGHT
98#define FRACTAL_ZOOM_IN_PRE BUTTON_SELECT
99#define FRACTAL_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
100#define FRACTAL_ZOOM_OUT_PRE BUTTON_SELECT
101#define FRACTAL_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
102#define FRACTAL_PRECISION_INC_PRE BUTTON_PLAY
103#define FRACTAL_PRECISION_INC (BUTTON_PLAY | BUTTON_REL)
104#define FRACTAL_PRECISION_DEC_PRE BUTTON_PLAY
105#define FRACTAL_PRECISION_DEC (BUTTON_PLAY | BUTTON_REPEAT)
106#define FRACTAL_RESET BUTTON_REC
107
108#elif CONFIG_KEYPAD == GIGABEAT_PAD
109#define FRACTAL_QUIT BUTTON_POWER
110#define FRACTAL_UP BUTTON_UP
111#define FRACTAL_DOWN BUTTON_DOWN
112#define FRACTAL_LEFT BUTTON_LEFT
113#define FRACTAL_RIGHT BUTTON_RIGHT
114#define FRACTAL_ZOOM_IN_PRE BUTTON_SELECT
115#define FRACTAL_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
116#define FRACTAL_ZOOM_OUT_PRE BUTTON_SELECT
117#define FRACTAL_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
118#define FRACTAL_PRECISION_INC BUTTON_VOL_UP
119#define FRACTAL_PRECISION_DEC BUTTON_VOL_DOWN
120#define FRACTAL_RESET BUTTON_A
121
122#elif CONFIG_KEYPAD == SANSA_E200_PAD
123#define FRACTAL_QUIT BUTTON_POWER
124#define FRACTAL_UP BUTTON_UP
125#define FRACTAL_DOWN BUTTON_DOWN
126#define FRACTAL_LEFT BUTTON_LEFT
127#define FRACTAL_RIGHT BUTTON_RIGHT
128#define FRACTAL_ZOOM_IN BUTTON_SCROLL_FWD
129#define FRACTAL_ZOOM_OUT BUTTON_SCROLL_BACK
130#define FRACTAL_PRECISION_INC (BUTTON_SELECT | BUTTON_RIGHT)
131#define FRACTAL_PRECISION_DEC (BUTTON_SELECT | BUTTON_LEFT)
132#define FRACTAL_RESET BUTTON_REC
133
134#elif CONFIG_KEYPAD == SANSA_FUZE_PAD
135#define FRACTAL_QUIT (BUTTON_HOME|BUTTON_REPEAT)
136#define FRACTAL_UP BUTTON_UP
137#define FRACTAL_DOWN BUTTON_DOWN
138#define FRACTAL_LEFT BUTTON_LEFT
139#define FRACTAL_RIGHT BUTTON_RIGHT
140#define FRACTAL_ZOOM_IN BUTTON_SCROLL_FWD
141#define FRACTAL_ZOOM_OUT BUTTON_SCROLL_BACK
142#define FRACTAL_PRECISION_INC (BUTTON_SELECT | BUTTON_RIGHT)
143#define FRACTAL_PRECISION_DEC (BUTTON_SELECT | BUTTON_LEFT)
144#define FRACTAL_RESET (BUTTON_SELECT | BUTTON_REPEAT)
145
146#elif CONFIG_KEYPAD == SANSA_C200_PAD
147#define FRACTAL_QUIT BUTTON_POWER
148#define FRACTAL_UP BUTTON_UP
149#define FRACTAL_DOWN BUTTON_DOWN
150#define FRACTAL_LEFT BUTTON_LEFT
151#define FRACTAL_RIGHT BUTTON_RIGHT
152#define FRACTAL_ZOOM_IN BUTTON_VOL_UP
153#define FRACTAL_ZOOM_OUT BUTTON_VOL_DOWN
154#define FRACTAL_PRECISION_INC (BUTTON_SELECT | BUTTON_RIGHT)
155#define FRACTAL_PRECISION_DEC (BUTTON_SELECT | BUTTON_LEFT)
156#define FRACTAL_RESET BUTTON_REC
157
158#elif CONFIG_KEYPAD == SANSA_CLIP_PAD
159#define FRACTAL_QUIT BUTTON_POWER
160#define FRACTAL_UP BUTTON_UP
161#define FRACTAL_DOWN BUTTON_DOWN
162#define FRACTAL_LEFT BUTTON_LEFT
163#define FRACTAL_RIGHT BUTTON_RIGHT
164#define FRACTAL_ZOOM_IN BUTTON_VOL_UP
165#define FRACTAL_ZOOM_OUT BUTTON_VOL_DOWN
166#define FRACTAL_PRECISION_INC (BUTTON_SELECT | BUTTON_RIGHT)
167#define FRACTAL_PRECISION_DEC (BUTTON_SELECT | BUTTON_LEFT)
168#define FRACTAL_RESET BUTTON_HOME
169
170#elif CONFIG_KEYPAD == SANSA_M200_PAD
171#define FRACTAL_QUIT BUTTON_POWER
172#define FRACTAL_UP BUTTON_UP
173#define FRACTAL_DOWN BUTTON_DOWN
174#define FRACTAL_LEFT BUTTON_LEFT
175#define FRACTAL_RIGHT BUTTON_RIGHT
176#define FRACTAL_ZOOM_IN BUTTON_VOL_UP
177#define FRACTAL_ZOOM_OUT BUTTON_VOL_DOWN
178#define FRACTAL_PRECISION_INC (BUTTON_SELECT | BUTTON_RIGHT)
179#define FRACTAL_PRECISION_DEC (BUTTON_SELECT | BUTTON_LEFT)
180#define FRACTAL_RESET (BUTTON_SELECT | BUTTON_UP)
181
182#elif CONFIG_KEYPAD == IRIVER_H10_PAD
183#define FRACTAL_QUIT BUTTON_POWER
184#define FRACTAL_UP BUTTON_SCROLL_UP
185#define FRACTAL_DOWN BUTTON_SCROLL_DOWN
186#define FRACTAL_LEFT BUTTON_LEFT
187#define FRACTAL_RIGHT BUTTON_RIGHT
188#define FRACTAL_ZOOM_IN_PRE BUTTON_PLAY
189#define FRACTAL_ZOOM_IN (BUTTON_PLAY | BUTTON_REL)
190#define FRACTAL_ZOOM_OUT_PRE BUTTON_PLAY
191#define FRACTAL_ZOOM_OUT (BUTTON_PLAY | BUTTON_REPEAT)
192#define FRACTAL_PRECISION_INC BUTTON_FF
193#define FRACTAL_PRECISION_DEC BUTTON_REW
194#define FRACTAL_RESET (BUTTON_PLAY | BUTTON_REW)
195
196#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
197#define FRACTAL_QUIT BUTTON_EQ
198#define FRACTAL_UP BUTTON_UP
199#define FRACTAL_DOWN BUTTON_DOWN
200#define FRACTAL_LEFT BUTTON_LEFT
201#define FRACTAL_RIGHT BUTTON_RIGHT
202#define FRACTAL_ZOOM_IN_PRE BUTTON_SELECT
203#define FRACTAL_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
204#define FRACTAL_ZOOM_OUT_PRE BUTTON_SELECT
205#define FRACTAL_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
206#define FRACTAL_PRECISION_INC (BUTTON_PLAY | BUTTON_RIGHT)
207#define FRACTAL_PRECISION_DEC (BUTTON_PLAY | BUTTON_LEFT)
208#define FRACTAL_RESET BUTTON_MODE
209
210#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
211#define FRACTAL_QUIT BUTTON_BACK
212#define FRACTAL_UP BUTTON_UP
213#define FRACTAL_DOWN BUTTON_DOWN
214#define FRACTAL_LEFT BUTTON_LEFT
215#define FRACTAL_RIGHT BUTTON_RIGHT
216#define FRACTAL_ZOOM_IN BUTTON_VOL_UP
217#define FRACTAL_ZOOM_OUT BUTTON_VOL_DOWN
218#define FRACTAL_PRECISION_INC BUTTON_PREV
219#define FRACTAL_PRECISION_DEC BUTTON_NEXT
220#define FRACTAL_RESET BUTTON_MENU
221
222#elif CONFIG_KEYPAD == MROBE100_PAD
223#define FRACTAL_QUIT BUTTON_POWER
224#define FRACTAL_UP BUTTON_UP
225#define FRACTAL_DOWN BUTTON_DOWN
226#define FRACTAL_LEFT BUTTON_LEFT
227#define FRACTAL_RIGHT BUTTON_RIGHT
228#define FRACTAL_ZOOM_IN_PRE BUTTON_SELECT
229#define FRACTAL_ZOOM_IN (BUTTON_SELECT | BUTTON_REL)
230#define FRACTAL_ZOOM_OUT_PRE BUTTON_SELECT
231#define FRACTAL_ZOOM_OUT (BUTTON_SELECT | BUTTON_REPEAT)
232#define FRACTAL_PRECISION_INC BUTTON_MENU
233#define FRACTAL_PRECISION_DEC BUTTON_PLAY
234#define FRACTAL_RESET BUTTON_DISPLAY
235
236#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
237#define FRACTAL_QUIT BUTTON_RC_REC
238#define FRACTAL_UP BUTTON_RC_VOL_UP
239#define FRACTAL_DOWN BUTTON_RC_VOL_DOWN
240#define FRACTAL_LEFT BUTTON_RC_REW
241#define FRACTAL_RIGHT BUTTON_RC_FF
242#define FRACTAL_ZOOM_IN_PRE BUTTON_RC_PLAY
243#define FRACTAL_ZOOM_IN (BUTTON_RC_PLAY | BUTTON_REL)
244#define FRACTAL_ZOOM_OUT_PRE BUTTON_RC_PLAY
245#define FRACTAL_ZOOM_OUT (BUTTON_RC_PLAY | BUTTON_REPEAT)
246#define FRACTAL_PRECISION_INC_PRE BUTTON_RC_MODE
247#define FRACTAL_PRECISION_INC (BUTTON_RC_MODE|BUTTON_REL)
248#define FRACTAL_PRECISION_DEC_PRE BUTTON_RC_MODE
249#define FRACTAL_PRECISION_DEC (BUTTON_RC_MODE|BUTTON_REPEAT)
250#define FRACTAL_RESET BUTTON_RC_MENU
251
252#elif CONFIG_KEYPAD == COWON_D2_PAD
253#define FRACTAL_QUIT BUTTON_POWER
254
255#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
256#define FRACTAL_QUIT BUTTON_BACK
257#define FRACTAL_UP BUTTON_UP
258#define FRACTAL_DOWN BUTTON_DOWN
259#define FRACTAL_LEFT BUTTON_LEFT
260#define FRACTAL_RIGHT BUTTON_RIGHT
261#define FRACTAL_ZOOM_IN BUTTON_PLAY
262#define FRACTAL_ZOOM_OUT BUTTON_MENU
263#define FRACTAL_PRECISION_INC (BUTTON_UP | BUTTON_CUSTOM)
264#define FRACTAL_PRECISION_DEC (BUTTON_DOWN | BUTTON_CUSTOM)
265#define FRACTAL_RESET BUTTON_SELECT
266
267#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
268#define FRACTAL_QUIT BUTTON_POWER
269#define FRACTAL_UP BUTTON_UP
270#define FRACTAL_DOWN BUTTON_DOWN
271#define FRACTAL_LEFT BUTTON_LEFT
272#define FRACTAL_RIGHT BUTTON_RIGHT
273#define FRACTAL_ZOOM_IN BUTTON_VIEW
274#define FRACTAL_ZOOM_OUT BUTTON_PLAYLIST
275#define FRACTAL_PRECISION_INC BUTTON_VOL_UP
276#define FRACTAL_PRECISION_DEC BUTTON_VOL_DOWN
277#define FRACTAL_RESET BUTTON_MENU
278
279#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
280#define FRACTAL_QUIT BUTTON_POWER
281#define FRACTAL_UP BUTTON_UP
282#define FRACTAL_DOWN BUTTON_DOWN
283#define FRACTAL_LEFT BUTTON_PREV
284#define FRACTAL_RIGHT BUTTON_NEXT
285#define FRACTAL_ZOOM_IN BUTTON_RIGHT
286#define FRACTAL_ZOOM_OUT BUTTON_LEFT
287#define FRACTAL_PRECISION_INC BUTTON_VOL_UP
288#define FRACTAL_PRECISION_DEC BUTTON_VOL_DOWN
289#define FRACTAL_RESET BUTTON_MENU
290
291#elif CONFIG_KEYPAD == ONDAVX747_PAD || CONFIG_KEYPAD == MROBE500_PAD
292#define FRACTAL_QUIT BUTTON_POWER
293
294#elif CONFIG_KEYPAD == ONDAVX777_PAD
295#define FRACTAL_QUIT BUTTON_POWER
296
297#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
298#define FRACTAL_QUIT BUTTON_REC
299#define FRACTAL_UP BUTTON_UP
300#define FRACTAL_DOWN BUTTON_DOWN
301#define FRACTAL_LEFT BUTTON_LEFT
302#define FRACTAL_RIGHT BUTTON_RIGHT
303#define FRACTAL_ZOOM_IN_PRE (BUTTON_FFWD | BUTTON_UP)
304#define FRACTAL_ZOOM_IN (BUTTON_REW | BUTTON_UP)
305#define FRACTAL_ZOOM_OUT_PRE (BUTTON_FFWD | BUTTON_DOWN)
306#define FRACTAL_ZOOM_OUT (BUTTON_REW | BUTTON_DOWN)
307#define FRACTAL_PRECISION_INC (BUTTON_PLAY | BUTTON_UP)
308#define FRACTAL_PRECISION_DEC (BUTTON_FFWD | BUTTON_DOWN)
309#define FRACTAL_RESET (BUTTON_PLAY | BUTTON_RIGHT)
310
311#else
312#error No keymap defined!
313#endif
314
315#ifdef HAVE_TOUCHSCREEN
316#ifndef FRACTAL_UP
317#define FRACTAL_UP BUTTON_TOPMIDDLE
318#endif
319#ifndef FRACTAL_DOWN
320#define FRACTAL_DOWN BUTTON_BOTTOMMIDDLE
321#endif
322#ifndef FRACTAL_LEFT
323#define FRACTAL_LEFT BUTTON_MIDLEFT
324#endif
325#ifndef FRACTAL_RIGHT
326#define FRACTAL_RIGHT BUTTON_MIDRIGHT
327#endif
328#ifndef FRACTAL_ZOOM_IN_PRE
329#define FRACTAL_ZOOM_IN_PRE BUTTON_TOPRIGHT
330#endif
331#ifndef FRACTAL_ZOOM_IN
332#define FRACTAL_ZOOM_IN (BUTTON_TOPRIGHT | BUTTON_REL)
333#endif
334#ifndef FRACTAL_ZOOM_OUT_PRE
335#define FRACTAL_ZOOM_OUT_PRE BUTTON_TOPLEFT
336#endif
337#ifndef FRACTAL_ZOOM_OUT
338#define FRACTAL_ZOOM_OUT (BUTTON_TOPLEFT | BUTTON_REL)
339#endif
340#ifndef FRACTAL_PRECISION_INC
341#define FRACTAL_PRECISION_INC BUTTON_BOTTOMRIGHT
342#endif
343#ifndef FRACTAL_PRECISION_DEC
344#define FRACTAL_PRECISION_DEC BUTTON_BOTTOMLEFT
345#endif
346#ifndef FRACTAL_RESET
347#define FRACTAL_RESET BUTTON_CENTER
348#endif
349#endif
350
351#endif
352
diff --git a/apps/plugins/fractals/fractal_rect.c b/apps/plugins/fractals/fractal_rect.c
new file mode 100644
index 0000000000..af846d3f7a
--- /dev/null
+++ b/apps/plugins/fractals/fractal_rect.c
@@ -0,0 +1,209 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "fractal_rect.h"
23
24#define RECT_QUEUE_LEN 32
25
26#define QUEUE_NEXT(i) (((i) + 1) % RECT_QUEUE_LEN)
27#define QUEUE_PREV(i) (((i) - 1) % RECT_QUEUE_LEN)
28#define QUEUE_IS_EMPTY (QUEUE_NEXT(rectq.head) == rectq.tail)
29#define QUEUE_TAIL \
30 (&rectq.rects[rectq.tail]);
31#define QUEUE_ITEM(i) &rectq.rects[(i)]
32
33struct rect_queue
34{
35 struct fractal_rect rects[RECT_QUEUE_LEN];
36 unsigned head;
37 unsigned tail;
38};
39
40static struct rect_queue rectq;
41
42/*#define FRACTAL_RECT_DEBUG*/
43#if defined(FRACTAL_RECT_DEBUG) && defined(SIMULATOR)
44#include <stdio.h>
45
46static void rectq_print(void)
47{
48 unsigned i = rectq.head;
49
50 printf("Rects queue:\n");
51 for (i = rectq.head; i != rectq.tail; i = QUEUE_PREV(i))
52 {
53 printf("\tItem %d/%d; idx %d; (%d,%d),(%d,%d),%svalid%s%s\n",
54 (i - rectq.head + 1) % RECT_QUEUE_LEN,
55 (rectq.head - rectq.tail) % RECT_QUEUE_LEN,
56 i,
57 rectq.rects[(i)].px_min,
58 rectq.rects[(i)].py_min,
59 rectq.rects[(i)].px_max,
60 rectq.rects[(i)].py_max,
61 (rectq.rects[(i)].valid ? "" : "in"),
62 ((i == rectq.head) ? ",head" : ""),
63 ((i == rectq.tail) ? ",tail" : ""));
64 }
65}
66#else
67#define rectq_print(...)
68#endif
69
70static int rects_add(int px_min, int py_min, int px_max, int py_max)
71{
72 struct fractal_rect *rect = &rectq.rects[rectq.tail];
73
74 if (rectq.head == QUEUE_PREV(rectq.tail)) /* queue is full */
75 return 1;
76
77 rect->px_min = px_min;
78 rect->py_min = py_min;
79 rect->px_max = px_max;
80 rect->py_max = py_max;
81 rect->valid = 1;
82 rectq.tail = QUEUE_PREV(rectq.tail);
83
84 return 0;
85}
86
87static void rects_queue_reset(void)
88{
89 rectq.tail = 0;
90 rectq.head = 0;
91}
92
93void rects_queue_init(void)
94{
95 rects_queue_reset();
96 rects_add(0, 0, LCD_WIDTH, LCD_HEIGHT);
97}
98
99void rects_calc_all(int (*calc)(struct fractal_rect *, int (*)(void *), void *),
100 int (*button_yield_cb)(void *), void *ctx)
101{
102 while (rectq.head != rectq.tail) /* queue is not empty */
103 {
104 struct fractal_rect *rect = &rectq.rects[rectq.head];
105
106 rectq_print();
107 if (rect->valid)
108 {
109 if (calc(rect, button_yield_cb, ctx))
110 return; /* interrupted by key-press */
111 }
112
113 rectq.head = QUEUE_PREV(rectq.head); /* dequeue */
114 }
115 rects_queue_reset();
116}
117
118int rects_move_up(void)
119{
120 unsigned i;
121
122 /* move current regions up */
123 for (i = rectq.head; i != rectq.tail; i = QUEUE_PREV((i)))
124 {
125 struct fractal_rect *rect = QUEUE_ITEM(i);
126
127 rect->py_min -= LCD_SHIFT_Y;
128 rect->py_max -= LCD_SHIFT_Y;
129
130 if (rect->py_min < 0)
131 rect->py_min = 0;
132
133 if (rect->py_max < 0)
134 rect->valid = 0;
135 }
136
137 /* add bottom region */
138 return rects_add(0, LCD_HEIGHT - LCD_SHIFT_Y, LCD_WIDTH, LCD_HEIGHT);
139}
140
141int rects_move_down(void)
142{
143 unsigned i;
144
145 /* move current regions down */
146 for (i = rectq.head; i != rectq.tail; i = QUEUE_PREV((i)))
147 {
148 struct fractal_rect *rect = QUEUE_ITEM(i);
149
150 rect->py_min += LCD_SHIFT_Y;
151 rect->py_max += LCD_SHIFT_Y;
152
153 if (rect->py_max > LCD_HEIGHT)
154 rect->py_max = LCD_HEIGHT;
155
156 if (LCD_HEIGHT <= rect->py_min)
157 rect->valid = 0;
158 }
159
160 /* add top region */
161 return rects_add(0, 0, LCD_WIDTH, LCD_SHIFT_Y);
162}
163
164int rects_move_left(void)
165{
166 unsigned i;
167
168 /* move current regions left */
169 for (i = rectq.head; i != rectq.tail; i = QUEUE_PREV((i)))
170 {
171 struct fractal_rect *rect = QUEUE_ITEM(i);
172
173 rect->px_min -= LCD_SHIFT_X;
174 rect->px_max -= LCD_SHIFT_X;
175
176 if (rect->px_min < 0)
177 rect->px_min = 0;
178
179 if (rect->px_max < 0)
180 rect->valid = 0;
181 }
182
183 /* add right region */
184 return rects_add(LCD_WIDTH - LCD_SHIFT_X, 0, LCD_WIDTH, LCD_HEIGHT);
185}
186
187int rects_move_right(void)
188{
189 unsigned i;
190
191 /* move current regions right */
192 for (i = rectq.head; i != rectq.tail; i = QUEUE_PREV((i)))
193 {
194 struct fractal_rect *rect = QUEUE_ITEM(i);
195
196 rect->px_min += LCD_SHIFT_X;
197 rect->px_max += LCD_SHIFT_X;
198
199 if (rect->px_max > LCD_WIDTH)
200 rect->px_max = LCD_WIDTH;
201
202 if (LCD_WIDTH <= rect->px_min)
203 rect->valid = 0;
204 }
205
206 /* add left region */
207 return rects_add(0, 0, LCD_SHIFT_X, LCD_HEIGHT);
208}
209
diff --git a/apps/plugins/fractals/fractal_rect.h b/apps/plugins/fractals/fractal_rect.h
new file mode 100644
index 0000000000..eca66556d3
--- /dev/null
+++ b/apps/plugins/fractals/fractal_rect.h
@@ -0,0 +1,38 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _FRACTAL_RECT_H
22#define _FRACTAL_RECT_H
23
24#include "fractal_sets.h"
25
26#define LCD_SHIFT_X (LCD_WIDTH / 8)
27#define LCD_SHIFT_Y (LCD_HEIGHT / 8)
28
29void rects_queue_init(void);
30void rects_calc_all(int (*calc)(struct fractal_rect *, int (*)(void *), void *),
31 int (*button_yield_cb)(void *), void *ctx);
32int rects_move_up(void);
33int rects_move_down(void);
34int rects_move_left(void);
35int rects_move_right(void);
36
37#endif
38
diff --git a/apps/plugins/fractals/fractal_sets.h b/apps/plugins/fractals/fractal_sets.h
new file mode 100644
index 0000000000..c5339d63d7
--- /dev/null
+++ b/apps/plugins/fractals/fractal_sets.h
@@ -0,0 +1,52 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _FRACTAL_SETS_H
22#define _FRACTAL_SETS_H
23
24#include "lib/grey.h"
25#include "lib/xlcd.h"
26
27#ifdef USEGSLIB
28extern unsigned char imgbuffer[LCD_HEIGHT];
29#else
30extern fb_data imgbuffer[LCD_HEIGHT];
31#endif
32
33struct fractal_rect
34{
35 int px_min;
36 int py_min;
37 int px_max;
38 int py_max;
39 int valid;
40};
41
42struct fractal_ops
43{
44 void (*init)(void);
45 int (*calc)(struct fractal_rect *rect, int (*button_yield_cb)(void *ctx),
46 void *button_yield_ctx);
47 void (*move)(int dx, int dy);
48 void (*zoom)(int factor);
49 int (*precision)(int d);
50};
51
52#endif
diff --git a/apps/plugins/fractals/fractals.make b/apps/plugins/fractals/fractals.make
new file mode 100644
index 0000000000..48bff5c611
--- /dev/null
+++ b/apps/plugins/fractals/fractals.make
@@ -0,0 +1,21 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10FRACTALSSRCDIR := $(APPSDIR)/plugins/fractals
11FRACTALSBUILDDIR := $(BUILDDIR)/apps/plugins/fractals
12
13ROCKS += $(FRACTALSBUILDDIR)/fractals.rock
14
15FRACTALS_SRC := $(call preprocess, $(FRACTALSSRCDIR)/SOURCES)
16FRACTALS_OBJ := $(call c2obj, $(FRACTALS_SRC))
17
18# add source files to OTHER_SRC to get automatic dependencies
19OTHER_SRC += $(FRACTALS_SRC)
20
21$(FRACTALSBUILDDIR)/fractals.rock: $(FRACTALS_OBJ)
diff --git a/apps/plugins/fractals/mandelbrot_set.c b/apps/plugins/fractals/mandelbrot_set.c
new file mode 100644
index 0000000000..ccc65b8e91
--- /dev/null
+++ b/apps/plugins/fractals/mandelbrot_set.c
@@ -0,0 +1,392 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: mandelbrot.c 24010 2009-12-15 20:51:41Z tomers $
9 *
10 * Copyright (C) 2004 Matthias Wientapper
11 * Heavily extended 2005 Jens Arnold
12 *
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23#include "mandelbrot_set.h"
24
25#define BUTTON_YIELD_TIMEOUT (HZ / 4)
26
27/* 8 entries cyclical, last entry is black (convergence) */
28#ifdef HAVE_LCD_COLOR
29static const fb_data color[9] = {
30 LCD_RGBPACK(255, 0, 159), LCD_RGBPACK(159, 0, 255), LCD_RGBPACK(0, 0, 255),
31 LCD_RGBPACK(0, 159, 255), LCD_RGBPACK(0, 255, 128), LCD_RGBPACK(128, 255, 0),
32 LCD_RGBPACK(255, 191, 0), LCD_RGBPACK(255, 0, 0), LCD_RGBPACK(0, 0, 0)
33};
34#else /* greyscale */
35static const unsigned char color[9] = {
36 255, 223, 191, 159, 128, 96, 64, 32, 0
37};
38#endif
39
40#if CONFIG_LCD == LCD_SSD1815
41/* Recorder, Ondio: pixel_height == 1.25 * pixel_width */
42#define MB_HEIGHT (LCD_HEIGHT*5/4)
43#else
44/* square pixels */
45#define MB_HEIGHT LCD_HEIGHT
46#endif
47
48#define MB_XOFS (-0x03000000L) /* -0.75 (s5.26) */
49#if 3000*MB_HEIGHT/LCD_WIDTH >= 2400 /* width is limiting factor */
50#define MB_XFAC (0x06000000LL) /* 1.5 (s5.26) */
51#define MB_YFAC (MB_XFAC*MB_HEIGHT/LCD_WIDTH)
52#else /* height is limiting factor */
53#define MB_YFAC (0x04cccccdLL) /* 1.2 (s5.26) */
54#define MB_XFAC (MB_YFAC*LCD_WIDTH/MB_HEIGHT)
55#endif
56
57#if (LCD_DEPTH < 8)
58#else
59#define UPDATE_FREQ (HZ/50)
60#endif
61
62/* Fixed point format s5.26: sign, 5 bits integer part, 26 bits fractional part */
63struct mandelbrot_ctx
64{
65 struct fractal_ops *ops;
66 long x_min;
67 long x_max;
68 long x_step;
69 long x_delta;
70 long y_min;
71 long y_max;
72 long y_step;
73 long y_delta;
74 int step_log2;
75 unsigned max_iter;
76} ctx;
77
78static void mandelbrot_init(void);
79
80static int mandelbrot_calc_low_prec(struct fractal_rect *rect,
81 int (*button_yield_cb)(void *), void *button_yield_ctx);
82
83static int mandelbrot_calc_high_prec(struct fractal_rect *rect,
84 int (*button_yield_cb)(void *), void *button_yield_ctx);
85
86static void mandelbrot_move(int dx, int dy);
87
88static void mandelbrot_zoom(int factor);
89
90static int mandelbrot_precision(int d);
91
92struct fractal_ops mandelbrot_ops =
93{
94 .init = mandelbrot_init,
95 .calc = NULL,
96 .move = mandelbrot_move,
97 .zoom = mandelbrot_zoom,
98 .precision = mandelbrot_precision,
99};
100
101static int ilog2_fp(long value) /* calculate integer log2(value_fp_6.26) */
102{
103 int i = 0;
104
105 if (value <= 0)
106 {
107 return -32767;
108 }
109 else if (value > (1L << 26))
110 {
111 while (value >= (2L << 26))
112 {
113 value >>= 1;
114 i++;
115 }
116 }
117 else
118 {
119 while (value < (1L<<26))
120 {
121 value <<= 1;
122 i--;
123 }
124 }
125 return i;
126}
127
128static void recalc_parameters(void)
129{
130 ctx.x_step = (ctx.x_max - ctx.x_min) / LCD_WIDTH;
131 ctx.x_delta = (ctx.x_step * LCD_WIDTH) / 8;
132 ctx.y_step = (ctx.y_max - ctx.y_min) / LCD_HEIGHT;
133 ctx.y_delta = (ctx.y_step * LCD_HEIGHT) / 8;
134 ctx.step_log2 = ilog2_fp(MIN(ctx.x_step, ctx.y_step));
135 ctx.max_iter = MAX(15, -15 * ctx.step_log2 - 45);
136
137 ctx.ops->calc = (ctx.step_log2 <= -10) ?
138 mandelbrot_calc_high_prec : mandelbrot_calc_low_prec;
139}
140
141static void mandelbrot_init(void)
142{
143 ctx.ops = &mandelbrot_ops;
144
145 ctx.x_min = MB_XOFS - MB_XFAC;
146 ctx.x_max = MB_XOFS + MB_XFAC;
147 ctx.y_min = -MB_YFAC;
148 ctx.y_max = MB_YFAC;
149
150 recalc_parameters();
151}
152
153static int mandelbrot_calc_low_prec(struct fractal_rect *rect,
154 int (*button_yield_cb)(void *), void *button_yield_ctx)
155{
156#ifndef USEGSLIB
157 long next_update = *rb->current_tick;
158 int last_px = rect->px_min;
159#endif
160 unsigned n_iter;
161 long a32, b32;
162 short x, x2, y, y2, a, b;
163 int p_x, p_y;
164 unsigned long last_yield = *rb->current_tick;
165 unsigned long last_button_yield = *rb->current_tick;
166
167 a32 = ctx.x_min + ctx.x_step * rect->px_min;
168
169 for (p_x = rect->px_min; p_x < rect->px_max; p_x++)
170 {
171 a = a32 >> 16;
172
173 b32 = ctx.y_min + ctx.y_step * (LCD_HEIGHT - rect->py_max);
174
175 for (p_y = rect->py_max - 1; p_y >= rect->py_min; p_y--)
176 {
177 b = b32 >> 16;
178 x = a;
179 y = b;
180 n_iter = 0;
181
182 while (++n_iter <= ctx.max_iter)
183 {
184 x2 = MULS16_ASR10(x, x);
185 y2 = MULS16_ASR10(y, y);
186
187 if (x2 + y2 > (4<<10)) break;
188
189 y = 2 * MULS16_ASR10(x, y) + b;
190 x = x2 - y2 + a;
191 }
192
193 if (n_iter > ctx.max_iter)
194 imgbuffer[p_y] = color[8];
195 else
196 imgbuffer[p_y] = color[n_iter & 7];
197
198 /* be nice to other threads:
199 * if at least one tick has passed, yield */
200 if (TIME_AFTER(*rb->current_tick, last_yield))
201 {
202 rb->yield();
203 last_yield = *rb->current_tick;
204 }
205
206 if (TIME_AFTER(*rb->current_tick, last_button_yield))
207 {
208 if (button_yield_cb(button_yield_ctx))
209 {
210#ifndef USEGSLIB
211 /* update screen part that was changed since last yield */
212 rb->lcd_update_rect(last_px, rect->py_min,
213 p_x - last_px + 1, rect->py_max - rect->py_min);
214#endif
215 rect->px_min = (p_x == 0) ? 0 : p_x - 1;
216
217 return 1;
218 }
219
220 last_button_yield = *rb->current_tick + BUTTON_YIELD_TIMEOUT;
221 }
222
223 b32 += ctx.y_step;
224 }
225#ifdef USEGSLIB
226 grey_ub_gray_bitmap_part(imgbuffer, 0, rect->py_min, 1,
227 p_x, rect->py_min, 1, rect->py_max - rect->py_min);
228#else
229 rb->lcd_bitmap_part(imgbuffer, 0, rect->py_min, 1,
230 p_x, rect->py_min, 1, rect->py_max - rect->py_min);
231
232 if ((p_x == rect->px_max - 1) ||
233 TIME_AFTER(*rb->current_tick, next_update))
234 {
235 next_update = *rb->current_tick + UPDATE_FREQ;
236
237 /* update screen part that was changed since last yield */
238 rb->lcd_update_rect(last_px, rect->py_min,
239 p_x - last_px + 1, rect->py_max - rect->py_min);
240 last_px = p_x;
241 }
242#endif
243
244 a32 += ctx.x_step;
245 }
246
247 rect->valid = 0;
248
249 return 0;
250}
251
252static int mandelbrot_calc_high_prec(struct fractal_rect *rect,
253 int (*button_yield_cb)(void *), void *button_yield_ctx)
254{
255#ifndef USEGSLIB
256 long next_update = *rb->current_tick;
257 int last_px = rect->px_min;
258#endif
259 unsigned n_iter;
260 long x, x2, y, y2, a, b;
261 int p_x, p_y;
262 unsigned long last_yield = *rb->current_tick;
263 unsigned long last_button_yield = *rb->current_tick;
264
265 MULS32_INIT();
266
267 a = ctx.x_min + ctx.x_step * rect->px_min;
268
269 for (p_x = rect->px_min; p_x < rect->px_max; p_x++)
270 {
271 b = ctx.y_min + ctx.y_step * (LCD_HEIGHT - rect->py_max);
272
273 for (p_y = rect->py_max - 1; p_y >= rect->py_min; p_y--)
274 {
275 x = a;
276 y = b;
277 n_iter = 0;
278
279 while (++n_iter <= ctx.max_iter)
280 {
281 x2 = MULS32_ASR26(x, x);
282 y2 = MULS32_ASR26(y, y);
283
284 if (x2 + y2 > (4L<<26)) break;
285
286 y = 2 * MULS32_ASR26(x, y) + b;
287 x = x2 - y2 + a;
288 }
289
290 if (n_iter > ctx.max_iter)
291 imgbuffer[p_y] = color[8];
292 else
293 imgbuffer[p_y] = color[n_iter & 7];
294
295 /* be nice to other threads:
296 * if at least one tick has passed, yield */
297 if (TIME_AFTER(*rb->current_tick, last_yield))
298 {
299 rb->yield();
300 last_yield = *rb->current_tick;
301 }
302
303 if (TIME_AFTER(*rb->current_tick, last_button_yield))
304 {
305 if (button_yield_cb(button_yield_ctx))
306 {
307#ifndef USEGSLIB
308 /* update screen part that was changed since last yield */
309 rb->lcd_update_rect(last_px, rect->py_min,
310 p_x - last_px + 1, rect->py_max - rect->py_min);
311#endif
312 rect->px_min = (p_x == 0) ? 0 : p_x - 1;
313
314 return 1;
315 }
316
317 last_button_yield = *rb->current_tick + BUTTON_YIELD_TIMEOUT;
318 }
319
320 b += ctx.y_step;
321 }
322#ifdef USEGSLIB
323 grey_ub_gray_bitmap_part(imgbuffer, 0, rect->py_min, 1,
324 p_x, rect->py_min, 1, rect->py_max - rect->py_min);
325#else
326 rb->lcd_bitmap_part(imgbuffer, 0, rect->py_min, 1,
327 p_x, rect->py_min, 1, rect->py_max - rect->py_min);
328
329 if ((p_x == rect->px_max - 1) ||
330 TIME_AFTER(*rb->current_tick, next_update))
331 {
332 next_update = *rb->current_tick + UPDATE_FREQ;
333
334 /* update screen part that was changed since last yield */
335 rb->lcd_update_rect(last_px, rect->py_min,
336 p_x - last_px + 1, rect->py_max - rect->py_min);
337 last_px = p_x;
338 }
339#endif
340 a += ctx.x_step;
341 }
342
343 rect->valid = 0;
344
345 return 0;
346}
347
348static void mandelbrot_move(int dx, int dy)
349{
350 long d_x = (long)dx * ctx.x_delta;
351 long d_y = (long)dy * ctx.y_delta;
352
353 ctx.x_min += d_x;
354 ctx.x_max += d_x;
355 ctx.y_min += d_y;
356 ctx.y_max += d_y;
357}
358
359static void mandelbrot_zoom(int factor)
360{
361 long factor_x = (long)factor * ctx.x_delta;
362 long factor_y = (long)factor * ctx.y_delta;
363
364 ctx.x_min += factor_x;
365 ctx.x_max -= factor_x;
366 ctx.y_min += factor_y;
367 ctx.y_max -= factor_y;
368
369 recalc_parameters();
370}
371
372static int mandelbrot_precision(int d)
373{
374 int changed = 0;
375
376 /* Precision increase */
377 for (; d > 0; d--)
378 {
379 ctx.max_iter += ctx.max_iter / 2;
380 changed = 1;
381 }
382
383 /* Precision decrease */
384 for (; d < 0 && ctx.max_iter >= 15; d++)
385 {
386 ctx.max_iter -= ctx.max_iter / 3;
387 changed = 1;
388 }
389
390 return changed;
391}
392
diff --git a/apps/plugins/fractals/mandelbrot_set.h b/apps/plugins/fractals/mandelbrot_set.h
new file mode 100644
index 0000000000..4eeb68461b
--- /dev/null
+++ b/apps/plugins/fractals/mandelbrot_set.h
@@ -0,0 +1,60 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 Tomer Shalev
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef _MANDELBROT_SET_H
22#define _MANDELBROT_SET_H
23
24#include "fractal_sets.h"
25
26/* CPU stuff */
27#if CONFIG_CPU == SH7034
28#include "cpu_sh7043.h"
29#elif defined CPU_COLDFIRE
30#include "cpu_coldfire.h"
31#elif defined CPU_ARM
32#include "cpu_arm.h"
33#endif
34
35#if CONFIG_CPU == SH7034
36#define MULS16_ASR10(a, b) muls16_asr10(a, b)
37#define MULS32_ASR26(a, b) muls32_asr26(a, b)
38#elif defined CPU_COLDFIRE
39/* Needs the EMAC initialised to fractional mode w/o rounding and saturation */
40#define MULS32_INIT() coldfire_set_macsr(EMAC_FRACTIONAL)
41#define MULS16_ASR10(a, b) muls16_asr10(a, b)
42#define MULS32_ASR26(a, b) muls32_asr26(a, b)
43#elif defined CPU_ARM
44#define MULS32_ASR26(a, b) muls32_asr26(a, b)
45#endif
46
47/* default macros */
48#ifndef MULS16_ASR10
49#define MULS16_ASR10(a, b) ((short)(((long)(a) * (long)(b)) >> 10))
50#endif
51#ifndef MULS32_ASR26
52#define MULS32_ASR26(a, b) ((long)(((long long)(a) * (long long)(b)) >> 26))
53#endif
54#ifndef MULS32_INIT
55#define MULS32_INIT()
56#endif
57
58extern struct fractal_ops mandelbrot_ops;
59
60#endif
diff --git a/manual/plugins/mandelbrot.tex b/manual/plugins/fractals.tex
index 7a1f945eb5..99a2ac0f41 100644
--- a/manual/plugins/mandelbrot.tex
+++ b/manual/plugins/fractals.tex
@@ -1,4 +1,4 @@
1\subsection{Mandelbrot} 1\subsection{Fractals}
2\screenshot{plugins/images/ss-mandelbrot}{Mandelbrot}{img:mandelbrot} 2\screenshot{plugins/images/ss-mandelbrot}{Mandelbrot}{img:mandelbrot}
3This demonstration draws fractal images from the Mandelbrot set 3This demonstration draws fractal images from the Mandelbrot set
4\opt{archos,iriverh100}{using the greyscale engine}. 4\opt{archos,iriverh100}{using the greyscale engine}.
diff --git a/manual/plugins/main.tex b/manual/plugins/main.tex
index 62271161e9..a7dc3d7bf0 100644
--- a/manual/plugins/main.tex
+++ b/manual/plugins/main.tex
@@ -102,9 +102,9 @@ text files%
102 102
103\opt{lcd_bitmap}{\input{plugins/fire.tex}} 103\opt{lcd_bitmap}{\input{plugins/fire.tex}}
104 104
105{\input{plugins/logo.tex}} 105\opt{lcd_bitmap}{\input{plugins/fractals.tex}}
106 106
107\opt{lcd_bitmap}{\input{plugins/mandelbrot.tex}} 107{\input{plugins/logo.tex}}
108 108
109{\input{plugins/mosaic.tex}} 109{\input{plugins/mosaic.tex}}
110 110