X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2Fcd_sys.c;h=03bf0d222ed8ec1781890c4f3a0bdc0d0cff2b7b;hb=6a13ef3f56a80ac698d463f5d00235ea2a090f52;hp=a482b7eb8afc424334356fc839faf2f6d77ae6c9;hpb=1cd356a33daf2eec34e52c075b06d62866f5fb2f;p=picodrive.git diff --git a/Pico/cd/cd_sys.c b/Pico/cd/cd_sys.c index a482b7e..03bf0d2 100644 --- a/Pico/cd/cd_sys.c +++ b/Pico/cd/cd_sys.c @@ -1,11 +1,18 @@ +/*********************************************************** + * * + * This source file was taken from the Gens project * + * Written by Stéphane Dallongeville * + * Copyright (c) 2002 by Stéphane Dallongeville * + * Modified/adapted for PicoDrive by notaz, 2007 * + * * + ***********************************************************/ + #include -#include "cd_sys.h" -#include "cd_file.h" #include "../PicoInt.h" +#include "cd_sys.h" +#include "cd_file.h" -#define cdprintf dprintf -//#define cdprintf(x...) #define DEBUG_CD #define TRAY_OPEN 0x0500 // TRAY OPEN CDD status @@ -17,19 +24,7 @@ #define PLAYING 0x0100 // PLAYING audio track CDD status -/* -int CDDA_Enable; - -int CD_Audio_Buffer_L[8192]; -int CD_Audio_Buffer_R[8192]; -int CD_Audio_Buffer_Read_Pos = 0; -int CD_Audio_Buffer_Write_Pos = 2000; -int CD_Audio_Starting; -*/ - static int CD_Present = 0; -// int CD_Timer_Counter = 0; // TODO: check refs - #define CHECK_TRAY_OPEN \ @@ -65,27 +60,13 @@ if (!CD_Present) \ } -#if 0 -static void MSB2DWORD(unsigned int *d, unsigned char *b) -{ - unsigned int retVal; - - retVal = (unsigned int )b[0]; - retVal = (retVal<<8) + (unsigned int )b[1]; - retVal = (retVal<<8) + (unsigned int )b[2]; - retVal = (retVal<<8) + (unsigned int )b[3]; - - *d = retVal; -} -#endif - static int MSF_to_LBA(_msf *MSF) { return (MSF->M * 60 * 75) + (MSF->S * 75) + MSF->F - 150; } -void LBA_to_MSF(int lba, _msf *MSF) +PICO_INTERNAL void LBA_to_MSF(int lba, _msf *MSF) { if (lba < -150) lba = 0; else lba += 150; @@ -139,7 +120,7 @@ static void Track_to_MSF(int track, _msf *MSF) } -int Track_to_LBA(int track) +PICO_INTERNAL int Track_to_LBA(int track) { _msf MSF; @@ -148,7 +129,7 @@ int Track_to_LBA(int track) } -void Check_CD_Command(void) +PICO_INTERNAL void Check_CD_Command(void) { cdprintf("CHECK CD COMMAND"); @@ -192,41 +173,43 @@ void Check_CD_Command(void) } -int Init_CD_Driver(void) +PICO_INTERNAL int Init_CD_Driver(void) { return 0; } -void End_CD_Driver(void) +PICO_INTERNAL void End_CD_Driver(void) { - FILE_End(); + Unload_ISO(); } -void Reset_CD(void) +PICO_INTERNAL void Reset_CD(void) { Pico_mcd->scd.Cur_Track = 0; Pico_mcd->scd.Cur_LBA = -150; - Pico_mcd->scd.Status_CDD = READY; + Pico_mcd->scd.Status_CDC &= ~1; + Pico_mcd->scd.Status_CDD = CD_Present ? READY : NOCD; Pico_mcd->scd.CDD_Complete = 0; + Pico_mcd->scd.File_Add_Delay = 0; } -int Insert_CD(char *iso_name, int is_bin) +int Insert_CD(char *cdimg_name, int type) { - int ret = 0; - -// memset(CD_Audio_Buffer_L, 0, 4096 * 4); -// memset(CD_Audio_Buffer_R, 0, 4096 * 4); + int ret = 1; CD_Present = 0; + Pico_mcd->scd.Status_CDD = NOCD; - if (iso_name != NULL) + if (cdimg_name != NULL && type != CIT_NOT_CD) { - ret = Load_ISO(iso_name, is_bin); - if (ret == 0) + ret = Load_CD_Image(cdimg_name, type); + if (ret == 0) { CD_Present = 1; + Pico_mcd->scd.Status_CDD = READY; + } } return ret; @@ -240,14 +223,15 @@ void Stop_CD(void) } -void Change_CD(void) +/* +PICO_INTERNAL void Change_CD(void) { if (Pico_mcd->scd.Status_CDD == TRAY_OPEN) Close_Tray_CDD_cC(); else Open_Tray_CDD_cD(); } +*/ - -int Get_Status_CDD_c0(void) +PICO_INTERNAL int Get_Status_CDD_c0(void) { cdprintf("Status command : Cur LBA = %d", Pico_mcd->scd.Cur_LBA); @@ -265,7 +249,7 @@ int Get_Status_CDD_c0(void) } -int Stop_CDD_c1(void) +PICO_INTERNAL int Stop_CDD_c1(void) { CHECK_TRAY_OPEN @@ -288,7 +272,7 @@ int Stop_CDD_c1(void) } -int Get_Pos_CDD_c20(void) +PICO_INTERNAL int Get_Pos_CDD_c20(void) { _msf MSF; @@ -320,7 +304,7 @@ int Get_Pos_CDD_c20(void) } -int Get_Track_Pos_CDD_c21(void) +PICO_INTERNAL int Get_Track_Pos_CDD_c21(void) { int elapsed_time; _msf MSF; @@ -354,7 +338,7 @@ int Get_Track_Pos_CDD_c21(void) } -int Get_Current_Track_CDD_c22(void) +PICO_INTERNAL int Get_Current_Track_CDD_c22(void) { cdprintf("Status CDD = %.4X Status = %.4X", Pico_mcd->scd.Status_CDD, Pico_mcd->cdd.Status); @@ -383,7 +367,7 @@ int Get_Current_Track_CDD_c22(void) } -int Get_Total_Lenght_CDD_c23(void) +PICO_INTERNAL int Get_Total_Lenght_CDD_c23(void) { CHECK_TRAY_OPEN @@ -407,7 +391,7 @@ int Get_Total_Lenght_CDD_c23(void) } -int Get_First_Last_Track_CDD_c24(void) +PICO_INTERNAL int Get_First_Last_Track_CDD_c24(void) { CHECK_TRAY_OPEN @@ -430,7 +414,7 @@ int Get_First_Last_Track_CDD_c24(void) } -int Get_Track_Adr_CDD_c25(void) +PICO_INTERNAL int Get_Track_Adr_CDD_c25(void) { int track_number; @@ -464,7 +448,7 @@ int Get_Track_Adr_CDD_c25(void) } -int Play_CDD_c3(void) +PICO_INTERNAL int Play_CDD_c3(void) { _msf MSF; int delay, new_lba; @@ -505,8 +489,7 @@ int Play_CDD_c3(void) else { Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO - //CD_Audio_Starting = 1; - FILE_Play_CD_LBA(); + cdda_start_play(); } if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02; @@ -522,7 +505,7 @@ int Play_CDD_c3(void) } -int Seek_CDD_c4(void) +PICO_INTERNAL int Seek_CDD_c4(void) { _msf MSF; @@ -560,7 +543,7 @@ int Seek_CDD_c4(void) } -int Pause_CDD_c6(void) +PICO_INTERNAL int Pause_CDD_c6(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -583,7 +566,7 @@ int Pause_CDD_c6(void) } -int Resume_CDD_c7(void) +PICO_INTERNAL int Resume_CDD_c7(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -608,8 +591,7 @@ int Resume_CDD_c7(void) else { Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO - //CD_Audio_Starting = 1; - FILE_Play_CD_LBA(); + cdda_start_play(); } if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02; @@ -625,7 +607,7 @@ int Resume_CDD_c7(void) } -int Fast_Foward_CDD_c8(void) +PICO_INTERNAL int Fast_Foward_CDD_c8(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -646,7 +628,7 @@ int Fast_Foward_CDD_c8(void) } -int Fast_Rewind_CDD_c9(void) +PICO_INTERNAL int Fast_Rewind_CDD_c9(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -667,33 +649,25 @@ int Fast_Rewind_CDD_c9(void) } -int Close_Tray_CDD_cC(void) +PICO_INTERNAL int Close_Tray_CDD_cC(void) { + CD_Present = 0; //Clear_Sound_Buffer(); Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read - { -#if 0 // TODO - char new_iso[1024]; - - memset(new_iso, 0, 1024); + elprintf(EL_STATUS, "tray close\n"); - while (!Change_File_L(new_iso, Rom_Dir, "Load SegaCD image file", "SegaCD image file\0*.bin;*.iso;*.raw\0All files\0*.*\0\0", "")); - Reload_SegaCD(new_iso); + if (PicoMCDcloseTray != NULL) + CD_Present = PicoMCDcloseTray(); - CD_Present = 1; -#else - CD_Present = 0; -#endif - Pico_mcd->scd.Status_CDD = STOPPED; - Pico_mcd->cdd.Status = 0x0000; + Pico_mcd->scd.Status_CDD = CD_Present ? STOPPED : NOCD; + Pico_mcd->cdd.Status = 0x0000; - Pico_mcd->cdd.Minute = 0; - Pico_mcd->cdd.Seconde = 0; - Pico_mcd->cdd.Frame = 0; - Pico_mcd->cdd.Ext = 0; - } + Pico_mcd->cdd.Minute = 0; + Pico_mcd->cdd.Seconde = 0; + Pico_mcd->cdd.Frame = 0; + Pico_mcd->cdd.Ext = 0; Pico_mcd->scd.CDD_Complete = 1; @@ -701,15 +675,20 @@ int Close_Tray_CDD_cC(void) } -int Open_Tray_CDD_cD(void) +PICO_INTERNAL int Open_Tray_CDD_cD(void) { CHECK_TRAY_OPEN Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read + elprintf(EL_STATUS, "tray open\n"); + Unload_ISO(); CD_Present = 0; + if (PicoMCDopenTray != NULL) + PicoMCDopenTray(); + Pico_mcd->scd.Status_CDD = TRAY_OPEN; Pico_mcd->cdd.Status = 0x0E00; @@ -724,7 +703,7 @@ int Open_Tray_CDD_cD(void) } -int CDD_cA(void) +PICO_INTERNAL int CDD_cA(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -745,7 +724,7 @@ int CDD_cA(void) } -int CDD_Def(void) +PICO_INTERNAL int CDD_Def(void) { Pico_mcd->cdd.Status = Pico_mcd->scd.Status_CDD; @@ -758,193 +737,3 @@ int CDD_Def(void) } - - -/*************************** - * Others CD functions * - **************************/ - - -// do we need them? -#if 0 -void Write_CD_Audio(short *Buf, int rate, int channel, int lenght) -{ - unsigned int lenght_src, lenght_dst; - unsigned int pos_src, pas_src; - - if (rate == 0) return; - if (Sound_Rate == 0) return; - - if (CD_Audio_Starting) - { - CD_Audio_Starting = 0; - memset(CD_Audio_Buffer_L, 0, 4096 * 4); - memset(CD_Audio_Buffer_R, 0, 4096 * 4); - CD_Audio_Buffer_Write_Pos = (CD_Audio_Buffer_Read_Pos + 2000) & 0xFFF; - } - - lenght_src = rate / 75; // 75th of a second - lenght_dst = Sound_Rate / 75; // 75th of a second - - pas_src = (lenght_src << 16) / lenght_dst; - pos_src = 0; - -#ifdef DEBUG_CD - fprintf(debug_SCD_file, "\n********* Write Pos = %d ", CD_Audio_Buffer_Write_Pos); -#endif - - if (channel == 2) - { - __asm - { - mov edi, CD_Audio_Buffer_Write_Pos - mov ebx, Buf - xor esi, esi - mov ecx, lenght_dst - xor eax, eax - mov edx, pas_src - dec ecx - jmp short loop_stereo - -align 16 - -loop_stereo: - movsx eax, word ptr [ebx + esi * 4] - mov CD_Audio_Buffer_L[edi * 4], eax - movsx eax, word ptr [ebx + esi * 4 + 2] - mov CD_Audio_Buffer_R[edi * 4], eax - mov esi, dword ptr pos_src - inc edi - add esi, edx - and edi, 0xFFF - mov dword ptr pos_src, esi - shr esi, 16 - dec ecx - jns short loop_stereo - - mov CD_Audio_Buffer_Write_Pos, edi - } - } - else - { - __asm - { - mov edi, CD_Audio_Buffer_Write_Pos - mov ebx, Buf - xor esi, esi - mov ecx, lenght_dst - xor eax, eax - mov edx, pas_src - dec ecx - jmp short loop_mono - -align 16 - -loop_mono: - movsx eax, word ptr [ebx + esi * 2] - mov CD_Audio_Buffer_L[edi * 4], eax - mov CD_Audio_Buffer_R[edi * 4], eax - mov esi, dword ptr pos_src - inc edi - add esi, edx - and edi, 0xFFF - mov dword ptr pos_src, esi - shr esi, 16 - dec ecx - jns short loop_mono - - mov CD_Audio_Buffer_Write_Pos, edi - } - } - -#ifdef DEBUG_CD - fprintf(debug_SCD_file, "Write Pos 2 = %d\n\n", CD_Audio_Buffer_Write_Pos); -#endif -} - - -void Update_CD_Audio(int **buf, int lenght) -{ - int *Buf_L, *Buf_R; - int diff; - - Buf_L = buf[0]; - Buf_R = buf[1]; - - if (Pico_mcd->s68k_regs[0x36] & 0x01) return; - if (!(Pico_mcd->scd.Status_CDC & 1)) return; - if (CD_Audio_Starting) return; - -#ifdef DEBUG_CD - fprintf(debug_SCD_file, "\n********* Read Pos Normal = %d ", CD_Audio_Buffer_Read_Pos); -#endif - - if (CD_Audio_Buffer_Write_Pos < CD_Audio_Buffer_Read_Pos) - { - diff = CD_Audio_Buffer_Write_Pos + (4096) - CD_Audio_Buffer_Read_Pos; - } - else - { - diff = CD_Audio_Buffer_Write_Pos - CD_Audio_Buffer_Read_Pos; - } - - if (diff < 500) CD_Audio_Buffer_Read_Pos -= 2000; - else if (diff > 3500) CD_Audio_Buffer_Read_Pos += 2000; - -#ifdef DEBUG_CD - else fprintf(debug_SCD_file, " pas de modifs "); -#endif - - CD_Audio_Buffer_Read_Pos &= 0xFFF; - -#ifdef DEBUG_CD - fprintf(debug_SCD_file, "Read Pos = %d ", CD_Audio_Buffer_Read_Pos); -#endif - - if (CDDA_Enable) - { - __asm - { - mov ecx, lenght - mov esi, CD_Audio_Buffer_Read_Pos - mov edi, Buf_L - dec ecx - -loop_L: - mov eax, CD_Audio_Buffer_L[esi * 4] - add [edi], eax - inc esi - add edi, 4 - and esi, 0xFFF - dec ecx - jns short loop_L - - mov ecx, lenght - mov esi, CD_Audio_Buffer_Read_Pos - mov edi, Buf_R - dec ecx - -loop_R: - mov eax, CD_Audio_Buffer_R[esi * 4] - add [edi], eax - inc esi - add edi, 4 - and esi, 0xFFF - dec ecx - jns short loop_R - - mov CD_Audio_Buffer_Read_Pos, esi - } - } - else - { - CD_Audio_Buffer_Read_Pos += lenght; - CD_Audio_Buffer_Read_Pos &= 0xFFF; - } - -#ifdef DEBUG_CD - fprintf(debug_SCD_file, "Read Pos 2 = %d\n\n", CD_Audio_Buffer_Read_Pos); -#endif -} -#endif -