Merge pull request #877 from srg320/master
Saturn: add support for multi-index tracks, send disc system ID data to FPGA
This commit is contained in:
11
cd.h
11
cd.h
@@ -19,7 +19,8 @@ typedef struct
|
||||
int end;
|
||||
int type;
|
||||
int sector_size;
|
||||
int index1;
|
||||
int indexes[100];
|
||||
int index_num;
|
||||
cd_subcode_types_t sbc_type;
|
||||
} cd_track_t;
|
||||
|
||||
@@ -38,6 +39,14 @@ typedef struct
|
||||
while ((this->tracks[i].end <= lba) && (i < this->last)) i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
int GetIndexByLBA(int track, int lba)
|
||||
{
|
||||
int i = 1;
|
||||
while ((lba - this->tracks[track].start >= this->tracks[track].indexes[i]) && (i < this->tracks[track].index_num)) i++;
|
||||
i--;
|
||||
return i;
|
||||
}
|
||||
} toc_t;
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -30,6 +30,8 @@ int mister_chd_log(const char *format, ...)
|
||||
|
||||
chd_error mister_load_chd(const char *filename, toc_t *cd_toc)
|
||||
{
|
||||
cd_toc->last = -1;
|
||||
|
||||
chd_error err = chd_open(getFullPath(filename), CHD_OPEN_READ, NULL, &cd_toc->chd_f);
|
||||
if (err != CHDERR_NONE)
|
||||
{
|
||||
@@ -78,6 +80,7 @@ chd_error mister_load_chd(const char *filename, toc_t *cd_toc)
|
||||
pregap_valid = false;
|
||||
|
||||
}
|
||||
|
||||
if (cd_toc->last)
|
||||
{
|
||||
if (!pregap_valid)
|
||||
@@ -91,7 +94,7 @@ chd_error mister_load_chd(const char *filename, toc_t *cd_toc)
|
||||
cd_toc->tracks[cd_toc->last].start += pregap;
|
||||
}
|
||||
|
||||
cd_toc->tracks[cd_toc->last].index1 = pregap;
|
||||
cd_toc->tracks[cd_toc->last].indexes[1] = pregap;
|
||||
}
|
||||
else {
|
||||
if (pregap_valid)
|
||||
@@ -101,8 +104,9 @@ chd_error mister_load_chd(const char *filename, toc_t *cd_toc)
|
||||
else {
|
||||
cd_toc->tracks[cd_toc->last].start = 0;
|
||||
}
|
||||
cd_toc->tracks[cd_toc->last].index1 = pregap;
|
||||
cd_toc->tracks[cd_toc->last].indexes[1] = pregap;
|
||||
}
|
||||
cd_toc->tracks[cd_toc->last].index_num = 2;
|
||||
|
||||
if (!pregap_valid)
|
||||
{
|
||||
|
||||
@@ -141,12 +141,12 @@ static int load_chd(const char *filename, toc_t *table)
|
||||
{
|
||||
if (i == 0) //First track fakes a pregap even if it doesn't exist
|
||||
{
|
||||
table->tracks[i].index1 = 150;
|
||||
table->tracks[i].indexes[1] = 150;
|
||||
table->tracks[i].start = 150;
|
||||
table->tracks[i].end += 150-1;
|
||||
} else {
|
||||
int frame_cnt = table->tracks[i].end - table->tracks[i].start;
|
||||
frame_cnt += table->tracks[i].index1;
|
||||
frame_cnt += table->tracks[i].indexes[1];
|
||||
table->tracks[i].start = table->tracks[i-1].end + 1;
|
||||
table->tracks[i].end = table->tracks[i].start + frame_cnt - 1;
|
||||
}
|
||||
@@ -290,23 +290,23 @@ static int load_cue(const char* filename, toc_t *table)
|
||||
table->tracks[table->last-1].end = table->tracks[table->last].start-1;
|
||||
if (pregap)
|
||||
{
|
||||
table->tracks[table->last].index1 = table->tracks[table->last].start - pregap;
|
||||
table->tracks[table->last].indexes[1] = table->tracks[table->last].start - pregap;
|
||||
if (!table->tracks[table->last].pregap)
|
||||
{
|
||||
table->tracks[table->last].offset -= 2352*table->tracks[table->last].index1;
|
||||
table->tracks[table->last].index1 = table->tracks[table->last].start - pregap;
|
||||
table->tracks[table->last].offset -= 2352*table->tracks[table->last].indexes[1];
|
||||
table->tracks[table->last].indexes[1] = table->tracks[table->last].start - pregap;
|
||||
} else {
|
||||
table->tracks[table->last].index1 = pregap;
|
||||
table->tracks[table->last].indexes[1] = pregap;
|
||||
}
|
||||
}
|
||||
} else if (table->tracks[table->last].type) {
|
||||
table->tracks[table->last].index1 = 150;
|
||||
table->tracks[table->last].indexes[1] = 150;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
table->tracks[table->last].index1 = bb + ss * 75 + mm * 60 * 75;
|
||||
if (table->tracks[table->last].type && !table->last) table->tracks[table->last].index1 = 150;
|
||||
table->tracks[table->last].indexes[1] = bb + ss * 75 + mm * 60 * 75;
|
||||
if (table->tracks[table->last].type && !table->last) table->tracks[table->last].indexes[1] = 150;
|
||||
table->tracks[table->last].start = table->end;
|
||||
table->end += (table->tracks[table->last].f.size / table->tracks[table->last].sector_size);
|
||||
table->tracks[table->last].end = table->end - 1;
|
||||
@@ -327,8 +327,8 @@ static int load_cue(const char* filename, toc_t *table)
|
||||
for (int i = 0; i < table->last; i++)
|
||||
{
|
||||
printf("\x1b[32mPSX: Track = %u, start = %u, end = %u, offset = %d, sector_size=%d, type = %u\n\x1b[0m", i, table->tracks[i].start, table->tracks[i].end, table->tracks[i].offset, table->tracks[i].sector_size, table->tracks[i].type);
|
||||
if (table->tracks[i].index1)
|
||||
printf("\x1b[32mPSX: Track = %u,Index1 = %u seconds\n\x1b[0m", i, table->tracks[i].index1 / 75);
|
||||
if (table->tracks[i].indexes[1])
|
||||
printf("\x1b[32mPSX: Track = %u,Index1 = %u seconds\n\x1b[0m", i, table->tracks[i].indexes[1] / 75);
|
||||
|
||||
}*/
|
||||
|
||||
@@ -401,7 +401,7 @@ static void send_cue_and_metadata(toc_t *table, uint16_t libcrypt_mask, enum reg
|
||||
for (int i = 0; i < table->last; i++)
|
||||
{
|
||||
printf("\x1b[32mPSX: Track = %u, start = %u, end = %u, offset = %d, sector_size=%d, type = %u\n\x1b[0m", i, table->tracks[i].start, table->tracks[i].end, table->tracks[i].offset, table->tracks[i].sector_size, table->tracks[i].type);
|
||||
if (table->tracks[i].index1) printf("\x1b[32mPSX: Track = %u,Index1 = %u seconds\n\x1b[0m", i, table->tracks[i].index1 / 75);
|
||||
if (table->tracks[i].indexes[1]) printf("\x1b[32mPSX: Track = %u,Index1 = %u seconds\n\x1b[0m", i, table->tracks[i].indexes[1] / 75);
|
||||
}
|
||||
|
||||
memset(disk, 0, sizeof(disk_t));
|
||||
@@ -418,8 +418,8 @@ static void send_cue_and_metadata(toc_t *table, uint16_t libcrypt_mask, enum reg
|
||||
{
|
||||
disk->track[i].start_lba = i ? table->tracks[i].start : 0;
|
||||
disk->track[i].end_lba = table->tracks[i].end;
|
||||
m = ((disk->track[i].start_lba + table->tracks[i].index1) / 75) / 60;
|
||||
s = ((disk->track[i].start_lba + table->tracks[i].index1) / 75) % 60;
|
||||
m = ((disk->track[i].start_lba + table->tracks[i].indexes[1]) / 75) / 60;
|
||||
s = ((disk->track[i].start_lba + table->tracks[i].indexes[1]) / 75) % 60;
|
||||
disk->track[i].bcd = ((BCD(m) << 8) | BCD(s)) | ((table->tracks[i].type ? 0 : 1) << 16);
|
||||
}
|
||||
|
||||
@@ -496,12 +496,12 @@ void psx_read_cd(uint8_t *buffer, int lba, int cnt)
|
||||
}
|
||||
while (cnt)
|
||||
{
|
||||
if (toc.tracks[i+1].pregap && lba > (toc.tracks[i+1].start-toc.tracks[i+1].index1))
|
||||
if (toc.tracks[i+1].pregap && lba > (toc.tracks[i+1].start-toc.tracks[i+1].indexes[1]))
|
||||
{
|
||||
//The TOC is setup so that pregap sectors are actually part of the
|
||||
//PREVIOUS track. If the pregap field is set the file doesn't contain
|
||||
//this data, so we have to fake it.
|
||||
//Check the next track's pregap and index1 values to determine
|
||||
//Check the next track's pregap and indexes[1] values to determine
|
||||
//if we're reading pregap sectors
|
||||
|
||||
|
||||
@@ -511,7 +511,7 @@ void psx_read_cd(uint8_t *buffer, int lba, int cnt)
|
||||
{
|
||||
|
||||
// The "fake" 150 sector pregap moves all the LBAs up by 150, so adjust here to read where the core actually wants data from
|
||||
int read_lba = lba - toc.tracks[0].index1;
|
||||
int read_lba = lba - toc.tracks[0].indexes[1];
|
||||
if (mister_chd_read_sector(toc.chd_f, (read_lba + toc.tracks[i].offset), 0, 0, CD_SECTOR_LEN, buffer, chd_hunkbuf, &chd_hunknum) == CHDERR_NONE)
|
||||
{
|
||||
if (!toc.tracks[i].type) //CHD requires byteswap of audio data
|
||||
|
||||
@@ -189,6 +189,11 @@ void saturn_set_image(int num, const char *filename)
|
||||
saturn_mount_save(filename);
|
||||
//cheats_init(filename, 0);
|
||||
}
|
||||
|
||||
if (satcdd.GetBootHeader((uint8_t*)buf) > 0)
|
||||
{
|
||||
saturn_send_data((uint8_t*)buf, 256, BOOT_IO_INDEX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,11 +57,13 @@ public:
|
||||
void CommandExec();
|
||||
uint8_t* GetStatus();
|
||||
int SetCommand(uint8_t* data);
|
||||
int GetBootHeader(uint8_t *buf);
|
||||
|
||||
private:
|
||||
toc_t toc;
|
||||
int lba;
|
||||
int track;
|
||||
int index;
|
||||
int seek_lba;
|
||||
uint16_t sectorSize;
|
||||
int toc_pos;
|
||||
@@ -87,6 +89,7 @@ private:
|
||||
int LoadCUE(const char* filename);
|
||||
void LBAToMSF(int lba, msf_t* msf);
|
||||
int GetFAD(uint8_t* cmd);
|
||||
int GetSectorOffsetByIndex(int tno, int idx);
|
||||
void SetChecksum(uint8_t* stat);
|
||||
int CheckCommand(uint8_t* cmd);
|
||||
void ReadData(uint8_t *buf);
|
||||
@@ -101,8 +104,9 @@ extern satcdd_t satcdd;
|
||||
extern uint32_t frame_cnt;
|
||||
|
||||
|
||||
#define CD_DATA_IO_INDEX 8
|
||||
#define SAVE_IO_INDEX 4 // fake download to trigger save loading
|
||||
#define CD_DATA_IO_INDEX 0x8
|
||||
#define BOOT_IO_INDEX 0xC
|
||||
#define SAVE_IO_INDEX 0x4 // fake download to trigger save loading
|
||||
|
||||
void saturn_poll();
|
||||
void saturn_set_image(int num, const char *filename);
|
||||
|
||||
@@ -82,20 +82,23 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
static char fname[1024 + 10];
|
||||
static char line[128];
|
||||
char *ptr, *lptr;
|
||||
static char toc[100 * 1024];
|
||||
static char cue[100 * 1024];
|
||||
int new_file = 0;
|
||||
int file_size = 0;
|
||||
|
||||
strcpy(fname, filename);
|
||||
|
||||
memset(toc, 0, sizeof(toc));
|
||||
if (!FileLoad(fname, toc, sizeof(toc) - 1)) return 1;
|
||||
memset(cue, 0, sizeof(cue));
|
||||
if (!FileLoad(fname, cue, sizeof(cue) - 1)) return 1;
|
||||
|
||||
#ifdef SATURN_DEBUG
|
||||
printf("\x1b[32mSaturn: Open CUE: %s\n\x1b[0m", fname);
|
||||
#endif // SATURN_DEBUG
|
||||
|
||||
int mm, ss, bb, pregap = 0;
|
||||
this->toc.last = -1;
|
||||
int idx, mm, ss, bb, pregap = 0;
|
||||
|
||||
char *buf = toc;
|
||||
char *buf = cue;
|
||||
while (sgets(line, sizeof(line), &buf))
|
||||
{
|
||||
lptr = line;
|
||||
@@ -104,6 +107,8 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
/* decode FILE commands */
|
||||
if (!(memcmp(lptr, "FILE", 4)))
|
||||
{
|
||||
if (this->toc.last == 99) break;
|
||||
|
||||
ptr = fname + strlen(fname) - 1;
|
||||
while ((ptr - fname) && (*ptr != '/') && (*ptr != '\\')) ptr--;
|
||||
if (ptr - fname) ptr++;
|
||||
@@ -124,7 +129,9 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
}
|
||||
*ptr = 0;
|
||||
|
||||
if (!FileOpen(&this->toc.tracks[this->toc.last].f, fname)) return -1;
|
||||
if (!FileOpen(&this->toc.tracks[this->toc.last + 1].f, fname)) return -1;
|
||||
FileSeek(&this->toc.tracks[this->toc.last + 1].f, 0, SEEK_SET);
|
||||
file_size = this->toc.tracks[this->toc.last + 1].f.size;
|
||||
|
||||
#ifdef SATURN_DEBUG
|
||||
printf("\x1b[32mSaturn: Open track file: %s\n\x1b[0m", fname);
|
||||
@@ -132,11 +139,11 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
|
||||
pregap = 0;
|
||||
|
||||
this->toc.tracks[this->toc.last].offset = 0;
|
||||
this->toc.tracks[this->toc.last + 1].offset = 0;
|
||||
|
||||
if (!strstr(lptr, "BINARY") && !strstr(lptr, "MOTOROLA") && !strstr(lptr, "WAVE"))
|
||||
{
|
||||
FileClose(&this->toc.tracks[this->toc.last].f);
|
||||
FileClose(&this->toc.tracks[this->toc.last + 1].f);
|
||||
#ifdef SATURN_DEBUG
|
||||
printf("\x1b[32mSaturn: unsupported file: %s\n\x1b[0m", fname);
|
||||
#endif // SATURN_DEBUG
|
||||
@@ -148,6 +155,9 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
/* decode TRACK commands */
|
||||
else if ((sscanf(lptr, "TRACK %02d %*s", &bb)) || (sscanf(lptr, "TRACK %d %*s", &bb)))
|
||||
{
|
||||
if (this->toc.last == 99) break;
|
||||
this->toc.last++;
|
||||
|
||||
if (bb != (this->toc.last + 1))
|
||||
{
|
||||
FileClose(&this->toc.tracks[this->toc.last].f);
|
||||
@@ -207,6 +217,17 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
this->toc.tracks[this->toc.last - 1].end = 0;
|
||||
}
|
||||
}
|
||||
|
||||
new_file = 1;
|
||||
if (!this->toc.tracks[this->toc.last].f.opened())
|
||||
{
|
||||
FileOpen(&this->toc.tracks[this->toc.last].f, fname);
|
||||
new_file = 0;
|
||||
}
|
||||
|
||||
#ifdef SATURN_DEBUG
|
||||
printf("\x1b[32mSaturn: track = %u, type = %u\n\x1b[0m", this->toc.last + 1, this->toc.tracks[this->toc.last].type);
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
|
||||
/* decode PREGAP commands */
|
||||
@@ -217,51 +238,79 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
}
|
||||
|
||||
/* decode INDEX commands */
|
||||
else if ((sscanf(lptr, "INDEX 00 %02d:%02d:%02d", &mm, &ss, &bb) == 3) ||
|
||||
(sscanf(lptr, "INDEX 0 %02d:%02d:%02d", &mm, &ss, &bb) == 3))
|
||||
else if ((sscanf(lptr, "INDEX %02d %02d:%02d:%02d", &idx, &mm, &ss, &bb) == 4) ||
|
||||
(sscanf(lptr, "INDEX %01d %02d:%02d:%02d", &idx, &mm, &ss, &bb) == 4))
|
||||
{
|
||||
if (this->toc.last && !this->toc.tracks[this->toc.last - 1].end)
|
||||
{
|
||||
this->toc.tracks[this->toc.last - 1].end = bb + ss * 75 + mm * 60 * 75 + pregap;
|
||||
}
|
||||
}
|
||||
else if ((sscanf(lptr, "INDEX 01 %02d:%02d:%02d", &mm, &ss, &bb) == 3) ||
|
||||
(sscanf(lptr, "INDEX 1 %02d:%02d:%02d", &mm, &ss, &bb) == 3))
|
||||
{
|
||||
this->toc.tracks[this->toc.last].offset += pregap * 2352;
|
||||
int idx_pos = bb + ss * 75 + mm * 60 * 75;
|
||||
if (idx == 0) {
|
||||
if (!new_file)
|
||||
{
|
||||
this->toc.tracks[this->toc.last].start = idx_pos + pregap;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->toc.tracks[this->toc.last].start = this->toc.end + pregap;
|
||||
}
|
||||
|
||||
if (!this->toc.tracks[this->toc.last].f.opened())
|
||||
{
|
||||
FileOpen(&this->toc.tracks[this->toc.last].f, fname);
|
||||
this->toc.tracks[this->toc.last].start = bb + ss * 75 + mm * 60 * 75 + pregap;
|
||||
if (this->toc.last && !this->toc.tracks[this->toc.last - 1].end)
|
||||
{
|
||||
this->toc.tracks[this->toc.last - 1].end = this->toc.tracks[this->toc.last].start - this->toc.tracks[this->toc.last].pregap;
|
||||
this->toc.tracks[this->toc.last - 1].end = /*idx_pos +*/ pregap;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
FileSeek(&this->toc.tracks[this->toc.last].f, 0, SEEK_SET);
|
||||
else if (idx == 1) {
|
||||
this->toc.tracks[this->toc.last].offset += pregap * 2352;
|
||||
|
||||
this->toc.tracks[this->toc.last].start = this->toc.end + pregap;
|
||||
this->toc.tracks[this->toc.last].offset += this->toc.end * 2352;
|
||||
if (!new_file)
|
||||
{
|
||||
if (this->toc.last && !this->toc.tracks[this->toc.last - 1].end)
|
||||
{
|
||||
this->toc.tracks[this->toc.last - 1].end = this->toc.tracks[this->toc.last].start - this->toc.tracks[this->toc.last].pregap;
|
||||
#ifdef SATURN_DEBUG
|
||||
printf("\x1b[32mSaturn: track = %u, start = %u, end = %u\n\x1b[0m", this->toc.last - 1 + 1, this->toc.tracks[this->toc.last - 1].start, this->toc.tracks[this->toc.last - 1].end);
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//this->toc.tracks[this->toc.last].start = this->toc.end + pregap;
|
||||
this->toc.tracks[this->toc.last].offset += this->toc.end * 2352;
|
||||
|
||||
int sectorSize = 2352;
|
||||
if (this->toc.tracks[this->toc.last].type) sectorSize = this->sectorSize;
|
||||
this->toc.tracks[this->toc.last].end = this->toc.tracks[this->toc.last].start + ((this->toc.tracks[this->toc.last].f.size + sectorSize - 1) / sectorSize);
|
||||
int sectorSize = 2352;
|
||||
if (this->toc.tracks[this->toc.last].type) sectorSize = this->sectorSize;
|
||||
this->toc.tracks[this->toc.last].end = this->toc.tracks[this->toc.last].start + ((file_size + sectorSize - 1) / sectorSize);
|
||||
|
||||
this->toc.tracks[this->toc.last].start += (bb + ss * 75 + mm * 60 * 75);
|
||||
this->toc.end = this->toc.tracks[this->toc.last].end;
|
||||
}
|
||||
//this->toc.tracks[this->toc.last].start += frames;
|
||||
this->toc.end = this->toc.tracks[this->toc.last].end;
|
||||
#ifdef SATURN_DEBUG
|
||||
printf("\x1b[32mSaturn: track = %u, start = %u, end = %u\n\x1b[0m", this->toc.last + 1, this->toc.tracks[this->toc.last].start, this->toc.tracks[this->toc.last].end);
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
|
||||
#ifdef SATURN_DEBUG
|
||||
printf("\x1b[32mSaturn: Track = %u, start = %u, end = %u, offset = %u, type = %u\n\x1b[0m", this->toc.last + 1, this->toc.tracks[this->toc.last].start, this->toc.tracks[this->toc.last].end, this->toc.tracks[this->toc.last].offset, this->toc.tracks[this->toc.last].type);
|
||||
printf("\x1b[32mSaturn: track = %u, offset = %u\n\x1b[0m", this->toc.last + 1, this->toc.tracks[this->toc.last].offset);
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
|
||||
this->toc.last++;
|
||||
if (this->toc.last == 99) break;
|
||||
if (idx == 0) {
|
||||
this->toc.tracks[this->toc.last].indexes[idx] = 0;
|
||||
}
|
||||
else {
|
||||
if (!new_file)
|
||||
{
|
||||
this->toc.tracks[this->toc.last].indexes[idx] = idx_pos - this->toc.tracks[this->toc.last].start;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->toc.tracks[this->toc.last].indexes[idx] = idx_pos;
|
||||
}
|
||||
}
|
||||
this->toc.tracks[this->toc.last].index_num = idx + 1;
|
||||
#ifdef SATURN_DEBUG
|
||||
//printf("\x1b[32mSaturn: index = %u, pos = %u\n\x1b[0m", idx, this->toc.tracks[this->toc.last].indexes[idx]);
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
}
|
||||
this->toc.last++;
|
||||
|
||||
if (this->toc.last && !this->toc.tracks[this->toc.last - 1].end)
|
||||
{
|
||||
@@ -269,7 +318,6 @@ int satcdd_t::LoadCUE(const char* filename) {
|
||||
this->toc.tracks[this->toc.last - 1].end = this->toc.end;
|
||||
}
|
||||
|
||||
FileClose(&this->toc.tracks[this->toc.last].f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -389,6 +437,31 @@ void satcdd_t::Unload()
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
|
||||
int satcdd_t::GetBootHeader(uint8_t *buf) {
|
||||
if (this->toc.last < 0) return -1;
|
||||
|
||||
int offset = 16;
|
||||
if (this->sectorSize == 2048)
|
||||
{
|
||||
offset = 0;
|
||||
}
|
||||
|
||||
if (this->toc.chd_f)
|
||||
{
|
||||
mister_chd_read_sector(this->toc.chd_f, 0, 0, offset, 256, buf, this->chd_hunkbuf, &this->chd_hunknum);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->toc.tracks[0].f.opened())
|
||||
{
|
||||
FileSeek(&this->toc.tracks[0].f, offset, SEEK_SET);
|
||||
FileReadAdv(&this->toc.tracks[0].f, buf, 256);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void satcdd_t::Reset() {
|
||||
state = Open;
|
||||
@@ -429,8 +502,25 @@ void satcdd_t::Reset() {
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
|
||||
int satcdd_t::GetSectorOffsetByIndex(int tno, int idx) {
|
||||
int track = tno - 1;
|
||||
if (track < 0) track = 0;
|
||||
else if (track > this->toc.last) track = this->toc.last;
|
||||
|
||||
if (idx > 99) idx = 99;
|
||||
|
||||
if (idx <= 0)
|
||||
return 0;
|
||||
else
|
||||
return this->toc.tracks[track].indexes[idx];
|
||||
}
|
||||
|
||||
void satcdd_t::CommandExec() {
|
||||
int fad = GetFAD(comm);
|
||||
int cmd_fad = GetFAD(comm);
|
||||
int cmd_idx = comm[4];
|
||||
int cmd_tno = comm[8];
|
||||
|
||||
int fad = cmd_fad + this->GetSectorOffsetByIndex(cmd_tno, cmd_idx);
|
||||
|
||||
switch (comm[0]) {
|
||||
case SATURN_COMM_NOP:
|
||||
@@ -444,6 +534,7 @@ void satcdd_t::CommandExec() {
|
||||
case SATURN_COMM_SEEK_RING:
|
||||
this->seek_lba = fad - 150;
|
||||
this->track = this->toc.GetTrackByLBA(this->seek_lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->seek_lba);
|
||||
|
||||
this->seek_ring = true;
|
||||
this->read_pend = false;
|
||||
@@ -487,6 +578,7 @@ void satcdd_t::CommandExec() {
|
||||
this->chd_audio_read_lba = this->lba;
|
||||
|
||||
this->track = this->toc.GetTrackByLBA(this->seek_lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->seek_lba);
|
||||
|
||||
this->read_pend = true;
|
||||
//this->seek_pend = true;
|
||||
@@ -500,7 +592,7 @@ void satcdd_t::CommandExec() {
|
||||
//printf("Command = %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", comm[0], comm[1], comm[2], comm[3], comm[4], comm[5], comm[6], comm[7], comm[8], comm[9], comm[10], comm[11]);
|
||||
//printf("\n\x1b[0m");
|
||||
printf("\x1b[32mSaturn: ");
|
||||
printf("Command Read Data: FAD = %u, track = %u, speed = %u", fad, this->toc.GetTrackByLBA(this->seek_lba) + 1, this->speed);
|
||||
printf("Command Read Data: tno = %u, idx = %u, start = %u, FAD = %u, track = %u, speed = %u", cmd_tno, cmd_idx, cmd_fad, fad, this->track + 1, this->speed);
|
||||
printf(" (%u)\n\x1b[0m", frame_cnt);
|
||||
#endif // SATURN_DEBUG
|
||||
break;
|
||||
@@ -521,6 +613,7 @@ void satcdd_t::CommandExec() {
|
||||
this->seek_lba = fad - 150;
|
||||
|
||||
this->track = this->toc.GetTrackByLBA(this->seek_lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->seek_lba);
|
||||
|
||||
this->seek_pend = true;
|
||||
this->read_pend = false;
|
||||
@@ -656,7 +749,7 @@ void satcdd_t::Process(uint8_t* time_mode) {
|
||||
stat[0] = SATURN_STAT_SEEK;
|
||||
stat[1] = q | 0x01;
|
||||
stat[2] = this->lba < this->toc.end ? BCD(this->track + 1) : 0xAA;
|
||||
stat[3] = this->lba < 0 ? 0x00 : 0x01;
|
||||
stat[3] = this->lba < 0 ? 0x00 : BCD(this->index);
|
||||
stat[4] = BCD(msf.m);
|
||||
stat[5] = BCD(msf.s);
|
||||
stat[6] = BCD(msf.f);
|
||||
@@ -747,14 +840,14 @@ void satcdd_t::Process(uint8_t* time_mode) {
|
||||
|
||||
LBAToMSF(this->lba + 150, &amsf);
|
||||
if (this->lba < 0)
|
||||
LBAToMSF(-this->lba, &msf);
|
||||
LBAToMSF(-this->lba + 150, &msf);
|
||||
else
|
||||
LBAToMSF(this->lba - this->toc.tracks[this->track].start, &msf);
|
||||
LBAToMSF(this->lba - this->toc.tracks[this->track].start + 150, &msf);
|
||||
|
||||
stat[0] = SATURN_STAT_DATA;
|
||||
stat[1] = q | 0x01;
|
||||
stat[2] = this->lba < this->toc.end ? BCD(this->track + 1) : 0xAA;
|
||||
stat[3] = this->lba < 0 ? 0x00 : 0x01;
|
||||
stat[3] = this->lba < 0 ? 0x00 : BCD(this->index);
|
||||
stat[4] = BCD(msf.m);
|
||||
stat[5] = BCD(msf.s);
|
||||
stat[6] = BCD(msf.f);
|
||||
@@ -766,9 +859,11 @@ void satcdd_t::Process(uint8_t* time_mode) {
|
||||
*time_mode = this->speed;
|
||||
|
||||
#ifdef SATURN_DEBUG
|
||||
//printf("\x1b[32mSaturn: ");
|
||||
//printf("Process read data, fad = %i, msf = %02X:%02X:%02X, ", this->lba + 150, BCD(msf.m), BCD(msf.s), BCD(msf.f));
|
||||
//printf(" (%u)\n\x1b[0m", frame_cnt);
|
||||
if (!this->toc.tracks[this->track].type) {
|
||||
printf("\x1b[32mSaturn: ");
|
||||
printf("Process read data, tno = %i, idx = %i, fad = %i, msf = %02X:%02X:%02X", this->track + 1, this->index, this->lba + 150, BCD(msf.m), BCD(msf.s), BCD(msf.f));
|
||||
printf(" (%u)\n\x1b[0m", frame_cnt);
|
||||
}
|
||||
#endif // SATURN_DEBUG
|
||||
}
|
||||
else if (this->pause_pend) {
|
||||
@@ -780,7 +875,7 @@ void satcdd_t::Process(uint8_t* time_mode) {
|
||||
stat[0] = SATURN_STAT_IDLE;
|
||||
stat[1] = q | 0x01;
|
||||
stat[2] = this->lba < this->toc.end ? BCD(this->track + 1) : 0xAA;
|
||||
stat[3] = this->lba < 0 ? 0x00 : 0x01;
|
||||
stat[3] = this->lba < 0 ? 0x00 : BCD(this->index);
|
||||
stat[4] = BCD(msf.m);
|
||||
stat[5] = BCD(msf.s);
|
||||
stat[6] = BCD(msf.f);
|
||||
@@ -828,7 +923,7 @@ void satcdd_t::Process(uint8_t* time_mode) {
|
||||
stat[0] = SATURN_STAT_IDLE;
|
||||
stat[1] = q | 0x01;
|
||||
stat[2] = this->lba < this->toc.end ? BCD(this->track + 1) : 0xAA;
|
||||
stat[3] = this->lba < 0 ? 0x00 : 0x01;
|
||||
stat[3] = this->lba < 0 ? 0x00 : BCD(this->index);
|
||||
stat[4] = BCD(msf.m);
|
||||
stat[5] = BCD(msf.s);
|
||||
stat[6] = BCD(msf.f);
|
||||
@@ -852,6 +947,7 @@ void satcdd_t::Update() {
|
||||
this->lba++;
|
||||
if (this->lba > this->seek_lba + 4) this->lba -= 4;
|
||||
this->track = this->toc.GetTrackByLBA(this->lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->lba);
|
||||
break;
|
||||
|
||||
case Open:
|
||||
@@ -919,13 +1015,14 @@ void satcdd_t::Update() {
|
||||
}
|
||||
|
||||
#ifdef SATURN_DEBUG
|
||||
//printf("\x1b[32mSaturn: ");
|
||||
//printf("Update read data, lba = %i, msf = %u:%u:%u", this->lba, msf.m, msf.s, msf.f);
|
||||
//printf(" (%u)\n\x1b[0m", frame_cnt);
|
||||
//printf("\x1b[3/*2mSaturn: ");
|
||||
//printf("Update read data, idx = %i, lba = %i, msf = %u:%u:%u", this->index, this->lba, msf.m, msf.s, msf.f);
|
||||
//printf(" (%u)\n\*/x1b[0m", frame_cnt);
|
||||
#endif // SATURN_DEBUG
|
||||
|
||||
this->lba++;
|
||||
this->track = this->toc.GetTrackByLBA(this->lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->lba);
|
||||
this->seek_lba = this->lba;
|
||||
this->chd_audio_read_lba++;
|
||||
break;
|
||||
@@ -933,6 +1030,7 @@ void satcdd_t::Update() {
|
||||
case Pause:
|
||||
case Stop:
|
||||
this->track = this->toc.GetTrackByLBA(this->lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->lba);
|
||||
break;
|
||||
|
||||
case Seek:
|
||||
@@ -942,11 +1040,12 @@ void satcdd_t::Update() {
|
||||
this->chd_audio_read_lba = this->lba;
|
||||
}
|
||||
this->track = this->toc.GetTrackByLBA(this->lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->lba);
|
||||
|
||||
#ifdef SATURN_DEBUG
|
||||
LBAToMSF(this->lba + 150, &msf);
|
||||
//LBAToMSF(this->lba + 150, &msf);
|
||||
//printf("\x1b[32mSaturn: ");
|
||||
//printf("Update seek, lba = %i, seek_lba = %i, msf = %u:%u:%u", this->lba, this->seek_lba, msf.m, msf.s, msf.f);
|
||||
//printf("Update seek, tno = %i, index = %i, lba = %i, seek_lba = %i, msf = %u:%u:%u", this->index + 1, this->index, this->lba, this->seek_lba, msf.m, msf.s, msf.f);
|
||||
//printf(" (%u)\n\x1b[0m", frame_cnt);
|
||||
#endif // SATURN_DEBUG
|
||||
break;
|
||||
@@ -955,6 +1054,7 @@ void satcdd_t::Update() {
|
||||
this->lba = this->seek_lba;
|
||||
this->chd_audio_read_lba = this->lba;
|
||||
this->track = this->toc.GetTrackByLBA(this->lba);
|
||||
this->index = this->toc.GetIndexByLBA(this->track, this->lba);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user