summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer/src/smartmedia.hcc
blob: 9ef714d3513ba67b112eda4440d7036032dfc0d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*! \file smartmedia.hcc
 *
 * \section generic	Here we interface with the SmartMedia card.
 *
 * \section project Project information.
 * Project Graphic Equalizer\n
 * \author O.M. Schinagl
 * \date 20041110
 * \version 0.1
 *
 * \section copyright Copyright
 * Copyright ©2004 Koninklijke Philips Electronics N.V. All rights reserved
 *
 * \section history Change history
 * 20041110: O.M. Schinagl\n	Initial version
 *
 ********************************************************************/

/******** System Includes *************/
#include <stdlib.hch>

#include "pal_master.hch"

/******** Application Includes ********/
#include "configuration.hch"
#include "display_shared.hch"
#include "smartmedia_shared.hch"
#include "smartmedia.hch"

#if HAVE_DEBUG
	#include "debug.hch"
#endif

#include "audio.hch"
#include "mouse_shared.hch"
#include "eventhandler_shared.hch"
#include "display.hch" /* FIXME: temporary include, needs to be moved to 'init' */

/*! \fn		unsigned 1 smartmedia_init(void);
 * \brief	We here initialize the Smart Media card and verify wether the
 *		card is inserted and such.
 * 
 * \return	We return 0 on success, 1 on error.
 * \retval	unsigned 1
 */
unsigned 1 smartmedia_init(void) {
	unsigned 1 retval;
	/*
	 * Firstly we enable both the CPLD and the SmartMedia.
	 */
	RC200CPLDEnable();
	RC200SmartMediaInit(&retval);

	if (retval) {
		RC200SmartMediaReset(&retval);
		RC200SmartMediaInit(&retval);
	}
	
	return retval;	
} /* --- smartmedia_init() --- */



/*! \fn		void smartmedia_loaddata(skindata_t *skindata);
 * \brief	We load our memory with skin and help data from the smartmedia.
 * 
 * \param	*skindata	skindata like boundries and colors of elements.
 *
 * \return	void
 * \retval	void
 */
void smartmedia_loaddata(skindata_t *skindata) {
	/*
	 * Setup RAM Handle, and determin maximum Data and Address widths
	 */
	macro expr RAM_BANK0 = PalPL2RAMCT(0);
	macro expr DW = PalPL2RAMGetMaxDataWidthCT();
	macro expr AW = PalPL2RAMGetMaxAddressWidthCT();

	unsigned DW data;
	unsigned 27 smartmedia_address, smartmedia_address_mask;
	unsigned AW address, address_offset;
	unsigned 8 mask, r, g, b;
	unsigned 4 stage;
	unsigned 1 result;

	extern ram unsigned 8 presets_default_values[768];

#if HAVE_DEBUG
	/*
	 * Print some nice stats about data loading.
	 */
	print_eol();
	print_hex_value(0);
#endif
	/*
	 * Before we enter our loop to fill our memory with valid data, we have
	 * to set the startup positions for the SmartMedia.
	 */
	address_offset = 0;
	smartmedia_address = 0;
	smartmedia_address_mask = SMARTMEDIA_ADDRESS_PRESET_DEMO_START;
	stage = STAGE_LOAD_PRESET;
	/*
	 * We start with the address of the skin, and do the loop until we have
	 * done the end of the help.
	 */
	while ((ADDRESS_ABOUT_BOTTOM_END +1) != (address_offset +address)) {
		if (STAGE_LOAD_PRESET == stage) {
			if (ADDRESS_PRESET_RESET_START == (address_offset +address)) {
				smartmedia_address_mask = SMARTMEDIA_ADDRESS_PRESET_RESET_START;
			}
			if (ADDRESS_PRESET_RESET_END == (address_offset +address)) { /* case ADRESS_SKIN_START */
#if HAVE_DEBUG
					print_string(" ADDRESS_SKIN_START");print_eol();
#endif
				address = 0;
				address_offset = ADDRESS_SKIN_START;
				smartmedia_address = SMARTMEDIA_ADDRESS_SKIN_START;
				smartmedia_address_mask = SMARTMEDIA_ADDRESS_SKINMASK_START;
				stage = STAGE_LOAD_SKIN;
			}
		} else {
			/*
			 * Once we are done with the loading of our skin, we need to
			 * change the smartmedia start addresses.
			 */
			switch (address_offset +address) {
				case ADDRESS_HELP_START:
#if HAVE_DEBUG
					print_string(" ADDRESS_HELP_START");print_eol();
#endif
					address = 0;
					address_offset = ADDRESS_HELP_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_HELP_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_HELPMASK_START;
					stage = STAGE_LOAD_HELP;
					break;
				case ADDRESS_GRAPHMASK_START:
#if HAVE_DEBUG
					print_string(" ADDRESS_GRAPHMASK_START");print_eol();
#endif
					address = 0;
					address_offset = ADDRESS_GRAPHMASK_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_GRAPHMASK_START;
					stage = STAGE_LOAD_GRAPH;
					break;
				case ADDRESS_ABOUT_TOP_FONTYS_START:
#if HAVE_DEBUG
					print_string(" ADDRESS_ABOUT_TOP_FONTYS_START: ");print_eol();
#endif
					address = 0;
					address_offset = ADDRESS_ABOUT_TOP_FONTYS_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_TOP_FONTYS_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_TOPMASK_START;
					stage = STAGE_LOAD_TOP_FONTYS;
					break;
				case ADDRESS_ABOUT_TOP_TASS_START:
#if HAVE_DEBUG
					print_string(" ADDRESS_ABOUT_TOP_TASS_START");print_eol();
#endif
 					address = 0;
					address_offset = ADDRESS_ABOUT_TOP_FONTYS_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_TOP_FONTYS_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_TOPMASK_START;
					stage = STAGE_LOAD_TOP_FONTYS;
					/*
					address_offset = ADDRESS_ABOUT_TOP_TASS_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_TOP_TASS_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_TOPMASK_START;
					stage = STAGE_LOAD_TOP_TASS;
					*/
					break;
				case ADDRESS_ABOUT_TOP_TRANSFER_START:
#if HAVE_DEBUG
					print_string(" ADDRESS_ABOUT_TOP_TRANSFER_START");print_eol();
#endif
					address = 0;
					address_offset = ADDRESS_ABOUT_TOP_TRANSFER_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_TOP_TRANSFER_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_TOPMASK_START;
					stage = STAGE_LOAD_TOP_TRANSFER;
					break;
				case ADDRESS_ABOUT_TOP_CELOXICA_START:
#if HAVE_DEBUG
					print_string(" ADDRESS_ABOUT_TOP_CELOXICA_START");print_eol();
#endif
					address = 0;
					address_offset = ADDRESS_ABOUT_TOP_CELOXICA_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_TOP_CELOXICA_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_TOPMASK_START;
					stage = STAGE_LOAD_TOP_CELOXICA;
					break;
/*
				case ADDRESS_ABOUT_TOP_DETAILS_START:
					address = 0;
					address_offset = ADDRESS_ABOUT_TOP_DETAILS_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_TOP_DETAILS_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_TOPMASK_START;
					stage = STAGE_LOAD_TOP_DETAILS;
					break;
*/
				case ADDRESS_ABOUT_BOTTOM_START:
#if HAVE_DEBUG
					print_string(" ADDRESS_ABOUT_BOTTOM_START");print_eol();
#endif
					address = 0;
					address_offset = ADDRESS_ABOUT_BOTTOM_START;
					smartmedia_address = SMARTMEDIA_ADDRESS_BOTTOM_START;
					smartmedia_address_mask = SMARTMEDIA_ADDRESS_BOTTOMMASK_START;
					stage = STAGE_LOAD_ABOUT_BOTTOM;
					break;
				default:
					break;
			}
		}

		/*
		 * Before reading our data from the smartmedia we set our
		 * address pointer to the address from our loop.
		 */
#if HAVE_SMARTMEDIA
		PalPL2RAMSetWriteAddress(RAM_BANK0, (STAGE_LOAD_GRAPH == stage) ? (address_offset +(0 @ (address \\ 2))) : (address_offset +address)); //(STAGE_LOAD_PRESET == stage) ? (address_offset +(0 @ (address \\ 2))) : 
#else
		PalPL2RAMSetWriteAddress(RAM_BANK0, 0);
#endif

		/*
		 * SmartMedia data is read one byte per call. Because we want
		 * to store the mask + the rgb values in one variable for later
		 * useage we need to read those 4 bytes from the smartmedia
		 * before storing it as one.
		 */
#if HAVE_SMARTMEDIA
		/*
		 * FIXME: Due to a bug in the DK2 smartmedia libraries we need
		 * stop reading after each byte with OperationEnd call. This is
		 * VERY slow and must be changed.
		 */
		if ((STAGE_LOAD_PRESET != stage) && (STAGE_LOAD_GRAPH != stage)) {
			RC200SmartMediaSetAddress(READ, smartmedia_address);
			RC200SmartMediaRead(&r, TRUE);
			RC200SmartMediaOperationEnd(&result);
			RC200SmartMediaSetAddress(READ, (smartmedia_address +1));
			RC200SmartMediaRead(&g, TRUE);
			RC200SmartMediaOperationEnd(&result);
			RC200SmartMediaSetAddress(READ, (smartmedia_address +2));
			RC200SmartMediaRead(&b, TRUE);
			RC200SmartMediaOperationEnd(&result);
		}

		if (STAGE_LOAD_GRAPH == stage) {
			RC200SmartMediaSetAddress(READ, smartmedia_address_mask +1);
			RC200SmartMediaRead(&r, TRUE);
			RC200SmartMediaOperationEnd(&result);
			RC200SmartMediaSetAddress(READ, (smartmedia_address_mask +2));
			RC200SmartMediaRead(&g, TRUE);
			RC200SmartMediaOperationEnd(&result);
			RC200SmartMediaSetAddress(READ, (smartmedia_address_mask +3));
			RC200SmartMediaRead(&b, TRUE);
			RC200SmartMediaOperationEnd(&result);
		}

		RC200SmartMediaSetAddress(READ, smartmedia_address_mask);
		RC200SmartMediaRead(&mask, TRUE);
		RC200SmartMediaOperationEnd(&result);

		switch (stage) {
			case STAGE_LOAD_PRESET:
				presets_default_values[address <- 10] = mask;
				break;
			case STAGE_LOAD_SKIN:		/* fall through */
			case STAGE_LOAD_HELP:		/* fall through */
			case STAGE_LOAD_GRAPH:		/* fall through */
			case STAGE_LOAD_TOP_FONTYS:	/* fall through */
			case STAGE_LOAD_TOP_TASS:	/* fall through */
			case STAGE_LOAD_TOP_TRANSFER:	/* fall through */
			case STAGE_LOAD_TOP_CELOXICA:	/* fall through */
			case STAGE_LOAD_TOP_DETAILS:	/* fall through */
			case STAGE_LOAD_ABOUT_BOTTOM:
				data = 0 @ mask @ r @ g @ b;
				break;
		//	case STAGE_LOAD_GRAPH:
		//		data = ((address <- 2) ? ((data << 8) +(0 @ mask)) : (0 @ mask));
		//		break;
		}
		
#else
		data = 0x0000ff00;
#endif
		/*
		 * Now that we have gathered all pixel data, store it in ram.
		 */
		PalPL2RAMWrite(RAM_BANK0, data);

#if HAVE_DEBUG
		/*
		 * Print some nice stats about data loading.
		 */
		if (!((address_offset +address) <- 10)) {
			print_cr();
			print_hex_value(0 @ ((address_offset +address) \\ 11));
			print_string(" / 000001D7 | data: ");
			print_hex_value(data <- 32);
			print_string(" | PL2: ");
			print_hex_value(0@(address_offset));
			print_string(" | SMC: ");
			print_hex_value(0@smartmedia_address);
		}
#endif

		/*
		 * Finally increase al our indexes approperiatly.
		 */
		smartmedia_address += 3;
		if (STAGE_LOAD_GRAPH == stage) {
			smartmedia_address_mask += 4;
		} else {
			smartmedia_address_mask++;
		}
		address++;
	}

	/*
	 * This block needs to probably move up into the fore loop where we
	 * calculate these settings later.
	 */
	skindata->spectrum.top = 200;
	skindata->spectrum.bottom = 335;
	skindata->spectrum.left = 77;
	skindata->spectrum.right = 575;
//	skindata->spectrum.color_primary = PIXEL_SPECTRUM;
//	skindata->spectrum.color_secondary = PIXEL_SPECTRUM;

	skindata->waveform.top = 46;
	skindata->waveform.bottom = 118;
	skindata->waveform.left = 76;
	skindata->waveform.right = 413;
	skindata->waveform.color_primary = PIXEL_WAVEFORM;

	skindata->volume.top = 112;
	skindata->volume.bottom = 66;
	skindata->volume.left = 439;
	skindata->volume.right = 455;
	skindata->volume.color_primary = PIXEL_VOLUME;

	skindata->equalizer.color_primary = PIXEL_EQUALIZER;
} /* --- smartmedia_loaddata() --- */