X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2Fcd_sys.c;h=6d4cb430eeef9d3e4af1fa5520601124a33aaf9b;hb=5c69a605aeaa09798db62a4cfcce7bba4f9dc2b6;hp=72d6c0eda38022db5b082f4f3c6b7437f9b0ac16;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/Pico/cd/cd_sys.c b/Pico/cd/cd_sys.c index 72d6c0e..6d4cb43 100644 --- a/Pico/cd/cd_sys.c +++ b/Pico/cd/cd_sys.c @@ -1,11 +1,12 @@ #include #include "cd_sys.h" -//#include "cd_file.h" +#include "cd_file.h" #include "../PicoInt.h" -#define cdprintf printf +#define cdprintf dprintf //#define cdprintf(x...) +#define DEBUG_CD #define TRAY_OPEN 0x0500 // TRAY OPEN CDD status #define NOCD 0x0000 // CD removed CDD status @@ -15,18 +16,6 @@ #define FAST_REV 0x10300 // FAST REVERSE track CDD status #define PLAYING 0x0100 // PLAYING audio track CDD status -/* -#include "gens.h" -#include "G_dsound.h" -#include "cdda_mp3.h" -#include "lc89510.h" -#include "Star_68k.h" -#include "Mem_M68K.h" -#include "Mem_S68K.h" -#include "save.h" -#include "misc.h" -*/ - /* int CDDA_Enable; @@ -39,13 +28,7 @@ int CD_Audio_Starting; */ static int CD_Present = 0; -int CD_Timer_Counter = 0; // TODO: check refs - -static int CDD_Complete; - -static int File_Add_Delay = 0; - -//_scd SCD; +// int CD_Timer_Counter = 0; // TODO: check refs @@ -59,7 +42,7 @@ if (Pico_mcd->scd.Status_CDD == TRAY_OPEN) \ Pico_mcd->cdd.Frame = 0; \ Pico_mcd->cdd.Ext = 0; \ \ - CDD_Complete = 1; \ + Pico_mcd->scd.CDD_Complete = 1; \ \ return 2; \ } @@ -76,7 +59,7 @@ if (!CD_Present) \ Pico_mcd->cdd.Frame = 0; \ Pico_mcd->cdd.Ext = 0; \ \ - CDD_Complete = 1; \ + Pico_mcd->scd.CDD_Complete = 1; \ \ return 3; \ } @@ -118,19 +101,19 @@ static unsigned int MSF_to_Track(_msf *MSF) Start = (MSF->M << 16) + (MSF->S << 8) + MSF->F; - for(i = Pico_mcd->scd.TOC.First_Track; i <= (Pico_mcd->scd.TOC.Last_Track + 1); i++) + for(i = 1; i <= (Pico_mcd->TOC.Last_Track + 1); i++) { - Cur = Pico_mcd->scd.TOC.Tracks[i - Pico_mcd->scd.TOC.First_Track].MSF.M << 16; - Cur += Pico_mcd->scd.TOC.Tracks[i - Pico_mcd->scd.TOC.First_Track].MSF.S << 8; - Cur += Pico_mcd->scd.TOC.Tracks[i - Pico_mcd->scd.TOC.First_Track].MSF.F; + Cur = Pico_mcd->TOC.Tracks[i - 1].MSF.M << 16; + Cur += Pico_mcd->TOC.Tracks[i - 1].MSF.S << 8; + Cur += Pico_mcd->TOC.Tracks[i - 1].MSF.F; if (Cur > Start) break; } --i; - if (i > Pico_mcd->scd.TOC.Last_Track) return 100; - if (i < Pico_mcd->scd.TOC.First_Track) i = Pico_mcd->scd.TOC.First_Track; + if (i > Pico_mcd->TOC.Last_Track) return 100; + else if (i < 1) i = 1; return (unsigned) i; } @@ -147,12 +130,12 @@ static unsigned int LBA_to_Track(int lba) static void Track_to_MSF(int track, _msf *MSF) { - if (track < Pico_mcd->scd.TOC.First_Track) track = Pico_mcd->scd.TOC.First_Track; - else if (track > Pico_mcd->scd.TOC.Last_Track) track = Pico_mcd->scd.TOC.Last_Track; + if (track < 1) track = 1; + else if (track > Pico_mcd->TOC.Last_Track) track = Pico_mcd->TOC.Last_Track; - MSF->M = Pico_mcd->scd.TOC.Tracks[track - Pico_mcd->scd.TOC.First_Track].MSF.M; - MSF->S = Pico_mcd->scd.TOC.Tracks[track - Pico_mcd->scd.TOC.First_Track].MSF.S; - MSF->F = Pico_mcd->scd.TOC.Tracks[track - Pico_mcd->scd.TOC.First_Track].MSF.F; + MSF->M = Pico_mcd->TOC.Tracks[track - 1].MSF.M; + MSF->S = Pico_mcd->TOC.Tracks[track - 1].MSF.S; + MSF->F = Pico_mcd->TOC.Tracks[track - 1].MSF.F; } @@ -167,35 +150,31 @@ int Track_to_LBA(int track) void Check_CD_Command(void) { - cdprintf("CHECK CD COMMAND\n"); - - // Check CDD - - if (CDD_Complete) - { - CDD_Complete = 0; - - CDD_Export_Status(); - } + cdprintf("CHECK CD COMMAND"); // Check CDC - if (Pico_mcd->scd.Status_CDC & 1) // CDC is reading data ... { - cdprintf("Sending a read command\n"); + cdprintf("Got a read command"); // DATA ? - if (Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type) + if (Pico_mcd->scd.Cur_Track == 1) Pico_mcd->s68k_regs[0x36] |= 0x01; else Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO - if (File_Add_Delay == 0) + if (Pico_mcd->scd.File_Add_Delay == 0) { -#if 0 // TODO FILE_Read_One_LBA_CDC(); -#endif } - else File_Add_Delay--; + else Pico_mcd->scd.File_Add_Delay--; + } + + // Check CDD + if (Pico_mcd->scd.CDD_Complete) + { + Pico_mcd->scd.CDD_Complete = 0; + + CDD_Export_Status(); } if (Pico_mcd->scd.Status_CDD == FAST_FOW) @@ -215,19 +194,13 @@ void Check_CD_Command(void) int Init_CD_Driver(void) { -#if 0 // TODO - FILE_Init(); -#endif - return 0; } void End_CD_Driver(void) { -#if 0 // TODO FILE_End(); -#endif } @@ -235,38 +208,36 @@ void Reset_CD(void) { Pico_mcd->scd.Cur_Track = 0; Pico_mcd->scd.Cur_LBA = -150; + Pico_mcd->scd.Status_CDC &= ~1; Pico_mcd->scd.Status_CDD = READY; - CDD_Complete = 0; + Pico_mcd->scd.CDD_Complete = 0; + Pico_mcd->scd.File_Add_Delay = 0; } -int Insert_CD(char *buf, char *iso_name) +int Insert_CD(char *iso_name, int is_bin) { + int ret = 0; + // memset(CD_Audio_Buffer_L, 0, 4096 * 4); // memset(CD_Audio_Buffer_R, 0, 4096 * 4); - if (iso_name == NULL) - { - CD_Present = 0; - } - else + CD_Present = 0; + + if (iso_name != NULL) { -#if 0 // TODO - Load_ISO(buf, iso_name); - CD_Present = 1; -#endif - return 0; + ret = Load_ISO(iso_name, is_bin); + if (ret == 0) + CD_Present = 1; } - return 0; + return ret; } void Stop_CD(void) { -#if 0 // TODO Unload_ISO(); -#endif CD_Present = 0; } @@ -280,7 +251,7 @@ void Change_CD(void) int Get_Status_CDD_c0(void) { - cdprintf("Status command : Cur LBA = %d\n", Pico_mcd->scd.Cur_LBA); + cdprintf("Status command : Cur LBA = %d", Pico_mcd->scd.Cur_LBA); // Clear immediat status if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0200) @@ -290,7 +261,7 @@ int Get_Status_CDD_c0(void) else if ((Pico_mcd->cdd.Status & 0x0F00) == 0x0E00) Pico_mcd->cdd.Status = (Pico_mcd->scd.Status_CDD & 0xFF00) | (Pico_mcd->cdd.Status & 0x00FF); - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -313,7 +284,7 @@ int Stop_CDD_c1(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -323,7 +294,7 @@ int Get_Pos_CDD_c20(void) { _msf MSF; - cdprintf("command 200 : Cur LBA = %d\n", Pico_mcd->scd.Cur_LBA); + cdprintf("command 200 : Cur LBA = %d", Pico_mcd->scd.Cur_LBA); CHECK_TRAY_OPEN @@ -336,7 +307,7 @@ int Get_Pos_CDD_c20(void) // else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; - cdprintf("Status CDD = %.4X Status = %.4X\n", Pico_mcd->scd.Status_CDD, Pico_mcd->cdd.Status); + cdprintf("Status CDD = %.4X Status = %.4X", Pico_mcd->scd.Status_CDD, Pico_mcd->cdd.Status); LBA_to_MSF(Pico_mcd->scd.Cur_LBA, &MSF); @@ -345,7 +316,7 @@ int Get_Pos_CDD_c20(void) Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F); Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -372,14 +343,14 @@ int Get_Track_Pos_CDD_c21(void) elapsed_time = Pico_mcd->scd.Cur_LBA - Track_to_LBA(LBA_to_Track(Pico_mcd->scd.Cur_LBA)); LBA_to_MSF(elapsed_time - 150, &MSF); - cdprintf(" elapsed = %d\n", elapsed_time); + cdprintf(" elapsed = %d", elapsed_time); Pico_mcd->cdd.Minute = INT_TO_BCDW(MSF.M); Pico_mcd->cdd.Seconde = INT_TO_BCDW(MSF.S); Pico_mcd->cdd.Frame = INT_TO_BCDW(MSF.F); Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -387,7 +358,7 @@ int Get_Track_Pos_CDD_c21(void) int Get_Current_Track_CDD_c22(void) { - cdprintf("Status CDD = %.4X Status = %.4X\n", Pico_mcd->scd.Status_CDD, Pico_mcd->cdd.Status); + cdprintf("Status CDD = %.4X Status = %.4X", Pico_mcd->scd.Status_CDD, Pico_mcd->cdd.Status); CHECK_TRAY_OPEN @@ -408,7 +379,7 @@ int Get_Current_Track_CDD_c22(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -427,18 +398,12 @@ int Get_Total_Lenght_CDD_c23(void) // else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; - Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.TOC.Last_Track - - Pico_mcd->scd.TOC.First_Track + 1].MSF.M); - Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.TOC.Last_Track - - Pico_mcd->scd.TOC.First_Track + 1].MSF.S); - Pico_mcd->cdd.Frame = INT_TO_BCDW(Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.TOC.Last_Track - - Pico_mcd->scd.TOC.First_Track + 1].MSF.F); + Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->TOC.Tracks[Pico_mcd->TOC.Last_Track].MSF.M); + Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->TOC.Tracks[Pico_mcd->TOC.Last_Track].MSF.S); + Pico_mcd->cdd.Frame = INT_TO_BCDW(Pico_mcd->TOC.Tracks[Pico_mcd->TOC.Last_Track].MSF.F); Pico_mcd->cdd.Ext = 0; -// FIXME: remove -Pico_mcd->cdd.Seconde = 2; - - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -456,15 +421,12 @@ int Get_First_Last_Track_CDD_c24(void) // else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; - Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.TOC.First_Track); - Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->scd.TOC.Last_Track); + Pico_mcd->cdd.Minute = INT_TO_BCDW(1); + Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->TOC.Last_Track); Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; -// FIXME: remove -Pico_mcd->cdd.Minute = Pico_mcd->cdd.Seconde = 1; - - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -489,17 +451,17 @@ int Get_Track_Adr_CDD_c25(void) // else if (!(CDC.CTRL.B.B0 & 0x80)) Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; Pico_mcd->cdd.Status |= Pico_mcd->scd.Status_CDD; - if (track_number > Pico_mcd->scd.TOC.Last_Track) track_number = Pico_mcd->scd.TOC.Last_Track; - else if (track_number < Pico_mcd->scd.TOC.First_Track) track_number = Pico_mcd->scd.TOC.First_Track; + if (track_number > Pico_mcd->TOC.Last_Track) track_number = Pico_mcd->TOC.Last_Track; + else if (track_number < 1) track_number = 1; - Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->scd.TOC.Tracks[track_number - Pico_mcd->scd.TOC.First_Track].MSF.M); - Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->scd.TOC.Tracks[track_number - Pico_mcd->scd.TOC.First_Track].MSF.S); - Pico_mcd->cdd.Frame = INT_TO_BCDW(Pico_mcd->scd.TOC.Tracks[track_number - Pico_mcd->scd.TOC.First_Track].MSF.F); + Pico_mcd->cdd.Minute = INT_TO_BCDW(Pico_mcd->TOC.Tracks[track_number - 1].MSF.M); + Pico_mcd->cdd.Seconde = INT_TO_BCDW(Pico_mcd->TOC.Tracks[track_number - 1].MSF.S); + Pico_mcd->cdd.Frame = INT_TO_BCDW(Pico_mcd->TOC.Tracks[track_number - 1].MSF.F); Pico_mcd->cdd.Ext = track_number % 10; - if (Pico_mcd->scd.TOC.Tracks[track_number - Pico_mcd->scd.TOC.First_Track].Type) Pico_mcd->cdd.Frame |= 0x0800; + if (track_number == 1) Pico_mcd->cdd.Frame |= 0x0800; // data track - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -528,7 +490,7 @@ int Play_CDD_c3(void) Pico_mcd->scd.Cur_LBA = new_lba; CDC_Update_Header(); - cdprintf("Read : Cur LBA = %d, M=%d, S=%d, F=%d\n", Pico_mcd->scd.Cur_LBA, MSF.M, MSF.S, MSF.F); + cdprintf("Read : Cur LBA = %d, M=%d, S=%d, F=%d", Pico_mcd->scd.Cur_LBA, MSF.M, MSF.S, MSF.F); if (Pico_mcd->scd.Status_CDD != PLAYING) delay += 20; @@ -536,9 +498,9 @@ int Play_CDD_c3(void) Pico_mcd->cdd.Status = 0x0102; // Pico_mcd->cdd.Status = COMM_OK; - if (File_Add_Delay == 0) File_Add_Delay = delay; + if (Pico_mcd->scd.File_Add_Delay == 0) Pico_mcd->scd.File_Add_Delay = delay; - if (Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type) + if (Pico_mcd->scd.Cur_Track == 1) { Pico_mcd->s68k_regs[0x36] |= 0x01; // DATA } @@ -546,9 +508,7 @@ int Play_CDD_c3(void) { Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO //CD_Audio_Starting = 1; -#if 0 // TODO FILE_Play_CD_LBA(); -#endif } if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02; @@ -559,7 +519,7 @@ int Play_CDD_c3(void) Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -587,7 +547,7 @@ int Seek_CDD_c4(void) Pico_mcd->cdd.Status = 0x0200; // DATA ? - if (Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type) + if (Pico_mcd->scd.Cur_Track == 1) Pico_mcd->s68k_regs[0x36] |= 0x01; else Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO @@ -596,7 +556,7 @@ int Seek_CDD_c4(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -619,7 +579,7 @@ int Pause_CDD_c6(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -636,14 +596,14 @@ int Resume_CDD_c7(void) { _msf MSF; LBA_to_MSF(Pico_mcd->scd.Cur_LBA, &MSF); - cdprintf("Resume read : Cur LBA = %d, M=%d, S=%d, F=%d\n", Pico_mcd->scd.Cur_LBA, MSF.M, MSF.S, MSF.F); + cdprintf("Resume read : Cur LBA = %d, M=%d, S=%d, F=%d", Pico_mcd->scd.Cur_LBA, MSF.M, MSF.S, MSF.F); } #endif Pico_mcd->scd.Status_CDD = PLAYING; Pico_mcd->cdd.Status = 0x0102; - if (Pico_mcd->scd.TOC.Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type) + if (Pico_mcd->scd.Cur_Track == 1) { Pico_mcd->s68k_regs[0x36] |= 0x01; // DATA } @@ -651,9 +611,7 @@ int Resume_CDD_c7(void) { Pico_mcd->s68k_regs[0x36] &= ~0x01; // AUDIO //CD_Audio_Starting = 1; -#if 0 // TODO FILE_Play_CD_LBA(); -#endif } if (Pico_mcd->scd.Cur_Track == 100) Pico_mcd->cdd.Minute = 0x0A02; @@ -664,12 +622,12 @@ int Resume_CDD_c7(void) Pico_mcd->scd.Status_CDC |= 1; // Read data with CDC - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } -int Fast_Foward_CDD_c8(void) +int Fast_Foward_CDD_c8(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -684,13 +642,13 @@ int Fast_Foward_CDD_c8(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } -int Fast_Rewind_CDD_c9(void) +int Fast_Rewind_CDD_c9(void) { CHECK_TRAY_OPEN CHECK_CD_PRESENT @@ -705,7 +663,7 @@ int Fast_Rewind_CDD_c9(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -739,7 +697,7 @@ int Close_Tray_CDD_cC(void) Pico_mcd->cdd.Ext = 0; } - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -751,9 +709,7 @@ int Open_Tray_CDD_cD(void) Pico_mcd->scd.Status_CDC &= ~1; // Stop CDC read -#if 0 // TODO Unload_ISO(); -#endif CD_Present = 0; Pico_mcd->scd.Status_CDD = TRAY_OPEN; @@ -764,7 +720,7 @@ int Open_Tray_CDD_cD(void) Pico_mcd->cdd.Frame = 0; Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; } @@ -785,7 +741,7 @@ int CDD_cA(void) Pico_mcd->cdd.Frame = INT_TO_BCDW(1); Pico_mcd->cdd.Ext = 0; - CDD_Complete = 1; + Pico_mcd->scd.CDD_Complete = 1; return 0; }