-/*
-#include <stdio.h>
-#include <string.h>
-#if defined(__WIN__)
-#include <windows.h>
-#else
-#include "port.h"
-#endif
-#include "cd_sys.h"
-#include "cd_file.h"
-#include "lc89510.h"
-#include "cdda_mp3.h"
-#include "star_68k.h"
-#include "rom.h"
-#include "mem_s68k.h"
-*/
-
#include <sys/stat.h>
#include "cd_file.h"
//#define cdprintf(x...)
#define DEBUG_CD
+// TODO: check refs, move 2 context
struct _file_track Tracks[100];
char Track_Played;
int Load_ISO(const char *iso_name, int is_bin)
{
struct stat file_stat;
- int i, j, num_track, Cur_LBA, index, ret;
+ 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;
char tmp_name[1024], tmp_ext[10];
static char *exts[] = {
"%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3",
"%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3",
+ "%02d.MP3", " %02d.MP3", "-%02d.MP3", "_%02d.MP3", " - %02d.MP3",
/* "%02d.wav", " %02d.wav", "-%02d.wav", "_%02d.wav", " - %02d.wav",
"%d.wav", " %d.wav", "-%d.wav", "_%d.wav", " - %2d.wav" */
};
ret = stat(iso_name, &file_stat);
if (ret != 0) return -1;
- Tracks[0].Lenght = file_stat.st_size;
+ Tracks[0].Length = file_stat.st_size;
- if (Tracks[0].Type == TYPE_ISO) Tracks[0].Lenght >>= 11; // size in sectors
- else Tracks[0].Lenght /= 2352; // size in sectors
+ 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");
if (Tracks[0].F == NULL)
{
Tracks[0].Type = 0;
- Tracks[0].Lenght = 0;
+ Tracks[0].Length = 0;
return -1;
}
SCD_TOC_Tracks[0].Num = 1;
SCD_TOC_Tracks[0].Type = 1; // DATA
- SCD_TOC_Tracks[0].MSF.M = 0;
- SCD_TOC_Tracks[0].MSF.S = 2;
- SCD_TOC_Tracks[0].MSF.F = 0;
+ 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");
- Cur_LBA = Tracks[0].Lenght; // Size in sectors
+ 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++)
+ for (num_track = 2, i = 0; i < 100; i++)
{
- if (sizeof(exts)/sizeof(char *) != 10) { printf("eee"); exit(1); }
-
for(j = 0; j < sizeof(exts)/sizeof(char *); j++)
{
- tmp_name[strlen(iso_name) - 4] = 0;
+ int ext_len;
sprintf(tmp_ext, exts[j], i);
+ ext_len = strlen(tmp_ext);
+
+ memcpy(tmp_name, iso_name, iso_name_len + 1);
+ tmp_name[iso_name_len - 4] = 0;
strcat(tmp_name, tmp_ext);
tmp_file = fopen(tmp_name, "rb");
+ if (!tmp_file && i > 1 && iso_name_len > ext_len) {
+ tmp_name[iso_name_len - ext_len] = 0;
+ strcat(tmp_name, tmp_ext);
+ tmp_file = fopen(tmp_name, "rb");
+ }
if (tmp_file)
{
- float fs;
+ // float fs;
+ int fs;
index = num_track - Pico_mcd->scd.TOC.First_Track;
- stat(tmp_name, &file_stat);
+ ret = stat(tmp_name, &file_stat);
+ fs = file_stat.st_size; // used to calculate lenght
- fs = (float) file_stat.st_size; // used to calculate lenght
+ Tracks[index].KBtps = (short) mp3_get_bitrate(tmp_file, fs);
+ Tracks[index].KBtps >>= 3;
+ if (ret != 0 || Tracks[index].KBtps <= 0)
+ {
+ cdprintf("Error track %i: stat %i, rate %i", index, ret, Tracks[index].KBtps);
+ fclose(tmp_file);
+ continue;
+ }
Tracks[index].F = tmp_file;
LBA_to_MSF(Cur_LBA, &(SCD_TOC_Tracks[index].MSF));
- cdprintf("Track %i - %02d:%02d:%02d %s", index, SCD_TOC_Tracks[index].MSF.M,
- SCD_TOC_Tracks[index].MSF.S, SCD_TOC_Tracks[index].MSF.F,
- SCD_TOC_Tracks[index].Type ? "DATA" : "AUDIO");
-
// MP3 File
Tracks[index].Type = TYPE_MP3;
- fs /= (128>>3); // (float) (MP3_Get_Bitrate(Tracks[num_track - 1].F) >> 3);
fs *= 75;
- Tracks[index].Lenght = (int) fs;
- Cur_LBA += Tracks[index].Lenght;
+ 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");
num_track++;
break;
{
if (Tracks[i].F) fclose(Tracks[i].F);
Tracks[i].F = NULL;
- Tracks[i].Lenght = 0;
+ Tracks[i].Length = 0;
Tracks[i].Type = 0;
}
}
if (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].Lenght) where_read = Tracks[0].Lenght - 1;
+ else if (Pico_mcd->scd.Cur_LBA >= Tracks[0].Length) where_read = Tracks[0].Length - 1;
else where_read = Pico_mcd->scd.Cur_LBA;
if (Tracks[0].Type == TYPE_ISO) where_read <<= 11;
if (Tracks[index].Type == TYPE_MP3)
{
+ int pos1000 = 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;
- // MP3_Play(index, Track_LBA_Pos); // TODO
+ mp3_start_play(Tracks[index].F, pos1000);
}
else
{