00001
00007 #include "vs10xx.h"
00008 #include "lcd.h"
00009 #include "filesys.h"
00010 #include "storage.h"
00011 #include "ui.h"
00012
00013
00014
00015
00017 unsigned int Mp3ReadRegister (unsigned char addressbyte){
00018 unsigned int resultvalue = 0;
00019
00020 Mp3SelectControl();
00021 SPIPutCharWithoutWaiting(VS_READ_COMMAND);
00022 SPIPutChar((addressbyte));
00023 SPIPutChar(0xff);
00024 SPIWait();
00025 resultvalue = (SPI_RESULT_BYTE) << 8;
00026 SPIPutCharWithoutWaiting(0xff);
00027 SPIWait();
00028 resultvalue |= (SPI_RESULT_BYTE);
00029 Mp3DeselectControl();
00030 return resultvalue;
00031 }
00032
00033 bit vs1103_recording_active;
00034 bit vs1103_record_mixer;
00035 bit vs1103_use_line_input;
00036 bit vs1103_do_reset;
00037 bit vs1103_mono_output;
00038 bit vs1103_terminate;
00039 bit vs1103_earSpkHi;
00040 bit vs1103_earSpkLo;
00041 bit vs1103_real_time_midi;
00042
00043 unsigned char currentMicGain;
00044
00045 void LoadPatch();
00046 void StartPatch();
00047
00048 void Vs1103SetMode(){
00049 unsigned char hiMode, loMode;
00050
00051 hiMode = SM_SDINEW;
00052 loMode = SM_SDI_ADPCM;
00053
00054 if (vs1103_use_line_input) hiMode |= SM_LINE_IN;
00055 if (vs1103_recording_active) hiMode |= SM_RECORD_ADPCM;
00056 if (vs1103_earSpkLo) hiMode |= SM_EARSPK_1;
00057 if (vs1103_earSpkHi) hiMode |= SM_EARSPK_2;
00058
00059 if (vs1103_do_reset) loMode |= SM_RESET;
00060 if (vs1103_mono_output) loMode |= SM_DIFF;
00061 if (vs1103_record_mixer) loMode |= SM_RECORD_MIXER;
00062 if (vs1103_terminate) loMode |= SM_OUTOFMIDI;
00063 if (vs1103_real_time_midi) loMode |= SM_RT_MIDI;
00064
00065 if (vs1103_real_time_midi){
00066
00067 Mp3WriteRegister(SCI_WRAMADDR, 0xc0, 0x1a);
00068 Mp3WriteRegister(SCI_WRAM, 0x00, 0x3f);
00069 }
00070
00071 Mp3WriteRegister (SCI_MODE, hiMode, loMode);
00072 ConsoleWrite("SetMode: ");
00073 ConsolePutHex8(hiMode);
00074 ConsolePutHex8(loMode);
00075 ConsolePutChar(13);
00076
00077
00078 while (!MP3_DREQ)
00079 ;
00080
00081
00082 if (!vs1103_real_time_midi){
00083
00084
00085
00086
00087 Mp3WriteRegister(SCI_WRAMADDR, 0xc0, 0x1a);
00088 Mp3WriteRegister(SCI_WRAM, 0x00, 0x0f);
00089 }
00090
00091 StartPatch();
00092
00093 }
00094
00095
00097 void Mp3SoftReset(){
00098
00099
00100 vs1103_do_reset = 1;
00101 Vs1103SetMode();
00102 vs1103_do_reset = 0;
00103
00104 Delay(1);
00105 while (!MP3_DREQ)
00106 ;
00107
00108 Mp3SetMixerVolume(25,25,25);
00109
00110 Delay(1);
00111
00112
00113
00114
00115 Delay(1);
00116 Mp3WriteRegister(SCI_ADPCMRECCTL, USE_512_BYTE_DREQ, 0x00 | 20);
00117
00118
00119 Delay(1);
00120
00121
00122 Mp3SelectData();
00123 SPIPutCharWithoutWaiting(0);
00124 SPIPutChar(0);
00125 SPIPutChar(0);
00126 SPIPutChar(0);
00127 SPIWait();
00128 Mp3DeselectData();
00129
00130 }
00131
00132
00133
00134
00136 void Mp3Reset(){
00137
00138 vs1103_recording_active = 0;
00139 vs1103_record_mixer = 1;
00140 vs1103_use_line_input = 1;
00141 vs1103_do_reset = 0;
00142 vs1103_mono_output = 0;
00143 vs1103_terminate = 0;
00144 vs1103_earSpkHi = 0;
00145 vs1103_earSpkLo = 0;
00146 vs1103_real_time_midi = 0;
00147
00148 SPISetSlowClock();
00149
00150 Mp3PutInReset();
00151 Delay(1);
00152
00153
00154 SPIPutCharWithoutWaiting(0xFF);
00155
00156
00157 Mp3DeselectControl();
00158 Mp3DeselectData();
00159 Mp3ReleaseFromReset();
00160
00161 Delay(1);
00162 while(!MP3_DREQ);
00163
00164 Mp3SetVolume(0xfe,0xfe);
00165 Mp3SetMixerVolume(0,0,0);
00166 LoadPatch();
00167 Vs1103SetMode();
00168
00169
00170 Mp3WriteRegister(SCI_CLOCKF, 0xa6, 0x96);
00171
00172
00173 Delay(500);
00174
00175 Mp3SetMixerVolume(1,1,1);
00176
00177
00178
00179
00180
00181 Mp3SetVolume(volume,volume);
00182
00183 SPISetFastClock();
00184
00185 Mp3SoftReset();
00186
00187
00188 ConsoleWrite ("\rInit: VS10XX\r");
00189
00190 }
00191
00192
00194 void VsSineTest(){
00195
00196
00197 Mp3PutInReset();
00198 Delay(100);
00199
00200
00201 SPIPutCharWithoutWaiting(0xFF);
00202
00203
00204 Mp3DeselectControl();
00205 Mp3DeselectData();
00206 Mp3ReleaseFromReset();
00207 Delay(100);
00208
00209
00210
00211
00212
00213
00214 Mp3SelectControl();
00215 SPIPutChar(0x02);
00216 SPIPutChar(0x00);
00217 SPIPutChar(0x08);
00218 SPIPutChar(0x20);
00219 SPIWait();
00220 Mp3DeselectControl();
00221
00222 while (!MP3_DREQ)
00223 ;
00224
00225
00226 Mp3SelectData();
00227
00228 SPIPutChar(0x53);
00229 SPIPutChar(0xef);
00230 SPIPutChar(0x6e);
00231 SPIPutChar(0x44);
00232 SPIPutChar(0x00);
00233 SPIPutChar(0x00);
00234 SPIPutChar(0x00);
00235 SPIPutChar(0x00);
00236 SPIWait();
00237 Mp3DeselectData();
00238
00239
00240 Delay (500);
00241
00242
00243
00244 Mp3SelectData();
00245 SPIPutChar(0x45);
00246 SPIPutChar(0x78);
00247 SPIPutChar(0x69);
00248 SPIPutChar(0x74);
00249 SPIPutChar(0x00);
00250 SPIPutChar(0x00);
00251 SPIPutChar(0x00);
00252 SPIPutChar(0x00);
00253 SPIWait();
00254 Mp3DeselectData();
00255
00256 Delay(500);
00257 }
00258
00260 void SendZerosToVS10xx(){
00261 Mp3SelectData();
00262 SPIPutCharWithoutWaiting(0);
00263 for (temp.i=0; temp.i<2048; temp.i++){
00264 while (!MP3_DREQ)
00265 ;
00266 SPIPutChar(0);
00267 }
00268 SPIWait();
00269 Mp3DeselectData();
00270 }
00271
00272
00276 unsigned char PlayDiskSectors (unsigned int nSectorsToPlay){
00277
00278 while (nSectorsToPlay){
00279
00280 if (MP3_DREQ){
00281 TransferSectorSDI(sectorAddress.l);
00282 sectorAddress.l++;
00283 nSectorsToPlay--;
00284 }
00285
00286 AvailableProcessorTime();
00287
00288
00289
00290 if ((playingState==PS_END_OF_SONG)||
00291 (playingState==PS_NEXT_SONG)||
00292 (playingState==PS_RECORDING)||
00293 (playingState==PS_PREVIOUS_SONG)){
00294 return playingState;
00295 }
00296
00297 }
00298 return 0;
00299 }
00300
00301
00302
00303 void Mp3SetMixerVolume(unsigned char gain1,
00304 unsigned char gain2,
00305 unsigned char gainInput){
00306 unsigned int i;
00307
00308 i=0x8000;
00309 i |= (gainInput << 10);
00310 i |= (gain2 << 5);
00311 i |= (gain1);
00312
00313 Mp3WriteRegister(SCI_MIXERVOL, (i >> 8), (i & 0xff));
00314
00315 }
00316
00317 void Vs1103B_SetMidiTranspose(int transpose){
00318 Mp3WriteRegister(SCI_WRAMADDR, 0x11, 0x32);
00319 while (!MP3_DREQ);
00320 Mp3WriteRegister(SCI_WRAM,(transpose >> 8),(transpose));
00321 }
00322
00323 void Vs1103B_SetChannelMask(unsigned int newMask){
00324 Mp3WriteRegister(SCI_WRAMADDR, 0x17, 0x15);
00325 while (!MP3_DREQ);
00326 Mp3WriteRegister(SCI_WRAM,(newMask >> 8),(newMask));
00327 }
00328
00329 void Vs1103SetMicGain(unsigned char gain){
00330 if (gain>31) gain=31;
00331 currentMicGain = gain;
00332 Mp3WriteRegister(SCI_ADPCMRECCTL, USE_512_BYTE_DREQ, 0x40 | gain);
00333 }
00334
00335 void Vs1103CancelWave(){
00336 Mp3WriteRegister(SCI_ADPCMRECCTL, USE_512_BYTE_DREQ, 0x80 | currentMicGain);
00337
00338 while (Mp3ReadRegister(SCI_ADPCMRECCTL) & 0x0080)
00339 ;
00340 }
00341
00342
00343 void Vs1103CancelMidi(){
00344 vs1103_terminate = 1;
00345 Vs1103SetMode();
00346 vs1103_terminate = 0;
00347
00348
00349
00350
00351
00352
00353 }