X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=Pico%2Fcd%2Fcd_file.c;h=a827a0c779e28db41b325becb5f7c63641c5d840;hb=83bd0b76aba19ff62368cfee76089e15579e3b7c;hp=cb78675c72b45ab1349d7d678b85bb415b005ad0;hpb=51a902ae2512cffdb3ac7751988c1bde4a641be4;p=picodrive.git diff --git a/Pico/cd/cd_file.c b/Pico/cd/cd_file.c index cb78675..a827a0c 100644 --- a/Pico/cd/cd_file.c +++ b/Pico/cd/cd_file.c @@ -7,19 +7,6 @@ //#define cdprintf(x...) #define DEBUG_CD -// TODO: check refs, move 2 context -struct _file_track Tracks[100]; -char Track_Played; - - -int FILE_Init(void) -{ -// MP3_Init(); // TODO - Unload_ISO(); - - return 0; -} - void FILE_End(void) { @@ -29,11 +16,10 @@ void FILE_End(void) int Load_ISO(const char *iso_name, int is_bin) { - struct stat file_stat; int i, j, num_track, Cur_LBA, index, ret, iso_name_len; - _scd_track *SCD_TOC_Tracks = Pico_mcd->scd.TOC.Tracks; - FILE *tmp_file; + _scd_track *Tracks = Pico_mcd->TOC.Tracks; char tmp_name[1024], tmp_ext[10]; + pm_file *pmf; static char *exts[] = { "%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3", "%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3", @@ -44,46 +30,28 @@ int Load_ISO(const char *iso_name, int is_bin) Unload_ISO(); - Tracks[0].Type = is_bin ? TYPE_BIN : TYPE_ISO; - - ret = stat(iso_name, &file_stat); - if (ret != 0) return -1; + Tracks[0].ftype = is_bin ? TYPE_BIN : TYPE_ISO; - Tracks[0].Length = file_stat.st_size; - - if (Tracks[0].Type == TYPE_ISO) Tracks[0].Length >>= 11; // size in sectors - else Tracks[0].Length /= 2352; // size in sectors - - - Tracks[0].F = fopen(iso_name, "rb"); + Tracks[0].F = pmf = pm_open(iso_name); if (Tracks[0].F == NULL) { - Tracks[0].Type = 0; + Tracks[0].ftype = 0; Tracks[0].Length = 0; return -1; } - if (Tracks[0].Type == TYPE_ISO) fseek(Tracks[0].F, 0x100, SEEK_SET); - else fseek(Tracks[0].F, 0x110, SEEK_SET); - - // fread(buf, 1, 0x200, Tracks[0].F); - fseek(Tracks[0].F, 0, SEEK_SET); - - Pico_mcd->scd.TOC.First_Track = 1; + if (Tracks[0].ftype == TYPE_ISO) + Tracks[0].Length = pmf->size >>= 11; // size in sectors + else Tracks[0].Length = pmf->size /= 2352; - SCD_TOC_Tracks[0].Num = 1; - SCD_TOC_Tracks[0].Type = 1; // DATA + Tracks[0].MSF.M = 0; // minutes + Tracks[0].MSF.S = 2; // seconds + Tracks[0].MSF.F = 0; // frames - SCD_TOC_Tracks[0].MSF.M = 0; // minutes - SCD_TOC_Tracks[0].MSF.S = 2; // seconds - SCD_TOC_Tracks[0].MSF.F = 0; // frames - - cdprintf("Track 0 - %02d:%02d:%02d %s", SCD_TOC_Tracks[0].MSF.M, SCD_TOC_Tracks[0].MSF.S, SCD_TOC_Tracks[0].MSF.F, - SCD_TOC_Tracks[0].Type ? "DATA" : "AUDIO"); + cdprintf("Track 0 - %02d:%02d:%02d DATA", Tracks[0].MSF.M, Tracks[0].MSF.S, Tracks[0].MSF.F); Cur_LBA = Tracks[0].Length; // Size in sectors - strcpy(tmp_name, iso_name); iso_name_len = strlen(iso_name); for (num_track = 2, i = 0; i < 100; i++) @@ -91,6 +59,7 @@ int Load_ISO(const char *iso_name, int is_bin) for(j = 0; j < sizeof(exts)/sizeof(char *); j++) { int ext_len; + FILE *tmp_file; sprintf(tmp_ext, exts[j], i); ext_len = strlen(tmp_ext); @@ -107,9 +76,9 @@ int Load_ISO(const char *iso_name, int is_bin) if (tmp_file) { - // float fs; int fs; - index = num_track - Pico_mcd->scd.TOC.First_Track; + struct stat file_stat; + index = num_track - 1; ret = stat(tmp_name, &file_stat); fs = file_stat.st_size; // used to calculate lenght @@ -125,21 +94,17 @@ int Load_ISO(const char *iso_name, int is_bin) Tracks[index].F = tmp_file; - SCD_TOC_Tracks[index].Num = num_track; - SCD_TOC_Tracks[index].Type = 0; // AUDIO - - LBA_to_MSF(Cur_LBA, &(SCD_TOC_Tracks[index].MSF)); + LBA_to_MSF(Cur_LBA, &Tracks[index].MSF); // MP3 File - Tracks[index].Type = TYPE_MP3; + Tracks[index].ftype = TYPE_MP3; fs *= 75; fs /= Tracks[index].KBtps * 1000; Tracks[index].Length = fs; Cur_LBA += Tracks[index].Length; - cdprintf("Track %i: %s - %02d:%02d:%02d len=%i %s", index, tmp_name, SCD_TOC_Tracks[index].MSF.M, - SCD_TOC_Tracks[index].MSF.S, SCD_TOC_Tracks[index].MSF.F, fs, - SCD_TOC_Tracks[index].Type ? "DATA" : "AUDIO"); + cdprintf("Track %i: %s - %02d:%02d:%02d len=%i AUDIO", index, tmp_name, Tracks[index].MSF.M, + Tracks[index].MSF.S, Tracks[index].MSF.F, fs); num_track++; break; @@ -147,16 +112,14 @@ int Load_ISO(const char *iso_name, int is_bin) } } - Pico_mcd->scd.TOC.Last_Track = num_track - 1; + Pico_mcd->TOC.Last_Track = num_track - 1; - index = num_track - Pico_mcd->scd.TOC.First_Track; - SCD_TOC_Tracks[index].Num = num_track; - SCD_TOC_Tracks[index].Type = 0; + index = num_track - 1; - LBA_to_MSF(Cur_LBA, &(SCD_TOC_Tracks[index].MSF)); + LBA_to_MSF(Cur_LBA, &Tracks[index].MSF); - cdprintf("End CD - %02d:%02d:%02d\n\n", SCD_TOC_Tracks[index].MSF.M, - SCD_TOC_Tracks[index].MSF.S, SCD_TOC_Tracks[index].MSF.F); + cdprintf("End CD - %02d:%02d:%02d\n\n", Tracks[index].MSF.M, + Tracks[index].MSF.S, Tracks[index].MSF.F); return 0; } @@ -166,36 +129,39 @@ void Unload_ISO(void) { int i; - Track_Played = 99; + if (Pico_mcd == NULL) return; - for(i = 0; i < 100; i++) + if (Pico_mcd->TOC.Tracks[0].F) pm_close(Pico_mcd->TOC.Tracks[0].F); + + for(i = 1; i < 100; i++) { - if (Tracks[i].F) fclose(Tracks[i].F); - Tracks[i].F = NULL; - Tracks[i].Length = 0; - Tracks[i].Type = 0; + if (Pico_mcd->TOC.Tracks[i].F) fclose(Pico_mcd->TOC.Tracks[i].F); } + memset(Pico_mcd->TOC.Tracks, 0, sizeof(Pico_mcd->TOC.Tracks)); } int FILE_Read_One_LBA_CDC(void) { - int where_read; - static char cp_buf[2560]; + int where_read = 0; +// static char cp_buf[2560]; if (Pico_mcd->s68k_regs[0x36] & 1) // DATA { - if (Tracks[0].F == NULL) return -1; + if (Pico_mcd->TOC.Tracks[0].F == NULL) return -1; - if (Pico_mcd->scd.Cur_LBA < 0) where_read = 0; - else if (Pico_mcd->scd.Cur_LBA >= Tracks[0].Length) where_read = Tracks[0].Length - 1; + if (Pico_mcd->scd.Cur_LBA < 0) + where_read = 0; + else if (Pico_mcd->scd.Cur_LBA >= Pico_mcd->TOC.Tracks[0].Length) + where_read = Pico_mcd->TOC.Tracks[0].Length - 1; else where_read = Pico_mcd->scd.Cur_LBA; - if (Tracks[0].Type == TYPE_ISO) where_read <<= 11; + if (Pico_mcd->TOC.Tracks[0].ftype == TYPE_ISO) where_read <<= 11; else where_read = (where_read * 2352 + 16); - fseek(Tracks[0].F, where_read, SEEK_SET); - fread(cp_buf, 1, 2048, Tracks[0].F); + // moved below.. + //fseek(Pico_mcd->TOC.Tracks[0].F, where_read, SEEK_SET); + //fread(cp_buf, 1, 2048, Pico_mcd->TOC.Tracks[0].F); cdprintf("Read file CDC 1 data sector :\n"); } @@ -203,7 +169,7 @@ int FILE_Read_One_LBA_CDC(void) { // int rate, channel; - if (Tracks[Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track].Type == TYPE_MP3) + if (Pico_mcd->TOC.Tracks[Pico_mcd->scd.Cur_Track - 1].ftype == TYPE_MP3) { // TODO // MP3_Update(cp_buf, &rate, &channel, 0); @@ -230,8 +196,11 @@ int FILE_Read_One_LBA_CDC(void) Pico_mcd->cdc.WA.N = (Pico_mcd->cdc.WA.N + 2352) & 0x7FFF; // add one sector to WA Pico_mcd->cdc.PT.N = (Pico_mcd->cdc.PT.N + 2352) & 0x7FFF; - memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N + 4], cp_buf, 2048); - memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N], &Pico_mcd->cdc.HEAD, 4); + *(unsigned int *)(Pico_mcd->cdc.Buffer + Pico_mcd->cdc.PT.N) = Pico_mcd->cdc.HEAD.N; + //memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N + 4], cp_buf, 2048); + + pm_seek(Pico_mcd->TOC.Tracks[0].F, where_read, SEEK_SET); + pm_read(Pico_mcd->cdc.Buffer + Pico_mcd->cdc.PT.N + 4, 2048, Pico_mcd->TOC.Tracks[0].F); #ifdef DEBUG_CD cdprintf("Read -> WA = %d Buffer[%d] =", Pico_mcd->cdc.WA.N, Pico_mcd->cdc.PT.N & 0x3FFF); @@ -262,7 +231,7 @@ int FILE_Read_One_LBA_CDC(void) { // CAUTION : lookahead bit not implemented - memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N], cp_buf, 2352); + //memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N], cp_buf, 2352); } } } @@ -291,8 +260,8 @@ int FILE_Read_One_LBA_CDC(void) SekInterruptS68k(5); } - Pico_mcd->cdc.IFSTAT &= ~0x20; // DEC interrupt happen - CDC_Decode_Reg_Read = 0; // Reset read after DEC int + Pico_mcd->cdc.IFSTAT &= ~0x20; // DEC interrupt happen + Pico_mcd->cdc.Decode_Reg_Read = 0; // Reset read after DEC int } } @@ -303,24 +272,25 @@ int FILE_Read_One_LBA_CDC(void) int FILE_Play_CD_LBA(void) { - int index = Pico_mcd->scd.Cur_Track - Pico_mcd->scd.TOC.First_Track; + int index = Pico_mcd->scd.Cur_Track - 1; + Pico_mcd->m.audio_track = index; - cdprintf("Play FILE Comp"); + cdprintf("Play track #%i", Pico_mcd->scd.Cur_Track); - if (Tracks[index].F == NULL) + if (Pico_mcd->TOC.Tracks[index].F == NULL) { return 1; } - if (Tracks[index].Type == TYPE_MP3) + if (Pico_mcd->TOC.Tracks[index].ftype == TYPE_MP3) { - int pos1000 = 0; + int pos1024 = 0; int Track_LBA_Pos = Pico_mcd->scd.Cur_LBA - Track_to_LBA(Pico_mcd->scd.Cur_Track); if (Track_LBA_Pos < 0) Track_LBA_Pos = 0; if (Track_LBA_Pos) - pos1000 = Track_LBA_Pos * 1024 / Tracks[index].Length; + pos1024 = Track_LBA_Pos * 1024 / Pico_mcd->TOC.Tracks[index].Length; - mp3_start_play(Tracks[index].F, pos1000); + mp3_start_play(Pico_mcd->TOC.Tracks[index].F, pos1024); } else {