summaryrefslogtreecommitdiffstats
path: root/Graphic_Equalizer_Original_Port/src/smartmedia.hcc
blob: ff405c1551df244d898b23b13eb3b69374e8d388 (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
/*! \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;
	unsigned 8 mask, r, g, b;
	unsigned 3 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.
	 */
	smartmedia_address = SMARTMEDIA_ADDRESS_SKIN_START;
	smartmedia_address_mask = SMARTMEDIA_ADDRESS_SKINMASK_START;
	stage = STAGE_LOAD_SKIN;
	/*
	 * We start with the address of the skin, and do the loop until we have
	 * done the end of the help.
	 */
	for (address = ADDRESS_SKIN_START; address != (ADDRESS_PRESET_RESET_END +1); address++) {
		/*
		 * Once we are done with the loading of our skin, we need to
		 * change the smartmedia start addresses.
		 */
		switch (address) {
			case 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:
				smartmedia_address_mask = SMARTMEDIA_ADDRESS_GRAPHMASK_START;
				stage = STAGE_LOAD_GRAPH;
				break;
			case ADDRESS_PRESET_DEMO_START:
				smartmedia_address_mask = SMARTMEDIA_ADDRESS_PRESET_DEMO_START;
				stage = STAGE_LOAD_PRESET;
				break;
			case ADDRESS_PRESET_RESET_START:
				smartmedia_address_mask = SMARTMEDIA_ADDRESS_PRESET_RESET_START;
				stage = STAGE_LOAD_PRESET;
				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, address);
#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_SKIN == stage) || (STAGE_LOAD_HELP == 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);
		}
		RC200SmartMediaSetAddress(READ, smartmedia_address_mask);
		RC200SmartMediaRead(&mask, TRUE);
		RC200SmartMediaOperationEnd(&result);

		switch (stage) {
			case STAGE_LOAD_SKIN:
				data = 0 @ mask @ r @ g @ b;
				break;
			case STAGE_LOAD_HELP:
				data = 0 @ mask @ r @ g @ b;
				break;
			case STAGE_LOAD_GRAPH:
				data = (unsigned DW)(0 @ mask) << 24;
				break;
			case STAGE_LOAD_PRESET:
				presets_default_values[(address -ADDRESS_PRESET_DEMO_START) <- 10] = mask;
		}
		
#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 <- 10)) {
			print_cr();
			print_hex_value(0 @ (address \\ 11));
			print_string(" / 000001C2 | data: ");
			print_hex_value(data <- 32);
		}
#endif

		/*
		 * Finally increase al our indexes approperiatly.
		 */
		smartmedia_address += 3;
		smartmedia_address_mask++;
	}

	/*
	 * This block needs to probably move up into the fore loop where we
	 * calculate these settings later.
	 */
	skindata->area_spectrum_top = 200;
	skindata->area_spectrum_bottom = 335;
	skindata->area_spectrum_left = 77;
	skindata->area_spectrum_right = 575;
	skindata->area_waveform_top = 46;
	skindata->area_waveform_bottom = 118;
	skindata->area_waveform_left = 76;
	skindata->area_waveform_right = 413;
	skindata->area_volume_top = 112;
	skindata->area_volume_bottom = 66;
	skindata->area_volume_left = 439;
	skindata->area_volume_right = 455;
	skindata->color_area_volume = PIXEL_VOLUME;
	skindata->color_area_waveform = PIXEL_WAVEFORM;
//	skindata->color_area_spectrum_top = PIXEL_SPECTRUM;
//	skindata->color_area_spectrum_bottom = PIXEL_SPECTRUM;
	skindata->color_equalizer = PIXEL_EQUALIZER;
} /* --- smartmedia_loaddata() --- */