diff --git a/src/cdrom/cdrom.c b/src/cdrom/cdrom.c index 2e1fe719e..0a6268013 100644 --- a/src/cdrom/cdrom.c +++ b/src/cdrom/cdrom.c @@ -8,7 +8,7 @@ * * Generic CD-ROM drive core. * - * Version: @(#)cdrom.c 1.0.1 2018/10/11 + * Version: @(#)cdrom.c 1.0.2 2018/10/17 * * Author: Miran Grca, * @@ -23,9 +23,10 @@ #include #define HAVE_STDARG_H #include "../86box.h" +#include "../config.h" #include "cdrom.h" #include "cdrom_image.h" -#include "cdrom_null.h" +#include "../plat.h" #include "../sound/sound.h" @@ -33,50 +34,50 @@ #define MAX_SEEK 333333 -cdrom_image_t cdrom_image[CDROM_NUM]; -cdrom_drive_t cdrom_drives[CDROM_NUM]; +cdrom_t cdrom[CDROM_NUM]; + #ifdef ENABLE_CDROM_LOG -int cdrom_do_log = ENABLE_CDROM_LOG; -#endif +int cdrom_do_log = ENABLE_CDROM_LOG; -static void -cdrom_log(const char *format, ...) +void +cdrom_log(const char *fmt, ...) { -#ifdef ENABLE_CDROM_LOG va_list ap; if (cdrom_do_log) { - va_start(ap, format); - pclog_ex(format, ap); + va_start(ap, fmt); + pclog_ex(fmt, ap); va_end(ap); } -#endif } +#else +#define cdrom_log(fmt, ...) +#endif int cdrom_lba_to_msf_accurate(int lba) { - int temp_pos; + int pos; int m, s, f; - temp_pos = lba + 150; - f = temp_pos % 75; - temp_pos -= f; - temp_pos /= 75; - s = temp_pos % 60; - temp_pos -= s; - temp_pos /= 60; - m = temp_pos; + pos = lba + 150; + f = pos % 75; + pos -= f; + pos /= 75; + s = pos % 60; + pos -= s; + pos /= 60; + m = pos; return ((m << 16) | (s << 8) | f); } -double -cdrom_get_short_seek(cdrom_drive_t *dev) +static double +cdrom_get_short_seek(cdrom_t *dev) { switch(dev->cur_speed) { case 0: @@ -107,8 +108,8 @@ cdrom_get_short_seek(cdrom_drive_t *dev) } -double -cdrom_get_long_seek(cdrom_drive_t *dev) +static double +cdrom_get_long_seek(cdrom_t *dev) { switch(dev->cur_speed) { case 0: @@ -140,7 +141,7 @@ cdrom_get_long_seek(cdrom_drive_t *dev) double -cdrom_seek_time(cdrom_drive_t *dev) +cdrom_seek_time(cdrom_t *dev) { uint32_t diff = dev->seek_diff; double sd = (double) (MAX_SEEK - MIN_SEEK); @@ -157,28 +158,35 @@ cdrom_seek_time(cdrom_drive_t *dev) void -cdrom_seek(cdrom_drive_t *dev, uint32_t pos) +cdrom_seek(cdrom_t *dev, uint32_t pos) { /* cdrom_log("CD-ROM %i: Seek %08X\n", dev->id, pos); */ if (!dev) return; dev->seek_pos = pos; - if (dev->handler && dev->handler->stop) - dev->handler->stop(dev->id); + if (dev->ops && dev->ops->stop) + dev->ops->stop(dev); } int -cdrom_playing_completed(cdrom_drive_t *dev) +cdrom_playing_completed(cdrom_t *dev) { dev->prev_status = dev->cd_status; - dev->cd_status = dev->handler->status(dev->id); + + if (dev->ops && dev->ops->status) + dev->cd_status = dev->ops->status(dev); + else { + dev->cd_status = CD_STATUS_EMPTY; + return 0; + } + if (((dev->prev_status == CD_STATUS_PLAYING) || (dev->prev_status == CD_STATUS_PAUSED)) && ((dev->cd_status != CD_STATUS_PLAYING) && (dev->cd_status != CD_STATUS_PAUSED))) return 1; - else - return 0; + + return 0; } @@ -187,44 +195,51 @@ void cdrom_global_init(void) { /* Clear the global data. */ - memset(cdrom_drives, 0x00, sizeof(cdrom_drives)); + memset(cdrom, 0x00, sizeof(cdrom)); } static void -cdrom_drive_reset(cdrom_drive_t *drv) +cdrom_drive_reset(cdrom_t *dev) { - drv->p = NULL; - drv->insert = NULL; - drv->get_volume = NULL; - drv->get_channel = NULL; - drv->close = NULL; + dev->p = NULL; + dev->insert = NULL; + dev->close = NULL; + dev->get_volume = NULL; + dev->get_channel = NULL; } void cdrom_hard_reset(void) { - int c; - cdrom_drive_t *drv; + cdrom_t *dev; + int i; - for (c = 0; c < CDROM_NUM; c++) { - if (cdrom_drives[c].bus_type) { - cdrom_log("CDROM hard_reset drive=%d\n", c); + for (i = 0; i < CDROM_NUM; i++) { + dev = &cdrom[i]; + if (dev->bus_type) { + cdrom_log("CDROM %i: hard_reset\n", i); - drv = &cdrom_drives[c]; - drv->id = c; + dev->id = i; - cdrom_drive_reset(drv); + cdrom_drive_reset(dev); - if ((drv->bus_type == CDROM_BUS_ATAPI) || (drv->bus_type == CDROM_BUS_SCSI)) - scsi_cdrom_drive_reset(c); + switch(dev->bus_type) { + case CDROM_BUS_ATAPI: + case CDROM_BUS_SCSI: + scsi_cdrom_drive_reset(i); + break; - if (drv->host_drive == 200) { - image_open(c, cdrom_image[c].image_path); - image_reset(c); - } else - cdrom_null_open(c); + default: + break; + } + + + if (dev->host_drive == 200) { + cdrom_image_open(dev, dev->image_path); + cdrom_image_reset(dev); + } } } @@ -232,39 +247,111 @@ cdrom_hard_reset(void) } -void -cdrom_close_handler(uint8_t id) -{ - cdrom_drive_t *dev = &cdrom_drives[id]; - - if (!dev) - return; - - switch (dev->host_drive) { - case 200: - image_close(id); - break; - default: - null_close(id); - break; - } - - dev->handler = NULL; -} - - void cdrom_close(void) { - int c; + cdrom_t *dev; + int i; - for (c = 0; c < CDROM_NUM; c++) { - if (cdrom_drives[c].handler) - cdrom_close_handler(c); + for (i = 0; i < CDROM_NUM; i++) { + dev = &cdrom[i]; - if (cdrom_drives[c].close) - cdrom_drives[c].close(cdrom_drives[c].p); + if (dev->ops && dev->ops->exit) + dev->ops->exit(dev); - cdrom_drive_reset(&cdrom_drives[c]); + dev->ops = NULL; + + if (dev->close) + dev->close(dev->p); + + cdrom_drive_reset(dev); } } + + +/* Signal disc change to the emulated machine. */ +void +cdrom_insert(uint8_t id) +{ + cdrom_t *dev = &cdrom[id]; + + if (dev->bus_type) { + if (dev->insert) + dev->insert(dev->p); + } +} + + +/* The mechanics of ejecting a CD-ROM from a drive. */ +void +cdrom_eject(uint8_t id) +{ + cdrom_t *dev = &cdrom[id]; + + /* This entire block should be in cdrom.c/cdrom_eject(dev*) ... */ + if (dev->host_drive == 0) { + /* Switch from empty to empty. Do nothing. */ + return; + } + + if (dev->prev_image_path) { + free(dev->prev_image_path); + dev->prev_image_path = NULL; + } + + if (dev->host_drive == 200) { + dev->prev_image_path = (wchar_t *) malloc(1024); + wcscpy(dev->prev_image_path, dev->image_path); + } + + dev->prev_host_drive = dev->host_drive; + dev->host_drive = 0; + + dev->ops->exit(dev); + dev->ops = NULL; + memset(dev->image_path, 0, sizeof(dev->image_path)); + + cdrom_insert(id); + + plat_cdrom_ui_update(id, 0); + + config_save(); +} + + +/* The mechanics of re-loading a CD-ROM drive. */ +void +cdrom_reload(uint8_t id) +{ + cdrom_t *dev = &cdrom[id]; + + if ((dev->host_drive == dev->prev_host_drive) || + (dev->prev_host_drive == 0) || (dev->host_drive != 0)) { + /* Switch from empty to empty. Do nothing. */ + return; + } + + if (dev->ops && dev->ops->exit) + dev->ops->exit(dev); + dev->ops = NULL; + memset(dev->image_path, 0, sizeof(dev->image_path)); + + if (dev->prev_host_drive == 200) { + /* Reload a previous image. */ + wcscpy(dev->image_path, dev->prev_image_path); + free(dev->prev_image_path); + dev->prev_image_path = NULL; + cdrom_image_open(dev, dev->image_path); + + cdrom_insert(id); + + if (wcslen(dev->image_path) == 0) + dev->host_drive = 0; + else + dev->host_drive = 200; + } + + plat_cdrom_ui_update(id, 1); + + config_save(); +} diff --git a/src/cdrom/cdrom.h b/src/cdrom/cdrom.h index 1bead62e3..8028d8c45 100644 --- a/src/cdrom/cdrom.h +++ b/src/cdrom/cdrom.h @@ -8,7 +8,7 @@ * * Generic CD-ROM drive core header. * - * Version: @(#)cdrom.h 1.0.14 2018/10/09 + * Version: @(#)cdrom.h 1.0.15 2018/10/17 * * Author: Miran Grca, * @@ -30,6 +30,14 @@ #define CDROM_IMAGE 200 +/* This is so that if/when this is changed to something else, + changing this one define will be enough. */ +#define CDROM_EMPTY !dev->host_drive + + +#ifdef __cplusplus +extern "C" { +#endif enum { CDROM_BUS_DISABLED = 0, @@ -39,85 +47,91 @@ enum { }; +/* To shut up the GCC compilers. */ +struct cdrom; + + +/* Define the various CD-ROM drive operations (ops). */ typedef struct { - int (*ready)(uint8_t id); - int (*medium_changed)(uint8_t id); - int (*media_type_id)(uint8_t id); + int (*ready)(struct cdrom *dev); + int (*medium_changed)(struct cdrom *dev); + int (*media_type_id)(struct cdrom *dev); - int (*audio_callback)(uint8_t id, int16_t *output, int len); - void (*audio_stop)(uint8_t id); - int (*readtoc)(uint8_t id, uint8_t *b, uint8_t starttrack, int msf, int maxlen, int single); - int (*readtoc_session)(uint8_t id, uint8_t *b, int msf, int maxlen); - int (*readtoc_raw)(uint8_t id, uint8_t *b, int maxlen); - uint8_t (*getcurrentsubchannel)(uint8_t id, uint8_t *b, int msf); - int (*readsector_raw)(uint8_t id, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, int cdrom_sector_flags, int *len); - uint8_t (*playaudio)(uint8_t id, uint32_t pos, uint32_t len, int ismsf); - void (*pause)(uint8_t id); - void (*resume)(uint8_t id); - uint32_t (*size)(uint8_t id); - int (*status)(uint8_t id); - void (*stop)(uint8_t id); - void (*exit)(uint8_t id); -} CDROM; + int (*audio_callback)(struct cdrom *dev, int16_t *output, int len); + void (*audio_stop)(struct cdrom *dev); + int (*readtoc)(struct cdrom *dev, uint8_t *b, uint8_t starttrack, int msf, int maxlen, int single); + int (*readtoc_session)(struct cdrom *dev, uint8_t *b, int msf, int maxlen); + int (*readtoc_raw)(struct cdrom *dev, uint8_t *b, int maxlen); + uint8_t (*getcurrentsubchannel)(struct cdrom *dev, uint8_t *b, int msf); + int (*readsector_raw)(struct cdrom *dev, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, int cdrom_sector_flags, int *len); + uint8_t (*playaudio)(struct cdrom *dev, uint32_t pos, uint32_t len, int ismsf); + void (*pause)(struct cdrom *dev); + void (*resume)(struct cdrom *dev); + uint32_t (*size)(struct cdrom *dev); + int (*status)(struct cdrom *dev); + void (*stop)(struct cdrom *dev); + void (*exit)(struct cdrom *dev); +} cdrom_ops_t; -typedef struct { - CDROM *handler; - - int16_t cd_buffer[BUF_SIZE]; - - uint8_t speed, ide_channel, - pad, bus_mode; /* Bit 0 = PIO suported; +typedef struct cdrom { + uint8_t id, + speed, cur_speed, + ide_channel, scsi_device_id, + bus_type, /* 0 = ATAPI, 1 = SCSI */ + bus_mode, /* Bit 0 = PIO suported; Bit 1 = DMA supportd. */ - int host_drive, prev_host_drive, - cd_status, prev_status, - cd_buflen, cd_state, - handler_inited, cur_speed, - id; + sound_on; - unsigned int bus_type, /* 0 = ATAPI, 1 = SCSI */ - scsi_device_id, sound_on; + FILE* img_fp; + int img_is_iso, + host_drive, prev_host_drive, + cd_status, prev_status, + cd_buflen, cd_state; uint32_t seek_pos, seek_diff, - cd_end, cdrom_capacity; + cd_end, + cdrom_capacity; + + const cdrom_ops_t *ops; + + void *image; void *p; void (*insert)(void *p); + void (*close)(void *p); uint32_t (*get_volume)(void *p, int channel); uint32_t (*get_channel)(void *p, int channel); - void (*close)(void *p); -} cdrom_drive_t; -typedef struct { wchar_t image_path[1024], *prev_image_path; - FILE* image; - int image_is_iso; -} cdrom_image_t; + int16_t cd_buffer[BUF_SIZE]; +} cdrom_t; -extern cdrom_drive_t cdrom_drives[CDROM_NUM]; -extern cdrom_image_t cdrom_image[CDROM_NUM]; - - -#ifdef __cplusplus -extern "C" { -#endif +extern cdrom_t cdrom[CDROM_NUM]; extern int cdrom_lba_to_msf_accurate(int lba); -extern double cdrom_get_short_seek(cdrom_drive_t *dev); -extern double cdrom_get_long_seek(cdrom_drive_t *dev); -extern double cdrom_seek_time(cdrom_drive_t *dev); -extern void cdrom_seek(cdrom_drive_t *dev, uint32_t pos); -extern int cdrom_playing_completed(cdrom_drive_t *dev); +extern double cdrom_seek_time(cdrom_t *dev); +extern void cdrom_seek(cdrom_t *dev, uint32_t pos); +extern int cdrom_playing_completed(cdrom_t *dev); extern void cdrom_close_handler(uint8_t id); -extern void cdrom_close(void); -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_eject(uint8_t id); +extern void cdrom_reload(uint8_t id); + +extern int cdrom_image_open(cdrom_t *dev, const wchar_t *fn); +extern void cdrom_image_close(cdrom_t *dev); +extern void cdrom_image_reset(cdrom_t *dev); + +extern void cdrom_update_cdb(uint8_t *cdb, int lba_pos, + int number_of_blocks); extern int find_cdrom_for_scsi_id(uint8_t scsi_id); +extern void cdrom_close(void); extern void cdrom_global_init(void); extern void cdrom_global_reset(void); extern void cdrom_hard_reset(void); diff --git a/src/cdrom/cdrom_image.cc b/src/cdrom/cdrom_image.cc index 0b05fe8d9..cf5bcf4fa 100644 --- a/src/cdrom/cdrom_image.cc +++ b/src/cdrom/cdrom_image.cc @@ -8,7 +8,7 @@ * * CD-ROM image support. * - * Version: @(#)cdrom_image.cc 1.0.2 2018/10/09 + * Version: @(#)cdrom_image.cc 1.0.3 2018/10/17 * * Author: RichardG867, * Miran Grca, @@ -33,7 +33,27 @@ #include "cdrom_dosbox.h" #include "cdrom.h" #include "cdrom_image.h" -#include "cdrom_null.h" + + +#ifdef ENABLE_CDROM_IMAGE_LOG +int cdrom_image_do_log = ENABLE_CDROM_IMAGE_LOG; + + +void +cdrom_image_log(const char *fmt, ...) +{ + va_list ap; + + if (cdrom_image_do_log) { + va_start(ap, fmt); + pclog_ex(fmt, ap); + va_end(ap); + } +} +#else +#define cdrom_image_log(fmt, ...) +#endif + #define CD_STATUS_EMPTY 0 #define CD_STATUS_DATA_ONLY 1 @@ -41,47 +61,42 @@ #define CD_STATUS_PAUSED 3 #define CD_STATUS_STOPPED 4 + /* The addresses sent from the guest are absolute, ie. a LBA of 0 corresponds to a MSF of 00:00:00. Otherwise, the counter displayed by the guest is wrong: there is a seeming 2 seconds in which audio plays but counter does not move, while a data track before audio jumps to 2 seconds before the actual start of the audio while audio still plays. With an absolute conversion, the counter is fine. */ #define MSFtoLBA(m,s,f) ((((m*60)+s)*75)+f) -extern CDROM image_cdrom; -typedef struct __attribute__((__packed__)) -{ +#pragma pack(push,1) +typedef struct { uint8_t user_data[2048], ecc[288]; } m1_data_t; -typedef struct __attribute__((__packed__)) -{ +typedef struct { uint8_t sub_header[8], user_data[2328]; } m2_data_t; -typedef union __attribute__((__packed__)) -{ +typedef union { m1_data_t m1_data; m2_data_t m2_data; uint8_t raw_data[2336]; } sector_data_t; -typedef struct __attribute__((__packed__)) -{ +typedef struct { uint8_t sync[12]; uint8_t header[4]; sector_data_t data; } sector_raw_data_t; -typedef union __attribute__((__packed__)) -{ +typedef union { sector_raw_data_t sector_data; uint8_t raw_data[2352]; } sector_t; -typedef struct __attribute__((__packed__)) -{ +typedef struct { sector_t sector; uint8_t c2[296]; uint8_t subchannel_raw[96]; @@ -89,70 +104,45 @@ typedef struct __attribute__((__packed__)) uint8_t subchannel_rw[96]; } cdrom_sector_t; -typedef union __attribute__((__packed__)) -{ +typedef union { cdrom_sector_t cdrom_sector; uint8_t buffer[2856]; } sector_buffer_t; +#pragma pack(pop) -sector_buffer_t cdrom_sector_buffer; -int cdrom_sector_size; -uint8_t raw_buffer[2448]; -uint8_t extra_buffer[296]; - -enum -{ +enum { CD_STOPPED = 0, CD_PLAYING, CD_PAUSED }; -#ifdef ENABLE_CDROM_IMAGE_LOG -int cdrom_image_do_log = ENABLE_CDROM_IMAGE_LOG; -#endif +static int cdrom_sector_size; +static uint8_t raw_buffer[2448]; +static uint8_t extra_buffer[296]; -static CDROM_Interface_Image* cdimg[CDROM_NUM] = { NULL, NULL, NULL, NULL }; -static char afn[1024]; - -void image_close(uint8_t id); - - -void -cdrom_image_log(const char *format, ...) +static int +audio_callback(cdrom_t *dev, int16_t *output, int len) { -#ifdef ENABLE_CDROM_IMAGE_LOG - if (cdrom_image_do_log) { - va_list ap; - va_start(ap, format); - vprintf(format, ap); - va_end(ap); - fflush(stdout); - } -#endif -} - - -int -image_audio_callback(uint8_t id, int16_t *output, int len) -{ - cdrom_drive_t *dev = &cdrom_drives[id]; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; int ret = 1; - if (!dev->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 (!dev->sound_on || (dev->cd_state != CD_PLAYING) || dev->img_is_iso) { + cdrom_image_log("image_audio_callback(i): Not playing\n", dev->id); if (dev->cd_state == CD_PLAYING) dev->seek_pos += (len >> 11); memset(output, 0, len * 2); return 0; } + while (dev->cd_buflen < len) { if (dev->seek_pos < dev->cd_end) { - if (!cdimg[id]->ReadSector((unsigned char*)&dev->cd_buffer[dev->cd_buflen], true, - dev->seek_pos)) { - memset(&dev->cd_buffer[dev->cd_buflen], 0, (BUF_SIZE - dev->cd_buflen) * 2); + if (!img->ReadSector((uint8_t *)&dev->cd_buffer[dev->cd_buflen], + true, dev->seek_pos)) { + memset(&dev->cd_buffer[dev->cd_buflen], + 0x00, (BUF_SIZE - dev->cd_buflen) * 2); dev->cd_state = CD_STOPPED; dev->cd_buflen = len; ret = 0; @@ -162,7 +152,8 @@ image_audio_callback(uint8_t id, int16_t *output, int len) ret = 1; } } else { - memset(&dev->cd_buffer[dev->cd_buflen], 0, (BUF_SIZE - dev->cd_buflen) * 2); + memset(&dev->cd_buffer[dev->cd_buflen], + 0x00, (BUF_SIZE - dev->cd_buflen) * 2); dev->cd_state = CD_STOPPED; dev->cd_buflen = len; ret = 0; @@ -172,41 +163,42 @@ image_audio_callback(uint8_t id, int16_t *output, int len) memcpy(output, dev->cd_buffer, len * 2); memmove(dev->cd_buffer, &dev->cd_buffer[len], (BUF_SIZE - len) * 2); dev->cd_buflen -= len; + return ret; } -void -image_audio_stop(uint8_t id) +static void +audio_stop(cdrom_t *dev) /* audio_stop */ { - cdrom_drive_t *dev = &cdrom_drives[id]; - dev->cd_state = CD_STOPPED; } static uint8_t -image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf) +audio_play(cdrom_t *dev, uint32_t pos, uint32_t len, int ismsf) { - cdrom_drive_t *dev = &cdrom_drives[id]; - if (!cdimg[id]) - return 0; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; int number; - unsigned char attr; + uint8_t attr; TMSF tmsf; int m = 0, s = 0, f = 0; - cdimg[id]->GetAudioTrackInfo(cdimg[id]->GetTrack(pos), number, tmsf, attr); + + if (!img) return 0; + + img->GetAudioTrackInfo(img->GetTrack(pos), number, tmsf, attr); if (attr == DATA_TRACK) { cdrom_image_log("Can't play data track\n"); dev->seek_pos = 0; dev->cd_state = CD_STOPPED; return 0; } + cdrom_image_log("Play audio - %08X %08X %i\n", pos, len, ismsf); if (ismsf == 2) { - cdimg[id]->GetAudioTrackInfo(pos, number, tmsf, attr); + img->GetAudioTrackInfo(pos, number, tmsf, attr); pos = MSFtoLBA(tmsf.min, tmsf.sec, tmsf.fr) - 150; - cdimg[id]->GetAudioTrackInfo(len, number, tmsf, attr); + img->GetAudioTrackInfo(len, number, tmsf, attr); len = MSFtoLBA(tmsf.min, tmsf.sec, tmsf.fr) - 150; } else if (ismsf == 1) { m = (pos >> 16) & 0xff; @@ -233,8 +225,8 @@ image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf) len += pos; } - dev->seek_pos = pos; - dev->cd_end = len; + dev->seek_pos = pos; + dev->cd_end = len; dev->cd_state = CD_PLAYING; dev->cd_buflen = 0; @@ -243,43 +235,35 @@ image_playaudio(uint8_t id, uint32_t pos, uint32_t len, int ismsf) static void -image_pause(uint8_t id) +audio_pause(cdrom_t *dev) { - cdrom_drive_t *dev = &cdrom_drives[id]; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if (!img || dev->img_is_iso) return; - if (!cdimg[id] || cdrom_image[id].image_is_iso) return; if (dev->cd_state == CD_PLAYING) dev->cd_state = CD_PAUSED; } static void -image_resume(uint8_t id) +audio_resume(cdrom_t *dev) { - cdrom_drive_t *dev = &cdrom_drives[id]; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if (!img || dev->img_is_iso) return; - if (!cdimg[id] || cdrom_image[id].image_is_iso) - return; if (dev->cd_state == CD_PAUSED) dev->cd_state = CD_PLAYING; } -static void -image_stop(uint8_t id) -{ - cdrom_drive_t *dev = &cdrom_drives[id]; - - if (!cdimg[id] || cdrom_image[id].image_is_iso) - return; - dev->cd_state = CD_STOPPED; -} - - static int -image_ready(uint8_t id) +image_ready(cdrom_t *dev) { - if (!cdimg[id] || (wcslen(cdrom_image[id].image_path) == 0)) + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if (!img || (wcslen(dev->image_path) == 0)) return 0; return 1; @@ -287,32 +271,33 @@ image_ready(uint8_t id) static int -image_get_last_block(uint8_t id) +image_get_last_block(cdrom_t *dev) { + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; int first_track, last_track; int number, c; unsigned char attr; TMSF tmsf; - uint32_t lb=0; + uint32_t lb = 0; + uint32_t address; - if (!cdimg[id]) - return 0; + if (!img) return 0; - cdimg[id]->GetAudioTracks(first_track, last_track, tmsf); + img->GetAudioTracks(first_track, last_track, tmsf); for (c = 0; c <= last_track; c++) { - uint32_t address; - cdimg[id]->GetAudioTrackInfo(c+1, number, tmsf, attr); + img->GetAudioTrackInfo(c+1, number, tmsf, attr); address = MSFtoLBA(tmsf.min, tmsf.sec, tmsf.fr) - 150; /* Do the - 150 here as well. */ if (address > lb) lb = address; } + return lb; } static int -image_medium_changed(uint8_t id) +image_medium_changed(UNUSED(cdrom_t *dev)) { /* There is no way to change the medium within an already mounted image. */ return 0; @@ -320,23 +305,21 @@ image_medium_changed(uint8_t id) static uint8_t -image_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf) +image_getcurrentsubchannel(cdrom_t *dev, uint8_t *b, int msf) { - cdrom_drive_t *dev = &cdrom_drives[id]; - uint8_t ret; - int pos = 0; - uint32_t cdpos; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + uint8_t attr, track, index, ret; TMSF relPos, absPos; - unsigned char attr, track, index; + uint32_t cdpos; + int pos = 0; cdpos = dev->seek_pos; - if (!cdimg[id]) - return 0; + if (!img) return 0; - cdimg[id]->GetAudioSub(cdpos, attr, track, index, relPos, absPos); + img->GetAudioSub(cdpos, attr, track, index, relPos, absPos); - if (cdrom_image[id].image_is_iso) + if (dev->img_is_iso) ret = 0x15; else { if (dev->cd_state == CD_PLAYING) @@ -352,14 +335,14 @@ image_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf) b[pos++] = index; if (msf) { - b[pos + 3] = (uint8_t) absPos.fr; - b[pos + 2] = (uint8_t) absPos.sec; - b[pos + 1] = (uint8_t) absPos.min; + b[pos + 3] = (uint8_t)absPos.fr; + b[pos + 2] = (uint8_t)absPos.sec; + b[pos + 1] = (uint8_t)absPos.min; b[pos] = 0; pos += 4; - b[pos + 3] = (uint8_t) relPos.fr; - b[pos + 2] = (uint8_t) relPos.sec; - b[pos + 1] = (uint8_t) relPos.min; + b[pos + 3] = (uint8_t)relPos.fr; + b[pos + 2] = (uint8_t)relPos.sec; + b[pos + 1] = (uint8_t)relPos.min; b[pos] = 0; pos += 4; } else { @@ -380,15 +363,15 @@ image_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf) static int -image_is_track_audio(uint8_t id, uint32_t pos, int ismsf) +image_is_track_audio(cdrom_t *dev, uint32_t pos, int ismsf) { - int m, s, f; - unsigned char attr; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + uint8_t attr; TMSF tmsf; + int m, s, f; int number; - if (!cdimg[id] || cdrom_image[id].image_is_iso) - return 0; + if (!img || dev->img_is_iso) return 0; if (ismsf) { m = (pos >> 16) & 0xff; @@ -398,52 +381,52 @@ image_is_track_audio(uint8_t id, uint32_t pos, int ismsf) } /* GetTrack requires LBA. */ - cdimg[id]->GetAudioTrackInfo(cdimg[id]->GetTrack(pos), number, tmsf, attr); + img->GetAudioTrackInfo(img->GetTrack(pos), number, tmsf, attr); return attr == AUDIO_TRACK; } static int -is_legal(int id, int cdrom_sector_type, int cdrom_sector_flags, int audio, int mode2) +is_legal(uint8_t id, int type, int flags, int audio, int mode2) { - if (!(cdrom_sector_flags & 0x70)) { /* 0x00/0x08/0x80/0x88 are illegal modes */ + if (!(flags & 0x70)) { /* 0x00/0x08/0x80/0x88 are illegal modes */ cdrom_image_log("CD-ROM %i: [Any Mode] 0x00/0x08/0x80/0x88 are illegal modes\n", id); return 0; } - if ((cdrom_sector_type != 1) && !audio) { - if (!(cdrom_sector_flags & 0x70)) { /* 0x00/0x08/0x80/0x88 are illegal modes */ + if ((type != 1) && !audio) { + if (!(flags & 0x70)) { /* 0x00/0x08/0x80/0x88 are illegal modes */ cdrom_image_log("CD-ROM %i: [Any Data Mode] 0x00/0x08/0x80/0x88 are illegal modes\n", id); return 0; } - if ((cdrom_sector_flags & 0x06) == 0x06) { + if ((flags & 0x06) == 0x06) { cdrom_image_log("CD-ROM %i: [Any Data Mode] Invalid error flags\n", id); return 0; } - if (((cdrom_sector_flags & 0x700) == 0x300) || ((cdrom_sector_flags & 0x700) > 0x400)) { - cdrom_image_log("CD-ROM %i: [Any Data Mode] Invalid subchannel data flags (%02X)\n", id, cdrom_sector_flags & 0x700); + if (((flags & 0x700) == 0x300) || ((flags & 0x700) > 0x400)) { + cdrom_image_log("CD-ROM %i: [Any Data Mode] Invalid subchannel data flags (%02X)\n", id, flags & 0x700); return 0; } - if ((cdrom_sector_flags & 0x18) == 0x08) { /* EDC/ECC without user data is an illegal mode */ + if ((flags & 0x18) == 0x08) { /* EDC/ECC without user data is an illegal mode */ cdrom_image_log("CD-ROM %i: [Any Data Mode] EDC/ECC without user data is an illegal mode\n", id); return 0; } - if (((cdrom_sector_flags & 0xf0) == 0x90) || ((cdrom_sector_flags & 0xf0) == 0xc0)) { /* 0x90/0x98/0xC0/0xC8 are illegal modes */ + if (((flags & 0xf0) == 0x90) || ((flags & 0xf0) == 0xc0)) { /* 0x90/0x98/0xC0/0xC8 are illegal modes */ cdrom_image_log("CD-ROM %i: [Any Data Mode] 0x90/0x98/0xC0/0xC8 are illegal modes\n", id); return 0; } - if (((cdrom_sector_type > 3) && (cdrom_sector_type != 8)) || (mode2 && (mode2 & 0x03))) { - if ((cdrom_sector_flags & 0xf0) == 0x30) { /* 0x30/0x38 are illegal modes */ + if (((type > 3) && (type != 8)) || (mode2 && (mode2 & 0x03))) { + if ((flags & 0xf0) == 0x30) { /* 0x30/0x38 are illegal modes */ cdrom_image_log("CD-ROM %i: [Any XA Mode 2] 0x30/0x38 are illegal modes\n", id); return 0; } - if (((cdrom_sector_flags & 0xf0) == 0xb0) || ((cdrom_sector_flags & 0xf0) == 0xd0)) { /* 0xBx and 0xDx are illegal modes */ + if (((flags & 0xf0) == 0xb0) || ((flags & 0xf0) == 0xd0)) { /* 0xBx and 0xDx are illegal modes */ cdrom_image_log("CD-ROM %i: [Any XA Mode 2] 0xBx and 0xDx are illegal modes\n", id); return 0; } @@ -455,11 +438,12 @@ is_legal(int id, int cdrom_sector_type, int cdrom_sector_flags, int audio, int m static void -read_sector_to_buffer(uint8_t id, uint8_t *raw_buffer, uint32_t msf, uint32_t lba, int mode2, int len) +read_sector_to_buffer(cdrom_t *dev, uint8_t *rbuf, uint32_t msf, uint32_t lba, int mode2, int len) { - uint8_t *bb = raw_buffer; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + uint8_t *bb = rbuf; - cdimg[id]->ReadSector(raw_buffer + 16, false, lba); + img->ReadSector(rbuf + 16, false, lba); /* Sync bytes */ bb[0] = 0; @@ -483,39 +467,44 @@ read_sector_to_buffer(uint8_t id, uint8_t *raw_buffer, uint32_t msf, uint32_t lb static void -read_audio(int id, uint32_t lba, uint8_t *b) +read_audio(cdrom_t *dev, uint32_t lba, uint8_t *b) { - if (cdimg[id]->GetSectorSize(lba) == 2352) - cdimg[id]->ReadSector(raw_buffer, true, lba); + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if (img->GetSectorSize(lba) == 2352) + img->ReadSector(raw_buffer, true, lba); else - cdimg[id]->ReadSectorSub(raw_buffer, lba); + img->ReadSectorSub(raw_buffer, lba); memcpy(b, raw_buffer, 2352); + cdrom_sector_size = 2352; } static void -read_mode1(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) +read_mode1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) { - if ((cdrom_image[id].image_is_iso) || (cdimg[id]->GetSectorSize(lba) == 2048)) - read_sector_to_buffer(id, raw_buffer, msf, lba, mode2, 2048); - else if (cdimg[id]->GetSectorSize(lba) == 2352) - cdimg[id]->ReadSector(raw_buffer, true, lba); + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if ((dev->img_is_iso) || (img->GetSectorSize(lba) == 2048)) + read_sector_to_buffer(dev, raw_buffer, msf, lba, mode2, 2048); + else if (img->GetSectorSize(lba) == 2352) + img->ReadSector(raw_buffer, true, lba); else - cdimg[id]->ReadSectorSub(raw_buffer, lba); + img->ReadSectorSub(raw_buffer, lba); cdrom_sector_size = 0; if (cdrom_sector_flags & 0x80) { /* Sync */ - cdrom_image_log("CD-ROM %i: [Mode 1] Sync\n", id); + cdrom_image_log("CD-ROM %i: [Mode 1] Sync\n", dev->id); memcpy(b, raw_buffer, 12); cdrom_sector_size += 12; b += 12; } if (cdrom_sector_flags & 0x20) { /* Header */ - cdrom_image_log("CD-ROM %i: [Mode 1] Header\n", id); + cdrom_image_log("CD-ROM %i: [Mode 1] Header\n", dev->id); memcpy(b, raw_buffer + 12, 4); cdrom_sector_size += 4; b += 4; @@ -523,7 +512,7 @@ read_mode1(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2 if (cdrom_sector_flags & 0x40) { /* Sub-header */ if (!(cdrom_sector_flags & 0x10)) { /* No user data */ - cdrom_image_log("CD-ROM %i: [Mode 1] Sub-header\n", id); + cdrom_image_log("CD-ROM %i: [Mode 1] Sub-header\n", dev->id); memcpy(b, raw_buffer + 16, 8); cdrom_sector_size += 8; b += 8; @@ -531,14 +520,14 @@ read_mode1(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2 } if (cdrom_sector_flags & 0x10) { /* User data */ - cdrom_image_log("CD-ROM %i: [Mode 1] User data\n", id); + cdrom_image_log("CD-ROM %i: [Mode 1] User data\n", dev->id); memcpy(b, raw_buffer + 16, 2048); cdrom_sector_size += 2048; b += 2048; } if (cdrom_sector_flags & 0x08) { /* EDC/ECC */ - cdrom_image_log("CD-ROM %i: [Mode 1] EDC/ECC\n", id); + cdrom_image_log("CD-ROM %i: [Mode 1] EDC/ECC\n", dev->id); memcpy(b, raw_buffer + 2064, 288); cdrom_sector_size += 288; b += 288; @@ -547,26 +536,28 @@ read_mode1(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2 static void -read_mode2_non_xa(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) +read_mode2_non_xa(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) { - if ((cdrom_image[id].image_is_iso) || (cdimg[id]->GetSectorSize(lba) == 2336)) - read_sector_to_buffer(id, raw_buffer, msf, lba, mode2, 2336); - else if (cdimg[id]->GetSectorSize(lba) == 2352) - cdimg[id]->ReadSector(raw_buffer, true, lba); + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if ((dev->img_is_iso) || (img->GetSectorSize(lba) == 2336)) + read_sector_to_buffer(dev, raw_buffer, msf, lba, mode2, 2336); + else if (img->GetSectorSize(lba) == 2352) + img->ReadSector(raw_buffer, true, lba); else - cdimg[id]->ReadSectorSub(raw_buffer, lba); + img->ReadSectorSub(raw_buffer, lba); cdrom_sector_size = 0; if (cdrom_sector_flags & 0x80) { /* Sync */ - cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Sync\n", id); + cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Sync\n", dev->id); memcpy(b, raw_buffer, 12); cdrom_sector_size += 12; b += 12; } if (cdrom_sector_flags & 0x20) { /* Header */ - cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Header\n", id); + cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Header\n", dev->id); memcpy(b, raw_buffer + 12, 4); cdrom_sector_size += 4; b += 4; @@ -574,14 +565,14 @@ read_mode2_non_xa(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, in /* Mode 1 sector, expected type is 1 type. */ if (cdrom_sector_flags & 0x40) { /* Sub-header */ - cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Sub-header\n", id); + cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Sub-header\n", dev->id); memcpy(b, raw_buffer + 16, 8); cdrom_sector_size += 8; b += 8; } if (cdrom_sector_flags & 0x10) { /* User data */ - cdrom_image_log("CD-ROM %i: [Mode 2 Formless] User data\n", id); + cdrom_image_log("CD-ROM %i: [Mode 2 Formless] User data\n", dev->id); memcpy(b, raw_buffer + 24, 2336); cdrom_sector_size += 2336; b += 2336; @@ -590,47 +581,49 @@ read_mode2_non_xa(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, in static void -read_mode2_xa_form1(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) +read_mode2_xa_form1(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) { - if ((cdrom_image[id].image_is_iso) || (cdimg[id]->GetSectorSize(lba) == 2048)) - read_sector_to_buffer(id, raw_buffer, msf, lba, mode2, 2048); - else if (cdimg[id]->GetSectorSize(lba) == 2352) - cdimg[id]->ReadSector(raw_buffer, true, lba); + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if ((dev->img_is_iso) || (img->GetSectorSize(lba) == 2048)) + read_sector_to_buffer(dev, raw_buffer, msf, lba, mode2, 2048); + else if (img->GetSectorSize(lba) == 2352) + img->ReadSector(raw_buffer, true, lba); else - cdimg[id]->ReadSectorSub(raw_buffer, lba); + img->ReadSectorSub(raw_buffer, lba); cdrom_sector_size = 0; if (cdrom_sector_flags & 0x80) { /* Sync */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Sync\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Sync\n", dev->id); memcpy(b, raw_buffer, 12); cdrom_sector_size += 12; b += 12; } if (cdrom_sector_flags & 0x20) { /* Header */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Header\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Header\n", dev->id); memcpy(b, raw_buffer + 12, 4); cdrom_sector_size += 4; b += 4; } if (cdrom_sector_flags & 0x40) { /* Sub-header */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Sub-header\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Sub-header\n", dev->id); memcpy(b, raw_buffer + 16, 8); cdrom_sector_size += 8; b += 8; } if (cdrom_sector_flags & 0x10) { /* User data */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] User data\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] User data\n", dev->id); memcpy(b, raw_buffer + 24, 2048); cdrom_sector_size += 2048; b += 2048; } if (cdrom_sector_flags & 0x08) { /* EDC/ECC */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] EDC/ECC\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] EDC/ECC\n", dev->id); memcpy(b, raw_buffer + 2072, 280); cdrom_sector_size += 280; b += 280; @@ -639,40 +632,42 @@ read_mode2_xa_form1(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, static void -read_mode2_xa_form2(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) +read_mode2_xa_form2(cdrom_t *dev, int cdrom_sector_flags, uint32_t lba, uint32_t msf, int mode2, uint8_t *b) { - if ((cdrom_image[id].image_is_iso) || (cdimg[id]->GetSectorSize(lba) == 2324)) - read_sector_to_buffer(id, raw_buffer, msf, lba, mode2, 2324); - else if (cdimg[id]->GetSectorSize(lba) == 2352) - cdimg[id]->ReadSector(raw_buffer, true, lba); + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; + + if ((dev->img_is_iso) || (img->GetSectorSize(lba) == 2324)) + read_sector_to_buffer(dev, raw_buffer, msf, lba, mode2, 2324); + else if (img->GetSectorSize(lba) == 2352) + img->ReadSector(raw_buffer, true, lba); else - cdimg[id]->ReadSectorSub(raw_buffer, lba); + img->ReadSectorSub(raw_buffer, lba); cdrom_sector_size = 0; if (cdrom_sector_flags & 0x80) { /* Sync */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Sync\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Sync\n", dev->id); memcpy(b, raw_buffer, 12); cdrom_sector_size += 12; b += 12; } if (cdrom_sector_flags & 0x20) { /* Header */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Header\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Header\n", dev->id); memcpy(b, raw_buffer + 12, 4); cdrom_sector_size += 4; b += 4; } if (cdrom_sector_flags & 0x40) { /* Sub-header */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Sub-header\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Sub-header\n", dev->id); memcpy(b, raw_buffer + 16, 8); cdrom_sector_size += 8; b += 8; } if (cdrom_sector_flags & 0x10) { /* User data */ - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] User data\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] User data\n", dev->id); memcpy(b, raw_buffer + 24, 2328); cdrom_sector_size += 2328; b += 2328; @@ -681,19 +676,16 @@ read_mode2_xa_form2(int id, int cdrom_sector_flags, uint32_t lba, uint32_t msf, static int -image_readsector_raw(uint8_t id, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, +image_readsector_raw(cdrom_t *dev, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, int cdrom_sector_flags, int *len) { + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; uint8_t *b, *temp_b; uint32_t msf, lba; int audio, mode2; int m, s, f; - if (!cdimg[id]) - return 0; - - if (!cdrom_drives[id].host_drive) - return 0; + if (!img || !dev->host_drive) return 0; b = temp_b = buffer; @@ -710,120 +702,122 @@ image_readsector_raw(uint8_t id, uint8_t *buffer, int sector, int ismsf, int cdr msf = cdrom_lba_to_msf_accurate(sector); } - if (cdrom_image[id].image_is_iso) { + if (dev->img_is_iso) { audio = 0; - mode2 = cdimg[id]->IsMode2(lba) ? 1 : 0; + mode2 = img->IsMode2(lba) ? 1 : 0; } else { - audio = image_is_track_audio(id, sector, ismsf); - mode2 = cdimg[id]->IsMode2(lba) ? 1 : 0; + audio = image_is_track_audio(dev, sector, ismsf); + mode2 = img->IsMode2(lba) ? 1 : 0; } mode2 <<= 2; - mode2 |= cdimg[id]->GetMode2Form(lba); + mode2 |= img->GetMode2Form(lba); memset(raw_buffer, 0, 2448); memset(extra_buffer, 0, 296); if (!(cdrom_sector_flags & 0xf0)) { /* 0x00 and 0x08 are illegal modes */ - cdrom_image_log("CD-ROM %i: [Mode 1] 0x00 and 0x08 are illegal modes\n", id); + cdrom_image_log("CD-ROM %i: [Mode 1] 0x00 and 0x08 are illegal modes\n", dev->id); return 0; } - if (!is_legal(id, cdrom_sector_type, cdrom_sector_flags, audio, mode2)) + if (!is_legal(dev->id, cdrom_sector_type, cdrom_sector_flags, audio, mode2)) return 0; if ((cdrom_sector_type == 3) || ((cdrom_sector_type > 4) && (cdrom_sector_type != 8))) { - if (cdrom_sector_type == 3) - cdrom_image_log("CD-ROM %i: Attempting to read a Yellowbook Mode 2 data sector from an image\n", id); - if (cdrom_sector_type > 4) - cdrom_image_log("CD-ROM %i: Attempting to read a XA Mode 2 Form 2 data sector from an image\n", id); + if (cdrom_sector_type == 3) { + cdrom_image_log("CD-ROM %i: Attempting to read a Yellowbook Mode 2 data sector from an image\n", dev->id); + } + if (cdrom_sector_type > 4) { + cdrom_image_log("CD-ROM %i: Attempting to read a XA Mode 2 Form 2 data sector from an image\n", dev->id); + } return 0; } else if (cdrom_sector_type == 1) { - if (!audio || cdrom_image[id].image_is_iso) { - cdrom_image_log("CD-ROM %i: [Audio] Attempting to read an audio sector from a data image\n", id); + if (!audio || dev->img_is_iso) { + cdrom_image_log("CD-ROM %i: [Audio] Attempting to read an audio sector from a data image\n", dev->id); return 0; } - read_audio(id, lba, temp_b); + read_audio(dev, lba, temp_b); } else if (cdrom_sector_type == 2) { if (audio || mode2) { - cdrom_image_log("CD-ROM %i: [Mode 1] Attempting to read a sector of another type\n", id); + cdrom_image_log("CD-ROM %i: [Mode 1] Attempting to read a sector of another type\n", dev->id); return 0; } - read_mode1(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode1(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); } else if (cdrom_sector_type == 3) { if (audio || !mode2 || (mode2 & 0x03)) { - cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Attempting to read a sector of another type\n", id); + cdrom_image_log("CD-ROM %i: [Mode 2 Formless] Attempting to read a sector of another type\n", dev->id); return 0; } - read_mode2_non_xa(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode2_non_xa(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); } else if (cdrom_sector_type == 4) { if (audio || !mode2 || ((mode2 & 0x03) != 1)) { - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Attempting to read a sector of another type\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 1] Attempting to read a sector of another type\n", dev->id); return 0; } - read_mode2_xa_form1(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode2_xa_form1(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); } else if (cdrom_sector_type == 5) { if (audio || !mode2 || ((mode2 & 0x03) != 2)) { - cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Attempting to read a sector of another type\n", id); + cdrom_image_log("CD-ROM %i: [XA Mode 2 Form 2] Attempting to read a sector of another type\n", dev->id); return 0; } - read_mode2_xa_form2(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode2_xa_form2(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); } else if (cdrom_sector_type == 8) { if (audio) { - cdrom_image_log("CD-ROM %i: [Any Data] Attempting to read a data sector from an audio track\n", id); + cdrom_image_log("CD-ROM %i: [Any Data] Attempting to read a data sector from an audio track\n", dev->id); return 0; } if (mode2 && ((mode2 & 0x03) == 1)) - read_mode2_xa_form1(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode2_xa_form1(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); else if (!mode2) - read_mode1(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode1(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); else { - cdrom_image_log("CD-ROM %i: [Any Data] Attempting to read a data sector whose cooked size is not 2048 bytes\n", id); + cdrom_image_log("CD-ROM %i: [Any Data] Attempting to read a data sector whose cooked size is not 2048 bytes\n", dev->id); return 0; } } else { if (mode2) { if ((mode2 & 0x03) == 0x01) - read_mode2_xa_form1(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode2_xa_form1(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); else if ((mode2 & 0x03) == 0x02) - read_mode2_xa_form2(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode2_xa_form2(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); else - read_mode2_non_xa(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode2_non_xa(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); } else { if (audio) - read_audio(id, lba, temp_b); + read_audio(dev, lba, temp_b); else - read_mode1(id, cdrom_sector_flags, lba, msf, mode2, temp_b); + read_mode1(dev, cdrom_sector_flags, lba, msf, mode2, temp_b); } } if ((cdrom_sector_flags & 0x06) == 0x02) { /* Add error flags. */ - cdrom_image_log("CD-ROM %i: Error flags\n", id); + cdrom_image_log("CD-ROM %i: Error flags\n", dev->id); memcpy(b + cdrom_sector_size, extra_buffer, 294); cdrom_sector_size += 294; } else if ((cdrom_sector_flags & 0x06) == 0x04) { /* Add error flags. */ - cdrom_image_log("CD-ROM %i: Full error flags\n", id); + cdrom_image_log("CD-ROM %i: Full error flags\n", dev->id); memcpy(b + cdrom_sector_size, extra_buffer, 296); cdrom_sector_size += 296; } if ((cdrom_sector_flags & 0x700) == 0x100) { - cdrom_image_log("CD-ROM %i: Raw subchannel data\n", id); + cdrom_image_log("CD-ROM %i: Raw subchannel data\n", dev->id); memcpy(b + cdrom_sector_size, raw_buffer + 2352, 96); cdrom_sector_size += 96; } else if ((cdrom_sector_flags & 0x700) == 0x200) { - cdrom_image_log("CD-ROM %i: Q subchannel data\n", id); + cdrom_image_log("CD-ROM %i: Q subchannel data\n", dev->id); memcpy(b + cdrom_sector_size, raw_buffer + 2352, 16); cdrom_sector_size += 16; } else if ((cdrom_sector_flags & 0x700) == 0x400) { - cdrom_image_log("CD-ROM %i: R/W subchannel data\n", id); + cdrom_image_log("CD-ROM %i: R/W subchannel data\n", dev->id); memcpy(b + cdrom_sector_size, raw_buffer + 2352, 96); cdrom_sector_size += 96; } @@ -835,34 +829,32 @@ image_readsector_raw(uint8_t id, uint8_t *buffer, int sector, int ismsf, int cdr static uint32_t -image_size(uint8_t id) +image_size(cdrom_t *dev) { - cdrom_drive_t *dev = &cdrom_drives[id]; - return dev->cdrom_capacity; } static int -image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, int msf, int maxlen, int single) +image_readtoc(cdrom_t *dev, unsigned char *b, unsigned char starttrack, int msf, UNUSED(int maxlen), int single) { + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; int number, len = 4; int c, d, first_track, last_track; uint32_t temp; unsigned char attr; TMSF tmsf; - if (!cdimg[id]) - return 0; + if (!img) return 0; - cdimg[id]->GetAudioTracks(first_track, last_track, tmsf); + img->GetAudioTracks(first_track, last_track, tmsf); b[2] = first_track; b[3] = last_track; d = 0; for (c = 0; c <= last_track; c++) { - cdimg[id]->GetAudioTrackInfo(c+1, number, tmsf, attr); + img->GetAudioTrackInfo(c+1, number, tmsf, attr); if (number >= starttrack) { d=c; break; @@ -870,12 +862,12 @@ image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, int msf, i } if (starttrack != 0xAA) { - cdimg[id]->GetAudioTrackInfo(c+1, number, tmsf, attr); + img->GetAudioTrackInfo(c+1, number, tmsf, attr); b[2] = number; } for (c = d; c <= last_track; c++) { - cdimg[id]->GetAudioTrackInfo(c+1, number, tmsf, attr); + img->GetAudioTrackInfo(c+1, number, tmsf, attr); b[len++] = 0; /* reserved */ b[len++] = attr; @@ -907,17 +899,17 @@ image_readtoc(uint8_t id, unsigned char *b, unsigned char starttrack, int msf, i static int -image_readtoc_session(uint8_t id, unsigned char *b, int msf, int maxlen) +image_readtoc_session(cdrom_t *dev, unsigned char *b, int msf, int maxlen) { + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; int number, len = 4; - TMSF tmsf; - unsigned char attr; + uint8_t attr; uint32_t temp; + TMSF tmsf; - if (!cdimg[id]) - return 0; + if (!img) return 0; - cdimg[id]->GetAudioTrackInfo(1, number, tmsf, attr); + img->GetAudioTrackInfo(1, number, tmsf, attr); if (number == 0) number = 1; @@ -948,24 +940,23 @@ image_readtoc_session(uint8_t id, unsigned char *b, int msf, int maxlen) static int -image_readtoc_raw(uint8_t id, unsigned char *b, int maxlen) +image_readtoc_raw(cdrom_t *dev, unsigned char *b, UNUSED(int maxlen)) { - int track, len = 4; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; int first_track, last_track; - int number; - unsigned char attr; + int number, track, len = 4; + uint8_t attr; TMSF tmsf; - if (!cdimg[id]) - return 0; + if (!img) return 0; - cdimg[id]->GetAudioTracks(first_track, last_track, tmsf); + img->GetAudioTracks(first_track, last_track, tmsf); b[2] = first_track; b[3] = last_track; for (track = first_track; track <= last_track; track++) { - cdimg[id]->GetAudioTrackInfo(track, number, tmsf, attr); + img->GetAudioTrackInfo(track, number, tmsf, attr); b[len++] = track; b[len++]= attr; @@ -985,22 +976,23 @@ image_readtoc_raw(uint8_t id, unsigned char *b, int maxlen) static int -image_status(uint8_t id) +image_status(cdrom_t *dev) { - cdrom_drive_t *dev = &cdrom_drives[id]; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; - if (!cdimg[id]) - return CD_STATUS_EMPTY; + if (!img) return CD_STATUS_EMPTY; - if (cdrom_image[id].image_is_iso) + if (dev->img_is_iso) return CD_STATUS_DATA_ONLY; - if (cdimg[id]->HasAudioTracks()) { + if (img->HasAudioTracks()) { switch(dev->cd_state) { case CD_PLAYING: return CD_STATUS_PLAYING; + case CD_PAUSED: return CD_STATUS_PAUSED; + case CD_STOPPED: default: return CD_STATUS_STOPPED; @@ -1011,97 +1003,121 @@ image_status(uint8_t id) } -void -image_reset(UNUSED(uint8_t id)) +static void +image_stop(cdrom_t *dev) { - return; -} + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; - -void -image_close(uint8_t id) -{ - cdrom_drive_t *dev = &cdrom_drives[id]; + if (!img || dev->img_is_iso) return; dev->cd_state = CD_STOPPED; - if (cdimg[id]) { - delete cdimg[id]; - cdimg[id] = NULL; - } -} - - -int -image_open(uint8_t id, wchar_t *fn) -{ - cdrom_drive_t *dev = &cdrom_drives[id]; - - wcscpy(cdrom_image[id].image_path, fn); - - if (! wcscasecmp(plat_get_extension(fn), L"ISO")) - cdrom_image[id].image_is_iso = 1; - else - cdrom_image[id].image_is_iso = 0; - - cdimg[id] = new CDROM_Interface_Image(); - memset(afn, 0, sizeof(afn)); - wcstombs(afn, fn, sizeof(afn)); - if (!cdimg[id]->SetDevice(afn, false)) { - image_close(id); - cdrom_set_null_handler(id); - cdrom_image_log("[f] image_open(): cdrom_drives[%i].handler = %08X\n", id, cdrom_drives[id].handler); - return 1; - } - dev->cd_state = CD_STOPPED; - dev->seek_pos = 0; - dev->cd_buflen = 0; - dev->cdrom_capacity = image_get_last_block(id) + 1; - cdrom_drives[id].handler = &image_cdrom; - - return 0; } static void -image_exit(uint8_t id) +image_exit(cdrom_t *dev) { - cdrom_drive_t *dev = &cdrom_drives[id]; + CDROM_Interface_Image *img = (CDROM_Interface_Image *)dev->image; - dev->handler_inited = 0; +cdrom_image_log("CDROM: image_exit(%ls)\n", dev->image_path); + dev->cd_state = CD_STOPPED; + + if (img) { + delete img; + dev->image = NULL; + } + + dev->ops = NULL; } /* TODO: Check for what data type a mixed CD is. */ -static int image_media_type_id(uint8_t id) +static int +image_media_type_id(cdrom_t *dev) { - if (image_size(id) > 405000) - return 65; /* DVD. */ - else { - if (cdrom_image[id].image_is_iso) - return 1; /* Data CD. */ - else - return 3; /* Mixed mode CD. */ - } + if (image_size(dev) > 405000) + return 65; /* DVD. */ + + if (dev->img_is_iso) + return 1; /* Data CD. */ + + return 3; /* Mixed mode CD. */ } -CDROM image_cdrom = -{ +static const cdrom_ops_t cdrom_image_ops = { image_ready, image_medium_changed, image_media_type_id, - image_audio_callback, - image_audio_stop, + audio_callback, + audio_stop, image_readtoc, image_readtoc_session, image_readtoc_raw, image_getcurrentsubchannel, image_readsector_raw, - image_playaudio, - image_pause, - image_resume, + audio_play, + audio_pause, + audio_resume, image_size, image_status, image_stop, image_exit }; + + +int +cdrom_image_open(cdrom_t *dev, const wchar_t *fn) +{ + char temp[1024]; + CDROM_Interface_Image *img; + + wcscpy(dev->image_path, fn); + + if (! wcscasecmp(plat_get_extension((wchar_t *) fn), L"ISO")) + dev->img_is_iso = 1; + else + dev->img_is_iso = 0; + + /* Create new instance of the CDROM_Image class. */ + img = new CDROM_Interface_Image(); + dev->image = img; + + /* Convert filename and open the image. */ + memset(temp, '\0', sizeof(temp)); + wcstombs(temp, fn, sizeof(temp)); + if (!img->SetDevice(temp, false)) { + cdrom_image_close(dev); + cdrom->ops = NULL; + cdrom_image_log("[f] image_open(): cdrom[%i]->ops = %08X\n", dev->id, dev->ops); + return 1; + } + + /* All good, reset state. */ + dev->cd_state = CD_STOPPED; + dev->seek_pos = 0; + dev->cd_buflen = 0; + dev->cdrom_capacity = image_get_last_block(dev) + 1; + + /* Attach this handler to the drive. */ + dev->ops = &cdrom_image_ops; + + return 0; +} + + +void +cdrom_image_close(cdrom_t *dev) +{ +cdrom_image_log("CDROM: image_close(%ls)\n", dev->image_path); + if (dev->ops->exit) + dev->ops->exit(dev); +} + + +void +cdrom_image_reset(UNUSED(cdrom_t *dev)) +{ +cdrom_image_log("CDROM: image_reset(%ls)\n", dev->image_path); + /* Nothing to do. */ +} diff --git a/src/cdrom/cdrom_null.c b/src/cdrom/cdrom_null.c deleted file mode 100644 index 7479e1230..000000000 --- a/src/cdrom/cdrom_null.c +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Implementation of the CD-ROM null interface for unmounted - * guest CD-ROM drives. - * - * Version: @(#)cdrom_null.c 1.0.9 2018/10/09 - * - * Authors: Sarah Walker, - * Miran Grca, - * - * Copyright 2008-2016 Sarah Walker. - * Copyright 2016-2018 Miran Grca. - */ -#include -#include -#include -#include -#include "../86box.h" -#include "../scsi/scsi_device.h" -#include "cdrom.h" - - -static CDROM null_cdrom; - - -static int -null_ready(uint8_t id) -{ - return(0); -} - - -/* Always return 0, the contents of a null CD-ROM drive never change. */ -static int -null_medium_changed(uint8_t id) -{ - return(0); -} - - -static uint8_t -null_getcurrentsubchannel(uint8_t id, uint8_t *b, int msf) -{ - return(0x13); -} - - -static int -null_readsector_raw(uint8_t id, uint8_t *buffer, int sector, int ismsf, int cdrom_sector_type, int cdrom_sector_flags, int *len) -{ - *len = 0; - - return(0); -} - - -static int -null_readtoc(uint8_t id, uint8_t *b, uint8_t starttrack, int msf, int maxlen, int single) -{ - return(0); -} - - -static int -null_readtoc_session(uint8_t id, uint8_t *b, int msf, int maxlen) -{ - return(0); -} - - -static int -null_readtoc_raw(uint8_t id, uint8_t *b, int maxlen) -{ - return(0); -} - - -static uint32_t -null_size(uint8_t id) -{ - return(0); -} - - -static int -null_status(uint8_t id) -{ - return(CD_STATUS_EMPTY); -} - - -void -cdrom_null_reset(uint8_t id) -{ -} - - -void cdrom_set_null_handler(uint8_t id); - -int -cdrom_null_open(uint8_t id) -{ - cdrom_set_null_handler(id); - - return(0); -} - - -void -null_close(uint8_t id) -{ -} - - -static -void null_exit(uint8_t id) -{ -} - - -static int -null_media_type_id(uint8_t id) -{ - return(0x70); -} - - -void -cdrom_set_null_handler(uint8_t id) -{ - cdrom_drives[id].handler = &null_cdrom; - cdrom_drives[id].host_drive = 0; - memset(cdrom_image[id].image_path, 0, sizeof(cdrom_image[id].image_path)); -} - - -static CDROM null_cdrom = { - null_ready, - null_medium_changed, - null_media_type_id, - NULL, - NULL, - null_readtoc, - null_readtoc_session, - null_readtoc_raw, - null_getcurrentsubchannel, - null_readsector_raw, - NULL, - NULL, - NULL, - null_size, - null_status, - NULL, - null_exit -}; diff --git a/src/cdrom/cdrom_null.h b/src/cdrom/cdrom_null.h deleted file mode 100644 index 480acb29c..000000000 --- a/src/cdrom/cdrom_null.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 86Box A hypervisor and IBM PC system emulator that specializes in - * running old operating systems and software designed for IBM - * PC systems and compatibles from 1981 through fairly recent - * system designs based on the PCI bus. - * - * This file is part of the 86Box distribution. - * - * Implementation of the CD-ROM null interface for unmounted - * guest CD-ROM drives. - * - * Version: @(#)cdrom_null.h 1.0.4 2018/03/31 - * - * Authors: Sarah Walker, - * Miran Grca, - * Copyright 2008-2018 Sarah Walker. - * Copyright 2016-2018 Miran Grca. - */ -#ifndef EMU_CDROM_NULL_H -#define EMU_CDROM_NULL_H - - -extern int cdrom_null_open(uint8_t id); -extern void cdrom_null_reset(uint8_t id); -extern void null_close(uint8_t id); - - -#endif /*EMU_CDROM_NULL_H*/ diff --git a/src/config.c b/src/config.c index 5fad5fb8a..805415ba7 100644 --- a/src/config.c +++ b/src/config.c @@ -8,7 +8,7 @@ * * Configuration file handler. * - * Version: @(#)config.c 1.0.57 2018/10/07 + * Version: @(#)config.c 1.0.58 2018/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -112,22 +112,22 @@ static list_t config_head; #ifdef ENABLE_CONFIG_LOG int config_do_log = ENABLE_CONFIG_LOG; -#endif static void -config_log(const char *format, ...) +config_log(const char *fmt, ...) { -#ifdef ENABLE_CONFIG_LOG va_list ap; if (config_do_log) { - va_start(ap, format); - pclog_ex(format, ap); + va_start(ap, fmt); + pclog_ex(fmt, ap); va_end(ap); } -#endif } +#else +#define config_log(fmt, ...) +#endif static section_t * @@ -1046,46 +1046,47 @@ load_other_removable_devices(void) char s[512]; unsigned int board = 0, dev = 0; wchar_t *wp; - int c; + int c, d = 0; memset(temp, 0x00, sizeof(temp)); for (c=0; c>1, (c+2)&1); p = config_get_string(cat, temp, tmp2); sscanf(p, "%01u:%01u", &board, &dev); board &= 3; dev &= 1; - cdrom_drives[c].ide_channel = (board<<1)+dev; + cdrom[c].ide_channel = (board<<1)+dev; - if (cdrom_drives[c].ide_channel > 7) - cdrom_drives[c].ide_channel = 7; + if (cdrom[c].ide_channel > 7) + cdrom[c].ide_channel = 7; } else { sprintf(temp, "cdrom_%02i_scsi_id", c+1); - if (cdrom_drives[c].bus_type == CDROM_BUS_SCSI) { - cdrom_drives[c].scsi_device_id = config_get_int(cat, temp, c+2); + if (cdrom[c].bus_type == CDROM_BUS_SCSI) { + cdrom[c].scsi_device_id = config_get_int(cat, temp, c+2); - if (cdrom_drives[c].scsi_device_id > 15) - cdrom_drives[c].scsi_device_id = 15; + if (cdrom[c].scsi_device_id > 15) + cdrom[c].scsi_device_id = 15; } else config_delete_var(cat, temp); } @@ -1107,20 +1108,20 @@ load_other_removable_devices(void) * with the EXE path. Just strip * that off for now... */ - wcsncpy(cdrom_image[c].image_path, &wp[wcslen(usr_path)], sizeof_w(cdrom_image[c].image_path)); + wcsncpy(cdrom[c].image_path, &wp[wcslen(usr_path)], sizeof_w(cdrom[c].image_path)); } else #endif - wcsncpy(cdrom_image[c].image_path, wp, sizeof_w(cdrom_image[c].image_path)); + wcsncpy(cdrom[c].image_path, wp, sizeof_w(cdrom[c].image_path)); - if (cdrom_drives[c].host_drive < 'A') - cdrom_drives[c].host_drive = 0; + if (cdrom[c].host_drive && (cdrom[c].host_drive != 200)) + cdrom[c].host_drive = 0; - if ((cdrom_drives[c].host_drive == 0x200) && - (wcslen(cdrom_image[c].image_path) == 0)) - cdrom_drives[c].host_drive = 0; + if ((cdrom[c].host_drive == 0x200) && + (wcslen(cdrom[c].image_path) == 0)) + cdrom[c].host_drive = 0; /* If the CD-ROM is disabled, delete all its variables. */ - if (cdrom_drives[c].bus_type == CDROM_BUS_DISABLED) { + if (cdrom[c].bus_type == CDROM_BUS_DISABLED) { sprintf(temp, "cdrom_%02i_host_drive", c+1); config_delete_var(cat, temp); @@ -1231,8 +1232,7 @@ config_load(void) config_log("Loading config file '%ls'..\n", cfg_path); memset(hdd, 0, sizeof(hard_disk_t)); - memset(cdrom_drives, 0, sizeof(cdrom_drive_t) * CDROM_NUM); - memset(cdrom_image, 0, sizeof(cdrom_image_t) * CDROM_NUM); + memset(cdrom, 0, sizeof(cdrom_t) * CDROM_NUM); #ifdef USE_IOCTL memset(cdrom_ioctl, 0, sizeof(cdrom_ioctl_t) * CDROM_NUM); #endif @@ -1813,51 +1813,50 @@ save_other_removable_devices(void) for (c=0; c 'Z') && (cdrom_drives[c].host_drive != 200))) { + if ((cdrom[c].bus_type == 0) || (cdrom[c].host_drive != 200)) { config_delete_var(cat, temp); } else { - config_set_int(cat, temp, cdrom_drives[c].host_drive); + config_set_int(cat, temp, cdrom[c].host_drive); } sprintf(temp, "cdrom_%02i_speed", c+1); - if ((cdrom_drives[c].bus_type == 0) || (cdrom_drives[c].speed == 8)) { + if ((cdrom[c].bus_type == 0) || (cdrom[c].speed == 8)) { config_delete_var(cat, temp); } else { - config_set_int(cat, temp, cdrom_drives[c].speed); + config_set_int(cat, temp, cdrom[c].speed); } sprintf(temp, "cdrom_%02i_parameters", c+1); - if (cdrom_drives[c].bus_type == 0) { + if (cdrom[c].bus_type == 0) { config_delete_var(cat, temp); } else { - sprintf(tmp2, "%u, %s", cdrom_drives[c].sound_on, - hdd_bus_to_string(cdrom_drives[c].bus_type, 1)); + sprintf(tmp2, "%u, %s", cdrom[c].sound_on, + hdd_bus_to_string(cdrom[c].bus_type, 1)); config_set_string(cat, temp, tmp2); } sprintf(temp, "cdrom_%02i_ide_channel", c+1); - if (cdrom_drives[c].bus_type != CDROM_BUS_ATAPI) + if (cdrom[c].bus_type != CDROM_BUS_ATAPI) config_delete_var(cat, temp); else { - sprintf(tmp2, "%01u:%01u", cdrom_drives[c].ide_channel>>1, - cdrom_drives[c].ide_channel & 1); + sprintf(tmp2, "%01u:%01u", cdrom[c].ide_channel>>1, + cdrom[c].ide_channel & 1); config_set_string(cat, temp, tmp2); } sprintf(temp, "cdrom_%02i_scsi_id", c + 1); - if (cdrom_drives[c].bus_type != CDROM_BUS_SCSI) { + if (cdrom[c].bus_type != CDROM_BUS_SCSI) { config_delete_var(cat, temp); } else { - config_set_int(cat, temp, cdrom_drives[c].scsi_device_id); + config_set_int(cat, temp, cdrom[c].scsi_device_id); } sprintf(temp, "cdrom_%02i_image_path", c + 1); - if ((cdrom_drives[c].bus_type == 0) || - (wcslen(cdrom_image[c].image_path) == 0)) { + if ((cdrom[c].bus_type == 0) || + (wcslen(cdrom[c].image_path) == 0)) { config_delete_var(cat, temp); } else { - config_set_wstring(cat, temp, cdrom_image[c].image_path); + config_set_wstring(cat, temp, cdrom[c].image_path); } } diff --git a/src/disk/hdc_ide.c b/src/disk/hdc_ide.c index e3d9015e1..483a2b472 100644 --- a/src/disk/hdc_ide.c +++ b/src/disk/hdc_ide.c @@ -9,7 +9,7 @@ * Implementation of the IDE emulation for hard disks and ATAPI * CD-ROM devices. * - * Version: @(#)hdc_ide.c 1.0.50 2018/10/10 + * Version: @(#)hdc_ide.c 1.0.51 2018/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -140,13 +140,11 @@ static void ide_callback(void *priv); #ifdef ENABLE_IDE_LOG int ide_do_log = ENABLE_IDE_LOG; -#endif static void ide_log(const char *fmt, ...) { -#ifdef ENABLE_IDE_LOG va_list ap; if (ide_do_log) { @@ -154,8 +152,10 @@ ide_log(const char *fmt, ...) pclog_ex(fmt, ap); va_end(ap); } -#endif } +#else +#define ide_log(fmt, ...) +#endif uint8_t @@ -2427,8 +2427,8 @@ secondary_ide_check(void) secondary_zips++; } for (i=0; i= 2) && (cdrom_drives[i].ide_channel <= 3) && - (cdrom_drives[i].bus_type == CDROM_BUS_ATAPI)) + if ((cdrom[i].ide_channel >= 2) && (cdrom[i].ide_channel <= 3) && + (cdrom[i].bus_type == CDROM_BUS_ATAPI)) secondary_cdroms++; } if (!secondary_zips && !secondary_cdroms) diff --git a/src/intel_piix.c b/src/intel_piix.c index 877605aeb..a23b89780 100644 --- a/src/intel_piix.c +++ b/src/intel_piix.c @@ -10,7 +10,7 @@ * word 0 - base address * word 1 - bits 1-15 = byte count, bit 31 = end of transfer * - * Version: @(#)intel_piix.c 1.0.18 2018/10/02 + * Version: @(#)intel_piix.c 1.0.19 2018/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -69,22 +69,22 @@ static void piix_bus_master_writel(uint16_t port, uint32_t val, void *priv); #ifdef ENABLE_PIIX_LOG int piix_do_log = ENABLE_PIIX_LOG; -#endif static void -piix_log(const char *format, ...) +piix_log(const char *fmt, ...) { -#ifdef ENABLE_PIIX_LOG va_list ap; if (piix_do_log) { - va_start(ap, format); - pclog_ex(format, ap); + va_start(ap, fmt); + pclog_ex(fmt, ap); va_end(ap); } -#endif } +#else +#define piix_log(fmt, ...) +#endif static void @@ -427,7 +427,9 @@ static void piix_bus_master_write(uint16_t port, uint8_t val, void *priv) { piix_busmaster_t *dev = (piix_busmaster_t *) priv; +#ifdef ENABLE_PIIX_LOG int channel = (port & 8) ? 1 : 0; +#endif piix_log("PIIX Bus master BYTE write: %04X %02X\n", port, val); @@ -610,11 +612,15 @@ static int piix_bus_master_dma_op(int channel, uint8_t *data, int transfer_length, int out, void *priv) { piix_busmaster_t *dev = (piix_busmaster_t *) priv; +#ifdef ENABLE_PIIX_LOG char *sop; +#endif int force_end = 0, buffer_pos = 0; +#ifdef ENABLE_PIIX_LOG sop = out ? "Writ" : "Read"; +#endif if (!(dev->status & 1)) return 2; /*DMA disabled*/ @@ -825,7 +831,7 @@ piix_reset(void *p) int i = 0; for (i = 0; i < CDROM_NUM; i++) { - if (cdrom_drives[i].bus_type == CDROM_BUS_ATAPI) + if (cdrom[i].bus_type == CDROM_BUS_ATAPI) scsi_cdrom_reset(scsi_cdrom[i]); } for (i = 0; i < ZIP_NUM; i++) { diff --git a/src/pc.c b/src/pc.c index 2d23b35a1..3a1ce5434 100644 --- a/src/pc.c +++ b/src/pc.c @@ -8,7 +8,7 @@ * * Main emulator module where most things are controlled. * - * Version: @(#)pc.c 1.0.83 2018/10/12 + * Version: @(#)pc.c 1.0.84 2018/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -65,7 +65,6 @@ #include "disk/zip.h" #include "scsi/scsi_disk.h" #include "cdrom/cdrom_image.h" -#include "cdrom/cdrom_null.h" #include "network/network.h" #include "sound/sound.h" #include "sound/midi.h" diff --git a/src/plat.h b/src/plat.h index fc7e5e252..b3b6e10a8 100644 --- a/src/plat.h +++ b/src/plat.h @@ -8,7 +8,7 @@ * * Define the various platform support functions. * - * Version: @(#)plat.h 1.0.26 2018/02/14 + * Version: @(#)plat.h 1.0.27 2018/10/17 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -104,14 +104,7 @@ extern void do_stop(void); /* Platform-specific device support. */ -extern uint8_t host_cdrom_drive_available[26]; -extern uint8_t host_cdrom_drive_available_num; - -#ifdef USE_IOCTL -extern void cdrom_init_host_drives(void); -#endif -extern void cdrom_eject(uint8_t id); -extern void cdrom_reload(uint8_t id); +extern void plat_cdrom_ui_update(uint8_t id, uint8_t reload); extern void zip_eject(uint8_t id); extern void zip_reload(uint8_t id); extern int ioctl_open(uint8_t id, char d); diff --git a/src/scsi/scsi_cdrom.c b/src/scsi/scsi_cdrom.c index 4b0c70352..157dcf90c 100644 --- a/src/scsi/scsi_cdrom.c +++ b/src/scsi/scsi_cdrom.c @@ -9,7 +9,7 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)scsi_cdrom.c 1.0.52 2018/10/09 + * Version: @(#)scsi_cdrom.c 1.0.53 2018/10/17 * * Author: Miran Grca, * @@ -32,12 +32,10 @@ #include "../nvr.h" #include "../disk/hdc.h" #include "../disk/hdc_ide.h" -#include "../plat.h" #include "../sound/sound.h" +#include "../plat.h" #include "../ui.h" #include "../cdrom/cdrom.h" -#include "../cdrom/cdrom_image.h" -#include "../cdrom/cdrom_null.h" #include "scsi_cdrom.h" @@ -335,13 +333,11 @@ static void scsi_cdrom_callback(void *p); #ifdef ENABLE_SCSI_CDROM_LOG int scsi_cdrom_do_log = ENABLE_SCSI_CDROM_LOG; -#endif static void scsi_cdrom_log(const char *format, ...) { -#ifdef ENABLE_SCSI_CDROM_LOG va_list ap; if (scsi_cdrom_do_log) { @@ -349,8 +345,10 @@ scsi_cdrom_log(const char *format, ...) pclog_ex(format, ap); va_end(ap); } -#endif } +#else +#define scsi_cdrom_log(format, ...) +#endif static void @@ -379,8 +377,8 @@ scsi_cdrom_init(scsi_cdrom_t *dev) if (!dev) return; - /* Tell the scsi_cdrom_t struct what cdrom_drives element corresponds to it. */ - dev->drv = &(cdrom_drives[dev->id]); + /* Tell the scsi_cdrom_t struct what cdrom element corresponds to it. */ + dev->drv = &(cdrom[dev->id]); /* Do a reset (which will also rezero it). */ scsi_cdrom_reset(dev); @@ -542,7 +540,8 @@ scsi_cdrom_read_capacity(void *p, uint8_t *cdb, uint8_t *buffer, uint32_t *len) scsi_cdrom_t *dev = (scsi_cdrom_t *) p; int size = 0; - size = dev->drv->handler->size(dev->id) - 1; /* IMPORTANT: What's returned is the last LBA block. */ + if (dev->drv->ops && dev->drv->ops->size) + size = dev->drv->ops->size(dev->drv) - 1; /* IMPORTANT: What's returned is the last LBA block. */ memset(buffer, 0, 8); buffer[0] = (size >> 24) & 0xff; buffer[1] = (size >> 16) & 0xff; @@ -1084,7 +1083,12 @@ scsi_cdrom_read_data(scsi_cdrom_t *dev, int msf, int type, int flags, int32_t *l int i = 0; int temp_len = 0; - cdsize = dev->drv->handler->size(dev->id); + if (dev->drv->ops && dev->drv->ops->size) + cdsize = dev->drv->ops->size(dev->drv); + else { + scsi_cdrom_not_ready(dev); + return 0; + } if (dev->sector_pos >= cdsize) { scsi_cdrom_log("CD-ROM %i: Trying to read from beyond the end of disc (%i >= %i)\n", dev->id, @@ -1104,8 +1108,13 @@ scsi_cdrom_read_data(scsi_cdrom_t *dev, int msf, int type, int flags, int32_t *l *len = 0; for (i = 0; i < dev->requested_blocks; i++) { - ret = dev->drv->handler->readsector_raw(dev->id, cdbufferb + dev->data_pos, dev->sector_pos + i, - msf, type, flags, &temp_len); + if (dev->drv->ops && dev->drv->ops->readsector_raw) + ret = dev->drv->ops->readsector_raw(dev->drv, cdbufferb + dev->data_pos, + dev->sector_pos + i, msf, type, flags, &temp_len); + else { + scsi_cdrom_not_ready(dev); + return 0; + } dev->data_pos += temp_len; dev->old_len += temp_len; @@ -1173,11 +1182,16 @@ static int scsi_cdrom_read_dvd_structure(scsi_cdrom_t *dev, int format, const uint8_t *packet, uint8_t *buf) { int layer = packet[6]; - uint64_t total_sectors; + uint64_t total_sectors = 0; switch (format) { case 0x00: /* Physical format information */ - total_sectors = (uint64_t) dev->drv->handler->size(dev->id); + if (dev->drv->ops && dev->drv->ops->size) + total_sectors = (uint64_t) dev->drv->ops->size(dev->drv); + else { + scsi_cdrom_not_ready(dev); + return 0; + } if (layer != 0) { scsi_cdrom_invalid_field(dev); @@ -1325,17 +1339,23 @@ scsi_cdrom_pre_execution_check(scsi_cdrom_t *dev, uint8_t *cdb) return 0; } - status = dev->drv->handler->status(dev->id); + if (dev->drv->ops && dev->drv->ops->status) + status = dev->drv->ops->status(dev->drv); + else + status = CD_STATUS_EMPTY; if ((status == CD_STATUS_PLAYING) || (status == CD_STATUS_PAUSED)) { ready = 1; goto skip_ready_check; } - if (dev->drv->handler->medium_changed(dev->id)) - scsi_cdrom_insert((void *) dev); + if (dev->drv->ops && dev->drv->ops->medium_changed) { + if (dev->drv->ops->medium_changed(dev->drv)) + scsi_cdrom_insert((void *) dev); + } - ready = dev->drv->handler->ready(dev->id); + if (dev->drv->ops && dev->drv->ops->ready) + ready = dev->drv->ops->ready(dev->drv); skip_ready_check: /* If the drive is not ready, there is no reason to keep the @@ -1461,10 +1481,13 @@ scsi_cdrom_request_sense_for_scsi(void *p, uint8_t *buffer, uint8_t alloc_length scsi_cdrom_t *dev = (scsi_cdrom_t *) p; int ready = 0; - if (dev->drv->handler->medium_changed(dev->id)) - scsi_cdrom_insert((void *) dev); + if (dev->drv->ops && dev->drv->ops->medium_changed) { + if (dev->drv->ops->medium_changed(dev->drv)) + scsi_cdrom_insert((void *) dev); + } - ready = dev->drv->handler->ready(dev->id); + if (dev->drv->ops && dev->drv->ops->ready) + ready = dev->drv->ops->ready(dev->drv); if (!ready && dev->unit_attention) { /* If the drive is not ready, there is no reason to keep the @@ -1551,7 +1574,10 @@ scsi_cdrom_command(void *p, uint8_t *cdb) memcpy(dev->current_cdb, cdb, 12); - dev->drv->cd_status = dev->drv->handler->status(dev->id); + if (dev->drv->ops && dev->drv->ops->status) + dev->drv->cd_status = dev->drv->ops->status(dev->drv); + else + dev->drv->cd_status = CD_STATUS_EMPTY; if (cdb[0] != 0) { scsi_cdrom_log("CD-ROM %i: Command 0x%02X, Sense Key %02X, Asc %02X, Ascq %02X, Unit attention: %i\n", @@ -1579,8 +1605,8 @@ scsi_cdrom_command(void *p, uint8_t *cdb) break; case GPCMD_REZERO_UNIT: - if (dev->drv->handler->stop) - dev->drv->handler->stop(dev->id); + if (dev->drv->ops->stop) + dev->drv->ops->stop(dev->drv); dev->sector_pos = dev->sector_len = 0; dev->drv->seek_diff = dev->drv->seek_pos; cdrom_seek(dev->drv, 0); @@ -1646,17 +1672,34 @@ scsi_cdrom_command(void *p, uint8_t *cdb) if (toc_format == 0) toc_format = (cdb[9] >> 6) & 3; + if (!dev->drv->ops) { + scsi_cdrom_not_ready(dev); + return; + } + switch (toc_format) { case 0: /*Normal*/ - len = dev->drv->handler->readtoc(dev->id, cdbufferb, cdb[6], msf, max_len, + if (!dev->drv->ops->readtoc) { + scsi_cdrom_not_ready(dev); + return; + } + len = dev->drv->ops->readtoc(dev->drv, cdbufferb, cdb[6], msf, max_len, 0); break; case 1: /*Multi session*/ - len = dev->drv->handler->readtoc_session(dev->id, cdbufferb, msf, max_len); + if (!dev->drv->ops->readtoc_session) { + scsi_cdrom_not_ready(dev); + return; + } + len = dev->drv->ops->readtoc_session(dev->drv, cdbufferb, msf, max_len); cdbufferb[0] = 0; cdbufferb[1] = 0xA; break; case 2: /*Raw*/ - len = dev->drv->handler->readtoc_raw(dev->id, cdbufferb, max_len); + if (!dev->drv->ops->readtoc_raw) { + scsi_cdrom_not_ready(dev); + return; + } + len = dev->drv->ops->readtoc_raw(dev->drv, cdbufferb, max_len); break; default: scsi_cdrom_invalid_field(dev); @@ -1826,7 +1869,10 @@ scsi_cdrom_command(void *p, uint8_t *cdb) len = scsi_cdrom_mode_sense(dev, cdbufferb, 4, cdb[2], block_desc); len = MIN(len, alloc_length); cdbufferb[0] = len - 1; - cdbufferb[1] = dev->drv->handler->media_type_id(dev->id); + if (dev->drv->ops && dev->drv->ops->media_type_id) + cdbufferb[1] = dev->drv->ops->media_type_id(dev->drv); + else + cdbufferb[1] = 0x70; if (block_desc) cdbufferb[3] = 8; } else { @@ -1834,7 +1880,10 @@ scsi_cdrom_command(void *p, uint8_t *cdb) len = MIN(len, alloc_length); cdbufferb[0]=(len - 2) >> 8; cdbufferb[1]=(len - 2) & 255; - cdbufferb[2] = dev->drv->handler->media_type_id(dev->id); + if (dev->drv->ops && dev->drv->ops->media_type_id) + cdbufferb[2] = dev->drv->ops->media_type_id(dev->drv); + else + cdbufferb[2] = 0x70; if (block_desc) { cdbufferb[6] = 0; cdbufferb[7] = 8; @@ -1892,8 +1941,9 @@ scsi_cdrom_command(void *p, uint8_t *cdb) * the number of sectors from the media tells us which profile * to use as current. 0 means there is no media */ - if (dev->drv->handler->ready(dev->id)) { - len = dev->drv->handler->size(dev->id); + if (dev->drv->ops && dev->drv->ops->ready && + dev->drv->ops->ready(dev->drv)) { + len = dev->drv->ops->size(dev->drv); if (len > CD_MAX_SECTORS) { b[6] = (MMC_PROFILE_DVD_ROM >> 8) & 0xff; b[7] = MMC_PROFILE_DVD_ROM & 0xff; @@ -2079,10 +2129,16 @@ scsi_cdrom_command(void *p, uint8_t *cdb) cdbufferb[5] = (0 << 5) | (0 << 4) | (4 << 0); /* not damaged, primary copy, data track */ cdbufferb[6] = (0 << 7) | (0 << 6) | (0 << 5) | (0 << 6) | (1 << 0); /* not reserved track, not blank, not packet writing, not fixed packet, data mode 1 */ cdbufferb[7] = (0 << 1) | (0 << 0); /* last recorded address not valid, next recordable address not valid */ - cdbufferb[24] = (dev->drv->handler->size(dev->id) >> 24) & 0xff; /* track size */ - cdbufferb[25] = (dev->drv->handler->size(dev->id) >> 16) & 0xff; /* track size */ - cdbufferb[26] = (dev->drv->handler->size(dev->id) >> 8) & 0xff; /* track size */ - cdbufferb[27] = dev->drv->handler->size(dev->id) & 0xff; /* track size */ + if (dev->drv->ops && dev->drv->ops->size) { + cdbufferb[24] = (dev->drv->ops->size(dev->drv) >> 24) & 0xff; /* track size */ + cdbufferb[25] = (dev->drv->ops->size(dev->drv) >> 16) & 0xff; /* track size */ + cdbufferb[26] = (dev->drv->ops->size(dev->drv) >> 8) & 0xff; /* track size */ + cdbufferb[27] = dev->drv->ops->size(dev->drv) & 0xff; /* track size */ + } else { + scsi_cdrom_not_ready(dev); + scsi_cdrom_buf_free(dev); + return; + } if (len > max_len) { len = max_len; @@ -2131,8 +2187,8 @@ scsi_cdrom_command(void *p, uint8_t *cdb) break; } - if (dev->drv->handler->playaudio) - ret = dev->drv->handler->playaudio(dev->id, pos, len, msf); + if (dev->drv->ops && dev->drv->ops->playaudio) + ret = dev->drv->ops->playaudio(dev->drv, pos, len, msf); else ret = 0; @@ -2181,7 +2237,13 @@ scsi_cdrom_command(void *p, uint8_t *cdb) cdbufferb[pos++] = 0; cdbufferb[pos++] = 0; /*Subchannel length*/ cdbufferb[pos++] = cdb[3] & 3; /*Format code*/ if (cdb[3] == 1) { - cdbufferb[1] = dev->drv->handler->getcurrentsubchannel(dev->id, &cdbufferb[5], msf); + if (dev->drv->ops && dev->drv->ops->getcurrentsubchannel) + cdbufferb[1] = dev->drv->ops->getcurrentsubchannel(dev->drv, &cdbufferb[5], msf); + else { + scsi_cdrom_not_ready(dev); + scsi_cdrom_buf_free(dev); + return; + } switch(dev->drv->cd_status) { case CD_STATUS_PLAYING: cdbufferb[1] = 0x11; @@ -2216,7 +2278,13 @@ scsi_cdrom_command(void *p, uint8_t *cdb) scsi_cdrom_buf_alloc(dev, alloc_length); - len = dev->drv->handler->size(dev->id); + if (dev->drv->ops && dev->drv->ops->size) + len = dev->drv->ops->size(dev->drv); + else { + scsi_cdrom_not_ready(dev); + scsi_cdrom_buf_free(dev); + return; + } if ((cdb[7] < 0xc0) && (len <= CD_MAX_SECTORS)) { scsi_cdrom_incompatible_format(dev); @@ -2249,15 +2317,16 @@ scsi_cdrom_command(void *p, uint8_t *cdb) switch(cdb[4] & 3) { case 0: /* Stop the disc. */ - if (dev->drv->handler->stop) - dev->drv->handler->stop(dev->id); + if (dev->drv->ops && dev->drv->ops->stop) + dev->drv->ops->stop(dev->drv); break; case 1: /* Start the disc and read the TOC. */ - dev->drv->handler->medium_changed(dev->id); /* This causes a TOC reload. */ + if (dev->drv->ops && dev->drv->ops->medium_changed) + dev->drv->ops->medium_changed(dev->drv); /* This causes a TOC reload. */ break; case 2: /* Eject the disc if possible. */ - if (dev->drv->handler->stop) - dev->drv->handler->stop(dev->id); + if (dev->drv->ops && dev->drv->ops->stop) + dev->drv->ops->stop(dev->drv); cdrom_eject(dev->id); break; case 3: /* Load the disc (close tray). */ @@ -2371,15 +2440,15 @@ atapi_out: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); if (cdb[8] & 1) { - if (dev->drv->handler->resume) - dev->drv->handler->resume(dev->id); + if (dev->drv->ops && dev->drv->ops->resume) + dev->drv->ops->resume(dev->drv); else { scsi_cdrom_illegal_mode(dev); break; } } else { - if (dev->drv->handler->pause) - dev->drv->handler->pause(dev->id); + if (dev->drv->ops && dev->drv->ops->pause) + dev->drv->ops->pause(dev->drv); else { scsi_cdrom_illegal_mode(dev); break; @@ -2423,8 +2492,8 @@ atapi_out: case GPCMD_STOP_PLAY_SCAN: scsi_cdrom_set_phase(dev, SCSI_PHASE_STATUS); - if (dev->drv->handler->stop) - dev->drv->handler->stop(dev->id); + if (dev->drv->ops && dev->drv->ops->stop) + dev->drv->ops->stop(dev->drv); else { scsi_cdrom_illegal_mode(dev); break; @@ -2630,7 +2699,9 @@ scsi_cdrom_irq_raise(scsi_cdrom_t *dev) static int scsi_cdrom_read_from_dma(scsi_cdrom_t *dev) { +#ifdef ENABLE_SCSI_CDROM_LOG int32_t *BufLen = &scsi_devices[dev->drv->scsi_device_id].buffer_length; +#endif int ret = 0; if (dev->drv->bus_type == CDROM_BUS_SCSI) @@ -2700,7 +2771,9 @@ scsi_cdrom_write_to_scsi_dma(uint8_t scsi_id) static int scsi_cdrom_write_to_dma(scsi_cdrom_t *dev) { +#ifdef ENABLE_SCSI_CDROM_LOG int32_t *BufLen = &scsi_devices[dev->drv->scsi_device_id].buffer_length; +#endif int ret = 0; if (dev->drv->bus_type == CDROM_BUS_SCSI) { @@ -2930,8 +3003,8 @@ scsi_cdrom_stop(void *p) { scsi_cdrom_t *dev = (scsi_cdrom_t *) p; - if (dev->drv->handler->stop) - dev->drv->handler->stop(dev->id); + if (dev->drv->ops && dev->drv->ops->stop) + dev->drv->ops->stop(dev->drv); } @@ -2993,6 +3066,7 @@ static void scsi_cdrom_identify(void *p, int ide_has_dma) { ide_t *ide = (ide_t *) p; +#if 0 scsi_cdrom_t *dev; char device_identify[9] = { '8', '6', 'B', '_', 'C', 'D', '0', '0', 0 }; @@ -3000,6 +3074,7 @@ scsi_cdrom_identify(void *p, int ide_has_dma) device_identify[7] = dev->id + 0x30; scsi_cdrom_log("ATAPI Identify: %s\n", device_identify); +#endif ide->buffer[0] = 0x8000 | (5<<8) | 0x80 | (2<<5); /* ATAPI device, CD-ROM drive, removable media, accelerated DRQ */ ide_padstr((char *) (ide->buffer + 10), "", 20); /* Serial Number */ @@ -3023,7 +3098,7 @@ scsi_cdrom_identify(void *p, int ide_has_dma) void scsi_cdrom_drive_reset(int c) { - cdrom_drive_t *drv = &cdrom_drives[c]; + cdrom_t *drv = &cdrom[c]; scsi_device_t *sd; ide_t *id; @@ -3063,7 +3138,7 @@ scsi_cdrom_drive_reset(int c) sd->read_capacity = scsi_cdrom_read_capacity; sd->type = SCSI_REMOVABLE_CDROM; - scsi_cdrom_log("SCSI CD-ROM drive %i attached to SCSI ID %i\n", c, cdrom_drives[c].scsi_device_id); + scsi_cdrom_log("SCSI CD-ROM drive %i attached to SCSI ID %i\n", c, cdrom[c].scsi_device_id); } else if (drv->bus_type == CDROM_BUS_ATAPI) { /* ATAPI CD-ROM, attach to the IDE bus. */ id = ide_drives[drv->ide_channel]; @@ -3086,6 +3161,6 @@ scsi_cdrom_drive_reset(int c) ide_atapi_attach(id); } - scsi_cdrom_log("ATAPI CD-ROM drive %i attached to IDE channel %i\n", c, cdrom_drives[c].ide_channel); + scsi_cdrom_log("ATAPI CD-ROM drive %i attached to IDE channel %i\n", c, cdrom[c].ide_channel); } } diff --git a/src/scsi/scsi_cdrom.h b/src/scsi/scsi_cdrom.h index a1741ac15..de4e5ff1b 100644 --- a/src/scsi/scsi_cdrom.h +++ b/src/scsi/scsi_cdrom.h @@ -9,7 +9,7 @@ * Implementation of the CD-ROM drive with SCSI(-like) * commands, for both ATAPI and SCSI usage. * - * Version: @(#)scsi_cdrom.h 1.0.0 2018/10/09 + * Version: @(#)scsi_cdrom.h 1.0.1 2018/10/17 * * Author: Miran Grca, * @@ -27,7 +27,7 @@ typedef struct { /* Common block. */ mode_sense_pages_t ms_pages_saved; - cdrom_drive_t *drv; + cdrom_t *drv; uint8_t *buffer, atapi_cdb[16], diff --git a/src/sound/sound.c b/src/sound/sound.c index f797bda96..028992c99 100644 --- a/src/sound/sound.c +++ b/src/sound/sound.c @@ -8,7 +8,7 @@ * * Sound emulation core. * - * Version: @(#)sound.c 1.0.21 2018/10/09 + * Version: @(#)sound.c 1.0.22 2018/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -110,13 +110,11 @@ static const SOUND_CARD sound_cards[] = #ifdef ENABLE_SOUND_LOG int sound_do_log = ENABLE_SOUND_LOG; -#endif static void sound_log(const char *fmt, ...) { -#ifdef ENABLE_SOUND_LOG va_list ap; if (sound_do_log) { @@ -124,8 +122,10 @@ sound_log(const char *fmt, ...) pclog_ex(fmt, ap); va_end(ap); } -#endif } +#else +#define sound_log(fmt, ...) +#endif int sound_card_available(int card) @@ -218,27 +218,27 @@ static void sound_cd_thread(void *param) for (i = 0; i < CDROM_NUM; i++) { has_audio = 0; - if ((cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) || !cdrom_drives[i].handler) + if ((cdrom[i].bus_type == CDROM_BUS_DISABLED) || !cdrom[i].ops) continue; - if (cdrom_drives[i].handler->audio_callback) + if (cdrom[i].ops->audio_callback) { - r = cdrom_drives[i].handler->audio_callback(i, cd_buffer[i], CD_BUFLEN*2); - has_audio = (cdrom_drives[i].bus_type && cdrom_drives[i].sound_on/* && r*/); + r = cdrom[i].ops->audio_callback(&(cdrom[i]), cd_buffer[i], CD_BUFLEN*2); + has_audio = (cdrom[i].bus_type && cdrom[i].sound_on/* && r*/); } else continue; if (soundon && has_audio) { - if (cdrom_drives[i].get_volume) { - audio_vol_l = cdrom_drives[i].get_volume(cdrom_drives[i].p, 0); - audio_vol_r = cdrom_drives[i].get_volume(cdrom_drives[i].p, 1); + if (cdrom[i].get_volume) { + audio_vol_l = cdrom[i].get_volume(cdrom[i].p, 0); + audio_vol_r = cdrom[i].get_volume(cdrom[i].p, 1); } else { audio_vol_l = 255; audio_vol_r = 255; } - if (cdrom_drives[i].get_channel) { - channel_select[0] = cdrom_drives[i].get_channel(cdrom_drives[i].p, 0); - channel_select[1] = cdrom_drives[i].get_channel(cdrom_drives[i].p, 1); + if (cdrom[i].get_channel) { + channel_select[0] = cdrom[i].get_channel(cdrom[i].p, 0); + channel_select[1] = cdrom[i].get_channel(cdrom[i].p, 1); } else { channel_select[0] = 1; channel_select[1] = 2; @@ -365,7 +365,7 @@ void sound_init(void) for (i = 0; i < CDROM_NUM; i++) { - if (cdrom_drives[i].bus_type != CDROM_BUS_DISABLED) + if (cdrom[i].bus_type != CDROM_BUS_DISABLED) { available_cdrom_drives++; } @@ -528,10 +528,10 @@ void sound_cd_thread_reset(void) int available_cdrom_drives = 0; for (i = 0; i < CDROM_NUM; i++) { - if (cdrom_drives[i].handler && cdrom_drives[i].handler->audio_stop) - cdrom_drives[i].handler->audio_stop(i); + if (cdrom[i].ops && cdrom[i].ops->audio_stop) + cdrom[i].ops->audio_stop(&(cdrom[i])); - if (cdrom_drives[i].bus_type != CDROM_BUS_DISABLED) + if (cdrom[i].bus_type != CDROM_BUS_DISABLED) available_cdrom_drives++; } diff --git a/src/win/86Box.rc b/src/win/86Box.rc index 328c574f8..005f264eb 100644 --- a/src/win/86Box.rc +++ b/src/win/86Box.rc @@ -333,13 +333,13 @@ DLG_CFG_VIDEO DIALOG DISCARDABLE 97, 0, 267, 45 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN - LTEXT "Video:",IDT_1707,7,8,55,10 - COMBOBOX IDC_COMBO_VIDEO,71,7,140,120,CBS_DROPDOWNLIST | + LTEXT "Video:",IDT_1707,7,8,48,10 + COMBOBOX IDC_COMBO_VIDEO,64,7,155,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_VID,214,7,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_VID,222,7,38,12 CONTROL "Voodoo Graphics",IDC_CHECK_VOODOO,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,7,27,199,10 - PUSHBUTTON "Configure",IDC_BUTTON_VOODOO,214,26,46,12 + PUSHBUTTON "Configure",IDC_BUTTON_VOODOO,222,26,38,12 END DLG_CFG_INPUT DIALOG DISCARDABLE 97, 0, 267, 65 @@ -438,49 +438,49 @@ DLG_CFG_PERIPHERALS DIALOG DISCARDABLE 97, 0, 267, 200 STYLE DS_CONTROL | WS_CHILD FONT 9, "Segoe UI" BEGIN - LTEXT "SCSI Controller:",IDT_1716,7,8,59,10 - COMBOBOX IDC_COMBO_SCSI,71,7,140,120,CBS_DROPDOWNLIST | + LTEXT "SCSI Controller:",IDT_1716,7,8,48,10 + COMBOBOX IDC_COMBO_SCSI,64,7,155,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI,214,7,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_SCSI,222,7,38,12 - LTEXT "HD Controller:",IDT_1717,7,26,61,10 - COMBOBOX IDC_COMBO_HDC,71,25,140,120,CBS_DROPDOWNLIST | + LTEXT "HD Controller:",IDT_1717,7,26,48,10 + COMBOBOX IDC_COMBO_HDC,64,25,155,120,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_HDC,214,25,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_HDC,222,25,38,12 CONTROL "Tertiary IDE Controller",IDC_CHECK_IDE_TER,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,7,44,199,10 - PUSHBUTTON "Configure",IDC_BUTTON_IDE_TER,214,43,46,12 + PUSHBUTTON "Configure",IDC_BUTTON_IDE_TER,222,43,38,12 CONTROL "Quaternary IDE Controller",IDC_CHECK_IDE_QUA,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,7,62,199,10 - PUSHBUTTON "Configure",IDC_BUTTON_IDE_QUA,214,61,46,12 + PUSHBUTTON "Configure",IDC_BUTTON_IDE_QUA,222,61,38,12 CONTROL "ISABugger device",IDC_CHECK_BUGGER,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,7,80,94,10 - LTEXT "ISA RTC",IDT_1767,7,99,61,10 - COMBOBOX IDC_COMBO_ISARTC,71,98,140,120, + LTEXT "ISA RTC",IDT_1767,7,99,48,10 + COMBOBOX IDC_COMBO_ISARTC,64,98,155,120, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_ISARTC,214,98,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_ISARTC,222,98,38,12 GROUPBOX "ISA Memory Expansion",IDC_GROUP_ISAMEM,7,118,255,70 LTEXT "#1:",IDT_1763,12,130,21,10 - COMBOBOX IDC_COMBO_ISAMEM_1,25,129,180,120, + COMBOBOX IDC_COMBO_ISAMEM_1,25,129,190,120, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_1,209,129,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_1,217,129,38,12 LTEXT "#2:",IDT_1764,12,144,21,10 - COMBOBOX IDC_COMBO_ISAMEM_2,25,143,180,120, + COMBOBOX IDC_COMBO_ISAMEM_2,25,143,190,120, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_2,209,143,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_2,217,143,38,12 LTEXT "#3:",IDT_1765,12,158,21,10 - COMBOBOX IDC_COMBO_ISAMEM_3,25,157,180,120, + COMBOBOX IDC_COMBO_ISAMEM_3,25,157,190,120, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_3,209,157,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_3,217,157,38,12 LTEXT "#4:",IDT_1766,12,172,21,10 - COMBOBOX IDC_COMBO_ISAMEM_4,25,171,180,120, + COMBOBOX IDC_COMBO_ISAMEM_4,25,171,190,120, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_4,209,171,46,12 + PUSHBUTTON "Configure",IDC_CONFIGURE_ISAMEM_4,217,171,38,12 END DLG_CFG_HARD_DISKS DIALOG DISCARDABLE 97, 0, 267, 154 diff --git a/src/win/Makefile.mingw b/src/win/Makefile.mingw index 10a7d238a..c4a24e07e 100644 --- a/src/win/Makefile.mingw +++ b/src/win/Makefile.mingw @@ -8,7 +8,7 @@ # # Makefile for Win32 (MinGW32) environment. # -# Version: @(#)Makefile.mingw 1.0.129 2018/10/12 +# Version: @(#)Makefile.mingw 1.0.130 2018/10/17 # # Authors: Miran Grca, # Fred N. van Kempen, @@ -471,7 +471,7 @@ HDDOBJ := hdd.o \ hdc_xtide.o hdc_ide.o CDROMOBJ := cdrom.o \ - cdrom_dosbox.o cdrom_image.o cdrom_null.o + cdrom_dosbox.o cdrom_image.o ZIPOBJ := zip.o diff --git a/src/win/win_cdrom.c b/src/win/win_cdrom.c index cf54de328..b349cd8d6 100644 --- a/src/win/win_cdrom.c +++ b/src/win/win_cdrom.c @@ -8,7 +8,7 @@ * * Handle the platform-side of CDROM drives. * - * Version: @(#)win_cdrom.c 1.0.10 2018/10/09 + * Version: @(#)win_cdrom.c 1.0.10 2018/10/17 * * Authors: Sarah Walker, * Miran Grca, @@ -32,8 +32,6 @@ #include "../scsi/scsi_device.h" #include "../cdrom/cdrom.h" #include "../disk/zip.h" -#include "../cdrom/cdrom_image.h" -#include "../cdrom/cdrom_null.h" #include "../scsi/scsi_disk.h" #include "../plat.h" #include "../ui.h" @@ -41,86 +39,24 @@ void -cdrom_eject(uint8_t id) +plat_cdrom_ui_update(uint8_t id, uint8_t reload) { - cdrom_drive_t *drv = &cdrom_drives[id]; - cdrom_image_t *img = &cdrom_image[id]; + cdrom_t *drv = &cdrom[id]; if (drv->host_drive == 0) { - /* Switch from empty to empty. Do nothing. */ - return; + ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_CHECKED); + drv->host_drive = 0; + ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_UNCHECKED); + ui_sb_update_icon_state(SB_CDROM|id, 1); + } else { + ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_UNCHECKED); + drv->host_drive = 200; + ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_CHECKED); + ui_sb_update_icon_state(SB_CDROM|id, 0); } - if (img->prev_image_path) { - free(img->prev_image_path); - img->prev_image_path = NULL; - } - - if (drv->host_drive == 200) { - img->prev_image_path = (wchar_t *) malloc(1024); - wcscpy(img->prev_image_path, img->image_path); - } - drv->prev_host_drive = drv->host_drive; - drv->handler->exit(id); - cdrom_close_handler(id); - memset(img->image_path, 0, 2048); - cdrom_null_open(id); - if (drv->insert) { - /* Signal disc change to the emulated machine. */ - drv->insert(drv->p); - } - - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_UNCHECKED); - drv->host_drive=0; - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_CHECKED); - ui_sb_update_icon_state(SB_CDROM|id, 1); - ui_sb_enable_menu_item(SB_CDROM|id, IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_ENABLED); + ui_sb_enable_menu_item(SB_CDROM|id, IDM_CDROM_RELOAD | id, MF_BYCOMMAND | (reload ? MF_GRAYED : MF_ENABLED)); ui_sb_update_tip(SB_CDROM|id); - - config_save(); -} - - -void -cdrom_reload(uint8_t id) -{ - cdrom_drive_t *drv = &cdrom_drives[id]; - cdrom_image_t *img = &cdrom_image[id]; - - if ((drv->host_drive == drv->prev_host_drive) || !drv->prev_host_drive || drv->host_drive) { - /* Switch from empty to empty. Do nothing. */ - return; - } - - cdrom_close_handler(id); - memset(img->image_path, 0, 2048); - - if (drv->prev_host_drive == 200) { - wcscpy(img->image_path, img->prev_image_path); - free(img->prev_image_path); - img->prev_image_path = NULL; - image_open(id, img->image_path); - if (drv->insert) { - /* Signal disc change to the emulated machine. */ - drv->insert(drv->p); - } - if (wcslen(img->image_path) == 0) { - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_CHECKED); - drv->host_drive = 0; - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_UNCHECKED); - ui_sb_update_icon_state(SB_CDROM|id, 1); - } else { - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_EMPTY | id, MF_UNCHECKED); - drv->host_drive = 200; - ui_sb_check_menu_item(SB_CDROM|id, IDM_CDROM_IMAGE | id, MF_CHECKED); - ui_sb_update_icon_state(SB_CDROM|id, 0); - } - } - - ui_sb_enable_menu_item(SB_CDROM|id, IDM_CDROM_RELOAD | id, MF_BYCOMMAND | MF_GRAYED); - ui_sb_update_tip(SB_CDROM|id); - - config_save(); } diff --git a/src/win/win_settings.c b/src/win/win_settings.c index 8d2bd3cd3..fb9995a05 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -8,7 +8,7 @@ * * Windows 86Box Settings dialog handler. * - * Version: @(#)win_settings.c 1.0.64 2018/10/08 + * Version: @(#)win_settings.c 1.0.65 2018/10/17 * * Authors: Miran Grca, * David Hrdlička, @@ -120,7 +120,7 @@ static int temp_fdd_turbo[FDD_NUM]; static int temp_fdd_check_bpb[FDD_NUM]; /* Other removable devices category */ -static cdrom_drive_t temp_cdrom_drives[CDROM_NUM]; +static cdrom_t temp_cdrom[CDROM_NUM]; static zip_drive_t temp_zip_drives[ZIP_NUM]; static HWND hwndParentDialog, hwndChildDialog; @@ -281,12 +281,12 @@ win_settings_init(void) } /* Other removable devices category */ - memcpy(temp_cdrom_drives, cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t)); + memcpy(temp_cdrom, cdrom, CDROM_NUM * sizeof(cdrom_t)); for (i = 0; i < CDROM_NUM; i++) { - if (cdrom_drives[i].bus_type == CDROM_BUS_ATAPI) - ide_tracking |= (2 << (cdrom_drives[i].ide_channel << 3)); - else if (cdrom_drives[i].bus_type == CDROM_BUS_SCSI) - scsi_tracking[cdrom_drives[i].scsi_device_id >> 3] |= (1 << ((cdrom_drives[i].scsi_device_id & 0x07) << 3)); + if (cdrom[i].bus_type == CDROM_BUS_ATAPI) + ide_tracking |= (2 << (cdrom[i].ide_channel << 3)); + else if (cdrom[i].bus_type == CDROM_BUS_SCSI) + scsi_tracking[cdrom[i].scsi_device_id >> 3] |= (1 << ((cdrom[i].scsi_device_id & 0x07) << 3)); } memcpy(temp_zip_drives, zip_drives, ZIP_NUM * sizeof(zip_drive_t)); for (i = 0; i < ZIP_NUM; i++) { @@ -372,7 +372,7 @@ win_settings_changed(void) } /* Other removable devices category */ - i = i || memcmp(cdrom_drives, temp_cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t)); + i = i || memcmp(cdrom, temp_cdrom, CDROM_NUM * sizeof(cdrom_t)); i = i || memcmp(zip_drives, temp_zip_drives, ZIP_NUM * sizeof(zip_drive_t)); i = i || !!temp_deviceconfig; @@ -482,7 +482,7 @@ win_settings_save(void) } /* Removable devices category */ - memcpy(cdrom_drives, temp_cdrom_drives, CDROM_NUM * sizeof(cdrom_drive_t)); + memcpy(cdrom, temp_cdrom, CDROM_NUM * sizeof(cdrom_t)); memcpy(zip_drives, temp_zip_drives, ZIP_NUM * sizeof(zip_drive_t)); /* Mark configuration as changed. */ @@ -3435,22 +3435,22 @@ win_settings_cdrom_drives_recalc_list(HWND hwndList) lvI.stateMask = lvI.iSubItem = lvI.state = 0; for (i = 0; i < 4; i++) { - fsid = combo_id_to_format_string_id(temp_cdrom_drives[i].bus_type); + fsid = combo_id_to_format_string_id(temp_cdrom[i].bus_type); lvI.iSubItem = 0; - switch (temp_cdrom_drives[i].bus_type) { + switch (temp_cdrom[i].bus_type) { case CDROM_BUS_DISABLED: default: lvI.pszText = plat_get_string(fsid); lvI.iImage = 0; break; case CDROM_BUS_ATAPI: - wsprintf(szText, plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); + wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].ide_channel >> 1, temp_cdrom[i].ide_channel & 1); lvI.pszText = szText; lvI.iImage = 1; break; case CDROM_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_cdrom_drives[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].scsi_device_id); lvI.pszText = szText; lvI.iImage = 1; break; @@ -3462,10 +3462,10 @@ win_settings_cdrom_drives_recalc_list(HWND hwndList) return FALSE; lvI.iSubItem = 1; - if (temp_cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) + if (temp_cdrom[i].bus_type == CDROM_BUS_DISABLED) lvI.pszText = plat_get_string(IDS_2112); else { - wsprintf(szText, L"%ix", temp_cdrom_drives[i].speed); + wsprintf(szText, L"%ix", temp_cdrom[i].speed); lvI.pszText = szText; } lvI.iItem = i; @@ -3698,21 +3698,21 @@ win_settings_cdrom_drives_update_item(HWND hwndList, int i) lvI.iSubItem = 0; lvI.iItem = i; - fsid = combo_id_to_format_string_id(temp_cdrom_drives[i].bus_type); + fsid = combo_id_to_format_string_id(temp_cdrom[i].bus_type); - switch (temp_cdrom_drives[i].bus_type) { + switch (temp_cdrom[i].bus_type) { case CDROM_BUS_DISABLED: default: lvI.pszText = plat_get_string(fsid); lvI.iImage = 0; break; case CDROM_BUS_ATAPI: - wsprintf(szText, plat_get_string(fsid), temp_cdrom_drives[i].ide_channel >> 1, temp_cdrom_drives[i].ide_channel & 1); + wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].ide_channel >> 1, temp_cdrom[i].ide_channel & 1); lvI.pszText = szText; lvI.iImage = 1; break; case CDROM_BUS_SCSI: - wsprintf(szText, plat_get_string(fsid), temp_cdrom_drives[i].scsi_device_id); + wsprintf(szText, plat_get_string(fsid), temp_cdrom[i].scsi_device_id); lvI.pszText = szText; lvI.iImage = 1; break; @@ -3722,10 +3722,10 @@ win_settings_cdrom_drives_update_item(HWND hwndList, int i) return; lvI.iSubItem = 1; - if (temp_cdrom_drives[i].bus_type == CDROM_BUS_DISABLED) + if (temp_cdrom[i].bus_type == CDROM_BUS_DISABLED) lvI.pszText = plat_get_string(IDS_2112); else { - wsprintf(szText, L"%ix", temp_cdrom_drives[i].speed); + wsprintf(szText, L"%ix", temp_cdrom[i].speed); lvI.pszText = szText; } lvI.iItem = i; @@ -3824,7 +3824,7 @@ static void cdrom_recalc_location_controls(HWND hdlg, int assign_id) int i = 0; HWND h; - int bus = temp_cdrom_drives[lv1_current_sel].bus_type; + int bus = temp_cdrom[lv1_current_sel].bus_type; for (i = IDT_1741; i < (IDT_1742 + 1); i++) { h = GetDlgItem(hdlg, i); @@ -3847,7 +3847,7 @@ static void cdrom_recalc_location_controls(HWND hdlg, int assign_id) } else { ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[lv1_current_sel].speed - 1, 0); + SendMessage(h, CB_SETCURSEL, temp_cdrom[lv1_current_sel].speed - 1, 0); } h = GetDlgItem(hdlg, IDT_1758); @@ -3866,12 +3866,12 @@ static void cdrom_recalc_location_controls(HWND hdlg, int assign_id) EnableWindow(h, TRUE); if (assign_id) - temp_cdrom_drives[lv1_current_sel].ide_channel = next_free_ide_channel(); + temp_cdrom[lv1_current_sel].ide_channel = next_free_ide_channel(); h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[lv1_current_sel].ide_channel, 0); + SendMessage(h, CB_SETCURSEL, temp_cdrom[lv1_current_sel].ide_channel, 0); break; case CDROM_BUS_SCSI: /* SCSI */ h = GetDlgItem(hdlg, IDT_1741); @@ -3879,12 +3879,12 @@ static void cdrom_recalc_location_controls(HWND hdlg, int assign_id) EnableWindow(h, TRUE); if (assign_id) - next_free_scsi_id((uint8_t *) &temp_cdrom_drives[lv1_current_sel].scsi_device_id); + next_free_scsi_id((uint8_t *) &temp_cdrom[lv1_current_sel].scsi_device_id); h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); ShowWindow(h, SW_SHOW); EnableWindow(h, TRUE); - SendMessage(h, CB_SETCURSEL, temp_cdrom_drives[lv1_current_sel].scsi_device_id, 0); + SendMessage(h, CB_SETCURSEL, temp_cdrom[lv1_current_sel].scsi_device_id, 0); break; } } @@ -3987,20 +3987,20 @@ zip_recalc_location_controls(HWND hdlg, int assign_id) static void cdrom_track(uint8_t id) { - if (temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI) - ide_tracking |= (2 << (temp_cdrom_drives[id].ide_channel << 3)); - else if (temp_cdrom_drives[id].bus_type == CDROM_BUS_SCSI) - scsi_tracking[temp_cdrom_drives[id].scsi_device_id >> 3] |= (1 << (temp_cdrom_drives[id].scsi_device_id & 0x07)); + if (temp_cdrom[id].bus_type == CDROM_BUS_ATAPI) + ide_tracking |= (2 << (temp_cdrom[id].ide_channel << 3)); + else if (temp_cdrom[id].bus_type == CDROM_BUS_SCSI) + scsi_tracking[temp_cdrom[id].scsi_device_id >> 3] |= (1 << (temp_cdrom[id].scsi_device_id & 0x07)); } static void cdrom_untrack(uint8_t id) { - if (temp_cdrom_drives[id].bus_type == CDROM_BUS_ATAPI) - ide_tracking &= ~(2 << (temp_cdrom_drives[id].ide_channel << 3)); - else if (temp_cdrom_drives[id].bus_type == CDROM_BUS_SCSI) - scsi_tracking[temp_cdrom_drives[id].scsi_device_id >> 3] &= ~(1 << (temp_cdrom_drives[id].scsi_device_id & 0x07)); + if (temp_cdrom[id].bus_type == CDROM_BUS_ATAPI) + ide_tracking &= ~(2 << (temp_cdrom[id].ide_channel << 3)); + else if (temp_cdrom[id].bus_type == CDROM_BUS_SCSI) + scsi_tracking[temp_cdrom[id].scsi_device_id >> 3] &= ~(1 << (temp_cdrom[id].scsi_device_id & 0x07)); } @@ -4157,7 +4157,7 @@ win_settings_other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); - switch (temp_cdrom_drives[lv1_current_sel].bus_type) { + switch (temp_cdrom[lv1_current_sel].bus_type) { case CDROM_BUS_DISABLED: default: b = 0; @@ -4224,7 +4224,7 @@ win_settings_other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam h = GetDlgItem(hdlg, IDC_COMBO_CD_BUS); - switch (temp_cdrom_drives[lv1_current_sel].bus_type) { + switch (temp_cdrom[lv1_current_sel].bus_type) { case CDROM_BUS_DISABLED: default: b = 0; @@ -4298,13 +4298,13 @@ win_settings_other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam b2 = CDROM_BUS_SCSI; break; } - if (b2 == temp_cdrom_drives[lv1_current_sel].bus_type) + if (b2 == temp_cdrom[lv1_current_sel].bus_type) break; cdrom_untrack(lv1_current_sel); - assign = (temp_cdrom_drives[lv1_current_sel].bus_type == b2) ? 0 : 1; - if (temp_cdrom_drives[lv1_current_sel].bus_type == CDROM_BUS_DISABLED) - temp_cdrom_drives[lv1_current_sel].speed = 8; - temp_cdrom_drives[lv1_current_sel].bus_type = b2; + assign = (temp_cdrom[lv1_current_sel].bus_type == b2) ? 0 : 1; + if (temp_cdrom[lv1_current_sel].bus_type == CDROM_BUS_DISABLED) + temp_cdrom[lv1_current_sel].speed = 8; + temp_cdrom[lv1_current_sel].bus_type = b2; cdrom_recalc_location_controls(hdlg, assign); cdrom_track(lv1_current_sel); h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); @@ -4314,7 +4314,7 @@ win_settings_other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam case IDC_COMBO_CD_ID: h = GetDlgItem(hdlg, IDC_COMBO_CD_ID); cdrom_untrack(lv1_current_sel); - temp_cdrom_drives[lv1_current_sel].scsi_device_id = SendMessage(h, CB_GETCURSEL, 0, 0); + temp_cdrom[lv1_current_sel].scsi_device_id = SendMessage(h, CB_GETCURSEL, 0, 0); cdrom_track(lv1_current_sel); h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); win_settings_cdrom_drives_update_item(h, lv1_current_sel); @@ -4323,7 +4323,7 @@ win_settings_other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam case IDC_COMBO_CD_CHANNEL_IDE: h = GetDlgItem(hdlg, IDC_COMBO_CD_CHANNEL_IDE); cdrom_untrack(lv1_current_sel); - temp_cdrom_drives[lv1_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0); + temp_cdrom[lv1_current_sel].ide_channel = SendMessage(h, CB_GETCURSEL, 0, 0); cdrom_track(lv1_current_sel); h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); win_settings_cdrom_drives_update_item(h, lv1_current_sel); @@ -4331,7 +4331,7 @@ win_settings_other_removable_devices_proc(HWND hdlg, UINT message, WPARAM wParam case IDC_COMBO_CD_SPEED: h = GetDlgItem(hdlg, IDC_COMBO_CD_SPEED); - temp_cdrom_drives[lv1_current_sel].speed = SendMessage(h, CB_GETCURSEL, 0, 0) + 1; + temp_cdrom[lv1_current_sel].speed = SendMessage(h, CB_GETCURSEL, 0, 0) + 1; h = GetDlgItem(hdlg, IDC_LIST_CDROM_DRIVES); win_settings_cdrom_drives_update_item(h, lv1_current_sel); break; diff --git a/src/win/win_stbar.c b/src/win/win_stbar.c index ca01be9e7..dd3fb49b0 100644 --- a/src/win/win_stbar.c +++ b/src/win/win_stbar.c @@ -8,7 +8,7 @@ * * Implement the application's Status Bar. * - * Version: @(#)win_stbar.c 1.0.20 2018/10/09 + * Version: @(#)win_stbar.c 1.0.21 2018/10/17 * * Authors: Miran Grca, * Fred N. van Kempen, @@ -41,7 +41,6 @@ #include "../cdrom/cdrom.h" #include "../disk/zip.h" #include "../cdrom/cdrom_image.h" -#include "../cdrom/cdrom_null.h" #include "../scsi/scsi_disk.h" #include "../network/network.h" #include "../video/video.h" @@ -153,13 +152,13 @@ StatusBarCreateCdromSubmenu(HMENU m, int id) AppendMenu(m, MF_STRING, IDM_CDROM_IMAGE | id, plat_get_string(IDS_2089)); - if (! cdrom_drives[id].sound_on) + if (! cdrom[id].sound_on) CheckMenuItem(m, IDM_CDROM_MUTE | id, MF_CHECKED); - if (cdrom_drives[id].host_drive == 200) + if (cdrom[id].host_drive == 200) CheckMenuItem(m, IDM_CDROM_IMAGE | id, MF_CHECKED); else { - cdrom_drives[id].host_drive = 0; + cdrom[id].host_drive = 0; CheckMenuItem(m, IDM_CDROM_EMPTY | id, MF_CHECKED); } } @@ -269,16 +268,16 @@ StatusBarCreateCdromTip(int part) WCHAR *szText; int id; int drive = sb_part_meanings[part] & 0xf; - int bus = cdrom_drives[drive].bus_type; + int bus = cdrom[drive].bus_type; id = IDS_5377 + (bus - 1); szText = plat_get_string(id); - if (cdrom_drives[drive].host_drive == 200) { - if (wcslen(cdrom_image[drive].image_path) == 0) + if (cdrom[drive].host_drive == 200) { + if (wcslen(cdrom[drive].image_path) == 0) _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, plat_get_string(IDS_2057)); else - _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, cdrom_image[drive].image_path); + _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, cdrom[drive].image_path); } else _swprintf(tempTip, plat_get_string(IDS_5120), drive+1, szText, plat_get_string(IDS_2057)); @@ -518,14 +517,14 @@ ui_sb_update_panes(void) } for (i=0; iexit(id); - cdrom_close_handler(id); - memset(cdrom_image[id].image_path, 0, 2048); - image_open(id, temp_path); + if (!cdrom[id].prev_image_path) + cdrom[id].prev_image_path = (wchar_t *) malloc(1024); + wcscpy(cdrom[id].prev_image_path, cdrom[id].image_path); + if (cdrom[id].ops && cdrom[id].ops->exit) + cdrom[id].ops->exit(&(cdrom[id])); + cdrom[id].ops = NULL; + memset(cdrom[id].image_path, 0, 2048); + cdrom_image_open(&(cdrom[id]), temp_path); /* Signal media change to the emulated machine. */ - if (cdrom_drives[id].insert) - cdrom_drives[id].insert(cdrom_drives[id].p); + if (cdrom[id].insert) + cdrom[id].insert(cdrom[id].p); CheckMenuItem(sb_menu_handles[part], IDM_CDROM_EMPTY | id, MF_UNCHECKED); - cdrom_drives[id].host_drive = (wcslen(cdrom_image[id].image_path) == 0) ? 0 : 200; - if (cdrom_drives[id].host_drive == 200) { + cdrom[id].host_drive = (wcslen(cdrom[id].image_path) == 0) ? 0 : 200; + if (cdrom[id].host_drive == 200) { CheckMenuItem(sb_menu_handles[part], IDM_CDROM_IMAGE | id, MF_CHECKED); ui_sb_update_icon_state(SB_CDROM | id, 0); } else {