1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 1999 Chris Allegretta
11 * Copyright (C) 2005 Alastair S - ported to podzilla
12 * Copyright (C) 2005 Jonas Häggqvist - ported to rockbox
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.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
27 * - The font is a bit large, create smaller one
28 * - For colour/greyscale displays, the font from the xscreensaver xmatrix
29 * should be converted and used
31 * - The animation "dies" after a few seconds, not sure why. Works in sim.
32 * Symtom Fixed Oct 2007 GRaTT (Gerritt Gonzales)
40 #define MAXCHARS 27 - 1
41 extern const fb_data matrix_bold
[];
42 extern const fb_data matrix_normal
[];
46 #define COLS LCD_WIDTH/COL_W
47 #define ROWS LCD_HEIGHT/COL_H
49 #define LEFTMARGIN (LCD_WIDTH-(COLS*COL_W))/2
50 #define TOPMARGIN (LCD_HEIGHT-(ROWS*COL_H))/2
52 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \
53 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
54 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
55 #define MATRIX_EXIT BUTTON_MENU
56 #define MATRIX_SLEEP_MORE BUTTON_SCROLL_BACK|BUTTON_REPEAT
57 #define MATRIX_SLEEP_LESS BUTTON_SCROLL_FWD|BUTTON_REPEAT
58 #define MATRIX_PAUSE BUTTON_PLAY
59 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
60 (CONFIG_KEYPAD == IRIVER_H300_PAD)
61 #define MATRIX_EXIT BUTTON_OFF
62 #define MATRIX_SLEEP_MORE BUTTON_UP
63 #define MATRIX_SLEEP_LESS BUTTON_DOWN
64 #define MATRIX_PAUSE BUTTON_SELECT
65 #elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
66 #define MATRIX_EXIT BUTTON_POWER
67 #define MATRIX_SLEEP_MORE BUTTON_SCROLL_UP|BUTTON_REPEAT
68 #define MATRIX_SLEEP_LESS BUTTON_SCROLL_DOWN|BUTTON_REPEAT
69 #define MATRIX_PAUSE BUTTON_PLAY
70 #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
71 #define MATRIX_EXIT BUTTON_POWER
72 #define MATRIX_SLEEP_MORE BUTTON_UP
73 #define MATRIX_SLEEP_LESS BUTTON_DOWN
74 #define MATRIX_PAUSE BUTTON_PLAY
75 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
76 #define MATRIX_EXIT BUTTON_A
77 #define MATRIX_SLEEP_MORE BUTTON_UP
78 #define MATRIX_SLEEP_LESS BUTTON_DOWN
79 #define MATRIX_PAUSE BUTTON_SELECT
80 #elif CONFIG_KEYPAD == SANSA_E200_PAD
81 #define MATRIX_EXIT BUTTON_POWER
82 #define MATRIX_SLEEP_MORE BUTTON_SCROLL_BACK|BUTTON_REPEAT
83 #define MATRIX_SLEEP_LESS BUTTON_SCROLL_FWD|BUTTON_REPEAT
84 #define MATRIX_PAUSE BUTTON_SELECT
85 #elif CONFIG_KEYPAD == SANSA_C200_PAD
86 #define MATRIX_EXIT BUTTON_POWER
87 #define MATRIX_SLEEP_MORE BUTTON_UP
88 #define MATRIX_SLEEP_LESS BUTTON_DOWN
89 #define MATRIX_PAUSE BUTTON_SELECT
90 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
91 #define MATRIX_EXIT BUTTON_BACK
92 #define MATRIX_SLEEP_MORE BUTTON_UP
93 #define MATRIX_SLEEP_LESS BUTTON_DOWN
94 #define MATRIX_PAUSE BUTTON_SELECT
95 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
96 #define MATRIX_EXIT BUTTON_RC_REC
97 #define MATRIX_SLEEP_MORE BUTTON_RC_VOL_UP
98 #define MATRIX_SLEEP_LESS BUTTON_RC_VOL_DOWN
99 #define MATRIX_PAUSE BUTTON_RC_PLAY
100 #elif (CONFIG_KEYPAD == COWOND2_PAD)
101 #define MATRIX_EXIT BUTTON_POWER
103 #error Unsupported keypad
108 #define MATRIX_EXIT BUTTON_TOPLEFT
110 #ifndef MATRIX_SLEEP_MORE
111 #define MATRIX_SLEEP_MORE BUTTON_MIDRIGHT
113 #ifndef MATRIX_SLEEP_LESS
114 #define MATRIX_SLEEP_LESS BUTTON_MIDLEFT
117 #define MATRIX_PAUSE BUTTON_CENTER
123 /* Codec api pointer */
124 static const struct plugin_api
* rb
;
126 /* Each position is of this type */
127 typedef struct cmatrix
{
132 /* The matrix - who'd have guessed it was just a few hundred bytes? */
133 static cmatrix matrix
[ROWS
][COLS
];
134 static int length
[COLS
];
135 static int spaces
[COLS
];
136 static int updates
[COLS
];
138 static void matrix_init(void) {
142 rb
->srand(*rb
->current_tick
);
144 /* Make the matrix */
145 for (i
= 0; i
<= ROWS
; i
++) {
146 for (j
= 0; j
<= COLS
- 1; j
++ ) {
147 matrix
[i
][j
].val
= -1;
148 matrix
[i
][j
].bold
= 0;
152 for (j
= 0; j
<= COLS
- 1; j
++) {
153 /* Set up spaces[] array of how many spaces to skip */
154 spaces
[j
] = rb
->rand() % ROWS
+ 1;
156 /* And length of the stream */
157 length
[j
] = rb
->rand() % (ROWS
- 3) + 3;
159 /* Sentinel value for creation of new objects */
160 matrix
[1][j
].val
= 129;
162 /* And set updates[] array for update speed. */
163 updates
[j
] = rb
->rand() % 3 + 1;
167 static void matrix_blit_char(const int row
, const int col
, int cha
)
169 if (cha
== 129 || cha
== 2 || cha
> MAXCHARS
)
172 if (matrix
[row
][col
].bold
== 1) {
173 rb
->lcd_bitmap_part(matrix_bold
, cha
*COL_W
, 0, 392,
174 col
*COL_W
+ LEFTMARGIN
, row
*COL_H
+ TOPMARGIN
, COL_W
, COL_H
);
177 rb
->lcd_bitmap_part(matrix_normal
, cha
*COL_W
, 0, 392,
178 col
*COL_W
+ LEFTMARGIN
, row
*COL_H
+ TOPMARGIN
, COL_W
, COL_H
);
182 static void matrix_loop(void)
184 int i
, j
= 0, y
, z
, firstcoldone
= 0;
185 static int count
= 0;
192 for (j
= 0; j
<= COLS
- 1; j
++) {
193 if (count
> updates
[j
]) {
194 /* New style scrolling */
195 if (matrix
[0][j
].val
== -1 && matrix
[1][j
].val
== 129
197 matrix
[0][j
].val
= -1;
199 } else if (matrix
[0][j
].val
== -1 && matrix
[1][j
].val
== 129){
200 length
[j
] = rb
->rand() % (ROWS
- 3) + 3;
201 matrix
[0][j
].val
= rb
->rand() % (MAXCHARS
-1) + 1;
202 if (rb
->rand() % 2 == 1)
203 matrix
[0][j
].bold
= 2;
204 spaces
[j
] = rb
->rand() % ROWS
+ 1;
210 /* Skip over spaces */
211 /* this is whear the characters were disappearing */
213 while (i <= ROWS && (matrix[i][j].val == 129 ||
214 matrix[i][j].val == -1))
217 /* A little more random now for spaces */
218 if (rb
->rand() % randomness
== 1){
219 while (i
<= ROWS
&& (matrix
[i
][j
].val
== 129 ||
220 matrix
[i
][j
].val
== -1)){
235 /* Go to the head of this collumn */
238 while (i
<= ROWS
&& (matrix
[i
][j
].val
!= 129 &&
239 matrix
[i
][j
].val
!= -1)) {
245 matrix
[z
][j
].val
= 129;
246 matrix
[ROWS
][j
].bold
= 1;
247 matrix_blit_char(z
- 1, j
, matrix
[z
][j
].val
);
251 matrix
[i
][j
].val
= rb
->rand() % (MAXCHARS
-1) + 1;
253 if (matrix
[i
- 1][j
].bold
== 2) {
254 matrix
[i
- 1][j
].bold
= 1;
255 matrix
[i
][j
].bold
= 2;
258 /* If we're at the top of the collumn and it's reached its
259 * full length (about to start moving down), we do this
260 * to get it moving. This is also how we keep segments
261 * not already growing from growing accidentally =>
263 if (y
> length
[j
] || firstcoldone
) {
264 matrix
[z
][j
].val
= 129;
265 matrix
[0][j
].val
= -1;
270 for (i
= 1; i
<= ROWS
; i
++) {
271 if (matrix
[i
][j
].val
== 0 || matrix
[i
][j
].bold
== 2) {
272 if (matrix
[i
][j
].val
== 0)
273 matrix_blit_char(i
- 1, j
, 20);
275 matrix_blit_char(i
- 1, j
, matrix
[i
][j
].val
);
277 if (matrix
[i
][j
].val
== 1)
278 matrix_blit_char(i
- 1, j
, 2);
279 else if (matrix
[i
][j
].val
== -1)
280 matrix_blit_char(i
- 1, j
, 129);
282 matrix_blit_char(i
- 1, j
, matrix
[i
][j
].val
);
289 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
) {
297 rb
->lcd_set_background(LCD_BLACK
);
298 rb
->lcd_set_backdrop(NULL
);
299 rb
->lcd_clear_display();
308 button
= rb
->button_get(false);
316 case MATRIX_SLEEP_MORE
:
320 case MATRIX_SLEEP_LESS
:
323 if (sleep
< 0) sleep
= 0;
326 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
) {
327 return PLUGIN_USB_CONNECTED
;