Numerous CD-ROM fixes (and disc changes now work correctly in Windows 98 SE);

Slight reworking in the mouse and network code (ported from VARCem) in preparation for a major change that will const a lot of things to further reduce RAM usage.
This commit is contained in:
OBattler
2018-03-18 20:48:10 +01:00
parent 0cb43db290
commit b6c393cc91
11 changed files with 196 additions and 191 deletions

View File

@@ -9,7 +9,7 @@
* Implementation of the CD-ROM drive with SCSI(-like)
* commands, for both ATAPI and SCSI usage.
*
* Version: @(#)cdrom.c 1.0.39 2018/03/17
* Version: @(#)cdrom.c 1.0.40 2018/03/18
*
* Author: Miran Grca, <mgrca8@gmail.com>
*
@@ -128,7 +128,7 @@ uint8_t cdrom_command_flags[0x100] =
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
IMPLEMENTED | CHECK_READY,
IMPLEMENTED | CHECK_READY, /* Read TOC - can get through UNIT_ATTENTION, per VIDE-CDD.SYS
IMPLEMENTED | CHECK_READY | ALLOW_UA, /* Read TOC - can get through UNIT_ATTENTION, per VIDE-CDD.SYS
NOTE: The ATAPI reference says otherwise, but I think this is a question of
interpreting things right - the UNIT ATTENTION condition we have here
is a tradition from not ready to ready, by definition the drive
@@ -232,7 +232,7 @@ static const mode_sense_pages_t cdrom_mode_sense_pages_default =
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ GPMODE_CAPABILITIES_PAGE, 0x14, 0x3B, 0, 0x71, 0x60, 0x29, 0, 0x02, 0xC2, 0, 2, 0, 0, 0x02, 0xC2, 0, 0, 0, 0, 0, 0 }
{ GPMODE_CAPABILITIES_PAGE, 0x12, 0, 0, 1, 0, 0, 0, 0x02, 0xC2, 1, 0, 0, 0, 0x02, 0xC2, 0, 0, 0, 0 }
} };
static const mode_sense_pages_t cdrom_mode_sense_pages_default_scsi =
@@ -279,7 +279,7 @@ static const mode_sense_pages_t cdrom_mode_sense_pages_default_scsi =
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ GPMODE_CAPABILITIES_PAGE, 0x14, 0x3B, 0, 0x71, 0x60, 0x29, 0, 0x02, 0xC2, 0, 2, 0, 0, 0x02, 0xC2, 0, 0, 0, 0, 0, 0 }
{ GPMODE_CAPABILITIES_PAGE, 0x12, 0, 0, 1, 0, 0, 0, 0x02, 0xC2, 1, 0, 0, 0, 0x02, 0xC2, 0, 0, 0, 0 }
} };
static const mode_sense_pages_t cdrom_mode_sense_pages_changeable =
@@ -326,12 +326,13 @@ static const mode_sense_pages_t cdrom_mode_sense_pages_changeable =
{ 0, 0 },
{ 0, 0 },
{ 0, 0 },
{ GPMODE_CAPABILITIES_PAGE, 0x14, 0x3B, 0, 0x71, 0x60, 0x29, 0, 0x02, 0xC2, 0, 2, 0, 0, 0x02, 0xC2, 0, 0, 0, 0, 0, 0 }
{ GPMODE_CAPABILITIES_PAGE, 0x12, 0, 0, 1, 0, 0, 0, 0x02, 0xC2, 1, 0, 0, 0, 0x02, 0xC2, 0, 0, 0, 0 }
} };
static mode_sense_pages_t cdrom_mode_sense_pages_saved[CDROM_NUM];
#define ENABLE_CDROM_LOG 1
#ifdef ENABLE_CDROM_LOG
int cdrom_do_log = ENABLE_CDROM_LOG;
#endif
@@ -475,6 +476,7 @@ void cdrom_init(int id, int cdb_len_setting)
cdrom_sense_key = cdrom_asc = cdrom_ascq = dev->unit_attention = 0;
dev->cdb_len_setting = 0;
dev->cdb_len = 12;
dev->cur_speed = cdrom_drives[id].speed;
}
int cdrom_supports_pio(int id)
@@ -697,8 +699,20 @@ uint32_t cdrom_mode_sense(uint8_t id, uint8_t *buf, uint32_t pos, uint8_t type,
msplen = cdrom_mode_sense_read(id, page_control, i, 1);
buf[pos++] = msplen;
cdrom_log("CD-ROM %i: MODE SENSE: Page [%02X] length %i\n", id, i, msplen);
for (j = 0; j < msplen; j++)
buf[pos++] = cdrom_mode_sense_read(id, page_control, i, 2 + j);
for (j = 0; j < msplen; j++) {
if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 6) && (j <= 7)) {
if (j & 1)
buf[pos++] = ((cdrom_drives[id].speed * 176) & 0xff);
else
buf[pos++] = ((cdrom_drives[id].speed * 176) >> 8);
} else if ((i == GPMODE_CAPABILITIES_PAGE) && (j >= 12) && (j <= 13)) {
if (j & 1)
buf[pos++] = ((dev->cur_speed * 176) & 0xff);
else
buf[pos++] = ((dev->cur_speed * 176) >> 8);
} else
buf[pos++] = cdrom_mode_sense_read(id, page_control, i, 2 + j);
}
}
}
}
@@ -852,6 +866,7 @@ static void cdrom_command_common(uint8_t id)
dev->callback = 0LL;
} else {
switch(dev->current_cdb[0]) {
case GPCMD_REZERO_UNIT:
case 0x0b:
case 0x2b:
/* Seek time is in us. */
@@ -877,7 +892,7 @@ static void cdrom_command_common(uint8_t id)
case 0xbe:
/* bytes_per_second = 150.0 * 1024.0; */
bytes_per_second = (1000000.0 / 12000.0) * 2048.0; /* Account for seek time. */
bytes_per_second *= (double) cdrom_drives[id].speed;
bytes_per_second *= (double) dev->cur_speed;
break;
default:
bytes_per_second = cdrom_bus_speed(id);
@@ -1434,6 +1449,8 @@ void cdrom_insert(uint8_t id)
cdrom_t *dev = cdrom[id];
dev->unit_attention = 1;
cdrom_log("CD-ROM %i: Media insert\n", id);
}
/*SCSI Sense Initialization*/
@@ -1500,7 +1517,7 @@ skip_ready_check:
/* Only increment the unit attention phase if the command can not pass through it. */
if (!(cdrom_command_flags[cdb[0]] & ALLOW_UA)) {
/* cdrom_log("CD-ROM %i: Unit attention now 2\n", id); */
dev->unit_attention = 2;
dev->unit_attention++;
cdrom_log("CD-ROM %i: UNIT ATTENTION: Command %02X not allowed to pass through\n", id, cdb[0]);
cdrom_unit_attention(id);
return 0;
@@ -1574,6 +1591,9 @@ void cdrom_reset(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!dev)
return;
cdrom_rezero(id);
dev->status = 0;
dev->callback = 0LL;
@@ -1771,6 +1791,7 @@ void cdrom_command(uint8_t id, uint8_t *cdb)
if (cdrom_drives[id].handler->stop)
cdrom_drives[id].handler->stop(id);
dev->sector_pos = dev->sector_len = 0;
dev->seek_diff = dev->seek_pos;
cdrom_seek(id, 0);
cdrom_set_phase(id, SCSI_PHASE_STATUS);
break;
@@ -1788,6 +1809,11 @@ void cdrom_command(uint8_t id, uint8_t *cdb)
case GPCMD_SET_SPEED:
case GPCMD_SET_SPEED_ALT:
dev->cur_speed = (cdb[3] | (cdb[2] << 8)) / 176;
if (dev->cur_speed < 1)
dev->cur_speed = 1;
else if (dev->cur_speed > cdrom_drives[id].speed)
dev->cur_speed = cdrom_drives[id].speed;
cdrom_set_phase(id, SCSI_PHASE_STATUS);
cdrom_command_complete(id);
break;

View File

@@ -9,7 +9,7 @@
* Implementation of the CD-ROM drive with SCSI(-like)
* commands, for both ATAPI and SCSI usage.
*
* Version: @(#)cdrom.h 1.0.8 2018/03/17
* Version: @(#)cdrom.h 1.0.9 2018/03/18
*
* Author: Miran Grca, <mgrca8@gmail.com>
*
@@ -165,6 +165,8 @@ typedef struct {
int handler_inited;
int disc_changed;
int cur_speed;
} cdrom_t;
typedef struct {
@@ -249,6 +251,7 @@ extern void cdrom_set_signature(int id);
extern void cdrom_request_sense_for_scsi(uint8_t id, uint8_t *buffer, uint8_t alloc_length);
extern void cdrom_update_cdb(uint8_t *cdb, int lba_pos, int number_of_blocks);
extern void cdrom_insert(uint8_t id);
extern void cdrom_new_image(uint8_t id);
extern int find_cdrom_for_scsi_id(uint8_t scsi_id, uint8_t scsi_lun);
extern int cdrom_read_capacity(uint8_t id, uint8_t *cdb, uint8_t *buffer, uint32_t *len);

View File

@@ -58,41 +58,41 @@ CDROM_Interface_Image::BinaryFile::BinaryFile(const char *filename, bool &error)
{
memset(fn, 0, sizeof(fn));
strcpy(fn, filename);
error = false;
file = fopen64(fn, "rb");
if (file == NULL)
error = true;
else
error = false;
}
CDROM_Interface_Image::BinaryFile::~BinaryFile()
{
fclose(file);
file = NULL;
memset(fn, 0, sizeof(fn));
}
bool CDROM_Interface_Image::BinaryFile::read(Bit8u *buffer, uint64_t seek, uint64_t count)
{
file = fopen64(fn, "rb");
if (file == NULL) return 0;
fseeko64(file, seek, SEEK_SET);
fread(buffer, 1, count, file);
fclose(file);
return 1;
}
uint64_t CDROM_Interface_Image::BinaryFile::getLength()
{
uint64_t ret = 0;
file = fopen64(fn, "rb");
if (file == NULL) return 0;
fseeko64(file, 0, SEEK_END);
ret = ftello64(file);
fclose(file);
return ret;
return ftello64(file);
}
CDROM_Interface_Image::CDROM_Interface_Image()
{
printf("CDROM_Interface_Image constructor\n");
}
CDROM_Interface_Image::~CDROM_Interface_Image()
{
printf("CDROM_Interface_Image destructor\n");
ClearTracks();
}
@@ -357,6 +357,7 @@ bool CDROM_Interface_Image::LoadCueSheet(char *cuefile)
ifstream in;
in.open(cuefile, ios::in);
if (in.fail()) return false;
int last_attr;
while(!in.eof()) {
// get next line
@@ -427,6 +428,7 @@ bool CDROM_Interface_Image::LoadCueSheet(char *cuefile)
track.attr = DATA_TRACK;
track.mode2 = true;
} else success = false;
last_attr = track.attr;
canAddTrack = true;
}
@@ -479,7 +481,8 @@ bool CDROM_Interface_Image::LoadCueSheet(char *cuefile)
track.number++;
track.track_number = 0xAA;
// track.attr = 0;//sync with load iso
track.attr = 0x16; /* Was 0x00 but I believe 0x16 is appropriate. */
// track.attr = 0x16; /* Was 0x00 but I believe 0x16 is appropriate. */
track.attr = last_attr | 0x02;
track.start = 0;
track.length = 0;
track.file = NULL;

View File

@@ -68,6 +68,7 @@ void image_audio_callback(uint8_t id, int16_t *output, int len)
{
cdrom_t *dev = cdrom[id];
return;
if (!cdrom_drives[id].sound_on || (dev->cd_state != CD_PLAYING) || cdrom_image[id].image_is_iso)
{
cdrom_image_log("image_audio_callback(i): Not playing\n", id);
@@ -216,12 +217,6 @@ static int image_ready(uint8_t id)
return 1;
}
if (dev->disc_changed)
{
dev->disc_changed = 0;
return 1;
}
return 1;
}
@@ -267,12 +262,6 @@ static int image_medium_changed(uint8_t id)
cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive;
return 1;
}
if (dev->disc_changed)
{
dev->disc_changed = 0;
return 1;
}
return 0;
}
@@ -848,7 +837,7 @@ static int image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack,
uint32_t temp;
int first_track;
int last_track;
int last_track, last_track_pos;
int number;
unsigned char attr;
TMSF tmsf;
@@ -881,6 +870,7 @@ static int image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack,
break;
cdimg[id]->GetAudioTrackInfo(c+1, number, tmsf, attr);
last_track_pos = 0;
b[len++] = 0; /* reserved */
b[len++] = attr;
b[len++] = number; /* track number */
@@ -971,10 +961,8 @@ static int image_readtoc_raw(uint8_t id, unsigned char *b, int maxlen)
cdimg[id]->GetAudioTracks(first_track, last_track, tmsf);
if (maxlen >= 3) b[2] = first_track;
if (maxlen >= 4) b[3] = last_track;
if (maxlen <= 4) return len;
b[2] = first_track;
b[3] = last_track;
for (track = first_track; track <= last_track; track++)
{
@@ -1057,18 +1045,7 @@ int image_open(uint8_t id, wchar_t *fn)
{
cdrom_t *dev = cdrom[id];
if (wcscmp(fn, cdrom_image[id].image_path) != 0)
{
dev->disc_changed = 1;
}
/* Make sure image_changed stays when changing from an image to another image. */
if (!dev->handler_inited && (cdrom_drives[id].host_drive != 200)) dev->disc_changed = 0;
if (!dev->handler_inited || dev->disc_changed)
{
wcscpy(cdrom_image[id].image_path, fn);
}
wcscpy(cdrom_image[id].image_path, fn);
if (! wcscasecmp(plat_get_extension(fn), L"ISO"))
{
@@ -1080,6 +1057,7 @@ int image_open(uint8_t id, wchar_t *fn)
}
cdimg[id] = new CDROM_Interface_Image();
memset(afn, 0, sizeof(afn));
wcstombs(afn, fn, sizeof(afn));
if (!cdimg[id]->SetDevice(afn, false))
{
@@ -1093,12 +1071,6 @@ int image_open(uint8_t id, wchar_t *fn)
dev->cdrom_capacity = image_get_last_block(id, 0, 0, 4096, 0) + 1;
cdrom_drives[id].handler = &image_cdrom;
if (!dev->handler_inited || dev->disc_changed)
{
if (!dev->handler_inited)
dev->handler_inited = 1;
}
return 0;
}