00001 00004 #define btUNKNOWN 0 00005 #define btLIST 1 00006 #define btSTR 2 00007 #define btAUDIO 3 00008 00009 00010 #define GetLongWord() {instream.b.b0 = FGetChar(); \ 00011 instream.b.b1 = FGetChar();\ 00012 instream.b.b2 = FGetChar();\ 00013 instream.b.b3 = FGetChar();} 00014 00015 void GetAVIBlock(){ 00016 00017 xdata addressType instream; 00018 xdata unsigned char blockType = 0; 00019 bit isPadded = 0; 00020 00021 GetLongWord(); 00022 if ((instream.b.b2 == 'w') && (instream.b.b3 == 'b')){ 00023 blockType = btAUDIO; 00024 } 00025 if (instream.l==1414744396){ //LIST 00026 blockType = btLIST; 00027 } 00028 GetLongWord(); 00029 //instream.l should now contain the chunk size. 00030 //its length must be even by spec. if it's odd, a pad byte is 00031 //in the file but its NOT part of chunk data. 00032 if (instream.b.b0&1){ 00033 isPadded = 1; //There is a pad byte to make chunk len even 00034 }else{ 00035 isPadded = 0; 00036 } 00037 00038 00039 if (blockType == btAUDIO){ 00040 //--------THIS PACKET IS SENT TO VS10xx--------- 00041 //superbly hilarious effects could happen if the avifile has 00042 //more than 1 soundtrack as all of them would be sent to VS10xx 00043 00044 while(instream.l){ 00045 unsigned char c; 00046 00047 while ((instream.l>16)&&(dataBufPtr < diskSect.raw.buf+496)){ 00048 //We have at least 16 octets of continuous stream in mem. 00049 if (!MP3_DREQ){ 00050 GREEN_LED = LED_ON; 00051 while (!MP3_DREQ){ 00052 Mp3DeselectData(); 00053 AvailableProcessorTime(); 00054 } 00055 } 00056 GREEN_LED = LED_OFF; 00057 Mp3SelectData(); 00058 SPIPutCharWithoutWaiting(*dataBufPtr++); 00059 SPIWait(); 00060 SPIPutChar(*dataBufPtr++); 00061 SPIPutChar(*dataBufPtr++); 00062 SPIPutChar(*dataBufPtr++); 00063 SPIPutChar(*dataBufPtr++); 00064 SPIPutChar(*dataBufPtr++); 00065 SPIPutChar(*dataBufPtr++); 00066 SPIPutChar(*dataBufPtr++); 00067 SPIPutChar(*dataBufPtr++); 00068 SPIPutChar(*dataBufPtr++); 00069 SPIPutChar(*dataBufPtr++); 00070 SPIPutChar(*dataBufPtr++); 00071 SPIPutChar(*dataBufPtr++); 00072 SPIPutChar(*dataBufPtr++); 00073 SPIPutChar(*dataBufPtr++); 00074 SPIPutChar(*dataBufPtr++); 00075 instream.l-=16; 00076 fileSize-=16; 00077 SPIWait(); 00078 } 00079 00080 MP3_XDCS=1; 00081 instream.l--; 00082 c=FGetChar(); //data comes first until end of sector and 00083 //then a new sector is loaded automagically. 00084 MP3_XDCS=0; 00085 SPIPutCharWithoutWaiting(c); 00086 //SPIWait(); 00087 } 00088 MP3_XDCS=1; 00089 }else if (blockType == btLIST){ 00090 ConsoleWrite("\rAVI: List of "); 00091 GetLongWord(); 00092 ConsolePutChar(instream.b.b0); 00093 ConsolePutChar(instream.b.b1); 00094 ConsolePutChar(instream.b.b2); 00095 ConsolePutChar(instream.b.b3); 00096 00097 }else{ 00098 //We don't need this chunk. Let's quickly skip over it. 00099 00100 //Is pad byte insertion needed? 00101 if (isPadded){ 00102 instream.l++; //instream.l contains chunk size 00103 isPadded = 0; 00104 } 00105 00106 //Skip to the end of sector 00107 if (instream.l>(temp.i=diskSect.raw.buf+512-dataBufPtr)){ 00108 //The packet continues after end of sector 00109 instream.l -= temp.i; 00110 fileSize -= temp.i; 00111 sectorAddress.l++; //Sector handled, go to next. 00112 dataBufPtr = 0; //Complete sector is handled. 00113 } 00114 00115 //Skip unnecessary sectors 00116 if (instream.l>512){ 00117 while (instream.l>512){ 00118 sectorAddress.l++; 00119 instream.l -= 512; 00120 fileSize -= 512; 00121 } 00122 dataBufPtr = 0; //Initialize for next call to FGetChar(); 00123 } 00124 00125 //Read last sector into memory 00126 if (dataBufPtr == 0){ 00127 ReadDiskSector(sectorAddress.l); 00128 dataBufPtr = diskSect.raw.buf; 00129 } 00130 while (instream.l--){ 00131 dataBufPtr++; 00132 } 00133 }//nothing interesting,skip block 00134 00135 if (isPadded){ 00136 FGetChar(); 00137 } 00138 00139 } 00140 00144 unsigned char PlayAvi(){ 00145 00146 ReadDiskSector(sectorAddress.l); 00147 00148 //DumpDiskSector(); 00149 00150 if (diskSect.raw.buf[8]!='A') return 0x11; 00151 if (diskSect.raw.buf[9]!='V') return 0x11; 00152 if (diskSect.raw.buf[10]!='I') return 0x11; 00153 ConsoleWrite("\rPlayAvi()\r"); 00154 00155 dataBufPtr=diskSect.raw.buf+12; 00156 00157 while(fileSize){ 00158 GetAVIBlock(); 00159 } 00160 00161 return 0; 00162 } 00163