-\r
-\r
-/***************************\r
- * Others CD functions *\r
- **************************/\r
-\r
-\r
-// do we need them?\r
-#if 0\r
-void Write_CD_Audio(short *Buf, int rate, int channel, int lenght)\r
-{\r
- unsigned int lenght_src, lenght_dst;\r
- unsigned int pos_src, pas_src;\r
-\r
- if (rate == 0) return;\r
- if (Sound_Rate == 0) return;\r
-\r
- if (CD_Audio_Starting)\r
- {\r
- CD_Audio_Starting = 0;\r
- memset(CD_Audio_Buffer_L, 0, 4096 * 4);\r
- memset(CD_Audio_Buffer_R, 0, 4096 * 4);\r
- CD_Audio_Buffer_Write_Pos = (CD_Audio_Buffer_Read_Pos + 2000) & 0xFFF;\r
- }\r
-\r
- lenght_src = rate / 75; // 75th of a second\r
- lenght_dst = Sound_Rate / 75; // 75th of a second\r
-\r
- pas_src = (lenght_src << 16) / lenght_dst;\r
- pos_src = 0;\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "\n********* Write Pos = %d ", CD_Audio_Buffer_Write_Pos);\r
-#endif\r
-\r
- if (channel == 2)\r
- {\r
- __asm\r
- {\r
- mov edi, CD_Audio_Buffer_Write_Pos\r
- mov ebx, Buf\r
- xor esi, esi\r
- mov ecx, lenght_dst\r
- xor eax, eax\r
- mov edx, pas_src\r
- dec ecx\r
- jmp short loop_stereo\r
-\r
-align 16\r
-\r
-loop_stereo:\r
- movsx eax, word ptr [ebx + esi * 4]\r
- mov CD_Audio_Buffer_L[edi * 4], eax\r
- movsx eax, word ptr [ebx + esi * 4 + 2]\r
- mov CD_Audio_Buffer_R[edi * 4], eax\r
- mov esi, dword ptr pos_src\r
- inc edi\r
- add esi, edx\r
- and edi, 0xFFF\r
- mov dword ptr pos_src, esi\r
- shr esi, 16\r
- dec ecx\r
- jns short loop_stereo\r
-\r
- mov CD_Audio_Buffer_Write_Pos, edi\r
- }\r
- }\r
- else\r
- {\r
- __asm\r
- {\r
- mov edi, CD_Audio_Buffer_Write_Pos\r
- mov ebx, Buf\r
- xor esi, esi\r
- mov ecx, lenght_dst\r
- xor eax, eax\r
- mov edx, pas_src\r
- dec ecx\r
- jmp short loop_mono\r
-\r
-align 16\r
-\r
-loop_mono:\r
- movsx eax, word ptr [ebx + esi * 2]\r
- mov CD_Audio_Buffer_L[edi * 4], eax\r
- mov CD_Audio_Buffer_R[edi * 4], eax\r
- mov esi, dword ptr pos_src\r
- inc edi\r
- add esi, edx\r
- and edi, 0xFFF\r
- mov dword ptr pos_src, esi\r
- shr esi, 16\r
- dec ecx\r
- jns short loop_mono\r
-\r
- mov CD_Audio_Buffer_Write_Pos, edi\r
- }\r
- }\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "Write Pos 2 = %d\n\n", CD_Audio_Buffer_Write_Pos);\r
-#endif\r
-}\r
-\r
-\r
-void Update_CD_Audio(int **buf, int lenght)\r
-{\r
- int *Buf_L, *Buf_R;\r
- int diff;\r
-\r
- Buf_L = buf[0];\r
- Buf_R = buf[1];\r
-\r
- if (Pico_mcd->s68k_regs[0x36] & 0x01) return;\r
- if (!(Pico_mcd->scd.Status_CDC & 1)) return;\r
- if (CD_Audio_Starting) return;\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "\n********* Read Pos Normal = %d ", CD_Audio_Buffer_Read_Pos);\r
-#endif\r
-\r
- if (CD_Audio_Buffer_Write_Pos < CD_Audio_Buffer_Read_Pos)\r
- {\r
- diff = CD_Audio_Buffer_Write_Pos + (4096) - CD_Audio_Buffer_Read_Pos;\r
- }\r
- else\r
- {\r
- diff = CD_Audio_Buffer_Write_Pos - CD_Audio_Buffer_Read_Pos;\r
- }\r
-\r
- if (diff < 500) CD_Audio_Buffer_Read_Pos -= 2000;\r
- else if (diff > 3500) CD_Audio_Buffer_Read_Pos += 2000;\r
-\r
-#ifdef DEBUG_CD\r
- else fprintf(debug_SCD_file, " pas de modifs ");\r
-#endif\r
-\r
- CD_Audio_Buffer_Read_Pos &= 0xFFF;\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "Read Pos = %d ", CD_Audio_Buffer_Read_Pos);\r
-#endif\r
-\r
- if (CDDA_Enable)\r
- {\r
- __asm\r
- {\r
- mov ecx, lenght\r
- mov esi, CD_Audio_Buffer_Read_Pos\r
- mov edi, Buf_L\r
- dec ecx\r
-\r
-loop_L:\r
- mov eax, CD_Audio_Buffer_L[esi * 4]\r
- add [edi], eax\r
- inc esi\r
- add edi, 4\r
- and esi, 0xFFF\r
- dec ecx\r
- jns short loop_L\r
-\r
- mov ecx, lenght\r
- mov esi, CD_Audio_Buffer_Read_Pos\r
- mov edi, Buf_R\r
- dec ecx\r
-\r
-loop_R:\r
- mov eax, CD_Audio_Buffer_R[esi * 4]\r
- add [edi], eax\r
- inc esi\r
- add edi, 4\r
- and esi, 0xFFF\r
- dec ecx\r
- jns short loop_R\r
-\r
- mov CD_Audio_Buffer_Read_Pos, esi\r
- }\r
- }\r
- else\r
- {\r
- CD_Audio_Buffer_Read_Pos += lenght;\r
- CD_Audio_Buffer_Read_Pos &= 0xFFF;\r
- }\r
-\r
-#ifdef DEBUG_CD\r
- fprintf(debug_SCD_file, "Read Pos 2 = %d\n\n", CD_Audio_Buffer_Read_Pos);\r
-#endif\r
-}\r
-#endif\r
-\r