savestates works

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@26 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-01-29 23:39:15 +00:00
parent 51a902ae25
commit 7573607016
16 changed files with 219 additions and 161 deletions

View file

@ -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)
{
@ -31,7 +18,7 @@ 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;
_scd_track *Tracks = Pico_mcd->TOC.Tracks;
FILE *tmp_file;
char tmp_name[1024], tmp_ext[10];
static char *exts[] = {
@ -44,42 +31,36 @@ int Load_ISO(const char *iso_name, int is_bin)
Unload_ISO();
Tracks[0].Type = is_bin ? TYPE_BIN : TYPE_ISO;
Tracks[0].ftype = is_bin ? TYPE_BIN : TYPE_ISO;
ret = stat(iso_name, &file_stat);
if (ret != 0) return -1;
Tracks[0].Length = file_stat.st_size;
if (Tracks[0].Type == TYPE_ISO) Tracks[0].Length >>= 11; // size in sectors
if (Tracks[0].ftype == 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].ftype = 0;
Tracks[0].Length = 0;
return -1;
}
if (Tracks[0].Type == TYPE_ISO) fseek(Tracks[0].F, 0x100, SEEK_SET);
if (Tracks[0].ftype == 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;
Tracks[0].MSF.M = 0; // minutes
Tracks[0].MSF.S = 2; // seconds
Tracks[0].MSF.F = 0; // frames
SCD_TOC_Tracks[0].Num = 1;
SCD_TOC_Tracks[0].Type = 1; // DATA
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
@ -109,7 +90,7 @@ int Load_ISO(const char *iso_name, int is_bin)
{
// float fs;
int fs;
index = num_track - Pico_mcd->scd.TOC.First_Track;
index = num_track - 1;
ret = stat(tmp_name, &file_stat);
fs = file_stat.st_size; // used to calculate lenght
@ -125,21 +106,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 +124,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 +141,39 @@ void Unload_ISO(void)
{
int i;
Track_Played = 99;
if (Pico_mcd == NULL) return;
for(i = 0; 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);
Pico_mcd->TOC.Tracks[i].F = NULL;
Pico_mcd->TOC.Tracks[i].Length = 0;
Pico_mcd->TOC.Tracks[i].ftype = 0;
}
}
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 +181,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 +208,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);
//memcpy(&Pico_mcd->cdc.Buffer[Pico_mcd->cdc.PT.N + 4], cp_buf, 2048);
fseek(Pico_mcd->TOC.Tracks[0].F, where_read, SEEK_SET);
fread(Pico_mcd->cdc.Buffer + Pico_mcd->cdc.PT.N + 4, 1, 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 +243,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 +272,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 +284,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
{