Saturn: fixes

-fix reverse seek delay
-add CRC calculation for data sectors (cdbtest)
This commit is contained in:
Sergiy Dvodnenko
2025-08-18 13:56:52 +03:00
committed by GitHub
parent eef9cbd6d9
commit 470ee2f5c3
2 changed files with 54 additions and 63 deletions

View File

@@ -100,6 +100,7 @@ private:
void ReadData(uint8_t *buf);
int ReadCDDA(uint8_t *buf, int first);
void MakeSecureRingData(uint8_t *buf);
uint32_t DataSectorCalcCRC(uint8_t* buf);
int DataSectorSend(uint8_t* header, int speed);
int AudioSectorSend(int first);
int RingDataSend(uint8_t* header, int speed);

View File

@@ -500,7 +500,7 @@ int satcdd_t::CalcSeekDelay(int lba_old, int lba_new)
if (n <= 4) n = 4;
else if (n > 30) n = 30;
if (diff < 0) n += 2;
if (diff < 0 && abs(diff) > 8) n += 2;
return n;
}
@@ -1001,7 +1001,7 @@ void satcdd_t::Update() {
else if (this->toc.tracks[this->track].type)
{
// CD-ROM Data (Mode 1/2)
uint8_t header[4];
uint8_t header[16];
#ifdef SATURN_DEBUG
//printf("\x1b[32mSaturn: ");
@@ -1010,10 +1010,22 @@ void satcdd_t::Update() {
#endif // SATURN_DEBUG
if (this->sectorSize == 2048 || (this->lba - this->toc.tracks[this->track].start) < 0) {
header[0] = BCD(msf.m);
header[1] = BCD(msf.s);
header[2] = BCD(msf.f);
header[3] = (uint8_t)this->toc.tracks[this->track].type;
header[0] = 0x00;
header[1] = 0xFF;
header[2] = 0xFF;
header[3] = 0xFF;
header[4] = 0xFF;
header[5] = 0xFF;
header[6] = 0xFF;
header[7] = 0xFF;
header[8] = 0xFF;
header[9] = 0xFF;
header[10] = 0xFF;
header[11] = 0x00;
header[12] = BCD(msf.m);
header[13] = BCD(msf.s);
header[14] = BCD(msf.f);
header[15] = 0x01;
DataSectorSend(header, this->speed);
}
else {
@@ -1132,6 +1144,29 @@ void satcdd_t::MakeSecureRingData(uint8_t *buf) {
}
}
uint32_t satcdd_t::DataSectorCalcCRC(uint8_t* buf)
{
static uint32_t crc_tab[256];
for (int i = 0; i < 256; i++)
{
uint32_t c = i;
for (unsigned j = 0; j < 8; j++)
c = (c >> 1) ^ ((c & 0x1) ? 0xD8018001 : 0);
crc_tab[i] = c;
}
uint32_t crc = 0;
for (int i = 0; i < 2064; i++)
{
crc ^= buf[i];
crc = (crc >> 8) ^ crc_tab[crc & 0xFF];
}
return crc;
}
void satcdd_t::ReadData(uint8_t *buf)
{
int offs = 0;
@@ -1219,13 +1254,20 @@ int satcdd_t::DataSectorSend(uint8_t* header, int speed)
uint8_t *shmem_ptr = (uint8_t*)shmem_map(SHMEM_ADDR, 4096 * 4);
uint8_t *data_ptr = shmem_ptr + (buf_num_write * 4096);
ReadData(data_ptr);
if (header) {
ReadData(data_ptr);
memcpy(data_ptr + 12 , header, 4);
}
else {
ReadData(data_ptr);
memcpy(data_ptr, header, 16);
}
uint32_t crc = DataSectorCalcCRC(data_ptr);
data_ptr[2064] = crc >> 0;
data_ptr[2065] = crc >> 8;
data_ptr[2066] = crc >> 16;
data_ptr[2067] = crc >> 24;
memset(data_ptr + 2068, 0, 2352-2068);
int boot = (data_ptr[12] == 0x00 && data_ptr[13] == 0x02 && data_ptr[14] == 0x00 && data_ptr[15] == 0x01);
shmem_unmap(shmem_ptr, 4096 * 4);
@@ -1289,55 +1331,3 @@ int satcdd_t::AudioSectorSend(int first)
return 0;
}
//int satcdd_t::DataSectorSend(uint8_t* header, int speed)
//{
// uint8_t* data_ptr = cd_buf + 2;
//
// if (header) {
// ReadData(data_ptr);
// memcpy(data_ptr + 12, header, 4);
// }
// else {
// ReadData(data_ptr);
// }
// cd_buf[0] = cd_buf[1] = (speed == 2 ? 0x01 : 0x00);
//
// if (SendData)
// return SendData(cd_buf, 2352 + 2, CD_DATA_IO_INDEX);
//
// return 0;
//}
//
//int satcdd_t::RingDataSend(uint8_t* header, int speed)
//{
// uint8_t* data_ptr = cd_buf + 2;
//
// if (header) {
// MakeSecureRingData(data_ptr);
// memcpy(data_ptr + 12, header, 12);
// memset(data_ptr + 2348, 0, 4);
// }
// cd_buf[0] = cd_buf[1] = (speed == 2 ? 1 : 0);
//
// if (SendData)
// return SendData(cd_buf, 2352 + 2, CD_DATA_IO_INDEX);
//
// return 0;
//}
//
//int satcdd_t::AudioSectorSend(int first)
//{
// int len;
// uint8_t* data_ptr = cd_buf + 2;
//
// len = ReadCDDA(data_ptr, first);
// cd_buf[0] = cd_buf[1] = 0x02;
//
// if (SendData)
// return SendData(cd_buf, len + 2, CD_DATA_IO_INDEX);
//
// return 0;
//}