summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/gray_blockfuncs.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/gray_blockfuncs.c')
-rw-r--r--apps/plugins/lib/gray_blockfuncs.c262
1 files changed, 0 insertions, 262 deletions
diff --git a/apps/plugins/lib/gray_blockfuncs.c b/apps/plugins/lib/gray_blockfuncs.c
deleted file mode 100644
index 85af0014e1..0000000000
--- a/apps/plugins/lib/gray_blockfuncs.c
+++ /dev/null
@@ -1,262 +0,0 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Grayscale framework
11* Low level block drawing functions
12*
13* This is a generic framework to use grayscale display within Rockbox
14* plugins. It obviously does not work for the player.
15*
16* Copyright (C) 2004 Jens Arnold
17*
18* All files in this archive are subject to the GNU General Public License.
19* See the file COPYING in the source tree root for full license agreement.
20*
21* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22* KIND, either express or implied.
23*
24****************************************************************************/
25
26#ifndef SIMULATOR /* not for simulator by now */
27#include "plugin.h"
28
29#if CONFIG_LCD == LCD_SSD1815 /* only for Recorder/Ondio */
30#include "gray.h"
31
32/* Prototypes */
33static void _writeblock(unsigned char *address, unsigned mask, unsigned bits);
34static void _invertblock(unsigned char *address, unsigned mask, unsigned bits);
35static void _writeblockfg(unsigned char *address, unsigned mask, unsigned bits);
36static void _writeblockbg(unsigned char *address, unsigned mask, unsigned bits);
37
38/* Block function pointer array */
39void (* const _gray_blockfuncs[4])(unsigned char *address, unsigned mask,
40 unsigned bits) = {
41 _invertblock, _writeblockfg, _writeblockbg, _writeblock
42};
43
44/* Write an 8-pixel block, defined by foreground and background pattern.
45 * Address is the byte in the first bitplane, mask determines which pixels to
46 * set, and bits determines if the pixel is foreground or background */
47static void _writeblock(unsigned char *address, unsigned mask, unsigned bits)
48{
49 unsigned long pat_stack[8];
50 register unsigned char *end_addr;
51 register unsigned long *pat_ptr = &pat_stack[8];
52
53 /* precalculate the bit patterns with random shifts (same RNG as _writepixel,
54 * see there for an explanation) for all 8 pixels and put them on an
55 * extra stack */
56 asm (
57 "mov #8,r3 \n" /* loop count in r3: 8 pixels */
58 "mov %6,r2 \n" /* copy mask */
59
60 ".wb_loop: \n" /** load pattern for pixel **/
61 "shlr r2 \n" /* shift out lsb of mask */
62 "bf .wb_skip \n" /* skip this pixel */
63
64 "mov %2,r4 \n" /* load foreground pattern */
65 "shlr %7 \n" /* shift out lsb of bits */
66 "bt .wb_fg \n" /* foreground? -> skip next insn */
67 "mov %3,r4 \n" /* load background pattern */
68 ".wb_fg: \n"
69
70 "mov #75,r0 \n"
71 "mulu r0,%0 \n" /* multiply by 75 */
72 "sts macl,%0 \n"
73 "add #74,%0 \n" /* add another 74 */
74 /* Since the lower bits are not very random: */
75 "swap.b %0,r1 \n" /* get bits 8..15 (need max. 5) */
76 "and %5,r1 \n" /* mask out unneeded bits */
77
78 "cmp/hs %4,r1 \n" /* random >= depth ? */
79 "bf .wb_ntrim \n"
80 "sub %4,r1 \n" /* yes: random -= depth; */
81 ".wb_ntrim: \n"
82
83 "mov.l .ashlsi3,r0 \n" /** rotate pattern **/
84 "jsr @r0 \n" /* r4 -> r0, shift left by r5 */
85 "mov r1,r5 \n"
86
87 "mov %4,r5 \n"
88 "sub r1,r5 \n" /* r5 = depth - r1 */
89 "mov.l .lshrsi3,r1 \n"
90 "jsr @r1 \n" /* r4 -> r0, shift right by r5 */
91 "mov r0,r1 \n" /* store previous result in r1 */
92
93 "bra .wb_store \n"
94 "or r1,r0 \n" /* rotated_pattern = r0 | r1 */
95
96 ".wb_skip: \n"
97 "shlr %7 \n" /* shift out lsb of bits to keep in sync */
98 "mov #0,r0 \n" /* pattern for skipped pixel must be 0 */
99
100 ".wb_store: \n"
101 "mov.l r0,@-%1 \n" /* push on pattern stack */
102
103 "add #-1,r3 \n" /* decrease loop count */
104 "cmp/pl r3 \n" /* loop count > 0? */
105 "bt .wb_loop \n" /* yes: loop */
106 : /* outputs */
107 /* %0, in & out */ "+r"(_gray_random_buffer),
108 /* %1, in & out */ "+r"(pat_ptr)
109 : /* inputs */
110 /* %2 */ "r"(_graybuf->fg_pattern),
111 /* %3 */ "r"(_graybuf->bg_pattern),
112 /* %4 */ "r"(_graybuf->depth),
113 /* %5 */ "r"(_graybuf->randmask),
114 /* %6 */ "r"(mask),
115 /* %7 */ "r"(bits)
116 : /* clobbers */
117 "r0", "r1", "r2", "r3", "r4", "r5", "macl", "pr"
118 );
119
120 end_addr = address + MULU16(_graybuf->depth, _graybuf->plane_size);
121
122 /* set the bits for all 8 pixels in all bytes according to the
123 * precalculated patterns on the pattern stack */
124 asm volatile (
125 "mov.l @%3+,r1 \n" /* pop all 8 patterns */
126 "mov.l @%3+,r2 \n"
127 "mov.l @%3+,r3 \n"
128 "mov.l @%3+,r8 \n"
129 "mov.l @%3+,r9 \n"
130 "mov.l @%3+,r10 \n"
131 "mov.l @%3+,r11 \n"
132 "mov.l @%3+,r12 \n"
133
134 "not %4,%4 \n" /* "set" mask -> "keep" mask */
135 "extu.b %4,%4 \n" /* mask out high bits */
136 "tst %4,%4 \n" /* nothing to keep? */
137 "bt .wb_sloop \n" /* yes: jump to short loop */
138
139 ".wb_floop: \n" /** full loop (there are bits to keep)**/
140 "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
141 "rotcl r0 \n" /* rotate t bit into r0 */
142 "shlr r2 \n"
143 "rotcl r0 \n"
144 "shlr r3 \n"
145 "rotcl r0 \n"
146 "shlr r8 \n"
147 "rotcl r0 \n"
148 "shlr r9 \n"
149 "rotcl r0 \n"
150 "shlr r10 \n"
151 "rotcl r0 \n"
152 "shlr r11 \n"
153 "rotcl r0 \n"
154 "shlr r12 \n"
155 "mov.b @%0,%3 \n" /* read old value */
156 "rotcl r0 \n"
157 "and %4,%3 \n" /* mask out unneeded bits */
158 "or r0,%3 \n" /* set new bits */
159 "mov.b %3,@%0 \n" /* store value to bitplane */
160 "add %2,%0 \n" /* advance to next bitplane */
161 "cmp/hi %0,%1 \n" /* last bitplane done? */
162 "bt .wb_floop \n" /* no: loop */
163
164 "bra .wb_end \n"
165 "nop \n"
166
167 ".wb_sloop: \n" /** short loop (nothing to keep) **/
168 "shlr r1 \n" /* rotate lsb of pattern 1 to t bit */
169 "rotcl r0 \n" /* rotate t bit into r0 */
170 "shlr r2 \n"
171 "rotcl r0 \n"
172 "shlr r3 \n"
173 "rotcl r0 \n"
174 "shlr r8 \n"
175 "rotcl r0 \n"
176 "shlr r9 \n"
177 "rotcl r0 \n"
178 "shlr r10 \n"
179 "rotcl r0 \n"
180 "shlr r11 \n"
181 "rotcl r0 \n"
182 "shlr r12 \n"
183 "rotcl r0 \n"
184 "mov.b r0,@%0 \n" /* store byte to bitplane */
185 "add %2,%0 \n" /* advance to next bitplane */
186 "cmp/hi %0,%1 \n" /* last bitplane done? */
187 "bt .wb_sloop \n" /* no: loop */
188
189 ".wb_end: \n"
190 : /* outputs */
191 : /* inputs */
192 /* %0 */ "r"(address),
193 /* %1 */ "r"(end_addr),
194 /* %2 */ "r"(_graybuf->plane_size),
195 /* %3 */ "r"(pat_ptr),
196 /* %4 */ "r"(mask)
197 : /* clobbers */
198 "r0", "r1", "r2", "r3", "r8", "r9", "r10", "r11", "r12"
199 );
200}
201
202/* References to C library routines used in _writeblock */
203asm (
204 ".align 2 \n"
205".ashlsi3: \n" /* C library routine: */
206 ".long ___ashlsi3 \n" /* shift r4 left by r5, return in r0 */
207".lshrsi3: \n" /* C library routine: */
208 ".long ___lshrsi3 \n" /* shift r4 right by r5, return in r0 */
209 /* both routines preserve r4, destroy r5 and take ~16 cycles */
210);
211
212/* Invert pixels within an 8-pixel block.
213 * Address is the byte in the first bitplane, mask and bits determine which
214 * pixels to invert ('And'ed together, for matching the parameters with
215 * _writeblock) */
216static void _invertblock(unsigned char *address, unsigned mask, unsigned bits)
217{
218 bits &= mask;
219 if (!bits)
220 return;
221
222 asm volatile (
223 "mov #0,r1 \n" /* current_plane = 0 */
224
225 ".im_loop: \n"
226 "mov.b @%1,r2 \n" /* get data byte */
227 "add #1,r1 \n" /* current_plane++; */
228 "xor %2,r2 \n" /* invert bits */
229 "mov.b r2,@%1 \n" /* store data byte */
230 "add %3,%1 \n" /* advance address to next bitplane */
231 "cmp/hi r1,%0 \n" /* current_plane < depth ? */
232 "bt .im_loop \n"
233 : /* outputs */
234 : /* inputs */
235 /* %0 */ "r"(_graybuf->depth),
236 /* %1 */ "r"(address),
237 /* %2 */ "r"(bits),
238 /* %3 */ "r"(_graybuf->plane_size)
239 : /* clobbers */
240 "r1", "r2", "macl"
241 );
242}
243
244/* Call _writeblock with the mask modified to draw foreground pixels only */
245static void _writeblockfg(unsigned char *address, unsigned mask, unsigned bits)
246{
247 mask &= bits;
248 if (mask)
249 _writeblock(address, mask, bits);
250}
251
252/* Call _writeblock with the mask modified to draw background pixels only */
253static void _writeblockbg(unsigned char *address, unsigned mask, unsigned bits)
254{
255 mask &= ~bits;
256 if (mask)
257 _writeblock(address, mask, bits);
258}
259
260#endif // #ifdef HAVE_LCD_BITMAP
261#endif // #ifndef SIMULATOR
262