CD-ROM code clean-ups, also reduces memory usage by a further about 2 MB.

This commit is contained in:
OBattler
2018-03-17 20:32:20 +01:00
parent f8f889b72c
commit a59dc8e436
13 changed files with 869 additions and 605 deletions

View File

@@ -8,7 +8,7 @@
*
* Main include file for the application.
*
* Version: @(#)86box.h 1.0.18 2018/03/13
* Version: @(#)86box.h 1.0.19 2018/03/17
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
@@ -52,7 +52,7 @@
#endif
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#ifdef __cplusplus
extern "C" {

File diff suppressed because it is too large Load Diff

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.6 2018/03/15
* Version: @(#)cdrom.h 1.0.8 2018/03/17
*
* Author: Miran Grca, <mgrca8@gmail.com>
*
@@ -121,6 +121,7 @@ typedef struct {
int callback;
int data_pos;
uint32_t seek_diff;
int cdb_len_setting;
int cdb_len;
@@ -150,6 +151,20 @@ typedef struct {
int init_length;
int16_t cd_buffer[BUF_SIZE];
uint8_t rcbuf[16];
uint8_t sub_q_data_format[16];
uint8_t sub_q_channel_data[256];
int last_subchannel_pos;
uint32_t cd_end;
uint32_t cdrom_capacity;
int cd_buflen;
int cd_state;
int handler_inited;
int disc_changed;
} cdrom_t;
typedef struct {
@@ -177,52 +192,31 @@ typedef struct {
typedef struct {
int image_is_iso;
uint32_t last_block;
uint32_t cdrom_capacity;
int image_inited;
wchar_t image_path[1024];
wchar_t prev_image_path[1024];
wchar_t *prev_image_path;
FILE* image;
int image_changed;
int cd_state;
uint32_t cd_pos;
uint32_t cd_end;
int cd_buflen;
} cdrom_image_t;
typedef struct {
uint32_t last_block;
uint32_t cdrom_capacity;
int ioctl_inited;
char ioctl_path[8];
int tocvalid;
int cd_state;
uint32_t cd_end;
int cd_buflen;
int actual_requested_blocks;
int last_track_pos;
int last_track_nr;
int capacity_read;
uint8_t rcbuf[16];
uint8_t sub_q_data_format[16];
uint8_t sub_q_channel_data[256];
int last_subchannel_pos;
} cdrom_ioctl_t;
extern cdrom_t cdrom[CDROM_NUM];
extern cdrom_t *cdrom[CDROM_NUM];
extern cdrom_drive_t cdrom_drives[CDROM_NUM];
extern uint8_t atapi_cdrom_drives[8];
extern uint8_t scsi_cdrom_drives[16][8];
extern cdrom_image_t cdrom_image[CDROM_NUM];
extern cdrom_ioctl_t cdrom_ioctl[CDROM_NUM];
extern uint8_t atapi_cdrom_drives[8];
extern uint8_t scsi_cdrom_drives[16][8];
#define cdrom_sense_error cdrom[id].sense[0]
#define cdrom_sense_key cdrom[id].sense[2]
#define cdrom_asc cdrom[id].sense[12]
#define cdrom_ascq cdrom[id].sense[13]
#define cdrom_sense_error cdrom[id]->sense[0]
#define cdrom_sense_key cdrom[id]->sense[2]
#define cdrom_asc cdrom[id]->sense[12]
#define cdrom_ascq cdrom[id]->sense[13]
#define cdrom_drive cdrom_drives[id].host_drive
@@ -247,6 +241,7 @@ extern uint32_t cdrom_read(uint8_t channel, int length);
extern void cdrom_write(uint8_t channel, uint32_t val, int length);
extern int cdrom_lba_to_msf_accurate(int lba);
extern void cdrom_destroy_drives(void);
extern void cdrom_close(uint8_t id);
extern void cdrom_reset(uint8_t id);

View File

@@ -66,51 +66,56 @@ void image_close(uint8_t id);
void image_audio_callback(uint8_t id, int16_t *output, int len)
{
if (!cdrom_drives[id].sound_on || (cdrom_image[id].cd_state != CD_PLAYING) || cdrom_image[id].image_is_iso)
cdrom_t *dev = cdrom[id];
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);
if (cdrom_ioctl[id].cd_state == CD_PLAYING)
if (dev->cd_state == CD_PLAYING)
{
cdrom[id].seek_pos += (len >> 11);
dev->seek_pos += (len >> 11);
}
memset(output, 0, len * 2);
return;
}
while (cdrom_image[id].cd_buflen < len)
while (dev->cd_buflen < len)
{
if (cdrom[id].seek_pos < cdrom_image[id].cd_end)
if (dev->seek_pos < dev->cd_end)
{
if (!cdimg[id]->ReadSector((unsigned char*)&cdrom[id].cd_buffer[cdrom_image[id].cd_buflen], true, cdrom[id].seek_pos))
if (!cdimg[id]->ReadSector((unsigned char*)&dev->cd_buffer[dev->cd_buflen], true, dev->seek_pos))
{
memset(&cdrom[id].cd_buffer[cdrom_image[id].cd_buflen], 0, (BUF_SIZE - cdrom_image[id].cd_buflen) * 2);
cdrom_image[id].cd_state = CD_STOPPED;
cdrom_image[id].cd_buflen = len;
memset(&dev->cd_buffer[dev->cd_buflen], 0, (BUF_SIZE - dev->cd_buflen) * 2);
dev->cd_state = CD_STOPPED;
dev->cd_buflen = len;
}
else
{
cdrom[id].seek_pos++;
cdrom_image[id].cd_buflen += (RAW_SECTOR_SIZE / 2);
dev->seek_pos++;
dev->cd_buflen += (RAW_SECTOR_SIZE / 2);
}
}
else
{
memset(&cdrom[id].cd_buffer[cdrom_image[id].cd_buflen], 0, (BUF_SIZE - cdrom_image[id].cd_buflen) * 2);
cdrom_image[id].cd_state = CD_STOPPED;
cdrom_image[id].cd_buflen = len;
memset(&dev->cd_buffer[dev->cd_buflen], 0, (BUF_SIZE - dev->cd_buflen) * 2);
dev->cd_state = CD_STOPPED;
dev->cd_buflen = len;
}
}
memcpy(output, cdrom[id].cd_buffer, len * 2);
memmove(cdrom[id].cd_buffer, &cdrom[id].cd_buffer[len], (BUF_SIZE - len) * 2);
cdrom_image[id].cd_buflen -= len;
memcpy(output, dev->cd_buffer, len * 2);
memmove(dev->cd_buffer, &dev->cd_buffer[len], (BUF_SIZE - len) * 2);
dev->cd_buflen -= len;
}
void image_audio_stop(uint8_t id)
{
cdrom_image[id].cd_state = CD_STOPPED;
cdrom_t *dev = cdrom[id];
dev->cd_state = CD_STOPPED;
}
static void image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id]) return;
int number;
unsigned char attr;
@@ -120,8 +125,8 @@ static void image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf)
if (attr == DATA_TRACK)
{
cdrom_image_log("Can't play data track\n");
cdrom[id].seek_pos = 0;
cdrom_image[id].cd_state = CD_STOPPED;
dev->seek_pos = 0;
dev->cd_state = CD_STOPPED;
return;
}
cdrom_image_log("Play audio - %08X %08X %i\n", pos, len, ismsf);
@@ -141,7 +146,7 @@ static void image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf)
if (pos == 0xffffff)
{
cdrom_image_log("Playing from current position (MSF)\n");
pos = cdrom[id].seek_pos;
pos = dev->seek_pos;
}
else
{
@@ -160,38 +165,46 @@ static void image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf)
if (pos == 0xffffffff)
{
cdrom_image_log("Playing from current position\n");
pos = cdrom[id].seek_pos;
pos = dev->seek_pos;
}
len += pos;
}
cdrom[id].seek_pos = pos;
cdrom_image[id].cd_end = len;
cdrom_image[id].cd_state = CD_PLAYING;
cdrom_image[id].cd_buflen = 0;
dev->seek_pos = pos;
dev->cd_end = len;
dev->cd_state = CD_PLAYING;
dev->cd_buflen = 0;
}
static void image_pause(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id] || cdrom_image[id].image_is_iso) return;
if (cdrom_image[id].cd_state == CD_PLAYING)
cdrom_image[id].cd_state = CD_PAUSED;
if (dev->cd_state == CD_PLAYING)
dev->cd_state = CD_PAUSED;
}
static void image_resume(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id] || cdrom_image[id].image_is_iso) return;
if (cdrom_image[id].cd_state == CD_PAUSED)
cdrom_image[id].cd_state = CD_PLAYING;
if (dev->cd_state == CD_PAUSED)
dev->cd_state = CD_PLAYING;
}
static void image_stop(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id] || cdrom_image[id].image_is_iso) return;
cdrom_image[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
}
static int image_ready(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id])
return 0;
@@ -203,9 +216,9 @@ static int image_ready(uint8_t id)
return 1;
}
if (cdrom_image[id].image_changed)
if (dev->disc_changed)
{
cdrom_image[id].image_changed = 0;
dev->disc_changed = 0;
return 1;
}
@@ -239,6 +252,8 @@ static int image_get_last_block(uint8_t id, UNUSED(uint8_t starttrack), UNUSED(i
static int image_medium_changed(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id])
return 0;
@@ -253,9 +268,9 @@ static int image_medium_changed(uint8_t id)
return 1;
}
if (cdrom_image[id].image_changed)
if (dev->disc_changed)
{
cdrom_image[id].image_changed = 0;
dev->disc_changed = 0;
return 1;
}
@@ -264,11 +279,12 @@ static int image_medium_changed(uint8_t id)
static uint8_t image_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id]) return 0;
uint8_t ret;
int pos=0;
uint32_t cdpos = cdrom[id].seek_pos;
uint32_t cdpos = dev->seek_pos;
TMSF relPos, absPos;
unsigned char attr, track, index;
cdimg[id]->GetAudioSub(cdpos, attr, track, index, relPos, absPos);
@@ -279,9 +295,9 @@ static uint8_t image_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf)
}
else
{
if (cdrom_image[id].cd_state == CD_PLAYING)
if (dev->cd_state == CD_PLAYING)
ret = 0x11;
else if (cdrom_image[id].cd_state == CD_PAUSED)
else if (dev->cd_state == CD_PAUSED)
ret = 0x12;
else
ret = 0x13;
@@ -819,7 +835,9 @@ read_mode2_xa_form2:
static uint32_t image_size(uint8_t id)
{
return cdrom_image[id].cdrom_capacity;
cdrom_t *dev = cdrom[id];
return dev->cdrom_capacity;
}
static int image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, int msf, int maxlen, int single)
@@ -996,11 +1014,12 @@ static int image_readtoc_raw(uint8_t id, unsigned char *b, int maxlen)
static int image_status(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdimg[id]) return CD_STATUS_EMPTY;
if (cdrom_image[id].image_is_iso) return CD_STATUS_DATA_ONLY;
if (cdimg[id]->HasAudioTracks())
{
switch(cdrom_image[id].cd_state)
switch(dev->cd_state)
{
case CD_PLAYING:
return CD_STATUS_PLAYING;
@@ -1021,7 +1040,9 @@ void image_reset(UNUSED(uint8_t id))
void image_close(uint8_t id)
{
cdrom_image[id].cd_state = CD_STOPPED;
cdrom_t *dev = cdrom[id];
dev->cd_state = CD_STOPPED;
if (cdimg[id])
{
delete cdimg[id];
@@ -1034,15 +1055,17 @@ static char afn[1024];
int image_open(uint8_t id, wchar_t *fn)
{
cdrom_t *dev = cdrom[id];
if (wcscmp(fn, cdrom_image[id].image_path) != 0)
{
cdrom_image[id].image_changed = 1;
dev->disc_changed = 1;
}
/* Make sure image_changed stays when changing from an image to another image. */
if (!cdrom_image[id].image_inited && (cdrom_drives[id].host_drive != 200)) cdrom_image[id].image_changed = 0;
if (!dev->handler_inited && (cdrom_drives[id].host_drive != 200)) dev->disc_changed = 0;
if (!cdrom_image[id].image_inited || cdrom_image[id].image_changed)
if (!dev->handler_inited || dev->disc_changed)
{
wcscpy(cdrom_image[id].image_path, fn);
}
@@ -1064,16 +1087,16 @@ int image_open(uint8_t id, wchar_t *fn)
cdrom_set_null_handler(id);
return 1;
}
cdrom_image[id].cd_state = CD_STOPPED;
cdrom[id].seek_pos = 0;
cdrom_image[id].cd_buflen = 0;
cdrom_image[id].cdrom_capacity = image_get_last_block(id, 0, 0, 4096, 0) + 1;
dev->cd_state = CD_STOPPED;
dev->seek_pos = 0;
dev->cd_buflen = 0;
dev->cdrom_capacity = image_get_last_block(id, 0, 0, 4096, 0) + 1;
cdrom_drives[id].handler = &image_cdrom;
if (!cdrom_image[id].image_inited || cdrom_image[id].image_changed)
if (!dev->handler_inited || dev->disc_changed)
{
if (!cdrom_image[id].image_inited)
cdrom_image[id].image_inited = 1;
if (!dev->handler_inited)
dev->handler_inited = 1;
}
return 0;
@@ -1081,7 +1104,9 @@ int image_open(uint8_t id, wchar_t *fn)
static void image_exit(uint8_t id)
{
cdrom_image[id].image_inited = 0;
cdrom_t *dev = cdrom[id];
dev->handler_inited = 0;
}
/* TODO: Check for what data type a mixed CD is. */

View File

@@ -8,7 +8,7 @@
*
* Configuration file handler.
*
* Version: @(#)config.c 1.0.44 2018/03/06
* Version: @(#)config.c 1.0.45 2018/03/17
*
* Authors: Sarah Walker,
* Miran Grca, <mgrca8@gmail.com>
@@ -1095,7 +1095,6 @@ load_removable_devices(void)
} else
#endif
wcsncpy(cdrom_image[c].image_path, wp, sizeof_w(cdrom_image[c].image_path));
wcscpy(cdrom_image[c].prev_image_path, cdrom_image[c].image_path);
if (cdrom_drives[c].host_drive < 'A')
cdrom_drives[c].host_drive = 0;
@@ -1288,7 +1287,6 @@ load_other_removable_devices(void)
} else
#endif
wcsncpy(cdrom_image[c].image_path, wp, sizeof_w(cdrom_image[c].image_path));
wcscpy(cdrom_image[c].prev_image_path, cdrom_image[c].image_path);
if (cdrom_drives[c].host_drive < 'A')
cdrom_drives[c].host_drive = 0;

View File

@@ -8,7 +8,7 @@
*
* Common code to handle all sorts of disk controllers.
*
* Version: @(#)hdc.c 1.0.9 2018/02/14
* Version: @(#)hdc.c 1.0.10 2018/03/17
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
@@ -24,6 +24,7 @@
#include "../machine/machine.h"
#include "../device.h"
#include "hdc.h"
#include "hdc_ide.h"
char *hdc_name; /* configured HDC name */
@@ -158,6 +159,15 @@ hdc_reset(void)
/* If we have a valid controller, add its device. */
if (hdc_current > 1)
device_add(controllers[hdc_current].device);
/* Reconfire and reset the IDE layer. */
ide_ter_disable();
ide_qua_disable();
if (ide_enable[2])
ide_ter_init();
if (ide_enable[3])
ide_qua_init();
ide_reset_hard();
}

View File

@@ -9,7 +9,7 @@
* Implementation of the IDE emulation for hard disks and ATAPI
* CD-ROM devices.
*
* Version: @(#)hdc_ide.c 1.0.37 2018/03/16
* Version: @(#)hdc_ide.c 1.0.38 2018/03/16
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -639,8 +639,8 @@ void ide_set_signature(IDE *ide)
else if (ide_drive_is_cdrom(ide))
{
cdrom_set_signature(cdrom_id);
ide->secount = cdrom[cdrom_id].phase;
ide->cylinder = cdrom[cdrom_id].request_length;
ide->secount = cdrom[cdrom_id]->phase;
ide->cylinder = cdrom[cdrom_id]->request_length;
}
else
{
@@ -832,7 +832,7 @@ void ide_reset(void)
}
else if ((d < 8) && ide_drive_is_cdrom(&ide_drives[d]))
{
cdrom[atapi_cdrom_drives[d]].status = READY_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[d]]->status = READY_STAT | DSC_STAT;
}
ide_drives[d].atastat = READY_STAT | DSC_STAT;
ide_drives[d].service = 0;
@@ -1033,7 +1033,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
else if (ide_drive_is_cdrom(ide))
{
ide_log("ATAPI transfer mode: %s\n", (val & 1) ? "DMA" : "PIO");
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].features = val;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->features = val;
}
ide->cylprecomp = val;
@@ -1043,7 +1043,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide_other))
{
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]].features = val;
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]]->features = val;
}
ide_other->cylprecomp = val;
return;
@@ -1057,7 +1057,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
else if (ide_drive_is_cdrom(ide))
{
ide_log("Sector count write: %i\n", val);
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].phase = val;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->phase = val;
}
ide->secount = val;
@@ -1069,7 +1069,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
else if (ide_drive_is_cdrom(ide_other))
{
ide_log("Other sector count write: %i\n", val);
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]].phase = val;
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]]->phase = val;
}
ide_other->secount = val;
return;
@@ -1089,8 +1089,8 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].request_length &= 0xFF00;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].request_length |= val;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->request_length &= 0xFF00;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->request_length |= val;
}
ide->cylinder = (ide->cylinder & 0xFF00) | val;
ide->lba_addr = (ide->lba_addr & 0xFFF00FF) | (val << 8);
@@ -1102,8 +1102,8 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide_other))
{
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]].request_length &= 0xFF00;
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]].request_length |= val;
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]]->request_length &= 0xFF00;
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]]->request_length |= val;
}
ide_other->cylinder = (ide_other->cylinder&0xFF00) | val;
ide_other->lba_addr = (ide_other->lba_addr&0xFFF00FF) | (val << 8);
@@ -1117,8 +1117,8 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].request_length &= 0xFF;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].request_length |= (val << 8);
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->request_length &= 0xFF;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->request_length |= (val << 8);
}
ide->cylinder = (ide->cylinder & 0xFF) | (val << 8);
ide->lba_addr = (ide->lba_addr & 0xF00FFFF) | (val << 16);
@@ -1130,8 +1130,8 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide_other))
{
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]].request_length &= 0xFF;
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]].request_length |= (val << 8);
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]]->request_length &= 0xFF;
cdrom[atapi_cdrom_drives[cur_ide[ide_board] ^ 1]]->request_length |= (val << 8);
}
ide_other->cylinder = (ide_other->cylinder & 0xFF) | (val << 8);
ide_other->lba_addr = (ide_other->lba_addr & 0xF00FFFF) | (val << 16);
@@ -1163,11 +1163,11 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = READY_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[ide->channel]].error = 1;
cdrom[atapi_cdrom_drives[ide->channel]].phase = 1;
cdrom[atapi_cdrom_drives[ide->channel]].request_length = 0xEB14;
cdrom[atapi_cdrom_drives[ide->channel]].callback = 0LL;
cdrom[atapi_cdrom_drives[ide->channel]]->status = READY_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->error = 1;
cdrom[atapi_cdrom_drives[ide->channel]]->phase = 1;
cdrom[atapi_cdrom_drives[ide->channel]]->request_length = 0xEB14;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 0LL;
ide->cylinder = 0xEB14;
}
@@ -1182,11 +1182,11 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide_other))
{
cdrom[atapi_cdrom_drives[ide_other->channel]].status = READY_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[ide_other->channel]].error = 1;
cdrom[atapi_cdrom_drives[ide_other->channel]].phase = 1;
cdrom[atapi_cdrom_drives[ide_other->channel]].request_length = 0xEB14;
cdrom[atapi_cdrom_drives[ide_other->channel]].callback = 0LL;
cdrom[atapi_cdrom_drives[ide_other->channel]]->status = READY_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[ide_other->channel]]->error = 1;
cdrom[atapi_cdrom_drives[ide_other->channel]]->phase = 1;
cdrom[atapi_cdrom_drives[ide_other->channel]]->request_length = 0xEB14;
cdrom[atapi_cdrom_drives[ide_other->channel]]->callback = 0LL;
ide->cylinder = 0xEB14;
}
@@ -1224,7 +1224,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].error = 0;
cdrom[atapi_cdrom_drives[ide->channel]]->error = 0;
}
if (((val >= WIN_RESTORE) && (val <= 0x1F)) || ((val >= WIN_SEEK) && (val <= 0x7F)))
{
@@ -1234,7 +1234,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = READY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = READY_STAT;
}
else
{
@@ -1247,7 +1247,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 100LL*IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 100LL*IDE_TIME;
}
idecallback[ide_board]=40000LL * TIMER_USEC /*100LL*IDE_TIME*/;
timer_update_outstanding();
@@ -1262,7 +1262,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
}
else
{
@@ -1275,7 +1275,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 100LL*IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 100LL*IDE_TIME;
}
idecallback[ide_board]=100LL*IDE_TIME;
timer_update_outstanding();
@@ -1299,7 +1299,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
}
else
{
@@ -1312,7 +1312,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 200LL*IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 200LL*IDE_TIME;
}
idecallback[ide_board]=200LL*IDE_TIME;
timer_update_outstanding();
@@ -1335,8 +1335,8 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = DRQ_STAT | DSC_STAT | READY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]].pos = 0;
cdrom[atapi_cdrom_drives[ide->channel]]->status = DRQ_STAT | DSC_STAT | READY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->pos = 0;
}
else
{
@@ -1353,7 +1353,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
}
else
{
@@ -1366,7 +1366,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 200LL*IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 200LL*IDE_TIME;
}
idecallback[ide_board]=200LL*IDE_TIME;
timer_update_outstanding();
@@ -1380,7 +1380,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
}
else
{
@@ -1393,7 +1393,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 200LL*IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 200LL*IDE_TIME;
}
idecallback[ide_board]=200LL*IDE_TIME;
timer_update_outstanding();
@@ -1418,7 +1418,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
}
else
{
@@ -1431,7 +1431,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 30LL*IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 30LL*IDE_TIME;
}
idecallback[ide_board]=30LL*IDE_TIME;
timer_update_outstanding();
@@ -1439,16 +1439,16 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
case WIN_DRIVE_DIAGNOSTICS: /* Execute Drive Diagnostics */
if (ide_drive_is_zip(ide))
zip[atapi_zip_drives[ide->channel]].status = BUSY_STAT;
zip[atapi_zip_drives[ide->channel]].status = BUSY_STAT;
else if (ide_drive_is_cdrom(ide))
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
else
ide->atastat = BUSY_STAT;
if (ide_drive_is_zip(ide_other))
zip[atapi_zip_drives[ide_other->channel]].status = BUSY_STAT;
else if (ide_drive_is_cdrom(ide_other))
cdrom[atapi_cdrom_drives[ide_other->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide_other->channel]]->status = BUSY_STAT;
else
ide_other->atastat = BUSY_STAT;
@@ -1456,7 +1456,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
if (ide_drive_is_zip(ide))
zip[atapi_zip_drives[ide->channel]].callback = 200LL * IDE_TIME;
else if (ide_drive_is_cdrom(ide))
cdrom[atapi_cdrom_drives[ide->channel]].callback = 200LL * IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 200LL * IDE_TIME;
idecallback[ide_board] = 200LL * IDE_TIME;
timer_update_outstanding();
return;
@@ -1472,7 +1472,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
if (ide_drive_is_zip(ide))
zip[atapi_zip_drives[ide->channel]].status = BUSY_STAT;
else if (ide_drive_is_cdrom(ide))
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
else
ide->atastat = BUSY_STAT;
timer_process();
@@ -1489,7 +1489,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
}
else
{
@@ -1502,7 +1502,7 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 200LL*IDE_TIME;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 200LL*IDE_TIME;
}
idecallback[ide_board]=200LL*IDE_TIME;
timer_update_outstanding();
@@ -1519,10 +1519,10 @@ void writeide(int ide_board, uint16_t addr, uint8_t val)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].packet_status = CDROM_PHASE_IDLE;
cdrom[atapi_cdrom_drives[ide->channel]].pos=0;
cdrom[atapi_cdrom_drives[ide->channel]].phase = 1;
cdrom[atapi_cdrom_drives[ide->channel]].status = READY_STAT | DRQ_STAT | (cdrom[cur_ide[ide_board]].status & ERR_STAT);
cdrom[atapi_cdrom_drives[ide->channel]]->packet_status = CDROM_PHASE_IDLE;
cdrom[atapi_cdrom_drives[ide->channel]]->pos=0;
cdrom[atapi_cdrom_drives[ide->channel]]->phase = 1;
cdrom[atapi_cdrom_drives[ide->channel]]->status = READY_STAT | DRQ_STAT | (cdrom[cur_ide[ide_board]]->status & ERR_STAT);
}
else
{
@@ -1544,8 +1544,8 @@ ide_bad_command:
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = READY_STAT | ERR_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[ide->channel]].error = ABRT_ERR;
cdrom[atapi_cdrom_drives[ide->channel]]->status = READY_STAT | ERR_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->error = ABRT_ERR;
}
else
{
@@ -1567,7 +1567,7 @@ ide_bad_command:
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].callback = 0LL;
cdrom[atapi_cdrom_drives[ide->channel]]->callback = 0LL;
}
idecallback[ide_board]=500LL*IDE_TIME;
timer_update_outstanding();
@@ -1586,7 +1586,7 @@ ide_bad_command:
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[ide->channel]].status = BUSY_STAT;
cdrom[atapi_cdrom_drives[ide->channel]]->status = BUSY_STAT;
}
ide->atastat = ide_other->atastat = BUSY_STAT;
}
@@ -1670,8 +1670,8 @@ uint32_t ide_read_data(int ide_board, int length)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].status = READY_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].packet_status = CDROM_PHASE_IDLE;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->status = READY_STAT | DSC_STAT;
cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->packet_status = CDROM_PHASE_IDLE;
}
if (ide->command == WIN_READ || ide->command == WIN_READ_NORETRY || ide->command == WIN_READ_MULTIPLE)
{
@@ -1733,7 +1733,7 @@ uint8_t readide(int ide_board, uint16_t addr)
}
else if (ide_drive_is_cdrom(ide))
{
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].error;
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->error;
}
else
{
@@ -1762,7 +1762,7 @@ uint8_t readide(int ide_board, uint16_t addr)
}
else if (ide_drive_is_cdrom(ide))
{
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].phase;
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->phase;
}
else
{
@@ -1787,7 +1787,7 @@ uint8_t readide(int ide_board, uint16_t addr)
}
else if (ide_drive_is_cdrom(ide))
{
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].request_length & 0xff;
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->request_length & 0xff;
}
else
{
@@ -1809,7 +1809,7 @@ uint8_t readide(int ide_board, uint16_t addr)
}
else if (ide_drive_is_cdrom(ide))
{
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].request_length >> 8;
temp = cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->request_length >> 8;
}
else
{
@@ -1838,7 +1838,7 @@ uint8_t readide(int ide_board, uint16_t addr)
}
else if (ide_drive_is_cdrom(ide))
{
temp = (cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].status & ~DSC_STAT) | (ide->service ? SERVICE_STAT : 0);
temp = (cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->status & ~DSC_STAT) | (ide->service ? SERVICE_STAT : 0);
}
else
{
@@ -1860,7 +1860,7 @@ uint8_t readide(int ide_board, uint16_t addr)
}
else if (ide_drive_is_cdrom(ide))
{
temp = (cdrom[atapi_cdrom_drives[cur_ide[ide_board]]].status & ~DSC_STAT) | (ide->service ? SERVICE_STAT : 0);
temp = (cdrom[atapi_cdrom_drives[cur_ide[ide_board]]]->status & ~DSC_STAT) | (ide->service ? SERVICE_STAT : 0);
}
else
{
@@ -1942,10 +1942,10 @@ void callbackide(int ide_board)
else if (ide_drive_is_cdrom(ide))
{
cdrom_id = atapi_cdrom_drives[cur_ide[ide_board]];
cdrom[cdrom_id].status = READY_STAT | DSC_STAT;
cdrom[cdrom_id].error = 1;
cdrom[cdrom_id].phase = 1;
cdrom[cdrom_id].request_length=0xEB14;
cdrom[cdrom_id]->status = READY_STAT | DSC_STAT;
cdrom[cdrom_id]->error = 1;
cdrom[cdrom_id]->phase = 1;
cdrom[cdrom_id]->request_length=0xEB14;
ide->cylinder = 0xEB14;
if (cdrom_drives[cdrom_id].handler->stop)
{
@@ -1968,10 +1968,10 @@ void callbackide(int ide_board)
else if (ide_drive_is_cdrom(ide_other))
{
cdrom_id_other = atapi_cdrom_drives[cur_ide[ide_board] ^ 1];
cdrom[cdrom_id_other].status = READY_STAT | DSC_STAT;
cdrom[cdrom_id_other].error = 1;
cdrom[cdrom_id_other].phase = 1;
cdrom[cdrom_id_other].request_length=0xEB14;
cdrom[cdrom_id_other]->status = READY_STAT | DSC_STAT;
cdrom[cdrom_id_other]->error = 1;
cdrom[cdrom_id_other]->phase = 1;
cdrom[cdrom_id_other]->request_length=0xEB14;
ide_other->cylinder = 0xEB14;
if (cdrom_drives[cdrom_id_other].handler->stop)
{
@@ -2028,9 +2028,9 @@ void callbackide(int ide_board)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[cdrom_id].status = READY_STAT | DSC_STAT;
cdrom[cdrom_id].error = 1;
cdrom[cdrom_id].phase = 1;
cdrom[cdrom_id]->status = READY_STAT | DSC_STAT;
cdrom[cdrom_id]->error = 1;
cdrom[cdrom_id]->phase = 1;
cdrom_reset(cdrom_id);
}
ide_irq_raise(ide);
@@ -2050,7 +2050,7 @@ void callbackide(int ide_board)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[cdrom_id].status = READY_STAT | DSC_STAT;
cdrom[cdrom_id]->status = READY_STAT | DSC_STAT;
}
else
{
@@ -2068,8 +2068,8 @@ void callbackide(int ide_board)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[cdrom_id].phase = 0xFF;
cdrom[cdrom_id].status = READY_STAT | DSC_STAT;
cdrom[cdrom_id]->phase = 0xFF;
cdrom[cdrom_id]->status = READY_STAT | DSC_STAT;
}
ide->secount = 0xFF;
ide->atastat = READY_STAT | DSC_STAT;
@@ -2361,8 +2361,8 @@ void callbackide(int ide_board)
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[cdrom_id].status = 0;
cdrom[cdrom_id].error = 1;
cdrom[cdrom_id]->status = 0;
cdrom[cdrom_id]->error = 1;
ide_irq_raise(ide);
}
else
@@ -2382,8 +2382,8 @@ void callbackide(int ide_board)
}
else if (ide_drive_is_cdrom(ide_other))
{
cdrom[cdrom_id_other].status = 0;
cdrom[cdrom_id_other].error = 1;
cdrom[cdrom_id_other]->status = 0;
cdrom[cdrom_id_other]->error = 1;
}
else
{
@@ -2426,10 +2426,10 @@ void callbackide(int ide_board)
{
ide_atapi_identify(ide);
ide->pos = 0;
cdrom[cdrom_id].phase = 2;
cdrom[cdrom_id].pos = 0;
cdrom[cdrom_id].error = 0;
cdrom[cdrom_id].status = DRQ_STAT | READY_STAT | DSC_STAT;
cdrom[cdrom_id]->phase = 2;
cdrom[cdrom_id]->pos = 0;
cdrom[cdrom_id]->error = 0;
cdrom[cdrom_id]->status = DRQ_STAT | READY_STAT | DSC_STAT;
ide_irq_raise(ide);
return;
}
@@ -2462,8 +2462,8 @@ void callbackide(int ide_board)
zip[zip_id].pos = 0;
}
else if (ide_drive_is_cdrom(ide)) {
cdrom[cdrom_id].status = READY_STAT | DSC_STAT;
cdrom[cdrom_id].pos = 0;
cdrom[cdrom_id]->status = READY_STAT | DSC_STAT;
cdrom[cdrom_id]->pos = 0;
}
ide->atastat = READY_STAT | DSC_STAT;
ide_irq_raise(ide);
@@ -2525,9 +2525,9 @@ abort_cmd:
}
else if (ide_drive_is_cdrom(ide))
{
cdrom[cdrom_id].status = READY_STAT | ERR_STAT | DSC_STAT;
cdrom[cdrom_id].error = ABRT_ERR;
cdrom[cdrom_id].pos = 0;
cdrom[cdrom_id]->status = READY_STAT | ERR_STAT | DSC_STAT;
cdrom[cdrom_id]->error = ABRT_ERR;
cdrom[cdrom_id]->pos = 0;
}
else
{

View File

@@ -9,7 +9,7 @@
* Implementation of the Iomega ZIP drive with SCSI(-like)
* commands, for both ATAPI and SCSI usage.
*
* Version: @(#)zip.c 1.0.10 2018/03/16
* Version: @(#)zip.c 1.0.12 2018/03/17
*
* Author: Miran Grca, <mgrca8@gmail.com>
*
@@ -952,12 +952,12 @@ static void zip_command_common(uint8_t id)
bytes_per_second = 8333333.333333333333333; /* 8.3 MB/s PIO-2 speed */
} else
bytes_per_second = 3333333.333333333333333; /* 3.3 MB/s PIO-0 speed */
}
period = 1000000.0 / bytes_per_second;
dusec = (double) TIMER_USEC;
dusec = dusec * period * (double) (zip[id].packet_len);
zip[id].callback = ((int64_t) dusec);
period = 1000000.0 / bytes_per_second;
dusec = (double) TIMER_USEC;
dusec = dusec * period * (double) (zip[id].packet_len);
zip[id].callback = ((int64_t) dusec);
}
zip_set_callback(id);
}
@@ -2511,15 +2511,6 @@ void zip_write(uint8_t channel, uint32_t val, int length)
}
}
void zip_hard_reset(void)
{
int i = 0;
for (i=0; i<ZIP_NUM; i++)
zip_mode_sense_load(i);
}
/* Peform a master init on the entire module. */
void
zip_global_init(void)
@@ -2531,7 +2522,7 @@ zip_global_init(void)
void
zip_global_reset(void)
zip_hard_reset(void)
{
int c;
@@ -2542,5 +2533,7 @@ zip_global_reset(void)
zip_log("ZIP global_reset drive=%d host=%02x\n", c, zip_drives[c].host_drive);
if (wcslen(zip_drives[c].image_path))
zip_load(c, zip_drives[c].image_path);
zip_mode_sense_load(c);
}
}

View File

@@ -9,7 +9,7 @@
* Implementation of the Iomega ZIP drive with SCSI(-like)
* commands, for both ATAPI and SCSI usage.
*
* Version: @(#)zip.h 1.0.2 2018/02/27
* Version: @(#)zip.h 1.0.3 2018/03/17
*
* Author: Miran Grca, <mgrca8@gmail.com>
*
@@ -199,7 +199,6 @@ extern int find_zip_for_scsi_id(uint8_t scsi_id, uint8_t scsi_lun);
extern int zip_read_capacity(uint8_t id, uint8_t *cdb, uint8_t *buffer, uint32_t *len);
extern void zip_global_init(void);
extern void zip_global_reset(void);
extern void zip_hard_reset(void);
extern int zip_load(uint8_t id, wchar_t *fn);

View File

@@ -527,12 +527,7 @@ pc_reload(wchar_t *fn)
fdd_close(i);
for (i=0; i<CDROM_NUM; i++) {
cdrom_drives[i].handler->exit(i);
if (cdrom_drives[i].host_drive == 200)
image_close(i);
else if ((cdrom_drives[i].host_drive >= 'A') && (cdrom_drives[i].host_drive <= 'Z'))
ioctl_close(i);
else
null_close(i);
cdrom_close(i);
}
pc_reset_hard_close();
@@ -658,9 +653,6 @@ again2:
ide_init_first();
cdrom_global_reset();
zip_global_reset();
device_init();
timer_reset();
@@ -675,11 +667,11 @@ again2:
ide_reset_hard();
scsi_card_init();
cdrom_hard_reset();
zip_hard_reset();
scsi_card_init();
pc_full_speed();
shadowbios = 0;
@@ -828,16 +820,6 @@ pc_reset_hard_init(void)
/* Reset the Hard Disk Controller module. */
hdc_reset();
/* Reconfire and reset the IDE layer. */
// FIXME: this should have been done via hdc_reset() above.. --FvK
ide_ter_disable();
ide_qua_disable();
if (ide_enable[2])
ide_ter_init();
if (ide_enable[3])
ide_qua_init();
ide_reset_hard();
/* Reset and reconfigure the SCSI layer. */
scsi_card_init();
@@ -970,6 +952,8 @@ pc_close(thread_t *ptr)
mem_destroy_pages();
ide_destroy_buffers();
cdrom_destroy_drives();
}

View File

@@ -8,7 +8,7 @@
*
* The generic SCSI device command handler.
*
* Version: @(#)scsi_device.c 1.0.14 2018/03/07
* Version: @(#)scsi_device.c 1.0.15 2018/03/16
*
* Authors: Miran Grca, <mgrca8@gmail.com>
* Fred N. van Kempen, <decwiz@yahoo.com>
@@ -106,7 +106,7 @@ static void scsi_device_target_save_cdb_byte(int lun_type, uint8_t id, uint8_t c
}
else if (lun_type == SCSI_CDROM)
{
cdrom[id].request_length = cdb_byte;
cdrom[id]->request_length = cdb_byte;
}
else if (lun_type == SCSI_ZIP)
{
@@ -133,7 +133,7 @@ int64_t scsi_device_get_callback(uint8_t scsi_id, uint8_t scsi_lun)
break;
case SCSI_CDROM:
id = scsi_cdrom_drives[scsi_id][scsi_lun];
return cdrom[id].callback;
return cdrom[id]->callback;
break;
case SCSI_ZIP:
id = scsi_zip_drives[scsi_id][scsi_lun];
@@ -160,7 +160,7 @@ uint8_t *scsi_device_sense(uint8_t scsi_id, uint8_t scsi_lun)
break;
case SCSI_CDROM:
id = scsi_cdrom_drives[scsi_id][scsi_lun];
return cdrom[id].sense;
return cdrom[id]->sense;
break;
case SCSI_ZIP:
id = scsi_zip_drives[scsi_id][scsi_lun];
@@ -301,7 +301,7 @@ int scsi_device_cdb_length(uint8_t scsi_id, uint8_t scsi_lun)
{
case SCSI_CDROM:
id = scsi_cdrom_drives[scsi_id][scsi_lun];
return cdrom[id].cdb_len;
return cdrom[id]->cdb_len;
case SCSI_ZIP:
id = scsi_zip_drives[scsi_id][scsi_lun];
return zip[id].cdb_len;

View File

@@ -8,7 +8,7 @@
*
* Handle the platform-side of CDROM drives.
*
* Version: @(#)win_cdrom.c 1.0.5 2018/03/06
* Version: @(#)win_cdrom.c 1.0.6 2018/03/17
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -79,7 +79,13 @@ cdrom_eject(uint8_t id)
IDM_CDROM_HOST_DRIVE | id | ((cdrom_drives[id].host_drive - 'A') << 3), MF_UNCHECKED);
}
if (cdrom_image[id].prev_image_path) {
free(cdrom_image[id].prev_image_path);
cdrom_image[id].prev_image_path = NULL;
}
if (cdrom_drives[id].host_drive == 200) {
cdrom_image[id].prev_image_path = (wchar_t *) malloc(1024);
wcscpy(cdrom_image[id].prev_image_path, cdrom_image[id].image_path);
}
cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive;
@@ -116,6 +122,8 @@ cdrom_reload(uint8_t id)
if (cdrom_drives[id].prev_host_drive == 200) {
wcscpy(cdrom_image[id].image_path, cdrom_image[id].prev_image_path);
free(cdrom_image[id].prev_image_path);
cdrom_image[id].prev_image_path = NULL;
image_open(id, cdrom_image[id].image_path);
if (cdrom_drives[id].bus_type) {
/* Signal disc change to the emulated machine. */

View File

@@ -9,7 +9,7 @@
* Implementation of the CD-ROM host drive IOCTL interface for
* Windows using SCSI Passthrough Direct.
*
* Version: @(#)cdrom_ioctl.c 1.0.13 2018/03/15
* Version: @(#)cdrom_ioctl.c 1.0.14 2018/03/17
*
* Authors: Sarah Walker, <http://pcem-emulator.co.uk/>
* Miran Grca, <mgrca8@gmail.com>
@@ -78,67 +78,72 @@ static int ioctl_hopen(uint8_t id);
void ioctl_audio_callback(uint8_t id, int16_t *output, int len)
{
cdrom_t *dev = cdrom[id];
RAW_READ_INFO in;
DWORD count;
if (!cdrom_drives[id].sound_on || (cdrom_ioctl[id].cd_state != CD_PLAYING))
if (!cdrom_drives[id].sound_on || (dev->cd_state != CD_PLAYING))
{
if (cdrom_ioctl[id].cd_state == CD_PLAYING)
if (dev->cd_state == CD_PLAYING)
{
cdrom[id].seek_pos += (len >> 11);
dev->seek_pos += (len >> 11);
}
memset(output, 0, len * 2);
return;
}
while (cdrom_ioctl[id].cd_buflen < len)
while (dev->cd_buflen < len)
{
if (cdrom[id].seek_pos < cdrom_ioctl[id].cd_end)
if (dev->seek_pos < dev->cd_end)
{
in.DiskOffset.LowPart = (cdrom[id].seek_pos - 150) * 2048;
in.DiskOffset.LowPart = (dev->seek_pos - 150) * 2048;
in.DiskOffset.HighPart = 0;
in.SectorCount = 1;
in.TrackMode = CDDA;
if (!DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL, IOCTL_CDROM_RAW_READ, &in, sizeof(in), &(cdrom[id].cd_buffer[cdrom_ioctl[id].cd_buflen]), 2352, &count, NULL))
if (!DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL, IOCTL_CDROM_RAW_READ, &in, sizeof(in), &(dev->cd_buffer[dev->cd_buflen]), 2352, &count, NULL))
{
memset(&(cdrom[id].cd_buffer[cdrom_ioctl[id].cd_buflen]), 0, (BUF_SIZE - cdrom_ioctl[id].cd_buflen) * 2);
memset(&(dev->cd_buffer[dev->cd_buflen]), 0, (BUF_SIZE - dev->cd_buflen) * 2);
cdrom_ioctl_windows[id].is_playing = 0;
ioctl_close(id);
cdrom_ioctl[id].cd_state = CD_STOPPED;
cdrom_ioctl[id].cd_buflen = len;
dev->cd_state = CD_STOPPED;
dev->cd_buflen = len;
}
else
{
cdrom[id].seek_pos++;
cdrom_ioctl[id].cd_buflen += (2352 / 2);
dev->seek_pos++;
dev->cd_buflen += (2352 / 2);
}
}
else
{
memset(&(cdrom[id].cd_buffer[cdrom_ioctl[id].cd_buflen]), 0, (BUF_SIZE - cdrom_ioctl[id].cd_buflen) * 2);
memset(&(dev->cd_buffer[dev->cd_buflen]), 0, (BUF_SIZE - dev->cd_buflen) * 2);
cdrom_ioctl_windows[id].is_playing = 0;
ioctl_close(id);
cdrom_ioctl[id].cd_state = CD_STOPPED;
cdrom_ioctl[id].cd_buflen = len;
dev->cd_state = CD_STOPPED;
dev->cd_buflen = len;
}
}
memcpy(output, cdrom[id].cd_buffer, len * 2);
memcpy(&cdrom[id].cd_buffer[0], &(cdrom[id].cd_buffer[len]), (BUF_SIZE - len) * 2);
cdrom_ioctl[id].cd_buflen -= len;
memcpy(output, dev->cd_buffer, len * 2);
memcpy(&dev->cd_buffer[0], &(dev->cd_buffer[len]), (BUF_SIZE - len) * 2);
dev->cd_buflen -= len;
}
void ioctl_audio_stop(uint8_t id)
{
cdrom_t *dev = cdrom[id];
cdrom_ioctl_windows[id].is_playing = 0;
ioctl_close(id);
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
}
static int get_track_nr(uint8_t id, uint32_t pos)
{
cdrom_t *dev = cdrom[id];
int c;
int track = 0;
if (!cdrom_ioctl[id].tocvalid)
if (dev->disc_changed)
{
return 0;
}
@@ -167,9 +172,10 @@ static int get_track_nr(uint8_t id, uint32_t pos)
static uint32_t get_track_msf(uint8_t id, uint32_t track_no)
{
cdrom_t *dev = cdrom[id];
int c;
if (!cdrom_ioctl[id].tocvalid)
if (dev->disc_changed)
{
return 0;
}
@@ -186,6 +192,7 @@ static uint32_t get_track_msf(uint8_t id, uint32_t track_no)
static void ioctl_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf)
{
cdrom_t *dev = cdrom[id];
int m = 0, s = 0, f = 0;
uint32_t start_msf = 0, end_msf = 0;
if (!cdrom_drives[id].host_drive)
@@ -222,7 +229,7 @@ static void ioctl_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf)
if (pos == 0xffffff)
{
cdrom_ioctl_log("Playing from current position (MSF)\n");
pos = cdrom[id].seek_pos;
pos = dev->seek_pos;
}
else
{
@@ -239,51 +246,54 @@ static void ioctl_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf)
if (pos == 0xffffffff)
{
cdrom_ioctl_log("Playing from current position\n");
pos = cdrom[id].seek_pos;
pos = dev->seek_pos;
}
len += pos;
}
cdrom[id].seek_pos = pos;
cdrom_ioctl[id].cd_end = len;
if (cdrom[id].seek_pos < 150)
dev->seek_pos = pos;
dev->cd_end = len;
if (dev->seek_pos < 150)
{
/* Adjust because the host expects a minimum adjusted LBA of 0 which is equivalent to an absolute LBA of 150. */
cdrom[id].seek_pos = 150;
dev->seek_pos = 150;
}
if (!cdrom_ioctl_windows[id].is_playing)
{
ioctl_hopen(id);
cdrom_ioctl_windows[id].is_playing = 1;
}
cdrom_ioctl[id].cd_state = CD_PLAYING;
dev->cd_state = CD_PLAYING;
}
static void ioctl_pause(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdrom_drives[id].host_drive)
{
return;
}
if (cdrom_ioctl[id].cd_state == CD_PLAYING)
if (dev->cd_state == CD_PLAYING)
{
cdrom_ioctl[id].cd_state = CD_PAUSED;
dev->cd_state = CD_PAUSED;
}
}
static void ioctl_resume(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdrom_drives[id].host_drive)
{
return;
}
if (cdrom_ioctl[id].cd_state == CD_PAUSED)
if (dev->cd_state == CD_PAUSED)
{
cdrom_ioctl[id].cd_state = CD_PLAYING;
dev->cd_state = CD_PLAYING;
}
}
static void ioctl_stop(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!cdrom_drives[id].host_drive)
{
return;
@@ -293,11 +303,12 @@ static void ioctl_stop(uint8_t id)
cdrom_ioctl_windows[id].is_playing = 0;
ioctl_close(id);
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
}
static int ioctl_ready(uint8_t id)
{
cdrom_t *dev = cdrom[id];
unsigned long size;
int temp;
CDROM_TOC ltoc;
@@ -322,9 +333,9 @@ static int ioctl_ready(uint8_t id)
if ((ltoc.TrackData[ltoc.LastTrack].Address[1] != cdrom_ioctl_windows[id].toc.TrackData[cdrom_ioctl_windows[id].toc.LastTrack].Address[1]) ||
(ltoc.TrackData[ltoc.LastTrack].Address[2] != cdrom_ioctl_windows[id].toc.TrackData[cdrom_ioctl_windows[id].toc.LastTrack].Address[2]) ||
(ltoc.TrackData[ltoc.LastTrack].Address[3] != cdrom_ioctl_windows[id].toc.TrackData[cdrom_ioctl_windows[id].toc.LastTrack].Address[3]) ||
!cdrom_ioctl[id].tocvalid || (cdrom_drives[id].host_drive != cdrom_drives[id].prev_host_drive))
dev->disc_changed || (cdrom_drives[id].host_drive != cdrom_drives[id].prev_host_drive))
{
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
if (cdrom_drives[id].host_drive != cdrom_drives[id].prev_host_drive)
{
cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive;
@@ -336,6 +347,7 @@ static int ioctl_ready(uint8_t id)
static int ioctl_get_last_block(uint8_t id, unsigned char starttrack, int msf, int maxlen, int single)
{
cdrom_t *dev = cdrom[id];
unsigned long size;
int c, d = 0;
CDROM_TOC lbtoc;
@@ -344,11 +356,11 @@ static int ioctl_get_last_block(uint8_t id, unsigned char starttrack, int msf, i
{
return 0;
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
ioctl_hopen(id);
DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL, IOCTL_CDROM_READ_TOC, NULL, 0, &lbtoc, sizeof(lbtoc), &size, NULL);
ioctl_close(id);
cdrom_ioctl[id].tocvalid=1;
dev->disc_changed = 0;
for (c=d; c <= lbtoc.LastTrack; c++)
{
uint32_t address;
@@ -365,6 +377,7 @@ static void ioctl_read_capacity(uint8_t id, uint8_t *b);
static int ioctl_medium_changed(uint8_t id)
{
cdrom_t *dev = cdrom[id];
unsigned long size;
int temp;
CDROM_TOC ltoc;
@@ -379,11 +392,11 @@ static int ioctl_medium_changed(uint8_t id)
{
return 0; /* Drive empty, a not ready handler matter, not disc change. */
}
if (!cdrom_ioctl[id].tocvalid || (cdrom_drives[id].host_drive != cdrom_drives[id].prev_host_drive))
if (dev->disc_changed || (cdrom_drives[id].host_drive != cdrom_drives[id].prev_host_drive))
{
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
cdrom_ioctl_windows[id].toc = ltoc;
cdrom_ioctl[id].tocvalid = 1;
dev->disc_changed = 0;
if (cdrom_drives[id].host_drive != cdrom_drives[id].prev_host_drive)
{
cdrom_drives[id].prev_host_drive = cdrom_drives[id].host_drive;
@@ -392,7 +405,7 @@ static int ioctl_medium_changed(uint8_t id)
cdrom_ioctl[id].capacity_read=0; /* With this two lines, we read the READ CAPACITY command output from the host drive into our cache buffer. */
ioctl_read_capacity(id, NULL);
ioctl_close(id);
cdrom_ioctl[id].cdrom_capacity = ioctl_get_last_block(id, 0, 0, 4096, 0);
dev->cdrom_capacity = ioctl_get_last_block(id, 0, 0, 4096, 0);
return 1;
}
else
@@ -401,14 +414,14 @@ static int ioctl_medium_changed(uint8_t id)
(ltoc.TrackData[ltoc.LastTrack].Address[2] != cdrom_ioctl_windows[id].toc.TrackData[cdrom_ioctl_windows[id].toc.LastTrack].Address[2]) ||
(ltoc.TrackData[ltoc.LastTrack].Address[3] != cdrom_ioctl_windows[id].toc.TrackData[cdrom_ioctl_windows[id].toc.LastTrack].Address[3]))
{
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
cdrom_ioctl_log("Setting TOC...\n");
cdrom_ioctl_windows[id].toc = ltoc;
ioctl_hopen(id);
cdrom_ioctl[id].capacity_read=0; /* With this two lines, we read the READ CAPACITY command output from the host drive into our cache buffer. */
ioctl_read_capacity(id, NULL);
ioctl_close(id);
cdrom_ioctl[id].cdrom_capacity = ioctl_get_last_block(id, 0, 0, 4096, 0);
dev->cdrom_capacity = ioctl_get_last_block(id, 0, 0, 4096, 0);
return 1; /* TOC mismatches. */
}
}
@@ -417,6 +430,7 @@ static int ioctl_medium_changed(uint8_t id)
static uint8_t ioctl_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf)
{
cdrom_t *dev = cdrom[id];
CDROM_SUB_Q_DATA_FORMAT insub;
SUB_Q_CHANNEL_DATA sub;
unsigned long size;
@@ -425,12 +439,12 @@ static uint8_t ioctl_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf)
if (!cdrom_drives[id].host_drive) return 0;
cdpos = cdrom[id].seek_pos;
cdpos = dev->seek_pos;
if (cdrom_ioctl[id].last_subchannel_pos == cdpos)
if (dev->last_subchannel_pos == cdpos)
{
memcpy(&insub, cdrom_ioctl[id].sub_q_data_format, sizeof(insub));
memcpy(&sub, cdrom_ioctl[id].sub_q_channel_data, sizeof(sub));
memcpy(&insub, dev->sub_q_data_format, sizeof(insub));
memcpy(&sub, dev->sub_q_channel_data, sizeof(sub));
}
else
{
@@ -438,14 +452,14 @@ static uint8_t ioctl_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf)
ioctl_hopen(id);
DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL,IOCTL_CDROM_READ_Q_CHANNEL,&insub,sizeof(insub),&sub,sizeof(sub),&size,NULL);
ioctl_close(id);
memset(cdrom_ioctl[id].sub_q_data_format, 0, 16);
memcpy(cdrom_ioctl[id].sub_q_data_format, &insub, sizeof(insub));
memset(cdrom_ioctl[id].sub_q_channel_data, 0, 256);
memcpy(cdrom_ioctl[id].sub_q_channel_data, &sub, sizeof(sub));
cdrom_ioctl[id].last_subchannel_pos = cdpos;
memset(dev->sub_q_data_format, 0, 16);
memcpy(dev->sub_q_data_format, &insub, sizeof(insub));
memset(dev->sub_q_channel_data, 0, 256);
memcpy(dev->sub_q_channel_data, &sub, sizeof(sub));
dev->last_subchannel_pos = cdpos;
}
if (cdrom_ioctl[id].cd_state == CD_PLAYING || cdrom_ioctl[id].cd_state == CD_PAUSED)
if (dev->cd_state == CD_PLAYING || dev->cd_state == CD_PAUSED)
{
track = get_track_nr(id, cdpos);
track_address = cdrom_ioctl_windows[id].toc.TrackData[track].Address[3] + (cdrom_ioctl_windows[id].toc.TrackData[track].Address[2] * 75) + (cdrom_ioctl_windows[id].toc.TrackData[track].Address[1] * 75 * 60);
@@ -484,7 +498,7 @@ static uint8_t ioctl_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf)
b[pos++] = cdpos & 0xff;
}
if (cdrom_ioctl[id].cd_state == CD_PLAYING) return 0x11;
if (dev->cd_state == CD_PLAYING) return 0x11;
return 0x12;
}
@@ -525,6 +539,7 @@ static uint8_t ioctl_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf)
static void ioctl_eject(uint8_t id)
{
cdrom_t *dev = cdrom[id];
unsigned long size;
if (!cdrom_drives[id].host_drive)
{
@@ -535,7 +550,7 @@ static void ioctl_eject(uint8_t id)
cdrom_ioctl_windows[id].is_playing = 0;
ioctl_stop(id);
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
ioctl_hopen(id);
DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL,IOCTL_STORAGE_EJECT_MEDIA,NULL,0,NULL,0,&size,NULL);
ioctl_close(id);
@@ -543,6 +558,7 @@ static void ioctl_eject(uint8_t id)
static void ioctl_load(uint8_t id)
{
cdrom_t *dev = cdrom[id];
unsigned long size;
if (!cdrom_drives[id].host_drive)
{
@@ -553,23 +569,25 @@ static void ioctl_load(uint8_t id)
cdrom_ioctl_windows[id].is_playing = 0;
ioctl_stop(id);
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
ioctl_hopen(id);
DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL,IOCTL_STORAGE_LOAD_MEDIA,NULL,0,NULL,0,&size,NULL);
cdrom_ioctl[id].capacity_read=0; /* With this two lines, we read the READ CAPACITY command output from the host drive into our cache buffer. */
ioctl_read_capacity(id, NULL);
ioctl_close(id);
cdrom_ioctl[id].cdrom_capacity = ioctl_get_last_block(id, 0, 0, 4096, 0);
dev->cdrom_capacity = ioctl_get_last_block(id, 0, 0, 4096, 0);
}
static int ioctl_is_track_audio(uint8_t id, uint32_t pos, int ismsf)
{
cdrom_t *dev = cdrom[id];
int c;
int control = 0;
uint32_t track_address = 0;
if (!cdrom_ioctl[id].tocvalid)
if (dev->disc_changed)
{
return 0;
}
@@ -639,6 +657,8 @@ struct sptd_with_sense
static int ioctl_get_block_length(uint8_t id, const UCHAR *cdb, int number_of_blocks, int no_length_check)
{
cdrom_t *dev = cdrom[id];
int sector_type = 0;
int temp_len = 0;
@@ -732,7 +752,7 @@ common_handler:
cdrom_illegal_mode(id);
return -1;
}
return temp_len * cdrom[id].requested_blocks;
return temp_len * dev->requested_blocks;
break;
default:
/* Other commands */
@@ -792,6 +812,7 @@ static int SCSICommand(uint8_t id, const UCHAR *cdb, UCHAR *buf, uint32_t *len,
static void ioctl_read_capacity(uint8_t id, uint8_t *b)
{
cdrom_t *dev = cdrom[id];
uint32_t len = 0;
const UCHAR cdb[] = { 0x25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -801,12 +822,12 @@ static void ioctl_read_capacity(uint8_t id, uint8_t *b)
{
SCSICommand(id, cdb, buf, &len, 1);
memcpy(cdrom_ioctl[id].rcbuf, buf, len);
memcpy(dev->rcbuf, buf, len);
cdrom_ioctl[id].capacity_read = 1;
}
else
{
memcpy(b, cdrom_ioctl[id].rcbuf, 16);
memcpy(b, dev->rcbuf, 16);
}
}
@@ -937,23 +958,26 @@ static int ioctl_get_sector_data_type(uint8_t id, uint8_t b0, uint8_t b1, uint8_
static void ioctl_validate_toc(uint8_t id)
{
cdrom_t *dev = cdrom[id];
unsigned long size;
if (!cdrom_drives[id].host_drive)
{
return;
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
ioctl_hopen(id);
cdrom_ioctl_log("Validating TOC...\n");
DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL,IOCTL_CDROM_READ_TOC, NULL,0,&cdrom_ioctl_windows[id].toc,sizeof(cdrom_ioctl_windows[id].toc),&size,NULL);
ioctl_close(id);
cdrom_ioctl[id].tocvalid=1;
dev->disc_changed = 0;
}
UCHAR buf[262144];
static int ioctl_pass_through(uint8_t id, uint8_t *in_cdb, uint8_t *b, uint32_t *len)
{
cdrom_t *dev = cdrom[id];
const UCHAR cdb[12];
int ret = 0;
@@ -976,17 +1000,17 @@ static int ioctl_pass_through(uint8_t id, uint8_t *in_cdb, uint8_t *b, uint32_t
memcpy((void *) cdb, in_cdb, 12);
temp_len = 0;
temp_block_length = ioctl_get_block_length(id, cdb, cdrom[id].requested_blocks, 0);
temp_block_length = ioctl_get_block_length(id, cdb, dev->requested_blocks, 0);
if (temp_block_length != -1) {
cdrom_ioctl[id].actual_requested_blocks = 1;
if ((cdb[0] == 0x08) || (cdb[0] == 0x28) || (cdb[0] == 0xA8) || (cdb[0] == 0xB9) || (cdb[0] == 0xBE)) {
buffer_pos = 0;
temp_len = 0;
for (i = 0; i < cdrom[id].requested_blocks; i++)
for (i = 0; i < dev->requested_blocks; i++)
{
cdrom_ioctl_log("CD-ROM %i: ioctl_pass_through(): Transferring block...\n", id, cdrom_ioctl[id].actual_requested_blocks);
cdrom_update_cdb((uint8_t *) cdb, cdrom[id].sector_pos + i, 1);
cdrom_update_cdb((uint8_t *) cdb, dev->sector_pos + i, 1);
ret = SCSICommand(id, cdb, b + buffer_pos, &temp_len, 0);
buffer_pos += temp_len;
}
@@ -1009,6 +1033,7 @@ static int ioctl_pass_through(uint8_t id, uint8_t *in_cdb, uint8_t *b, uint32_t
static int ioctl_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, int msf, int maxlen, int single)
{
cdrom_t *dev = cdrom[id];
int len=4;
DWORD size;
int c,d;
@@ -1018,11 +1043,11 @@ static int ioctl_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack,
{
return 0;
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
ioctl_hopen(id);
DeviceIoControl(cdrom_ioctl_windows[id].hIOCTL,IOCTL_CDROM_READ_TOC, NULL,0,&cdrom_ioctl_windows[id].toc,sizeof(cdrom_ioctl_windows[id].toc),&size,NULL);
ioctl_close(id);
cdrom_ioctl[id].tocvalid = 1;
dev->disc_changed = 0;
b[2]=cdrom_ioctl_windows[id].toc.FirstTrack;
b[3]=cdrom_ioctl_windows[id].toc.LastTrack;
d=0;
@@ -1071,6 +1096,7 @@ static int ioctl_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack,
static int ioctl_readtoc_session(uint8_t id, unsigned char *b, int msf, int maxlen)
{
cdrom_t *dev = cdrom[id];
int len=4;
int size;
uint32_t temp;
@@ -1080,7 +1106,7 @@ static int ioctl_readtoc_session(uint8_t id, unsigned char *b, int msf, int maxl
{
return 0;
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
memset(&toc_ex,0,sizeof(toc_ex));
memset(&toc,0,sizeof(toc));
toc_ex.Format=CDROM_READ_TOC_EX_FORMAT_SESSION;
@@ -1116,6 +1142,7 @@ static int ioctl_readtoc_session(uint8_t id, unsigned char *b, int msf, int maxl
static int ioctl_readtoc_raw(uint8_t id, uint8_t *b, int maxlen)
{
cdrom_t *dev = cdrom[id];
int len=4;
int size;
int i;
@@ -1125,7 +1152,7 @@ static int ioctl_readtoc_raw(uint8_t id, uint8_t *b, int maxlen)
{
return 0;
}
cdrom_ioctl[id].cd_state = CD_STOPPED;
dev->cd_state = CD_STOPPED;
memset(&toc_ex,0,sizeof(toc_ex));
memset(&toc,0,sizeof(toc));
toc_ex.Format=CDROM_READ_TOC_EX_FORMAT_FULL_TOC;
@@ -1185,12 +1212,14 @@ static uint32_t ioctl_size(uint8_t id)
static int ioctl_status(uint8_t id)
{
cdrom_t *dev = cdrom[id];
if (!(ioctl_ready(id)) && (cdrom_drives[id].host_drive <= 0))
{
return CD_STATUS_EMPTY;
}
switch(cdrom_ioctl[id].cd_state)
switch(dev->cd_state)
{
case CD_PLAYING:
return CD_STATUS_PLAYING;
@@ -1205,12 +1234,14 @@ static int ioctl_status(uint8_t id)
void ioctl_reset(uint8_t id)
{
cdrom_t *dev = cdrom[id];
CDROM_TOC ltoc;
unsigned long size;
if (!cdrom_drives[id].host_drive)
{
cdrom_ioctl[id].tocvalid = 0;
dev->disc_changed = 1;
return;
}
@@ -1219,7 +1250,7 @@ void ioctl_reset(uint8_t id)
ioctl_close(id);
cdrom_ioctl_windows[id].toc = ltoc;
cdrom_ioctl[id].tocvalid = 1;
dev->disc_changed = 0;
}
int ioctl_hopen(uint8_t id)
@@ -1231,11 +1262,12 @@ int ioctl_hopen(uint8_t id)
int ioctl_open(uint8_t id, char d)
{
cdrom_t *dev = cdrom[id];
sprintf(cdrom_ioctl[id].ioctl_path,"\\\\.\\%c:",d);
cdrom_ioctl[id].tocvalid=0;
dev->disc_changed = 1;
cdrom_ioctl_windows[id].hIOCTL = CreateFile(cdrom_ioctl[id].ioctl_path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
cdrom_drives[id].handler = &ioctl_cdrom;
cdrom_ioctl[id].ioctl_inited=1;
dev->handler_inited=1;
cdrom_ioctl[id].capacity_read=0; /* With this two lines, we read the READ CAPACITY command output from the host drive into our cache buffer. */
ioctl_read_capacity(id, NULL);
CloseHandle(cdrom_ioctl_windows[id].hIOCTL);
@@ -1255,10 +1287,11 @@ void ioctl_close(uint8_t id)
static void ioctl_exit(uint8_t id)
{
cdrom_t *dev = cdrom[id];
cdrom_ioctl_windows[id].is_playing = 0;
ioctl_stop(id);
cdrom_ioctl[id].ioctl_inited=0;
cdrom_ioctl[id].tocvalid=0;
dev->handler_inited=0;
dev->disc_changed = 1;
}
static CDROM ioctl_cdrom=